Magisk/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java

66 lines
2.1 KiB
Java
Raw Normal View History

2017-02-07 02:01:32 +08:00
package com.topjohnwu.magisk;
import android.content.SharedPreferences;
2017-10-21 22:54:47 +08:00
import android.content.pm.PackageManager;
2018-08-01 14:16:44 +08:00
import android.content.res.Configuration;
2017-02-07 02:01:32 +08:00
import android.preference.PreferenceManager;
2018-02-12 23:07:35 +08:00
import android.text.TextUtils;
2017-02-07 02:01:32 +08:00
2018-04-06 01:54:09 +08:00
import com.topjohnwu.magisk.database.MagiskDatabaseHelper;
2018-04-07 00:45:10 +08:00
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
2018-07-31 17:35:58 +08:00
import com.topjohnwu.magisk.utils.LocaleManager;
2018-06-02 22:00:52 +08:00
import com.topjohnwu.magisk.utils.RootUtils;
2018-07-30 20:37:00 +08:00
import com.topjohnwu.superuser.ContainerApp;
2018-01-21 06:07:24 +08:00
import com.topjohnwu.superuser.Shell;
2018-06-02 22:00:52 +08:00
2017-10-16 00:54:48 +08:00
import java.lang.ref.WeakReference;
2017-02-07 02:01:32 +08:00
2018-07-30 20:37:00 +08:00
public class MagiskManager extends ContainerApp {
2017-02-07 02:01:32 +08:00
// Info
2017-11-06 04:47:24 +08:00
public boolean hasInit = false;
2017-02-07 02:01:32 +08:00
2017-06-01 00:19:52 +08:00
// Global resources
2017-02-07 02:01:32 +08:00
public SharedPreferences prefs;
2018-04-06 01:54:09 +08:00
public MagiskDatabaseHelper mDB;
2017-07-21 00:46:13 +08:00
public RepoDatabaseHelper repoDB;
2017-02-07 02:01:32 +08:00
2017-10-16 11:51:34 +08:00
public MagiskManager() {
2018-07-31 17:41:54 +08:00
Data.weakApp = new WeakReference<>(this);
2018-02-12 23:07:35 +08:00
}
@Override
public void onCreate() {
super.onCreate();
2018-07-27 04:48:32 +08:00
Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER);
Shell.Config.verboseLogging(BuildConfig.DEBUG);
Shell.Config.setInitializer(RootUtils.class);
2017-10-16 11:51:34 +08:00
2017-08-12 01:31:34 +08:00
prefs = PreferenceManager.getDefaultSharedPreferences(this);
2018-04-06 01:54:09 +08:00
mDB = MagiskDatabaseHelper.getInstance(this);
2018-02-13 03:27:27 +08:00
String pkg = mDB.getStrings(Const.Key.SU_MANAGER, null);
if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) {
mDB.setStrings(Const.Key.SU_MANAGER, null);
Shell.su("pm uninstall " + pkg).exec();
}
if (TextUtils.equals(pkg, getPackageName())) {
try {
// We are the manager, remove com.topjohnwu.magisk as it could be malware
getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
RootUtils.uninstallPkg(Const.ORIG_PKG_NAME);
} catch (PackageManager.NameNotFoundException ignored) {}
2018-02-13 03:27:27 +08:00
}
2018-08-01 14:16:44 +08:00
LocaleManager.setLocale(this);
2018-07-31 17:41:54 +08:00
Data.loadConfig();
2017-08-12 01:31:34 +08:00
}
2018-08-01 14:16:44 +08:00
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleManager.setLocale(this);
}
2017-02-07 02:01:32 +08:00
}