public static VUserHandle getCallingUserHandle() { return new VUserHandle(VUserHandle.getUserId(getCallingUid())); } }
/** * Returns true if this VUserHandle refers to the owner user; false otherwise. * @return true if this VUserHandle refers to the owner user; false otherwise. * @hide */ public final boolean isOwner() { return this.equals(OWNER); }
/** * Generate a text representation of the vuid, breaking out its individual * components -- user, app, isolated, etc. * @hide */ public static String formatUid(int uid) { StringBuilder sb = new StringBuilder(); formatUid(sb, uid); return sb.toString(); }
public static VUserHandle myUserHandle() { return new VUserHandle(myUserId()); }
@Override public String[] getPackagesForUid(int uid) { int userId = VUserHandle.getUserId(uid); checkUserId(userId); synchronized (this) { List<String> pkgList = new ArrayList<>(2); for (VPackage p : mPackages.values()) { PackageSetting settings = (PackageSetting) p.mExtras; if (VUserHandle.getUid(userId, settings.appId) == uid) { pkgList.add(p.packageName); } } return pkgList.toArray(new String[pkgList.size()]); } }
/** * Return the serial number for a user. This is a device-unique * number assigned to that user; if the user is deleted and then a new * user created, the new users will not be given the same serial number. * @param user The user whose serial number is to be retrieved. * @return The serial number of the given user; returns -1 if the * given VUserHandle does not exist. * @see #getUserForSerialNumber(long) */ public long getSerialNumberForUser(VUserHandle user) { return getUserSerialNumber(user.getIdentifier()); }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { String permName = (String) args[0]; String pkgName = (String) args[1]; int userId = VUserHandle.myUserId(); return VPackageManager.get().checkPermission(permName, pkgName, userId); }
@Override public int getPackageUid(String packageName, int userId) { checkUserId(userId); synchronized (mPackages) { VPackage p = mPackages.get(packageName); if (p != null) { PackageSetting ps = (PackageSetting) p.mExtras; return VUserHandle.getUid(userId, ps.appId); } return -1; } }
/** @hide */ public static boolean isApp(int uid) { if (uid > 0) { final int appId = getAppId(uid); return appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID; } else { return false; } }
public static void formatUid(StringBuilder sb, int uid) { if (uid < Process.FIRST_APPLICATION_UID) { sb.append(uid); } else { sb.append('u'); sb.append(getUserId(uid)); final int appId = getAppId(uid); if (appId >= FIRST_ISOLATED_UID && appId <= LAST_ISOLATED_UID) { sb.append('i'); sb.append(appId - FIRST_ISOLATED_UID); } else if (appId >= Process.FIRST_APPLICATION_UID) { sb.append('a'); sb.append(appId - Process.FIRST_APPLICATION_UID); } else { sb.append('s'); sb.append(appId); } } }
/** * Read a VUserHandle from a Parcel that was previously written * with {@link #writeToParcel(VUserHandle, Parcel)}, returning either * a null or new object as appropriate. * * @param in The Parcel from which to read the VUserHandle * @return Returns a new VUserHandle matching the previously written * object, or null if a null had been written. * * @see #writeToParcel(VUserHandle, Parcel) */ public static VUserHandle readFromParcel(Parcel in) { int h = in.readInt(); return h != USER_NULL ? new VUserHandle(h) : null; }
@SuppressLint("MissingSuperCall") @Override protected void onCreate(Bundle savedInstanceState) { final int titleResource; final Intent intent = makeMyIntent(); final Set<String> categories = intent.getCategories(); if (Intent.ACTION_MAIN.equals(intent.getAction()) && categories != null && categories.size() == 1 && categories.contains(Intent.CATEGORY_HOME)) { titleResource = R.string.choose; } else { titleResource = R.string.choose; } onCreate(savedInstanceState, intent, getResources().getText(titleResource), null, null, true, VUserHandle.getCallingUserId()); }
/** * Write a VUserHandle to a Parcel, handling null pointers. Must be * read with {@link #readFromParcel(Parcel)}. * * @param h The VUserHandle to be written. * @param out The Parcel in which the VUserHandle will be placed. * * @see #readFromParcel(Parcel) */ public static void writeToParcel(VUserHandle h, Parcel out) { if (h != null) { h.writeToParcel(out, 0); } else { out.writeInt(USER_NULL); } }
public void sendBroadcastAsUser(Intent intent, VUserHandle user) { SpecialComponentList.protectIntent(intent); Context context = VirtualCore.get().getContext(); if (user != null) { intent.putExtra("_VA_|_user_id_", user.getIdentifier()); } context.sendBroadcast(intent); }
public AuthenticatorDescription[] getAuthenticatorTypes() { try { return getRemote().getAuthenticatorTypes(VUserHandle.myUserId()); } catch (RemoteException e) { return VirtualRuntime.crash(e); } }
private void sendFirstLaunchBroadcast(PackageSetting ps, int userId) { Intent intent = new Intent(Intent.ACTION_PACKAGE_FIRST_LAUNCH, Uri.fromParts("package", ps.packageName, null)); intent.setPackage(ps.packageName); intent.putExtra(Intent.EXTRA_UID, VUserHandle.getUid(ps.appId, userId)); intent.putExtra("android.intent.extra.user_handle", userId); sendBroadcastAsUser(intent, null); }
/** * Checks to see if both uids are referring to the same app id, ignoring the user id part of the * uids. * @param uid1 vuid to compare * @param uid2 other vuid to compare * @return whether the appId is the same for both uids * @hide */ public static final boolean isSameApp(int uid1, int uid2) { return getAppId(uid1) == getAppId(uid2); }
@Override public String[] getPackagesForUid(int uid) { int userId = VUserHandle.getUserId(uid); checkUserId(userId); synchronized (this) { List<String> pkgList = new ArrayList<>(2); for (VPackage p : mPackages.values()) { PackageSetting settings = (PackageSetting) p.mExtras; if (VUserHandle.getUid(userId, settings.appId) == uid) { pkgList.add(p.packageName); } } return pkgList.toArray(new String[pkgList.size()]); } }
/** * Generate a text representation of the vuid, breaking out its individual * components -- user, app, isolated, etc. * @hide */ public static void formatUid(PrintWriter pw, int uid) { if (uid < Process.FIRST_APPLICATION_UID) { pw.print(uid); } else { pw.print('u'); pw.print(getUserId(uid)); final int appId = getAppId(uid); if (appId >= FIRST_ISOLATED_UID && appId <= LAST_ISOLATED_UID) { pw.print('i'); pw.print(appId - FIRST_ISOLATED_UID); } else if (appId >= Process.FIRST_APPLICATION_UID) { pw.print('a'); pw.print(appId - Process.FIRST_APPLICATION_UID); } else { pw.print('s'); pw.print(appId); } } }