Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Commit

Permalink
Change new magisk database
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Dec 11, 2017
1 parent aa75c8e commit fd6cbb1
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 181 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/topjohnwu/magisk/LogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.topjohnwu.magisk.adapters.TabFragmentAdapter;
import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.utils.Const;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -33,7 +34,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

TabFragmentAdapter adapter = new TabFragmentAdapter(getChildFragmentManager());

adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
if (!(Const.USER_ID > 0 && getApplication().multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
}
adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk));
tab.setupWithViewPager(viewPager);
tab.setVisibility(View.VISIBLE);
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/topjohnwu/magisk/MagiskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class MagiskManager extends Application {

// Info
public boolean hasInit = false;
public int userId;
public String magiskVersionString;
public int magiskVersionCode = -1;
public String remoteMagiskVersionString;
Expand Down Expand Up @@ -95,14 +94,6 @@ public MagiskManager() {
public void onCreate() {
super.onCreate();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
userId = getApplicationInfo().uid / 100000;

if (Utils.getDatabasePath(this, SuDatabaseHelper.DB_NAME).exists()) {
// Don't migrate yet, wait and check Magisk version
suDB = new SuDatabaseHelper(this);
} else {
suDB = new SuDatabaseHelper();
}

// Handle duplicate package
if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
Expand All @@ -113,11 +104,15 @@ public void onCreate() {
startActivity(intent);
return;
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
} else {
}

suDB = new SuDatabaseHelper(true);

if (getPackageName().equals(Const.ORIG_PKG_NAME)) {
String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null);
if (pkg != null) {
suDB.setStrings(Const.Key.SU_REQUESTER, null);
Shell.su_raw("pm uninstall " + pkg);
Utils.uninstallPkg(pkg);
}
}

Expand Down Expand Up @@ -216,6 +211,11 @@ public void loadMagiskInfo() {
} catch (NumberFormatException e) {
keepEnc = false;
}

if (suDB != null) {
suDB.close();
suDB = new SuDatabaseHelper();
}
}

public void setPermissionGrantCallback(Runnable callback) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/topjohnwu/magisk/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ public void checkHideSection() {
menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && mm.magiskVersionCode >= 1300
&& prefs.getBoolean(Const.Key.MAGISKHIDE, false));
menu.findItem(R.id.modules).setVisible(
menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) &&
Shell.rootAccess() && mm.magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus() &&
Shell.rootAccess() && mm.magiskVersionCode >= 0);
menu.setGroupVisible(R.id.second_group, !mm.prefs.getBoolean(Const.Key.COREONLY, false));
menu.findItem(R.id.downloads).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false)
&& Utils.checkNetworkStatus() && Shell.rootAccess() && mm.magiskVersionCode >= 0);
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(Shell.rootAccess() &&
!(Const.USER_ID > 0 && mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED));
}

public void navigate(String item) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/topjohnwu/magisk/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ public void onCreate(Bundle savedInstanceState) {

setSummary();

// Disable dangerous settings in user mode if selected owner manage
if (mm.userId > 0) {
// Disable dangerous settings in secondary user
if (Const.USER_ID > 0) {
suCategory.removePreference(multiuserMode);
}

// Remove re-authentication option on Android O, it will not work
// Disable re-authentication option on Android O, it will not work
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
reauth.setEnabled(false);
reauth.setSummary(R.string.android_o_not_support);
Expand All @@ -155,9 +155,13 @@ public void onCreate(Bundle savedInstanceState) {
generalCatagory.removePreference(hideManager);
}

if (!Shell.rootAccess() || (Const.USER_ID > 0 &&
mm.multiuserMode == Const.Value.MULTIUSER_MODE_OWNER_MANAGED)) {
prefScreen.removePreference(suCategory);
}

if (!Shell.rootAccess()) {
prefScreen.removePreference(magiskCategory);
prefScreen.removePreference(suCategory);
generalCatagory.removePreference(hideManager);
} else if (mm.magiskVersionCode < 1300) {
prefScreen.removePreference(magiskCategory);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/topjohnwu/magisk/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.asyncs.UpdateRepos;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.database.SuDatabaseHelper;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Const;
import com.topjohnwu.magisk.utils.Shell;
Expand Down Expand Up @@ -68,9 +67,6 @@ protected void onCreate(Bundle savedInstanceState) {
mm.bootBlock = ret.get(0);
}

// Setup suDB
SuDatabaseHelper.setupSuDB();

// Add update checking service
if (Const.Value.UPDATE_SERVICE_VER > mm.prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1)) {
ComponentName service = new ComponentName(this, UpdateCheckService.class);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FlashZip(Activity context, Uri uri, List<String> console, List<String> lo

private boolean unzipAndCheck() throws Exception {
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android", true);
List<String> ret = Utils.readFile(new File(mCachedFile.getParentFile(), "updater-script").getPath());
List<String> ret = Utils.readFile(new File(mCachedFile.getParentFile(), "updater-script"));
return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK");
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.FileInputStream;
import java.security.SecureRandom;
import java.util.List;
import java.util.Locale;
import java.util.jar.JarEntry;

public class HideManager extends ParallelTask<Void, Void, Boolean> {
Expand Down Expand Up @@ -130,7 +129,7 @@ protected Boolean doInBackground(Void... voids) {

mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
Utils.dumpPrefs();
Shell.su_raw("pm uninstall " + Const.ORIG_PKG_NAME);
Utils.uninstallPkg(Const.ORIG_PKG_NAME);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.List;

public class RestoreStockBoot extends ParallelTask<Void, Void, Boolean> {
public class RestoreImages extends ParallelTask<Void, Void, Boolean> {

@Override
protected Boolean doInBackground(Void... voids) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/topjohnwu/magisk/container/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Policy implements Comparable<Policy>{
public Policy(int uid, PackageManager pm) throws PackageManager.NameNotFoundException {
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs == null || pkgs.length == 0) throw new PackageManager.NameNotFoundException();
this.uid = uid % 100000;
this.uid = uid;
packageName = pkgs[0];
info = pm.getApplicationInfo(packageName, 0);
appName = info.loadLabel(pm).toString();
Expand Down
Loading

0 comments on commit fd6cbb1

Please sign in to comment.