Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Multi-user fixes
Browse files Browse the repository at this point in the history
refs #357
  • Loading branch information
M66B committed Dec 26, 2013
1 parent 6171aa1 commit 88129e5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,17 @@ public static boolean getRestricted(XHook hook, int uid, String permission) {
public static final int LAST_SHARED_APPLICATION_GID = 59999;

public static boolean isApplication(int uid) {
uid = Util.getAppId(uid);
return (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID);
}

public static boolean isShared(int uid) {
uid = Util.getAppId(uid);
return (uid >= FIRST_SHARED_APPLICATION_GID && uid <= LAST_SHARED_APPLICATION_GID);
}

public static boolean isIsolated(int uid) {
uid = Util.getAppId(uid);
return (uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID);
}

Expand All @@ -417,7 +420,7 @@ private static boolean isProviderUsable(Context context) {
if (isIsolated(Process.myUid()))
return false;

if (Process.myUid() == cAndroidUid)
if (Util.getAppId(Process.myUid()) == cAndroidUid)
if (!PrivacyManager.getSettingBool(null, null, 0, PrivacyManager.cSettingAndroidUsage, false, false))
return false;

Expand Down
14 changes: 1 addition & 13 deletions src/biz/bokhorst/xprivacy/PrivacyProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand All @@ -26,9 +25,7 @@
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -514,17 +511,8 @@ public static void flush() {

// Helper methods

@SuppressLint("NewApi")
private void enforcePermission() throws SecurityException {
// UserHandle: public static final int getAppId(int uid)
int uid = Binder.getCallingUid();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
try {
Method method = (Method) UserHandle.class.getDeclaredMethod("getAppId", int.class);
uid = (Integer) method.invoke(null, uid);
} catch (Throwable ex) {
Util.bug(null, ex);
}
int uid = Util.getAppId(Binder.getCallingUid());
if (uid != Process.myUid())
throw new SecurityException();
}
Expand Down
23 changes: 20 additions & 3 deletions src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,36 @@ public static String hasProLicense(Context context) {
}

@SuppressLint("NewApi")
public static String getUserDataDirectory() {
// UserHandle: public static final int getUserId(int uid)
public static int getAppId(int uid) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
try {
// UserHandle: public static final int getAppId(int uid)
Method method = (Method) UserHandle.class.getDeclaredMethod("getAppId", int.class);
uid = (Integer) method.invoke(null, uid);
} catch (Throwable ex) {
Util.bug(null, ex);
}
return uid;
}

@SuppressLint("NewApi")
public static int getUserId(int uid) {
int userId = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
try {
// UserHandle: public static final int getUserId(int uid)
Method method = (Method) UserHandle.class.getDeclaredMethod("getUserId", int.class);
userId = (Integer) method.invoke(null, Process.myUid());
userId = (Integer) method.invoke(null, uid);
} catch (Throwable ex) {
Util.bug(null, ex);
}
return userId;
}

public static String getUserDataDirectory() {
// Build data directory
String dataDir = Environment.getDataDirectory() + File.separator;
int userId = getUserId(Process.myUid());
if (userId == 0 && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
dataDir += "data";
else
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void after(MethodHookParam param) throws Throwable {
}

// Install receiver for package management
if (Process.myUid() != PrivacyManager.cAndroidUid) {
if (Util.getAppId(Process.myUid()) != PrivacyManager.cAndroidUid) {
boolean experimental = PrivacyManager.getSettingBool(null, null, 0,
PrivacyManager.cSettingExperimental, PrivacyManager.cTestVersion, true);
if (experimental && !mReceiverInstalled)
Expand Down
2 changes: 1 addition & 1 deletion src/biz/bokhorst/xprivacy/XIoBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void before(MethodHookParam param) throws Throwable {
String fileName = (String) param.args[0];
if (fileName != null && (fileName.startsWith(mFileName) || mFileName.contains("..."))) {
// Zygote, Android
if (Process.myUid() <= 0 || Process.myUid() == PrivacyManager.cAndroidUid)
if (Process.myUid() <= 0 || Util.getAppId(Process.myUid()) == PrivacyManager.cAndroidUid)
return;

// /proc
Expand Down

0 comments on commit 88129e5

Please sign in to comment.