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

Commit 3289775

Browse files
committed
Add NoodleDebug for user-debugging and update FoxCompat to fix a bug.
1 parent 95b1c80 commit 3289775

File tree

6 files changed

+281
-7
lines changed

6 files changed

+281
-7
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ dependencies {
117117
implementation "dev.rikka.rikkax.insets:insets:1.3.0"
118118
implementation 'com.github.Dimezis:BlurView:version-1.6.6'
119119
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
120-
implementation 'com.github.Fox2Code:FoxCompat:0.1.3'
120+
implementation 'com.github.Fox2Code:FoxCompat:0.1.4b'
121121

122122
// Utils
123123
implementation 'androidx.work:work-runtime:2.7.1'

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

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.fox2code.mmm.utils.ExternalHelper;
3535
import com.fox2code.mmm.utils.Http;
3636
import com.fox2code.mmm.utils.IntentHelper;
37+
import com.fox2code.mmm.utils.NoodleDebug;
3738
import com.google.android.material.progressindicator.LinearProgressIndicator;
3839

3940
import eightbitlab.com.blurview.BlurView;
@@ -44,6 +45,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
4445
OverScrollManager.OverScrollHelper {
4546
private static final String TAG = "MainActivity";
4647
private static final int PRECISION = 10000;
48+
public static boolean noodleDebugState = BuildConfig.DEBUG;
4749
public final ModuleViewListBuilder moduleViewListBuilder;
4850
public LinearProgressIndicator progressIndicator;
4951
private ModuleViewAdapter moduleViewAdapter;
@@ -59,6 +61,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
5961
private RecyclerView moduleList;
6062
private CardView searchCard;
6163
private SearchView searchView;
64+
private NoodleDebug noodleDebug;
6265
private boolean initMode;
6366

6467
public MainActivity() {
@@ -106,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
106109
this.moduleList = findViewById(R.id.module_list);
107110
this.searchCard = findViewById(R.id.search_card);
108111
this.searchView = findViewById(R.id.search_bar);
112+
this.noodleDebug = new NoodleDebug(this, R.id.noodle_debug);
109113
this.moduleViewAdapter = new ModuleViewAdapter();
110114
this.moduleList.setAdapter(this.moduleViewAdapter);
111115
this.moduleList.setLayoutManager(new LinearLayoutManager(this));
@@ -152,6 +156,8 @@ public void onPathReceived(String path) {
152156
moduleViewListBuilder.addNotification(NotificationType.MAGISK_OUTDATED);
153157
if (!MainApplication.isShowcaseMode())
154158
moduleViewListBuilder.addNotification(NotificationType.INSTALL_FROM_STORAGE);
159+
noodleDebug.setEnabled(noodleDebugState);
160+
noodleDebug.bind();
155161
ModuleManager.getINSTANCE().scan();
156162
ModuleManager.getINSTANCE().runAfterScan(
157163
moduleViewListBuilder::appendInstalledModules);
@@ -161,18 +167,22 @@ public void onPathReceived(String path) {
161167
@Override
162168
public void onFailure(int error) {
163169
Log.i(TAG, "Failed to get magisk path!");
170+
noodleDebug.setEnabled(noodleDebugState);
171+
noodleDebug.bind();
164172
moduleViewListBuilder.addNotification(
165173
InstallerInitializer.getErrorNotification());
166174
this.commonNext();
167175
}
168176

169177
public void commonNext() {
178+
NoodleDebug noodleDebug = NoodleDebug.getNoodleDebug();
170179
swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
171180
updateScreenInsets(); // Fix an edge case
172181
if (MainApplication.isShowcaseMode())
173182
moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE);
174183
if (!Http.hasWebView()) // Check Http for WebView availability
175184
moduleViewListBuilder.addNotification(NotificationType.NO_WEB_VIEW);
185+
noodleDebug.push("Apply");
176186
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
177187
runOnUiThread(() -> {
178188
progressIndicator.setIndeterminate(false);
@@ -181,11 +191,14 @@ public void commonNext() {
181191
updateScreenInsets(getResources().getConfiguration());
182192
});
183193
Log.i(TAG, "Scanning for modules!");
194+
noodleDebug.replace("Initialize Update");
184195
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
185196
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
186197
Log.w(TAG, "Need update on create?");
187198
}
199+
noodleDebug.replace("Check Update Compat");
188200
AppUpdateManager.getAppUpdateManager().checkUpdateCompat();
201+
noodleDebug.replace("Check Update");
189202
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () ->
190203
progressIndicator.setProgressCompat(
191204
(int) (value * PRECISION), true) :() ->
@@ -196,13 +209,17 @@ public void commonNext() {
196209
} else {
197210
// Compatibility data still needs to be updated
198211
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
212+
noodleDebug.replace("Check App Update");
199213
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
200214
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
215+
noodleDebug.replace("Check Json Update");
201216
if (max != 0) {
202217
int current = 0;
218+
noodleDebug.push("");
203219
for (LocalModuleInfo localModuleInfo :
204220
ModuleManager.getINSTANCE().getModules().values()) {
205221
if (localModuleInfo.updateJson != null) {
222+
noodleDebug.replace(localModuleInfo.id);
206223
try {
207224
localModuleInfo.checkModuleUpdate();
208225
} catch (Exception e) {
@@ -216,6 +233,7 @@ public void commonNext() {
216233
+ (PRECISION * 0.75F)), true));
217234
}
218235
}
236+
noodleDebug.pop();
219237
}
220238
}
221239
runOnUiThread(() -> {
@@ -225,10 +243,13 @@ public void commonNext() {
225243
setActionBarBackground(null);
226244
updateScreenInsets(getResources().getConfiguration());
227245
});
246+
noodleDebug.push("Apply");
228247
RepoManager.getINSTANCE().runAfterUpdate(
229248
moduleViewListBuilder::appendRemoteModules);
230249
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
250+
noodleDebug.pop();
231251
Log.i(TAG, "Finished app opening state!");
252+
noodleDebug.unbind();
232253
}
233254
}, true);
234255
ExternalHelper.INSTANCE.refreshHelper(this);
@@ -321,6 +342,8 @@ public void onPathReceived(String path) {
321342
moduleViewListBuilder.addNotification(NotificationType.MAGISK_OUTDATED);
322343
if (!MainApplication.isShowcaseMode())
323344
moduleViewListBuilder.addNotification(NotificationType.INSTALL_FROM_STORAGE);
345+
noodleDebug.setEnabled(noodleDebugState);
346+
noodleDebug.bind();
324347
ModuleManager.getINSTANCE().scan();
325348
ModuleManager.getINSTANCE().runAfterScan(
326349
moduleViewListBuilder::appendInstalledModules);
@@ -331,23 +354,28 @@ public void onPathReceived(String path) {
331354
public void onFailure(int error) {
332355
moduleViewListBuilder.addNotification(
333356
InstallerInitializer.getErrorNotification());
357+
noodleDebug.setEnabled(noodleDebugState);
358+
noodleDebug.bind();
334359
this.commonNext();
335360
}
336361

337362
public void commonNext() {
338363
Log.i(TAG, "Common Before");
364+
NoodleDebug noodleDebug = NoodleDebug.getNoodleDebug();
339365
if (MainApplication.isShowcaseMode())
340366
moduleViewListBuilder.addNotification(NotificationType.SHOWCASE_MODE);
341367
if (!NotificationType.NO_INTERNET.shouldRemove())
342368
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
343369
else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
344370
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
345371
RepoManager.getINSTANCE().updateEnabledStates();
372+
noodleDebug.push("");
346373
if (RepoManager.getINSTANCE().getCustomRepoManager().needUpdate()) {
347374
runOnUiThread(() -> {
348375
progressIndicator.setIndeterminate(false);
349376
progressIndicator.setMax(PRECISION);
350377
});
378+
noodleDebug.replace("Check Update");
351379
RepoManager.getINSTANCE().update(value -> runOnUiThread(() ->
352380
progressIndicator.setProgressCompat(
353381
(int) (value * PRECISION), true)));
@@ -356,11 +384,14 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(false))
356384
progressIndicator.setVisibility(View.GONE);
357385
});
358386
}
387+
noodleDebug.replace("Apply");
359388
RepoManager.getINSTANCE().runAfterUpdate(
360389
moduleViewListBuilder::appendRemoteModules);
361390
Log.i(TAG, "Common Before applyTo");
362391
moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
392+
noodleDebug.pop();
363393
Log.i(TAG, "Common After");
394+
noodleDebug.unbind();
364395
}
365396
});
366397
this.initMode = false;
@@ -384,14 +415,49 @@ public void onRefresh() {
384415
this.swipeRefreshBlocker = System.currentTimeMillis() + 5_000L;
385416
// this.swipeRefreshLayout.setRefreshing(true); ??
386417
new Thread(() -> {
418+
noodleDebug.setEnabled(noodleDebugState);
419+
NoodleDebug noodleDebug = this.noodleDebug.bind();
387420
Http.cleanDnsCache(); // Allow DNS reload from network
388-
RepoManager.getINSTANCE().update(value -> runOnUiThread(() ->
389-
this.progressIndicator.setProgressCompat(
390-
(int) (value * PRECISION), true)));
391-
if (!NotificationType.NO_INTERNET.shouldRemove())
421+
noodleDebug.push("Check Update");
422+
final int max = ModuleManager.getINSTANCE().getUpdatableModuleCount();
423+
RepoManager.getINSTANCE().update(value -> runOnUiThread(max == 0 ? () ->
424+
progressIndicator.setProgressCompat(
425+
(int) (value * PRECISION), true) :() ->
426+
progressIndicator.setProgressCompat(
427+
(int) (value * PRECISION * 0.75F), true)));
428+
if (!NotificationType.NO_INTERNET.shouldRemove()) {
392429
moduleViewListBuilder.addNotification(NotificationType.NO_INTERNET);
393-
else if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
394-
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
430+
} else {
431+
// Compatibility data still needs to be updated
432+
AppUpdateManager appUpdateManager = AppUpdateManager.getAppUpdateManager();
433+
noodleDebug.replace("Check App Update");
434+
if (BuildConfig.ENABLE_AUTO_UPDATER && appUpdateManager.checkUpdate(true))
435+
moduleViewListBuilder.addNotification(NotificationType.UPDATE_AVAILABLE);
436+
noodleDebug.replace("Check Json Update");
437+
if (max != 0) {
438+
int current = 0;
439+
noodleDebug.push("");
440+
for (LocalModuleInfo localModuleInfo :
441+
ModuleManager.getINSTANCE().getModules().values()) {
442+
if (localModuleInfo.updateJson != null) {
443+
noodleDebug.replace(localModuleInfo.id);
444+
try {
445+
localModuleInfo.checkModuleUpdate();
446+
} catch (Exception e) {
447+
Log.e("MainActivity", "Failed to fetch update of: "
448+
+ localModuleInfo.id, e);
449+
}
450+
current++;
451+
final int currentTmp = current;
452+
runOnUiThread(() -> progressIndicator.setProgressCompat(
453+
(int) ((1F * currentTmp / max) * PRECISION * 0.25F
454+
+ (PRECISION * 0.75F)), true));
455+
}
456+
}
457+
noodleDebug.pop();
458+
}
459+
}
460+
noodleDebug.replace("Apply");
395461
runOnUiThread(() -> {
396462
this.progressIndicator.setVisibility(View.GONE);
397463
this.swipeRefreshLayout.setRefreshing(false);
@@ -403,6 +469,8 @@ else if (AppUpdateManager.getAppUpdateManager().checkUpdate(true))
403469
RepoManager.getINSTANCE().runAfterUpdate(
404470
moduleViewListBuilder::appendRemoteModules);
405471
this.moduleViewListBuilder.applyTo(moduleList, moduleViewAdapter);
472+
noodleDebug.pop();
473+
noodleDebug.unbind();
406474
},"Repo update thread").start();
407475
}
408476

app/src/main/java/com/fox2code/mmm/manager/ModuleManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fox2code.mmm.MainApplication;
99
import com.fox2code.mmm.installer.InstallerInitializer;
1010
import com.fox2code.mmm.utils.Http;
11+
import com.fox2code.mmm.utils.NoodleDebug;
1112
import com.fox2code.mmm.utils.PropUtils;
1213
import com.fox2code.mmm.utils.SyncManager;
1314
import com.topjohnwu.superuser.Shell;
@@ -47,6 +48,8 @@ private ModuleManager() {
4748
}
4849

4950
protected void scanInternal(@NonNull UpdateListener updateListener) {
51+
NoodleDebug noodleDebug = NoodleDebug.getNoodleDebug();
52+
noodleDebug.push("Initialize scan");
5053
boolean firstScan = this.bootPrefs.getBoolean("mm_first_scan", true);
5154
SharedPreferences.Editor editor = firstScan ? this.bootPrefs.edit() : null;
5255
for (ModuleInfo v : this.moduleInfos.values()) {
@@ -67,10 +70,13 @@ protected void scanInternal(@NonNull UpdateListener updateListener) {
6770
if (!FORCE_NEED_FALLBACK && needFallback) {
6871
Log.e(TAG, "Failed to detect modules folder, using fallback instead.");
6972
}
73+
noodleDebug.replace("Scan");
7074
if (modules != null) {
75+
noodleDebug.push("");
7176
for (String module : modules) {
7277
if (!new SuFile("/data/adb/modules/" + module).isDirectory())
7378
continue; // Ignore non directory files inside modules folder
79+
noodleDebug.replace(module);
7480
LocalModuleInfo moduleInfo = moduleInfos.get(module);
7581
if (moduleInfo == null) {
7682
moduleInfo = new LocalModuleInfo(module);
@@ -112,10 +118,16 @@ protected void scanInternal(@NonNull UpdateListener updateListener) {
112118
moduleInfo.flags |= FLAG_MM_INVALID;
113119
}
114120
}
121+
noodleDebug.pop();
115122
}
123+
noodleDebug.replace("Scan update");
116124
String[] modules_update = new SuFile("/data/adb/modules_update").list();
117125
if (modules_update != null) {
126+
noodleDebug.push("");
118127
for (String module : modules_update) {
128+
if (!new SuFile("/data/adb/modules_update/" + module).isDirectory())
129+
continue; // Ignore non directory files inside modules folder
130+
noodleDebug.replace(module);
119131
LocalModuleInfo moduleInfo = moduleInfos.get(module);
120132
if (moduleInfo == null) {
121133
moduleInfo = new LocalModuleInfo(module);
@@ -131,12 +143,16 @@ protected void scanInternal(@NonNull UpdateListener updateListener) {
131143
moduleInfo.flags |= FLAG_MM_INVALID;
132144
}
133145
}
146+
noodleDebug.pop();
134147
}
148+
noodleDebug.replace("Finalize scan");
135149
this.updatableModuleCount = 0;
136150
Iterator<LocalModuleInfo> moduleInfoIterator =
137151
this.moduleInfos.values().iterator();
152+
noodleDebug.push("");
138153
while (moduleInfoIterator.hasNext()) {
139154
LocalModuleInfo moduleInfo = moduleInfoIterator.next();
155+
noodleDebug.replace(moduleInfo.id);
140156
if ((moduleInfo.flags & FLAG_MM_UNPROCESSED) != 0) {
141157
moduleInfoIterator.remove();
142158
continue; // Don't process fallbacks if unreferenced
@@ -158,10 +174,12 @@ protected void scanInternal(@NonNull UpdateListener updateListener) {
158174
}
159175
moduleInfo.verify();
160176
}
177+
noodleDebug.pop();
161178
if (firstScan) {
162179
editor.putBoolean("mm_first_scan", false);
163180
editor.apply();
164181
}
182+
noodleDebug.pop();
165183
}
166184

167185
public HashMap<String, LocalModuleInfo> getModules() {

0 commit comments

Comments
 (0)