Masquerade: Rewrite AntiPiracy Handler
diff --git a/app/src/main/java/projekt/substratum/helper/services/Helper.java b/app/src/main/java/projekt/substratum/helper/services/Helper.java
index 5662e19..0226b1d 100644
--- a/app/src/main/java/projekt/substratum/helper/services/Helper.java
+++ b/app/src/main/java/projekt/substratum/helper/services/Helper.java
@@ -27,11 +27,11 @@
Root.requestRootAccess();
if (intent.getStringArrayListExtra("pm-uninstall") != null) {
- uninstall_handler(intent, false);
+ uninstall_handler(intent, "pm-uninstall", false);
}
if (intent.getStringArrayListExtra("pm-uninstall-specific") != null) {
- uninstall_handler(intent, true);
+ uninstall_handler(intent, "pm-uninstall-specific", true);
}
if (intent.getStringExtra("om-commands") != null) {
@@ -45,66 +45,72 @@
return (state5overlays.contains(package_name));
}
- private void uninstall_handler(Intent intent, boolean specific) {
- String final_commands_disable = "";
- String final_commands_uninstall = "";
+ private void uninstall_handler(Intent intent, String inheritor, boolean specific) {
+ try {
+ String final_commands_disable = "";
+ String final_commands_uninstall = "";
- Root.runCommand(
- "pm grant projekt.substratum.helper android.permission.READ_EXTERNAL_STORAGE");
- Root.runCommand(
- "pm grant projekt.substratum.helper android.permission.WRITE_EXTERNAL_STORAGE");
+ Root.runCommand(
+ "pm grant projekt.substratum.helper android.permission.READ_EXTERNAL_STORAGE");
+ Root.runCommand(
+ "pm grant projekt.substratum.helper android.permission.WRITE_EXTERNAL_STORAGE");
- ArrayList<String> packages_to_uninstall =
- new ArrayList<>(intent.getStringArrayListExtra("pm-uninstall"));
- Root.runCommand("cp /data/system/overlays" +
- ".xml " + Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/.substratum/current_overlays.xml");
- String[] state5initial = {Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/.substratum/current_overlays.xml", "5"};
- state5overlays = ReadOverlaysFile.main(state5initial);
+ ArrayList<String> packages_to_uninstall =
+ new ArrayList<>(intent.getStringArrayListExtra(inheritor));
+ Root.runCommand("cp /data/system/overlays" +
+ ".xml " + Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/.substratum/current_overlays.xml");
+ String[] state5initial = {Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/.substratum/current_overlays.xml", "5"};
+ state5overlays = ReadOverlaysFile.main(state5initial);
- for (int i = 0; i < packages_to_uninstall.size(); i++) {
- String current = packages_to_uninstall.get(i);
+ for (int i = 0; i < packages_to_uninstall.size(); i++) {
+ String current = packages_to_uninstall.get(i);
- Log.d("SubstratumHelper", "Intent received to purge referendum package file \"" +
- current + "\"");
- if (checkIfPackageActivated(packages_to_uninstall.get(i))) {
- Log.d("SubstratumHelper", "Package file \"" + current +
- "\" requires an overlay disable prior to uninstall...");
- if (final_commands_disable.length() == 0) {
- final_commands_disable = "om disable " + current;
+ Log.d("SubstratumHelper", "Intent received to purge referendum package file \"" +
+ current + "\"");
+ if (checkIfPackageActivated(packages_to_uninstall.get(i))) {
+ Log.d("SubstratumHelper", "Package file \"" + current +
+ "\" requires an overlay disable prior to uninstall...");
+ if (final_commands_disable.length() == 0) {
+ final_commands_disable = "om disable " + current;
+ } else {
+ final_commands_disable = final_commands_disable + " " + current;
+ }
+
+ if (final_commands_uninstall.length() == 0) {
+ final_commands_uninstall = "pm uninstall " + current;
+ } else {
+ final_commands_uninstall = final_commands_uninstall +
+ " && pm uninstall " + current;
+ }
} else {
- final_commands_disable = final_commands_disable + " " + current;
+ Log.d("SubstratumHelper", "\"" + current +
+ "\" has been redirected to the package manager in " +
+ "preparations of removal...");
+ Root.runCommand("pm uninstall " + current);
}
-
- if (final_commands_uninstall.length() == 0) {
- final_commands_uninstall = "pm uninstall " + current;
- } else {
- final_commands_uninstall = final_commands_uninstall +
- " && pm uninstall " + current;
- }
- } else {
- Root.runCommand("pm uninstall " + current);
}
- }
- if (final_commands_disable.length() > 0) {
- Log.d("SubstratumHelper", "Disable commands: " + final_commands_disable);
- Root.runCommand(final_commands_disable);
- } else {
+ if (final_commands_disable.length() > 0) {
+ Log.d("SubstratumHelper", "Disable commands: " + final_commands_disable);
+ Root.runCommand(final_commands_disable);
+ }
if (final_commands_uninstall.length() > 0) {
Log.d("SubstratumHelper", "Uninstall commands: " + final_commands_uninstall);
Root.runCommand(final_commands_uninstall);
}
- }
- if (!specific) {
- // Clear the resource idmapping files generated by OMS
- Log.d("SubstratumHelper", "Cleaning up resource-cache directory...");
- Root.runCommand("rm /data/resource-cache/*");
- // Now clear the persistent overlays database
- Log.d("SubstratumHelper", "Finalizing clean up of persistent overlays database...");
- Root.runCommand("rm -rf /data/system/overlays.xml");
+ if (!specific) {
+ // Clear the resource idmapping files generated by OMS
+ Log.d("SubstratumHelper", "Cleaning up resource-cache directory...");
+ Root.runCommand("rm /data/resource-cache/*");
+ // Now clear the persistent overlays database
+ Log.d("SubstratumHelper", "Finalizing clean up of persistent overlays database...");
+ Root.runCommand("rm -rf /data/system/overlays.xml");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
}
\ No newline at end of file