Masquerade: Clean up the entire app's code for our current usage
diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb6828..5d19981 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
diff --git a/app/build.gradle b/app/build.gradle
index 267fa06..e4651c1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -20,8 +20,8 @@
applicationId "masquerade.substratum"
minSdkVersion 23
targetSdkVersion 23
- versionCode 10
- versionName "ten"
+ versionCode 11
+ versionName "eleven"
}
buildTypes {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 993969d..94120e4 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -16,7 +16,7 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
- <receiver android:name="masquerade.substratum.services.Helper">
+ <receiver android:name=".util.Helper">
<intent-filter>
<action android:name="masquerade.substratum.COMMANDS"/>
</intent-filter>
diff --git a/app/src/main/java/masquerade/substratum/activities/LoaderActivity.java b/app/src/main/java/masquerade/substratum/activities/LoaderActivity.java
index b82ba3b..29279fa 100644
--- a/app/src/main/java/masquerade/substratum/activities/LoaderActivity.java
+++ b/app/src/main/java/masquerade/substratum/activities/LoaderActivity.java
@@ -14,7 +14,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Log.d("Masquerade", "Masquerade is now ensuring superuser permissions!");
+ Log.d("Masquerade", "Masquerade is now securing superuser permissions!");
Root.requestRootAccess();
finish();
}
diff --git a/app/src/main/java/masquerade/substratum/services/BootDetector.java b/app/src/main/java/masquerade/substratum/services/BootDetector.java
index 61e2702..70ef491 100644
--- a/app/src/main/java/masquerade/substratum/services/BootDetector.java
+++ b/app/src/main/java/masquerade/substratum/services/BootDetector.java
@@ -4,6 +4,8 @@
import android.content.Context;
import android.content.Intent;
+import masquerade.substratum.util.Helper;
+
/**
* @author Nicholas Chum (nicholaschum)
*/
@@ -11,9 +13,7 @@
public class BootDetector extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
- Intent pushIntent = new Intent(context, Helper.class);
- context.startService(pushIntent);
- }
+ Intent pushIntent = new Intent(context, Helper.class);
+ context.startService(pushIntent);
}
}
\ No newline at end of file
diff --git a/app/src/main/java/masquerade/substratum/services/Helper.java b/app/src/main/java/masquerade/substratum/services/Helper.java
deleted file mode 100644
index 576c12b..0000000
--- a/app/src/main/java/masquerade/substratum/services/Helper.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package masquerade.substratum.services;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Environment;
-import android.util.Log;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import masquerade.substratum.util.ReadOverlaysFile;
-import masquerade.substratum.util.Root;
-
-/**
- * @author Nicholas Chum (nicholaschum)
- */
-
-public class Helper extends BroadcastReceiver {
-
- private List<String> state5overlays = null;
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d("Masquerade",
- "BroadcastReceiver has accepted Substratum's commands and is running now...");
- Root.requestRootAccess();
-
- if (intent.getStringExtra("substratum-check") != null) {
- if (intent.getStringExtra("substratum-check").equals("masquerade-ball")) {
- Intent runCommand = new Intent();
- runCommand.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
- runCommand.setAction("projekt.substratum.MASQUERADE_BALL");
- runCommand.putExtra("substratum-check", "masquerade-ball");
- context.sendBroadcast(runCommand);
- Log.d("Masquerade",
- "BroadcastReceiver was triggered to check for system integrity and " +
- "service activation.");
-
- }
- }
-
- if (intent.getStringArrayListExtra("pm-uninstall") != null) {
- uninstall_handler(intent, "pm-uninstall", false);
- }
-
- if (intent.getStringArrayListExtra("pm-uninstall-specific") != null) {
- uninstall_handler(intent, "pm-uninstall-specific", true);
- }
-
- if (intent.getStringExtra("om-commands") != null) {
- Log.d("Masquerade", "Running command: \"" +
- intent.getStringExtra("om-commands") + "\"");
- Root.runCommand(intent.getStringExtra("om-commands"));
- }
- }
-
- private boolean checkIfPackageActivated(String package_name) {
- return (state5overlays.contains(package_name));
- }
-
- private void uninstall_handler(Intent intent, String inheritor, boolean specific) {
- try {
- String final_commands_disable = "";
- String final_commands_uninstall = "";
-
- Root.runCommand(
- "pm grant masquerade.substratum android.permission.READ_EXTERNAL_STORAGE");
- Root.runCommand(
- "pm grant masquerade.substratum android.permission.WRITE_EXTERNAL_STORAGE");
-
- ArrayList<String> packages_to_uninstall =
- new ArrayList<>(intent.getStringArrayListExtra(inheritor));
- File current_overlays = new File(Environment
- .getExternalStorageDirectory().getAbsolutePath() +
- "/.substratum/current_overlays.xml");
- if (current_overlays.exists()) {
- Root.runCommand("rm " + Environment
- .getExternalStorageDirectory().getAbsolutePath() +
- "/.substratum/current_overlays.xml");
- }
- 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);
-
- Log.d("Masquerade", "Intent received to purge referendum package file \"" +
- current + "\"");
- if (checkIfPackageActivated(packages_to_uninstall.get(i))) {
- Log.d("Masquerade", "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 {
- Log.d("Masquerade", "\"" + current +
- "\" has been redirected to the package manager in " +
- "preparations of removal...");
- Root.runCommand("pm uninstall " + current);
- }
- }
-
- if (final_commands_disable.length() > 0) {
- Log.d("Masquerade", "Disable commands: " + final_commands_disable);
- Root.runCommand(final_commands_disable);
- }
- if (final_commands_uninstall.length() > 0) {
- Log.d("Masquerade", "Uninstall commands: " + final_commands_uninstall);
- Root.runCommand(final_commands_uninstall);
- }
-
- if (!specific) {
- // Clear the resource idmapping files generated by OMS
- Log.d("Masquerade", "Cleaning up resource-cache directory...");
- Root.runCommand("rm /data/resource-cache/*");
- // Now clear the persistent overlays database
- Log.d("Masquerade", "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
diff --git a/app/src/main/java/masquerade/substratum/util/Helper.java b/app/src/main/java/masquerade/substratum/util/Helper.java
new file mode 100644
index 0000000..8ca6964
--- /dev/null
+++ b/app/src/main/java/masquerade/substratum/util/Helper.java
@@ -0,0 +1,40 @@
+package masquerade.substratum.util;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+/**
+ * @author Nicholas Chum (nicholaschum)
+ */
+
+public class Helper extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d("Masquerade",
+ "BroadcastReceiver has accepted Substratum's commands and is running now...");
+ Root.requestRootAccess();
+
+ if (intent.getStringExtra("substratum-check") != null) {
+ if (intent.getStringExtra("substratum-check").equals("masquerade-ball")) {
+ Intent runCommand = new Intent();
+ runCommand.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
+ runCommand.setAction("projekt.substratum.MASQUERADE_BALL");
+ runCommand.putExtra("substratum-check", "masquerade-ball");
+ context.sendBroadcast(runCommand);
+ Log.d("Masquerade", "BroadcastReceiver was triggered to check for system " +
+ "integrity and service activation.");
+ }
+ } else if (intent.getStringArrayListExtra("pm-uninstall") != null) {
+ new Uninstaller().Uninstaller(intent, "pm-uninstall", false);
+ } else if (intent.getStringArrayListExtra("pm-uninstall-specific") != null) {
+ new Uninstaller().Uninstaller(intent, "pm-uninstall-specific", true);
+ } else if (intent.getStringExtra("om-commands") != null) {
+ Log.d("Masquerade", "Running command: \"" +
+ intent.getStringExtra("om-commands") + "\"");
+ Root.runCommand(intent.getStringExtra("om-commands"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/masquerade/substratum/util/Uninstaller.java b/app/src/main/java/masquerade/substratum/util/Uninstaller.java
new file mode 100644
index 0000000..b75482e
--- /dev/null
+++ b/app/src/main/java/masquerade/substratum/util/Uninstaller.java
@@ -0,0 +1,115 @@
+package masquerade.substratum.util;
+
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Environment;
+import android.util.Log;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Nicholas Chum (nicholaschum)
+ */
+
+public class Uninstaller {
+
+ private Intent mIntent;
+ private String uninstallString;
+ private Boolean specific;
+
+ public void Uninstaller(Intent mIntent, String uninstallString, Boolean specific) {
+ this.mIntent = mIntent;
+ this.uninstallString = uninstallString;
+ this.specific = specific;
+ new UninstallAsync().execute("");
+ }
+
+ private class UninstallAsync extends AsyncTask<String, Integer, String> {
+
+ @Override
+ protected String doInBackground(String... sUrl) {
+ uninstall_handler(mIntent, uninstallString, specific);
+ return null;
+ }
+
+ private void uninstall_handler(Intent intent, String inheritor, boolean specific) {
+ try {
+ String final_commands_disable = "";
+ String final_commands_uninstall = "";
+
+ Root.runCommand(
+ "pm grant masquerade.substratum android.permission.READ_EXTERNAL_STORAGE");
+ Root.runCommand(
+ "pm grant masquerade.substratum android.permission.WRITE_EXTERNAL_STORAGE");
+
+ ArrayList<String> packages_to_uninstall =
+ new ArrayList<>(intent.getStringArrayListExtra(inheritor));
+ File current_overlays = new File(Environment
+ .getExternalStorageDirectory().getAbsolutePath() +
+ "/.substratum/current_overlays.xml");
+ if (current_overlays.exists()) {
+ Root.runCommand("rm " + Environment
+ .getExternalStorageDirectory().getAbsolutePath() +
+ "/.substratum/current_overlays.xml");
+ }
+ Root.runCommand("cp /data/system/overlays.xml " +
+ Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/.substratum/current_overlays.xml");
+ String[] state5initial = {Environment.getExternalStorageDirectory()
+ .getAbsolutePath() +
+ "/.substratum/current_overlays.xml", "5"};
+ List<String> state5overlays = ReadOverlaysFile.main(state5initial);
+
+ for (int i = 0; i < packages_to_uninstall.size(); i++) {
+ String current = packages_to_uninstall.get(i);
+
+ Log.d("Masquerade", "Intent received to purge referendum package file \"" +
+ current + "\"");
+ if (state5overlays.contains(packages_to_uninstall.get(i))) {
+ Log.d("Masquerade", "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 {
+ Log.d("Masquerade", "\"" + current +
+ "\" has been redirected to the package manager in " +
+ "preparations of removal...");
+ Root.runCommand("pm uninstall " + current);
+ }
+ }
+
+ if (final_commands_disable.length() > 0) {
+ Log.d("Masquerade", "Disable commands: " + final_commands_disable);
+ Root.runCommand(final_commands_disable);
+ }
+ if (final_commands_uninstall.length() > 0) {
+ Log.d("Masquerade", "Uninstall commands: " + final_commands_uninstall);
+ Root.runCommand(final_commands_uninstall);
+ }
+
+ if (!specific) {
+ // Clear the resource idmapping files generated by OMS
+ Log.d("Masquerade", "Cleaning up resource-cache directory...");
+ Root.runCommand("rm /data/resource-cache/*");
+ // Now clear the persistent overlays database
+ Log.d("Masquerade", "Finalizing clean up of persistent overlays database...");
+ Root.runCommand("rm -rf /data/system/overlays.xml");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}