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

Commit c1cad9b

Browse files
committed
Add MMT-Reborn support + add feedback for known errors + fix bugs.
1 parent c6adf58 commit c1cad9b

22 files changed

+287
-69
lines changed

DEVELOPERS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ support=<url>
7979
donate=<url>
8080
config=<package>
8181
changeBoot=<boolean>
82+
mmtReborn=<boolean>
8283
```
8384
Note: All urls must start with `https://`, or else will be ignored
8485
Note²: For `minMagisk`, `XX.Y` is parsed as `XXY00`, so you can just put the Magisk version name.
@@ -93,6 +94,8 @@ Note²: For `minMagisk`, `XX.Y` is parsed as `XXY00`, so you can just put the Ma
9394
- `config` package name of the application that configure your module
9495
(Note: The icon won't appear in the module list if the module or target app is not installed)
9596
- `changeBoot` tell the manager the module may change the boot image
97+
- `mmtReborn` tell the manager to use [MMT-Reborn](https://github.com/iamlooper/MMT-Reborn) logging style
98+
(For example `- Hello world` will be transformed to `[*] Hello world`, do not apply to modules installed from storage)
9699

97100
Note: Fox's Mmm use fallback
98101
[here](app/src/main/java/com/fox2code/mmm/utils/PropUtils.java#L36)

app/src/main/assets/module_installer_compat.sh

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ settings() {
5353
fi
5454
}
5555

56-
if [ $MAGISK_VER_CODE -ge 20400 ]; then
56+
if [ $MAGISK_VER_CODE -ge 20400 ] && [ -z "$MMM_MMT_REBORN" ]; then
5757
# New Magisk have complete installation logic within util_functions.sh
5858
install_module
5959
exit 0
6060
fi
6161

62-
#################
63-
# Legacy Support
64-
#################
62+
#######################################################
63+
# Legacy Support + compat mode for MMT Reborn template
64+
#######################################################
6565

6666
TMPDIR=/dev/tmp
6767
PERSISTDIR=/sbin/.magisk/mirror/persist
@@ -98,6 +98,7 @@ abort() {
9898

9999
rm -rf $TMPDIR 2>/dev/null
100100
mkdir -p $TMPDIR
101+
chcon u:object_r:system_file:s0 $TMPDIR || true
101102
cd $TMPDIR
102103

103104
# Preperation for flashable zips
@@ -121,7 +122,9 @@ $BOOTMODE && boot_actions || recovery_actions
121122
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
122123
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
123124

124-
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
125+
[ -z "$NVBASE" ] && NVBASE="/data/adb"
126+
MODDIRNAME=modules
127+
$BOOTMODE && MODDIRNAME=modules_update
125128
MODULEROOT=$NVBASE/$MODDIRNAME
126129
MODID=`grep_prop id $TMPDIR/module.prop`
127130
MODNAME=`grep_prop name $TMPDIR/module.prop`
@@ -166,6 +169,50 @@ if is_legacy_script; then
166169

167170
ui_print "- Setting permissions"
168171
set_permissions
172+
elif [ -n "$MMM_MMT_REBORN" ]; then
173+
# https://github.com/iamlooper/MMT-Reborn
174+
ui_print "[*] Using FoxMMM MMT-Reborn compatibility mode"
175+
176+
load_vksel() { source "$MODPATH/addon/Volume-Key-Selector/install.sh"; }
177+
178+
rmtouch() { [[ -e "$1" ]] && rm -rf "$1" 2>/dev/null; }
179+
180+
unzip -o "$ZIPFILE" -d "$MODPATH" >&2
181+
182+
# Load install script
183+
source "$MODPATH/setup.sh"
184+
185+
# Remove all old files before doing installation if want to
186+
"$CLEANSERVICE" && rm -rf "/data/adb/modules/$MODID"
187+
188+
# Enable debugging if true
189+
"$DEBUG" && set -x || set +x
190+
191+
# Print mod info
192+
info_print
193+
194+
# Auto vskel load
195+
"$AUTOVKSEL" && load_vksel
196+
197+
# Main
198+
init_main
199+
200+
# Skip mount
201+
"$SKIPMOUNT" && touch "$MODPATH/skip_mount"
202+
203+
# Set permissions
204+
set_permissions
205+
206+
# Remove stuffs that don't belong to modules
207+
rmtouch "$MODPATH/META-INF"
208+
rmtouch "$MODPATH/addon"
209+
rmtouch "$MODPATH/setup.sh"
210+
rmtouch "$MODPATH/LICENSE"
211+
rmtouch "$MODPATH/README.md"
212+
rmtouch "$MODPATH/system/bin/placeholder"
213+
rmtouch "$MODPATH/zygisk/placeholder"
214+
ui_print "[*] Exiting FoxMMM MMT-Reborn compatibility mode"
215+
sleep 0.5
169216
else
170217
print_modname
171218

@@ -198,13 +245,20 @@ if $BOOTMODE; then
198245
fi
199246

200247
# Copy over custom sepolicy rules
201-
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
202-
ui_print "- Installing custom sepolicy patch"
203-
# Remove old recovery logs (which may be filling partition) to make room
204-
rm -f $PERSISTDIR/cache/recovery/*
205-
PERSISTMOD=$PERSISTDIR/magisk/$MODID
206-
mkdir -p $PERSISTMOD
207-
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule || abort "! Insufficient partition size"
248+
if ! type copy_sepolicy_rules &>/dev/null; then
249+
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
250+
ui_print "- Installing custom sepolicy patch"
251+
# Remove old recovery logs (which may be filling partition) to make room
252+
rm -f $PERSISTDIR/cache/recovery/*
253+
PERSISTMOD=$PERSISTDIR/magisk/$MODID
254+
mkdir -p $PERSISTMOD
255+
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule || abort "! Insufficient partition size"
256+
fi
257+
else
258+
if [ -f $MODPATH/sepolicy.rule ]; then
259+
ui_print "- Installing custom sepolicy rules"
260+
copy_sepolicy_rules
261+
fi
208262
fi
209263

210264
# Remove stuff that doesn't belong to modules and clean up any empty directories

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
// See https://docs.github.com/en/rest/reference/repos#releases
2222
public class AppUpdateManager {
23-
public static final int FLAG_COMPAT_LOW_QUALITY = 0x01;
24-
public static final int FLAG_COMPAT_NO_EXT = 0x02;
25-
public static final int FLAG_COMPAT_MAGISK_CMD = 0x04;
26-
public static final int FLAG_COMPAT_NEED_32BIT = 0x08;
27-
public static final int FLAG_COMPAT_MALWARE = 0x10;
28-
public static final int FLAG_COMPAT_NO_ANSI = 0x20;
29-
public static final int FLAG_COMPAT_FORCE_ANSI = 0x40;
30-
public static final int FLAG_COMPAT_FORCE_HIDE = 0x80;
23+
public static final int FLAG_COMPAT_LOW_QUALITY = 0x0001;
24+
public static final int FLAG_COMPAT_NO_EXT = 0x0002;
25+
public static final int FLAG_COMPAT_MAGISK_CMD = 0x0004;
26+
public static final int FLAG_COMPAT_NEED_32BIT = 0x0008;
27+
public static final int FLAG_COMPAT_MALWARE = 0x0010;
28+
public static final int FLAG_COMPAT_NO_ANSI = 0x0020;
29+
public static final int FLAG_COMPAT_FORCE_ANSI = 0x0040;
30+
public static final int FLAG_COMPAT_FORCE_HIDE = 0x0080;
31+
public static final int FLAG_COMPAT_MMT_REBORN = 0x0100;
3132
private static final String TAG = "AppUpdateManager";
3233
private static final AppUpdateManager INSTANCE = new AppUpdateManager();
3334
private static final String RELEASES_API_URL =
@@ -213,6 +214,9 @@ private void parseCompatibilityFlags(InputStream inputStream) throws IOException
213214
case "forceHide":
214215
value |= FLAG_COMPAT_FORCE_HIDE;
215216
break;
217+
case "mmtReborn":
218+
value |= FLAG_COMPAT_MMT_REBORN;
219+
break;
216220
}
217221
}
218222
compatDataId.put(line.substring(0, i), value);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Constants {
1414
public static final String EXTRA_INSTALL_NAME = "extra_install_name";
1515
public static final String EXTRA_INSTALL_CONFIG = "extra_install_config";
1616
public static final String EXTRA_INSTALL_CHECKSUM = "extra_install_checksum";
17+
public static final String EXTRA_INSTALL_MMT_REBORN = "extra_install_mmt_reborn";
1718
public static final String EXTRA_INSTALL_NO_EXTENSIONS = "extra_install_no_extensions";
1819
public static final String EXTRA_INSTALL_TEST_ROOTLESS = "extra_install_test_rootless";
1920
public static final String EXTRA_ANDROIDACY_COMPAT_LEVEL = "extra_androidacy_compat_level";

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import eightbitlab.com.blurview.BlurView;
3939
import eightbitlab.com.blurview.RenderScriptBlur;
40-
import io.sentry.android.core.SentryAndroid;
4140

4241
public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener,
4342
SearchView.OnQueryTextListener, SearchView.OnCloseListener,
@@ -153,14 +152,16 @@ public void onPathReceived(String path) {
153152
if (!MainApplication.isShowcaseMode())
154153
moduleViewListBuilder.addNotification(NotificationType.INSTALL_FROM_STORAGE);
155154
ModuleManager.getINSTANCE().scan();
156-
moduleViewListBuilder.appendInstalledModules();
155+
ModuleManager.getINSTANCE().runAfterScan(
156+
moduleViewListBuilder::appendInstalledModules);
157157
this.commonNext();
158158
}
159159

160160
@Override
161161
public void onFailure(int error) {
162162
Log.i(TAG, "Failed to get magisk path!");
163-
moduleViewListBuilder.addNotification(NotificationType.NO_ROOT);
163+
moduleViewListBuilder.addNotification(
164+
InstallerInitializer.getErrorNotification());
164165
this.commonNext();
165166
}
166167

@@ -223,7 +224,8 @@ public void commonNext() {
223224
setActionBarBackground(null);
224225
updateScreenInsets(getResources().getConfiguration());
225226
});
226-
moduleViewListBuilder.appendRemoteModules();
227+
RepoManager.getINSTANCE().runAfterUpdate(
228+
moduleViewListBuilder::appendRemoteModules);
227229
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
228230
Log.i(TAG, "Finished app opening state!");
229231
}
@@ -318,13 +320,15 @@ public void onPathReceived(String path) {
318320
if (!MainApplication.isShowcaseMode())
319321
moduleViewListBuilder.addNotification(NotificationType.INSTALL_FROM_STORAGE);
320322
ModuleManager.getINSTANCE().scan();
321-
moduleViewListBuilder.appendInstalledModules();
323+
ModuleManager.getINSTANCE().runAfterScan(
324+
moduleViewListBuilder::appendInstalledModules);
322325
this.commonNext();
323326
}
324327

325328
@Override
326329
public void onFailure(int error) {
327-
moduleViewListBuilder.addNotification(NotificationType.NO_ROOT);
330+
moduleViewListBuilder.addNotification(
331+
InstallerInitializer.getErrorNotification());
328332
this.commonNext();
329333
}
330334

@@ -350,7 +354,8 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
350354
progressIndicator.setVisibility(View.GONE);
351355
});
352356
}
353-
moduleViewListBuilder.appendRemoteModules();
357+
RepoManager.getINSTANCE().runAfterUpdate(
358+
moduleViewListBuilder::appendRemoteModules);
354359
Log.i(TAG, "Common Before applyTo");
355360
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
356361
Log.i(TAG, "Common After");
@@ -393,7 +398,8 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
393398
this.moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
394399
}
395400
RepoManager.getINSTANCE().updateEnabledStates();
396-
this.moduleViewListBuilder.appendRemoteModules();
401+
RepoManager.getINSTANCE().runAfterUpdate(
402+
moduleViewListBuilder::appendRemoteModules);
397403
this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
398404
},"Repo update thread").start();
399405
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public boolean shouldRemove() {
3737
}) {
3838
@Override
3939
public boolean shouldRemove() {
40-
return InstallerInitializer.peekMagiskPath() != null;
40+
return InstallerInitializer.getErrorNotification() != this;
41+
}
42+
},
43+
ROOT_DENIED(R.string.fail_root_denied, R.drawable.ic_baseline_numbers_24) {
44+
@Override
45+
public boolean shouldRemove() {
46+
return InstallerInitializer.getErrorNotification() != this;
4147
}
4248
},
4349
MAGISK_OUTDATED(R.string.magisk_outdated, R.drawable.ic_baseline_update_24, v -> {
@@ -102,7 +108,7 @@ public boolean shouldRemove() {
102108
} else {
103109
IntentHelper.openInstaller(compatActivity, d.getAbsolutePath(),
104110
compatActivity.getString(
105-
R.string.local_install_title), null, null,
111+
R.string.local_install_title), null, null, false,
106112
BuildConfig.DEBUG && // Use debug mode if no root
107113
InstallerInitializer.peekMagiskPath() == null);
108114
}
@@ -115,7 +121,7 @@ public boolean shouldRemove() {
115121
} else if (s == IntentHelper.RESPONSE_URL) {
116122
IntentHelper.openInstaller(compatActivity, u.toString(),
117123
compatActivity.getString(
118-
R.string.remote_install_title), null, null,
124+
R.string.remote_install_title), null, null, false,
119125
BuildConfig.DEBUG && // Use debug mode if no root
120126
InstallerInitializer.peekMagiskPath() == null);
121127
}

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
213213
}
214214
moduleInfo.needRamdisk = jsonObject.optBoolean("needRamdisk", false);
215215
moduleInfo.changeBoot = jsonObject.optBoolean("changeBoot", false);
216+
moduleInfo.mmtReborn = jsonObject.optBoolean("mmtReborn", false);
216217
moduleInfo.support = filterURL(jsonObject.optString("support"));
217218
moduleInfo.donate = filterURL(jsonObject.optString("donate"));
218219
String config = jsonObject.optString("config", "");
@@ -226,6 +227,8 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
226227
RepoModule repoModule = moduleInfoIterator.next();
227228
if (!repoModule.processed) {
228229
moduleInfoIterator.remove();
230+
} else {
231+
repoModule.moduleInfo.verify();
229232
}
230233
}
231234
this.lastUpdate = lastLastUpdate;

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.fox2code.mmm.manager.LocalModuleInfo;
2424
import com.fox2code.mmm.manager.ModuleInfo;
2525
import com.fox2code.mmm.manager.ModuleManager;
26-
import com.fox2code.mmm.repo.RepoManager;
2726
import com.fox2code.mmm.repo.RepoModule;
2827
import com.fox2code.mmm.utils.Files;
2928
import com.fox2code.mmm.utils.Hashes;
@@ -67,9 +66,11 @@ void openNativeModuleDialogRaw(String moduleUrl, String installTitle,
6766
RepoModule repoModule = AndroidacyRepoData
6867
.getInstance().moduleHashMap.get(installTitle);
6968
String title, description;
69+
boolean mmtReborn = false;
7070
if (repoModule != null) {
7171
title = repoModule.moduleInfo.name;
7272
description = repoModule.moduleInfo.description;
73+
mmtReborn = repoModule.moduleInfo.mmtReborn;
7374
if (description == null || description.length() == 0) {
7475
description = this.activity.getString(R.string.no_desc_found);
7576
}
@@ -103,10 +104,11 @@ void openNativeModuleDialogRaw(String moduleUrl, String installTitle,
103104
}
104105
final String fModuleUrl = moduleUrl, fTitle = title,
105106
fConfig = config, fChecksum = checksum;
107+
final boolean fMMTReborn = mmtReborn;
106108
builder.setPositiveButton(hasUpdate ?
107109
R.string.update_module : R.string.install_module, (x, y) -> {
108110
IntentHelper.openInstaller(this.activity,
109-
fModuleUrl, fTitle, fConfig, fChecksum);
111+
fModuleUrl, fTitle, fConfig, fChecksum, fMMTReborn);
110112
});
111113
}
112114
builder.setOnCancelListener(dialogInterface -> {
@@ -247,13 +249,15 @@ public void install(String moduleUrl, String installTitle, String checksum) {
247249
RepoModule repoModule = AndroidacyRepoData
248250
.getInstance().moduleHashMap.get(installTitle);
249251
String config = null;
252+
boolean mmtReborn = false;
250253
if (repoModule != null && repoModule.moduleInfo.name.length() >= 3) {
251254
installTitle = repoModule.moduleInfo.name; // Set title to module name
252255
config = repoModule.moduleInfo.config;
256+
mmtReborn = repoModule.moduleInfo.mmtReborn;
253257
}
254258
this.activity.backOnResume = true;
255259
IntentHelper.openInstaller(this.activity,
256-
moduleUrl, installTitle, config, checksum);
260+
moduleUrl, installTitle, config, checksum, mmtReborn);
257261
}
258262
}
259263

app/src/main/java/com/fox2code/mmm/background/BackgroundBootListener.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.content.Intent;
66

77
import com.fox2code.mmm.MainApplication;
8+
import com.fox2code.mmm.installer.InstallerInitializer;
9+
import com.fox2code.mmm.manager.ModuleManager;
810

911
public class BackgroundBootListener extends BroadcastReceiver {
1012
private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
@@ -14,7 +16,21 @@ public void onReceive(Context context, Intent intent) {
1416
if (!BOOT_COMPLETED.equals(intent.getAction())) return;
1517
synchronized (BackgroundUpdateChecker.lock) {
1618
BackgroundUpdateChecker.onMainActivityCreate(context);
17-
BackgroundUpdateChecker.doCheck(context);
19+
if (MainApplication.isBackgroundUpdateCheckEnabled()) {
20+
BackgroundUpdateChecker.doCheck(context);
21+
}
22+
}
23+
if (ModuleManager.FORCE_NEED_FALLBACK &&
24+
MainApplication.hasGottenRootAccess()) {
25+
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
26+
@Override
27+
public void onPathReceived(String path) {
28+
ModuleManager.getINSTANCE().scan();
29+
}
30+
31+
@Override
32+
public void onFailure(int error) {}
33+
});
1834
}
1935
}
2036
}

0 commit comments

Comments
 (0)