From 1ec333ee5a84954b3fd93a980c4862761e6e3d7a Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Sat, 22 Oct 2016 13:04:58 -0500 Subject: [PATCH] Cleanup --- ...tFragment.java => MagiskHideFragment.java} | 52 ++++++++++++++++--- .../com/topjohnwu/magisk/MainActivity.java | 24 +++++++++ .../topjohnwu/magisk/SettingsFragment.java | 39 +------------- .../com/topjohnwu/magisk/SplashActivity.java | 47 +++++++++-------- .../magisk/utils/ApplicationAdapter.java | 2 + .../com/topjohnwu/magisk/utils/Utils.java | 30 +++++++++-- app/src/main/res/menu/drawer.xml | 6 +-- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/app_settings.xml | 28 ---------- build.gradle | 2 +- 10 files changed, 128 insertions(+), 104 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/{AutoRootFragment.java => MagiskHideFragment.java} (78%) diff --git a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java similarity index 78% rename from app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java rename to app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java index ff6691c30..ff2354ace 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AutoRootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java @@ -9,7 +9,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; - import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -18,6 +17,8 @@ import android.widget.ListView; import com.topjohnwu.magisk.utils.ApplicationAdapter; import com.topjohnwu.magisk.utils.Logger; +import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.Utils; import java.util.ArrayList; import java.util.Collections; @@ -26,12 +27,15 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class AutoRootFragment extends ListFragment { +import static com.topjohnwu.magisk.utils.Utils.WhichHide; + +public class MagiskHideFragment extends ListFragment { private PackageManager packageManager = null; private List applist = null; private ApplicationAdapter listadaptor = null; public ListView listView; public SharedPreferences prefs; + private int hideVersion; List arrayBlackList; @Override @@ -47,7 +51,7 @@ public class AutoRootFragment extends ListFragment { } view.setPadding(horizontalMargin, actionBarHeight, horizontalMargin, verticalMargin); - + hideVersion = WhichHide(getActivity()); return view; } @@ -62,9 +66,9 @@ public class AutoRootFragment extends ListFragment { public void onResume() { super.onResume(); initializeElements(); - super.onResume(); - getActivity().setTitle(R.string.auto_toggle); - + super.onResume(); + getActivity().setTitle(R.string.magiskhide); + hideVersion = WhichHide(getActivity()); } @@ -84,13 +88,29 @@ public class AutoRootFragment extends ListFragment { } private void ToggleApp(String appToCheck, int position, View v) { - Logger.dev("Magisk", "AutoRootFragment: ToggleApp called for " + appToCheck); + Logger.dev("Magisk", "MagiskHideFragment: ToggleApp called for " + appToCheck); Set blackListSet = prefs.getStringSet("auto_blacklist", null); assert blackListSet != null; arrayBlackList = new ArrayList<>(blackListSet); - + String UID = Utils.getAppUID(appToCheck); if (!arrayBlackList.contains(appToCheck)) { arrayBlackList.add(appToCheck); + switch (hideVersion) { + case 1 : + Shell.su("/magisk/.core/magiskhide/add " + appToCheck); + break; + case 2 : + Shell.su("/su/suhide/add " + UID); + break; + case 3 : + Shell.su("/su/suhide/add " + UID + "&& /magisk/.core/magiskhide/add " + appToCheck); + break; + default : + break; + + } + + } else { for (int i = 0; i < arrayBlackList.size(); i++) { @@ -98,6 +118,20 @@ public class AutoRootFragment extends ListFragment { arrayBlackList.remove(i); } } + switch (hideVersion) { + case 1 : + Shell.su("/magisk/.core/magiskhide/rm " + appToCheck); + break; + case 2 : + Shell.su("/su/suhide/rm " + UID); + break; + case 3 : + Shell.su("/su/suhide/rm " + UID + "&& /magisk/.core/magiskhide/rm " + appToCheck); + break; + default : + break; + + } } Logger.dev("Committing set, value is: " + arrayBlackList.toString()); @@ -108,6 +142,8 @@ public class AutoRootFragment extends ListFragment { } + + private List checkForLaunchIntent(List list) { ArrayList applist = new ArrayList<>(); for (ApplicationInfo info : list) { diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index c1a5e9e9b..baff0cabd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -19,11 +19,13 @@ import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.Utils; import butterknife.BindView; import butterknife.ButterKnife; @@ -90,9 +92,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } navigationView.setNavigationItemSelectedListener(this); + checkHideSection(); } + @Override + protected void onResume() { + super.onResume(); + checkHideSection(); + } + @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -120,6 +129,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On return true; } + private void checkHideSection() { + Menu menu = navigationView.getMenu(); + if (PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("magiskhide",false) | (Utils.itemExist("/data/su/suhide"))) { + + menu.findItem(R.id.magiskhide).setVisible(true); + } else { + menu.findItem(R.id.magiskhide).setVisible(false); + } + } + public void navigate(final int itemId) { Fragment navFragment = null; String tag = ""; @@ -139,6 +158,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On tag = "downloads"; navFragment = new ReposFragment(); break; + case R.id.magiskhide: + setTitle(R.string.magiskhide); + tag = "magiskhide"; + navFragment = new MagiskHideFragment(); + break; case R.id.log: setTitle(R.string.log); tag = "log"; diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java index 2b2d33972..d53d26cb0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsFragment.java @@ -27,8 +27,8 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.uisettings); - PreferenceManager.setDefaultValues(getActivity(), R.xml.uisettings, false); + addPreferencesFromResource(R.xml.app_settings); + PreferenceManager.setDefaultValues(getActivity(), R.xml.app_settings, false); } @Override @@ -105,41 +105,6 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer Logger.dev("SettingsFragment: theme is " + pref); - } else if (key.equals("enable_quicktile")) { - boolean checked = sharedPreferences.getBoolean("enable_quicktile", false); - if (checked) { - new AsyncTask () { - @Override - protected Boolean doInBackground(Void... voids) { - return Utils.installTile(getActivity()); - } - @Override - protected void onPostExecute(Boolean result) { - super.onPostExecute(result); - if (result) { - Toast.makeText(getActivity(), "Tile installed", Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(getActivity(), "Tile installation error", Toast.LENGTH_SHORT).show(); - } - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } else { - new AsyncTask () { - @Override - protected Boolean doInBackground(Void... voids) { - return Utils.uninstallTile(getActivity()); - } - @Override - protected void onPostExecute(Boolean result) { - super.onPostExecute(result); - if (result) { - Toast.makeText(getActivity(), "Tile uninstalled", Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(getActivity(), "Tile uninstallation error", Toast.LENGTH_SHORT).show(); - } - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } } else if (key.equals("busybox")) { boolean checked = sharedPreferences.getBoolean("busybox", false); new Async.LinkBusyBox(checked).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 607a2c7e9..23808f4cb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -7,11 +7,16 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; -import com.topjohnwu.magisk.services.MonitorService; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Logger; +import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class SplashActivity extends AppCompatActivity { @Override @@ -19,7 +24,7 @@ public class SplashActivity extends AppCompatActivity { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); - if (prefs.getString("theme","").equals("Dark")) { + if (prefs.getString("theme", "").equals("Dark")) { setTheme(R.style.AppTheme_dh); } @@ -27,10 +32,25 @@ public class SplashActivity extends AppCompatActivity { Logger.logShell = prefs.getBoolean("shell_logging", false); // Set up default preferences,make sure we add "extra" blacklist entries. - if (!defaultPrefs.contains("auto_blacklist")) { + int hideVersion = Utils.WhichHide(getApplication()); + List hideList; + Set set = new HashSet<>(); + switch (hideVersion) { + case 1: + hideList = Shell.su("/magisk/.core/magiskhide/list"); + set.addAll(hideList); + break; + case 2: + hideList = Shell.su("/su/suhide/list"); + break; + case 3: + hideList = Shell.su("/magisk/.core/magiskhide/list"); + hideList.addAll(Shell.su("/su/suhide/list")); + set.addAll(hideList); + } + if (!prefs.contains("auto_blacklist")) { Logger.dev("SplashActivity: Setting default preferences for application"); - SharedPreferences.Editor editor = defaultPrefs.edit(); - Set set = new HashSet<>(); + SharedPreferences.Editor editor = prefs.edit(); set.add("com.google.android.apps.walletnfcrel"); set.add("com.google.android.gms"); set.add("com.google.commerce.tapandpay"); @@ -40,23 +60,6 @@ public class SplashActivity extends AppCompatActivity { editor.apply(); } - // Set up toggle states based on preferences, start services, disable root if set - if (Utils.autoToggleEnabled(getApplicationContext())) { - if (!Utils.hasServicePermission(getApplicationContext())) { - Utils.toggleAutoRoot(false, getApplicationContext()); - } - } - if (Utils.autoToggleEnabled(getApplicationContext())) { - if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) { - Intent myIntent = new Intent(getApplication(), MonitorService.class); - getApplication().startService(myIntent); - } - } else if (defaultPrefs.getBoolean("keep_root_off", false)) { - Utils.toggleRoot(false, getApplication()); - } - - // Set up quick settings tile - Utils.setupQuickSettingsTile(getApplicationContext()); // Initialize prefs.edit() diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java index f55b68d99..d8d14bca1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ApplicationAdapter.java @@ -96,6 +96,8 @@ public class ApplicationAdapter extends ArrayAdapter { } + + private boolean CheckApp(String appToCheck) { boolean starter = false; Set set = prefs.getStringSet("auto_blacklist", null); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 5e3b51b36..7b55ba96a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -4,25 +4,24 @@ import android.Manifest; import android.app.DownloadManager; import android.content.Context; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Environment; +import android.preference.PreferenceManager; import android.support.v4.app.ActivityCompat; import android.util.Base64; import android.widget.Toast; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.receivers.DownloadReceiver; -import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver; -import com.topjohnwu.magisk.services.MonitorService; -import com.topjohnwu.magisk.services.TileServiceCompat; -import com.topjohnwu.magisk.services.TileServiceNewApi; import java.io.File; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import java.util.ArrayList; import java.util.List; import javax.crypto.BadPaddingException; @@ -53,6 +52,29 @@ public class Utils { } } + public static String getAppUID(String packageName) { + List retString = Shell.su("ls -nld /data/data/" + packageName); + String splitMe = retString.get(0); + String[] splitString = retString.get(0).split(" "); + return splitString[5]; + } + + public static int WhichHide(Context context) { + Boolean mh = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("magiskhide", false); + Boolean sh = Utils.itemExist("/su/suhide/add"); + if (mh && !sh) { + return 1; + } + if (sh && !mh) { + return 2; + } + if (sh && mh) { + return 3; + } + return 0; + + } + public static boolean commandExists(String s) { List ret; String command = "if [ -z $(which " + s + ") ]; then echo false; else echo true; fi"; diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml index 71dec8ffa..8471e2f7a 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -23,10 +23,10 @@ android:title="@string/downloads"/> + android:title="@string/magiskhide"/> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7a76894fd..1297a73c7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,7 +6,7 @@ Open navigation drawer Close navigation drawer - MagiskHide + MagiskHide Modules Downloads Log diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 5ed9f4448..b56b59563 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -31,34 +31,6 @@ - - - - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index 6f5ad8877..d8c8b5d16 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.1' + classpath 'com.android.tools.build:gradle:2.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files