Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 1bbb169

Browse files
committed
Release 0.2.9, Implement text wrap #10 and fix #37
1 parent b81509d commit 1bbb169

File tree

13 files changed

+147
-24
lines changed

13 files changed

+147
-24
lines changed

DEVELOPERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Variables:
8181
- `MMM_EXT_SUPPORT` declared if extensions are supported
8282
- `MMM_USER_LANGUAGE` the current user selected language
8383
- `MMM_APP_VERSION` display version of the app (Ex: `x.y.z`)
84+
- `MMM_TEXT_WRAP` is set to `1` if text wrapping is enabled
8485

8586
Note:
8687
The current behavior with unknown command is to ignore them,

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.fox2code.mmm"
1111
minSdk 21
1212
targetSdk 32
13-
versionCode 19
14-
versionName "0.2.8"
13+
versionCode 20
14+
versionName "0.2.9"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/sbin/sh
2+
# This script is only used to test debug builds
3+
4+
umask 022
5+
6+
API=$(getprop ro.build.version.sdk)
7+
OUTFD=$2
8+
ZIPFILE=$3
9+
MODPATH="${ZIPFILE%/*}"
10+
11+
ui_print() { echo "$1"; }
12+
abort() {
13+
ui_print "$1"
14+
[ -f $MODPATH/customize.sh ] && rm -f $MODPATH/customize.sh
15+
exit 1
16+
}
17+
18+
ui_print "! Using rootless installer test script"
19+
20+
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2
21+
22+
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
23+
24+
ui_print "- Done"

app/src/main/java/com/fox2code/mmm/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Constants {
1313
public static final String EXTRA_INSTALL_CONFIG = "extra_install_config";
1414
public static final String EXTRA_INSTALL_NO_PATCH = "extra_install_no_patch";
1515
public static final String EXTRA_INSTALL_NO_EXTENSIONS = "extra_install_no_extensions";
16+
public static final String EXTRA_INSTALL_TEST_ROOTLESS = "extra_install_test_rootless";
1617
public static final String EXTRA_MARKDOWN_URL = "extra_markdown_url";
1718
public static final String EXTRA_MARKDOWN_TITLE = "extra_markdown_title";
1819
public static final String EXTRA_MARKDOWN_CONFIG = "extra_markdown_config";

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public static boolean isForceDarkTerminal() {
102102
return getSharedPreferences().getBoolean("pref_force_dark_terminal", false);
103103
}
104104

105+
public static boolean isTextWrapEnabled() {
106+
return getSharedPreferences().getBoolean("pref_wrap_text", false);
107+
}
108+
105109
public static boolean isDeveloper() {
106110
return BuildConfig.DEBUG ||
107111
getSharedPreferences().getBoolean("developer", false);

app/src/main/java/com/fox2code/mmm/NotificationType.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
interface NotificationTypeCst {
2323
String TAG = "NotificationType";
24+
boolean ROOTLESS_TEST = true;
2425
}
2526

2627
public enum NotificationType implements NotificationTypeCst {
@@ -88,7 +89,9 @@ public boolean shouldRemove() {
8889
} else {
8990
IntentHelper.openInstaller(compatActivity, d.getAbsolutePath(),
9091
compatActivity.getString(
91-
R.string.local_install_title), null);
92+
R.string.local_install_title), null, false,
93+
BuildConfig.DEBUG && // Use debug mode if no root
94+
InstallerInitializer.peekMagiskPath() == null);
9295
}
9396
} catch (IOException ignored) {
9497
if (d.exists() && !d.delete())
@@ -99,14 +102,17 @@ public boolean shouldRemove() {
99102
} else if (s == IntentHelper.RESPONSE_URL) {
100103
IntentHelper.openInstaller(compatActivity, u.toString(),
101104
compatActivity.getString(
102-
R.string.remote_install_title), null);
105+
R.string.remote_install_title), null, false,
106+
BuildConfig.DEBUG && // Use debug mode if no root
107+
InstallerInitializer.peekMagiskPath() == null);
103108
}
104109
});
105110
}, true) {
106111
@Override
107112
public boolean shouldRemove() {
108-
return MainApplication.isShowcaseMode() ||
109-
InstallerInitializer.peekMagiskPath() == null;
113+
return (!(ROOTLESS_TEST && BuildConfig.DEBUG)) &&
114+
(MainApplication.isShowcaseMode() ||
115+
InstallerInitializer.peekMagiskPath() == null);
110116
}
111117
};
112118

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import android.view.WindowManager;
1313
import android.widget.Toast;
1414

15+
import androidx.recyclerview.widget.RecyclerView;
16+
1517
import com.fox2code.mmm.ActionButtonType;
1618
import com.fox2code.mmm.BuildConfig;
1719
import 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
}

app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import androidx.core.app.ActivityOptionsCompat;
1818

19+
import com.fox2code.mmm.BuildConfig;
1920
import com.fox2code.mmm.Constants;
2021
import com.fox2code.mmm.MainApplication;
2122
import com.fox2code.mmm.R;
@@ -88,6 +89,11 @@ public static void openMarkdown(Context context, String url, String title, Strin
8889
}
8990

9091
public static void openInstaller(Context context, String url, String title, String config) {
92+
openInstaller(context, url, title, config, false, false);
93+
}
94+
95+
public static void openInstaller(Context context, String url, String title, String config,
96+
boolean noPatch,boolean testDebug) {
9197
try {
9298
Intent intent = new Intent(context, InstallerActivity.class);
9399
intent.setAction(Constants.INTENT_INSTALL_INTERNAL);
@@ -96,6 +102,10 @@ public static void openInstaller(Context context, String url, String title, Stri
96102
intent.putExtra(Constants.EXTRA_INSTALL_NAME, title);
97103
if (config != null && !config.isEmpty())
98104
intent.putExtra(Constants.EXTRA_INSTALL_CONFIG, config);
105+
if (noPatch)
106+
intent.putExtra(Constants.EXTRA_INSTALL_NO_PATCH, true);
107+
if (testDebug && BuildConfig.DEBUG)
108+
intent.putExtra(Constants.EXTRA_INSTALL_TEST_ROOTLESS, true);
99109
startActivity(context, intent, true);
100110
} catch (ActivityNotFoundException e) {
101111
Toast.makeText(context,
@@ -158,6 +168,12 @@ public static Activity getActivity(Context context) {
158168
@SuppressLint("SdCardPath")
159169
public static void openFileTo(CompatActivity compatActivity, File destination,
160170
OnFileReceivedCallback callback) {
171+
File destinationFolder;
172+
if (destination == null || (destinationFolder = destination.getParentFile()) == null ||
173+
(!destinationFolder.isDirectory() && !destinationFolder.mkdirs())) {
174+
callback.onReceived(destination, null, RESPONSE_ERROR);
175+
return;
176+
}
161177
Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("application/zip");
162178
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
163179
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal"
7+
android:autoMirrored="true">
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M19,7v4H5.83l3.58,-3.59L8,6l-6,6 6,6 1.41,-1.41L5.83,13H21V7z"/>
11+
</vector>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<androidx.recyclerview.widget.RecyclerView
9+
android:id="@+id/install_terminal"
10+
android:background="@null"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:textSize="16sp"
14+
app:layout_constraintEnd_toEndOf="parent"
15+
app:layout_constraintStart_toStartOf="parent"
16+
app:layout_constraintTop_toTopOf="parent" />
17+
18+
<com.google.android.material.progressindicator.LinearProgressIndicator
19+
android:id="@+id/progress_bar"
20+
android:layout_height="wrap_content"
21+
android:layout_width="match_parent"
22+
android:indeterminate="true"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintTop_toTopOf="parent" />
26+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)