1212import android .view .WindowManager ;
1313import android .widget .Toast ;
1414
15+ import androidx .recyclerview .widget .RecyclerView ;
16+
1517import com .fox2code .mmm .ActionButtonType ;
1618import com .fox2code .mmm .BuildConfig ;
1719import com .fox2code .mmm .Constants ;
@@ -39,6 +41,7 @@ public class InstallerActivity extends CompatActivity {
3941 public InstallerTerminal installerTerminal ;
4042 private File moduleCache ;
4143 private File toDelete ;
44+ private boolean textWrap ;
4245
4346 @ Override
4447 protected void onCreate (Bundle savedInstanceState ) {
@@ -53,6 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
5356 final String name ;
5457 final boolean noPatch ;
5558 final boolean noExtensions ;
59+ final boolean rootless ;
5660 // Should we allow 3rd part app to install modules?
5761 if (Constants .INTENT_INSTALL_INTERNAL .equals (intent .getAction ())) {
5862 if (!MainApplication .checkSecret (intent )) {
@@ -65,6 +69,8 @@ protected void onCreate(Bundle savedInstanceState) {
6569 noPatch = intent .getBooleanExtra (Constants .EXTRA_INSTALL_NO_PATCH , false );
6670 noExtensions = intent .getBooleanExtra (// Allow intent to disable extensions
6771 Constants .EXTRA_INSTALL_NO_EXTENSIONS , false );
72+ rootless = intent .getBooleanExtra (// For debug only
73+ Constants .EXTRA_INSTALL_TEST_ROOTLESS , false );
6874 } else {
6975 Toast .makeText (this , "Unknown intent!" , Toast .LENGTH_SHORT ).show ();
7076 this .forceBackPressed ();
@@ -74,7 +80,9 @@ protected void onCreate(Bundle savedInstanceState) {
7480 boolean urlMode = target .startsWith ("http://" ) || target .startsWith ("https://" );
7581 getWindow ().addFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
7682 setTitle (name );
77- setContentView (R .layout .installer );
83+ setContentView ((this .textWrap =
84+ MainApplication .isTextWrapEnabled ()) ?
85+ R .layout .installer_wrap :R .layout .installer );
7886 int background ;
7987 int foreground ;
8088 if (MainApplication .getINSTANCE ().isLightTheme () &&
@@ -85,11 +93,13 @@ protected void onCreate(Bundle savedInstanceState) {
8593 background = Color .BLACK ;
8694 foreground = Color .WHITE ;
8795 }
88- findViewById (R .id .install_horizontal_scroller )
89- . setBackground ( new ColorDrawable ( background )) ;
96+ View horizontalScroller = findViewById (R .id .install_horizontal_scroller );
97+ RecyclerView installTerminal ;
9098 this .progressIndicator = findViewById (R .id .progress_bar );
9199 this .installerTerminal = new InstallerTerminal (
92- findViewById (R .id .install_terminal ), foreground );
100+ installTerminal = findViewById (R .id .install_terminal ), foreground );
101+ (horizontalScroller != null ? horizontalScroller : installTerminal )
102+ .setBackground (new ColorDrawable (background ));
93103 this .progressIndicator .setVisibility (View .GONE );
94104 this .progressIndicator .setIndeterminate (true );
95105 if (urlMode ) {
@@ -134,7 +144,7 @@ protected void onCreate(Bundle savedInstanceState) {
134144 this .runOnUiThread (() -> {
135145 this .installerTerminal .addLine ("- Installing " + name );
136146 });
137- this .doInstall (moduleCache , noExtensions );
147+ this .doInstall (moduleCache , noExtensions , rootless );
138148 } catch (IOException e ) {
139149 Log .e (TAG , "Failed to download module zip" , e );
140150 this .setInstallStateFinished (false ,
@@ -144,19 +154,32 @@ protected void onCreate(Bundle savedInstanceState) {
144154 } else {
145155 this .installerTerminal .addLine ("- Installing " + name );
146156 new Thread (() -> this .doInstall (
147- this .toDelete = new File (target ), noExtensions ),
157+ this .toDelete = new File (target ), noExtensions , rootless ),
148158 "Install Thread" ).start ();
149159 }
150160 }
151161
152- private void doInstall (File file ,boolean noExtensions ) {
162+ private void doInstall (File file ,boolean noExtensions , boolean rootless ) {
153163 Log .i (TAG , "Installing: " + moduleCache .getName ());
154164 InstallerController installerController = new InstallerController (
155165 this .progressIndicator , this .installerTerminal ,
156166 file .getAbsoluteFile (), noExtensions );
157167 InstallerMonitor installerMonitor ;
158168 Shell .Job installJob ;
159- if (MainApplication .isUsingMagiskCommand () || noExtensions ) {
169+ if (rootless ) { // rootless is only used for debugging
170+ File installScript = this .extractInstallScript ("module_installer_test.sh" );
171+ if (installScript == null ) {
172+ this .setInstallStateFinished (false ,
173+ "! Failed to extract test install script" , "" );
174+ return ;
175+ }
176+ installerMonitor = new InstallerMonitor (installScript );
177+ installJob = Shell .sh ("export MMM_EXT_SUPPORT=1" ,
178+ "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
179+ "sh \" " + installScript .getAbsolutePath () + "\" " +
180+ " /dev/null 1 \" " + file .getAbsolutePath () + "\" " )
181+ .to (installerController , installerMonitor );
182+ } else if (MainApplication .isUsingMagiskCommand () || noExtensions ) {
160183 installerMonitor = new InstallerMonitor (new File (InstallerInitializer
161184 .peekMagiskPath ().equals ("/sbin" ) ? "/sbin/magisk" : "/system/bin/magisk" ));
162185 if (noExtensions ) {
@@ -170,12 +193,13 @@ private void doInstall(File file,boolean noExtensions) {
170193 "en-US" : Resources .getSystem ()
171194 .getConfiguration ().locale .toLanguageTag ()),
172195 "export MMM_APP_VERSION=" + BuildConfig .VERSION_NAME ,
196+ "export MMM_TEXT_WRAP=" + (this .textWrap ? "1" : "0" ),
173197 "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
174198 "magisk --install-module \" " + file .getAbsolutePath () + "\" " )
175199 .to (installerController , installerMonitor );
176200 }
177201 } else {
178- File installScript = this .extractCompatScript ( );
202+ File installScript = this .extractInstallScript ( "module_installer_compat.sh" );
179203 if (installScript == null ) {
180204 this .setInstallStateFinished (false ,
181205 "! Failed to extract module install script" , "" );
@@ -187,6 +211,7 @@ private void doInstall(File file,boolean noExtensions) {
187211 "en-US" : Resources .getSystem ()
188212 .getConfiguration ().locale .toLanguageTag ()),
189213 "export MMM_APP_VERSION=" + BuildConfig .VERSION_NAME ,
214+ "export MMM_TEXT_WRAP=" + (this .textWrap ? "1" : "0" ),
190215 "cd \" " + this .moduleCache .getAbsolutePath () + "\" " ,
191216 "sh \" " + installScript .getAbsolutePath () + "\" " +
192217 " /dev/null 1 \" " + file .getAbsolutePath () + "\" " )
@@ -370,16 +395,16 @@ private String doCleanUp() {
370395
371396 private static boolean didExtract = false ;
372397
373- private File extractCompatScript ( ) {
374- File compatInstallScript = new File (this .moduleCache , "module_installer_compat.sh" );
398+ private File extractInstallScript ( String script ) {
399+ File compatInstallScript = new File (this .moduleCache , script );
375400 if (!compatInstallScript .exists () || compatInstallScript .length () == 0 || !didExtract ) {
376401 try {
377402 Files .write (compatInstallScript , Files .readAllBytes (
378- this .getAssets ().open ("module_installer_compat.sh" )));
403+ this .getAssets ().open (script )));
379404 didExtract = true ;
380405 } catch (IOException e ) {
381406 compatInstallScript .delete ();
382- Log .e (TAG , "Failed to extract module_installer_compat.sh" , e );
407+ Log .e (TAG , "Failed to extract " + script , e );
383408 return null ;
384409 }
385410 }
0 commit comments