mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
Fix permission grant inside work profile
This commit is contained in:
parent
4a44fa28af
commit
9c7a1d0952
@ -41,7 +41,6 @@ import java.util.Arrays;
|
||||
|
||||
public class AppsResolver {
|
||||
private static final String TAG = "AppsResolver";
|
||||
public static final int PER_USER_RANGE = 100000;
|
||||
private final SparseArray<AppDescriptor> mApps;
|
||||
private final PackageManager mPm;
|
||||
private final Context mContext;
|
||||
@ -140,7 +139,7 @@ public class AppsResolver {
|
||||
if(getPackageInfoAsUser == null)
|
||||
getPackageInfoAsUser = PackageManager.class.getDeclaredMethod("getPackageInfoAsUser", String.class, int.class, int.class);
|
||||
|
||||
PackageInfo pinfo = (PackageInfo) getPackageInfoAsUser.invoke(mPm, packageName, pm_flags, uid / PER_USER_RANGE);
|
||||
PackageInfo pinfo = (PackageInfo) getPackageInfoAsUser.invoke(mPm, packageName, pm_flags, Utils.getUserId(uid));
|
||||
if(pinfo != null)
|
||||
return new AppDescriptor(mPm, pinfo);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
|
||||
@ -421,7 +421,7 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
} else {
|
||||
// Root capture
|
||||
if(checkCallingOrSelfPermission(Utils.INTERACT_ACROSS_USERS) != PackageManager.PERMISSION_GRANTED) {
|
||||
boolean success = Utils.rootGrantPermission(Utils.INTERACT_ACROSS_USERS);
|
||||
boolean success = Utils.rootGrantPermission(this, Utils.INTERACT_ACROSS_USERS);
|
||||
Utils.showToast(this, success ? R.string.permission_granted : R.string.permission_grant_fail, "INTERACT_ACROSS_USERS");
|
||||
}
|
||||
}
|
||||
@ -1021,15 +1021,6 @@ public class CaptureService extends VpnService implements Runnable {
|
||||
|
||||
public int blockQuick() { return(mSettings.block_quic ? 1 : 0); }
|
||||
|
||||
public int getOwnAppUid() {
|
||||
AppDescriptor app = AppsResolver.resolve(getPackageManager(), BuildConfig.APPLICATION_ID, 0);
|
||||
|
||||
if(app != null)
|
||||
return app.getUid();
|
||||
|
||||
return Utils.UID_NO_FILTER;
|
||||
}
|
||||
|
||||
// returns 1 if dumpPcapData should be called
|
||||
public int pcapDumpEnabled() {
|
||||
return((mSettings.dump_mode != Prefs.DumpMode.NONE) ? 1 : 0);
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
package com.emanuelef.remote_capture;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.PendingIntent;
|
||||
@ -128,6 +129,7 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
public class Utils {
|
||||
static final String TAG = "Utils";
|
||||
public static final String INTERACT_ACROSS_USERS = "android.permission.INTERACT_ACROSS_USERS";
|
||||
public static final int PER_USER_RANGE = 100000;
|
||||
public static final int UID_UNKNOWN = -1;
|
||||
public static final int UID_NO_FILTER = -2;
|
||||
private static Boolean rootAvailable = null;
|
||||
@ -1184,7 +1186,21 @@ public class Utils {
|
||||
tv.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public static boolean rootGrantPermission(String perm) {
|
||||
return CaptureService.rootCmd("pm", String.format("grant %s %s", BuildConfig.APPLICATION_ID, perm)) == 0;
|
||||
public static int getPCAPdroidUid(Context context) {
|
||||
// NOTE: when called from a work profile, it correctly returns the work profile UID
|
||||
AppDescriptor app = AppsResolver.resolve(context.getPackageManager(), BuildConfig.APPLICATION_ID, 0);
|
||||
if(app != null)
|
||||
return app.getUid();
|
||||
return Utils.UID_UNKNOWN;
|
||||
}
|
||||
|
||||
// returns the user ID of a given app uid
|
||||
public static int getUserId(int uid) {
|
||||
return uid / PER_USER_RANGE;
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static boolean rootGrantPermission(Context context, String perm) {
|
||||
return CaptureService.rootCmd("pm", String.format("grant --user %d %s %s", getUserId(getPCAPdroidUid(context)), BuildConfig.APPLICATION_ID, perm)) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user