mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Cleanup
This commit is contained in:
parent
bbae93aa16
commit
1ec333ee5a
@ -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<ApplicationInfo> applist = null;
|
||||
private ApplicationAdapter listadaptor = null;
|
||||
public ListView listView;
|
||||
public SharedPreferences prefs;
|
||||
private int hideVersion;
|
||||
List<String> 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<String> 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<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
|
||||
ArrayList<ApplicationInfo> applist = new ArrayList<>();
|
||||
for (ApplicationInfo info : list) {
|
@ -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";
|
||||
|
@ -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<Void, Void, Boolean> () {
|
||||
@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<Void, Void, Boolean> () {
|
||||
@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);
|
||||
|
@ -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<String> hideList;
|
||||
Set<String> 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<String> 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()
|
||||
|
@ -96,6 +96,8 @@ public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean CheckApp(String appToCheck) {
|
||||
boolean starter = false;
|
||||
Set<String> set = prefs.getStringSet("auto_blacklist", null);
|
||||
|
@ -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<String> 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<String> ret;
|
||||
String command = "if [ -z $(which " + s + ") ]; then echo false; else echo true; fi";
|
||||
|
@ -23,10 +23,10 @@
|
||||
android:title="@string/downloads"/>
|
||||
|
||||
<item
|
||||
<item
|
||||
android:id="@+id/autoroot"
|
||||
android:id="@+id/magiskhide"
|
||||
android:icon="@drawable/ic_autoroot"
|
||||
android:title="@string/auto_toggle"/>
|
||||
android:title="@string/magiskhide"/>
|
||||
<item
|
||||
android:id="@+id/log"
|
||||
android:icon="@drawable/ic_bug_report"
|
||||
android:title="@string/log"/>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<!--Welcome Activity-->
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="auto_toggle">MagiskHide</string>
|
||||
<string name="magiskhide">MagiskHide</string>
|
||||
<string name="modules">Modules</string>
|
||||
<string name="downloads">Downloads</string>
|
||||
<string name="log">Log</string>
|
||||
|
@ -31,34 +31,6 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_quicksettings_category">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="enable_quicktile"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/settings_enable_quicktile_title"
|
||||
android:summary="@string/settings_enable_quicktile_summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_root_category">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="keep_root_off"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/settings_keep_root_off_title"
|
||||
android:summary="@string/settings_keep_root_off_summary" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="hide_root_notification"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/settings_hide_root_notification_title"
|
||||
android:summary="@string/settings_hide_root_notification_summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_development_category">
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user