Fix UID stored in multiuser mode

This commit is contained in:
topjohnwu 2017-10-28 15:12:29 +08:00
parent f5cc2af5d0
commit 4956d826fb
5 changed files with 27 additions and 28 deletions

View File

@ -110,7 +110,6 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
// Disable dangerous settings in user mode if selected owner manage
if (mm.userId > 0) {
suCategory.removePreference(multiuserMode);
generalCatagory.removePreference(hideManager);
}
// Remove re-authentication option on Android O, it will not work

View File

@ -20,12 +20,11 @@ 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) {
this.uid = uid;
packageName = pkgs[0];
info = pm.getApplicationInfo(packageName, 0);
appName = info.loadLabel(pm).toString();
} else throw new PackageManager.NameNotFoundException();
if (pkgs == null || pkgs.length == 0) throw new PackageManager.NameNotFoundException();
this.uid = uid % 100000;
packageName = pkgs[0];
info = pm.getApplicationInfo(packageName, 0);
appName = info.loadLabel(pm).toString();
}
public Policy(Cursor c, PackageManager pm) throws PackageManager.NameNotFoundException {

View File

@ -44,7 +44,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
public static final String REQUESTER = "requester";
public static final String DB_NAME = "su.db";
private static final int DATABASE_VER = 4;
private static final int DATABASE_VER = 5;
private static final String POLICY_TABLE = "policies";
private static final String LOG_TABLE = "logs";
private static final String SETTINGS_TABLE = "settings";
@ -166,6 +166,10 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
"(key TEXT, value TEXT, PRIMARY KEY(key))");
++oldVersion;
}
if (oldVersion == 4) {
db.execSQL("UPDATE " + POLICY_TABLE + " SET uid=uid%100000");
++oldVersion;
}
if (!Utils.itemExist(GLOBAL_DB)) {
// Hard link our DB globally
@ -173,6 +177,15 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
}
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Remove everything, we do not support downgrade
db.delete(POLICY_TABLE, null, null);
db.delete(LOG_TABLE, null, null);
db.delete(SETTINGS_TABLE, null, null);
db.delete(STRINGS_TABLE, null, null);
}
public File getDbFile() {
return mContext.getDatabasePath(DB_NAME);
}
@ -220,7 +233,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
public Policy getPolicy(int uid) {
Policy policy = null;
try (Cursor c = mDb.query(POLICY_TABLE, null, "uid=?", new String[] { String.valueOf(uid) }, null, null, null)) {
try (Cursor c = mDb.query(POLICY_TABLE, null, "uid=?", new String[] { String.valueOf(uid % 100000) }, null, null, null)) {
if (c.moveToNext()) {
policy = new Policy(c, pm);
}
@ -259,18 +272,6 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
while (c.moveToNext()) {
try {
Policy policy = new Policy(c, pm);
// The application changed UID for some reason, check user config
if (policy.info.uid != policy.uid) {
if (MagiskManager.get().suReauth) {
// Reauth required, remove from DB
deletePolicy(policy);
continue;
} else {
// No reauth, update to use the new UID
policy.uid = policy.info.uid;
updatePolicy(policy);
}
}
ret.add(policy);
} catch (PackageManager.NameNotFoundException e) {
// The app no longer exist, remove from DB

View File

@ -48,7 +48,7 @@ public class SuRequestActivity extends Activity {
private String socketPath;
private LocalSocket socket;
private PackageManager pm;
private MagiskManager magiskManager;
private MagiskManager mm;
private boolean hasTimeout;
private Policy policy;
@ -60,7 +60,7 @@ public class SuRequestActivity extends Activity {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
pm = getPackageManager();
magiskManager = getMagiskManager();
mm = getMagiskManager();
Intent intent = getIntent();
socketPath = intent.getStringExtra("socket");
@ -85,7 +85,7 @@ public class SuRequestActivity extends Activity {
}
private void showRequest() {
switch (magiskManager.suResponseType) {
switch (mm.suResponseType) {
case AUTO_DENY:
handleAction(Policy.DENY, 0);
return;
@ -114,7 +114,7 @@ public class SuRequestActivity extends Activity {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeout.setAdapter(adapter);
timer = new CountDownTimer(magiskManager.suRequestTimeout * 1000, 1000) {
timer = new CountDownTimer(mm.suRequestTimeout * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")"));
@ -176,7 +176,7 @@ public class SuRequestActivity extends Activity {
policy.policy = action;
if (time >= 0) {
policy.until = (time == 0) ? 0 : (System.currentTimeMillis() / 1000 + time * 60);
magiskManager.suDB.addPolicy(policy);
mm.suDB.addPolicy(policy);
}
handleAction();
}
@ -216,7 +216,7 @@ public class SuRequestActivity extends Activity {
}
int uid = payload.getAsInteger("uid");
policy = magiskManager.suDB.getPolicy(uid);
policy = mm.suDB.getPolicy(uid);
if (policy == null) {
policy = new Policy(uid, pm);
}

View File

@ -8,7 +8,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc1'
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files