Java Code Examples for android.os.UserHandle#getUid()
The following examples show how to use
android.os.UserHandle#getUid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceEncryptedDataDir = deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialEncryptedDataDir = credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 2
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 3
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 4
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 5
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 6
Source File: ApplicationInfo.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceEncryptedDataDir = deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialEncryptedDataDir = credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 7
Source File: NetworkStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Clean up {@link #mUidRecorder} after user is removed. */ @GuardedBy("mStatsLock") private void removeUserLocked(int userId) { if (LOGV) Slog.v(TAG, "removeUserLocked() for userId=" + userId); // Build list of UIDs that we should clean up int[] uids = new int[0]; final List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications( PackageManager.MATCH_ANY_USER | PackageManager.MATCH_DISABLED_COMPONENTS); for (ApplicationInfo app : apps) { final int uid = UserHandle.getUid(userId, app.uid); uids = ArrayUtils.appendInt(uids, uid); } removeUidsLocked(uids); }
Example 8
Source File: ApplicationInfo.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** {@hide} */ public void initForUser(int userId) { uid = UserHandle.getUid(userId, UserHandle.getAppId(uid)); if ("android".equals(packageName)) { dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); return; } deviceProtectedDataDir = Environment .getDataUserDePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); credentialProtectedDataDir = Environment .getDataUserCePackageDirectory(volumeUuid, userId, packageName) .getAbsolutePath(); if ((privateFlags & PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { dataDir = deviceProtectedDataDir; } else { dataDir = credentialProtectedDataDir; } }
Example 9
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
public static ApplicationInfo generateApplicationInfo(Package p, int flags, PackageUserState state, int userId) { if (p == null) return null; if (!checkUseInstalled(flags, state)) { return null; } if (!copyNeeded(flags, p, state, null, userId) && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { // In this case it is safe to directly modify the internal ApplicationInfo state: // - CompatibilityMode is global state, so will be the same for every call. // - We only come in to here if the app should reported as installed; this is the // default state, and we will do a copy otherwise. // - The enable state will always be reported the same for the application across // calls; the only exception is for the UNTIL_USED mode, and in that case we will // be doing a copy. updateApplicationInfo(p.applicationInfo, flags, state); return p.applicationInfo; } // Make shallow copy so we can store the metadata/libraries safely ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); if (userId != 0) { ai.uid = UserHandle.getUid(userId, ai.uid); ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName); } if ((flags & PackageManager.GET_META_DATA) != 0) { ai.metaData = p.mAppMetaData; } if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { ai.sharedLibraryFiles = p.usesLibraryFiles; } if (state.stopped) { ai.flags |= ApplicationInfo.FLAG_STOPPED; } else { ai.flags &= ~ApplicationInfo.FLAG_STOPPED; } updateApplicationInfo(ai, flags, state); return ai; }
Example 10
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
public static ApplicationInfo generateApplicationInfo(Package p, int flags, PackageUserState state, int userId) { if (p == null) return null; if (!checkUseInstalledOrBlocked(flags, state)) { return null; } if (!copyNeeded(flags, p, state, null, userId) && ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0 || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) { // In this case it is safe to directly modify the internal ApplicationInfo state: // - CompatibilityMode is global state, so will be the same for every call. // - We only come in to here if the app should reported as installed; this is the // default state, and we will do a copy otherwise. // - The enable state will always be reported the same for the application across // calls; the only exception is for the UNTIL_USED mode, and in that case we will // be doing a copy. updateApplicationInfo(p.applicationInfo, flags, state); return p.applicationInfo; } // Make shallow copy so we can store the metadata/libraries safely ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); if (userId != 0) { ai.uid = UserHandle.getUid(userId, ai.uid); ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName); } if ((flags & PackageManager.GET_META_DATA) != 0) { ai.metaData = p.mAppMetaData; } if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { ai.sharedLibraryFiles = p.usesLibraryFiles; } if (state.stopped) { ai.flags |= ApplicationInfo.FLAG_STOPPED; } else { ai.flags &= ~ApplicationInfo.FLAG_STOPPED; } updateApplicationInfo(ai, flags, state); return ai; }
Example 11
Source File: BasePermission.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public int[] computeGids(int userId) { if (perUser) { final int[] userGids = new int[gids.length]; for (int i = 0; i < gids.length; i++) { userGids[i] = UserHandle.getUid(userId, gids[i]); } return userGids; } else { return gids; } }
Example 12
Source File: AppErrors.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
void resetProcessCrashTimeLocked(boolean resetEntireUser, int appId, int userId) { final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap(); for (int ip = pmap.size() - 1; ip >= 0; ip--) { SparseArray<Long> ba = pmap.valueAt(ip); for (int i = ba.size() - 1; i >= 0; i--) { boolean remove = false; final int entUid = ba.keyAt(i); if (!resetEntireUser) { if (userId == UserHandle.USER_ALL) { if (UserHandle.getAppId(entUid) == appId) { remove = true; } } else { if (entUid == UserHandle.getUid(userId, appId)) { remove = true; } } } else if (UserHandle.getUserId(entUid) == userId) { remove = true; } if (remove) { ba.removeAt(i); } } if (ba.size() == 0) { pmap.removeAt(ip); } } }
Example 13
Source File: PackageParser.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
public static ApplicationInfo generateApplicationInfo(Package p, int flags, PackageUserState state, int userId) { if (p == null) return null; if (!checkUseInstalled(flags, state)) { return null; } if (!copyNeeded(flags, p, state, null, userId)) { // CompatibilityMode is global state. It's safe to modify the instance // of the package. if (!sCompatibilityModeEnabled) { p.applicationInfo.disableCompatibilityMode(); } // Make sure we report as installed. Also safe to do, since the // default state should be installed (we will always copy if we // need to report it is not installed). p.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED; if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { p.applicationInfo.enabled = true; } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { p.applicationInfo.enabled = false; } p.applicationInfo.enabledSetting = state.enabled; return p.applicationInfo; } // Make shallow copy so we can store the metadata/libraries safely ApplicationInfo ai = new ApplicationInfo(p.applicationInfo); if (userId != 0) { ai.uid = UserHandle.getUid(userId, ai.uid); ai.dataDir = PackageManager.getDataDirForUser(userId, ai.packageName); } if ((flags & PackageManager.GET_META_DATA) != 0) { ai.metaData = p.mAppMetaData; } if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) { ai.sharedLibraryFiles = p.usesLibraryFiles; } if (!sCompatibilityModeEnabled) { ai.disableCompatibilityMode(); } if (state.stopped) { ai.flags |= ApplicationInfo.FLAG_STOPPED; } else { ai.flags &= ~ApplicationInfo.FLAG_STOPPED; } if (state.installed) { ai.flags |= ApplicationInfo.FLAG_INSTALLED; } else { ai.flags &= ~ApplicationInfo.FLAG_INSTALLED; } if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { ai.enabled = true; } else if (state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED || state.enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) { ai.enabled = false; } ai.enabledSetting = state.enabled; return ai; }
Example 14
Source File: PermissionManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void revokeRuntimePermission(String permName, String packageName, boolean overridePolicy, int callingUid, int userId, PermissionCallback callback) { if (!mUserManagerInt.exists(userId)) { Log.e(TAG, "No such user:" + userId); return; } mContext.enforceCallingOrSelfPermission( android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS, "revokeRuntimePermission"); enforceCrossUserPermission(Binder.getCallingUid(), userId, true, // requireFullPermission true, // checkShell false, // requirePermissionWhenSameUser "revokeRuntimePermission"); final int appId; final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); if (pkg == null || pkg.mExtras == null) { throw new IllegalArgumentException("Unknown package: " + packageName); } if (mPackageManagerInt.filterAppAccess(pkg, Binder.getCallingUid(), userId)) { throw new IllegalArgumentException("Unknown package: " + packageName); } final BasePermission bp = mSettings.getPermissionLocked(permName); if (bp == null) { throw new IllegalArgumentException("Unknown permission: " + permName); } bp.enforceDeclaredUsedAndRuntimeOrDevelopment(pkg); // If a permission review is required for legacy apps we represent // their permissions as always granted runtime ones since we need // to keep the review required permission flag per user while an // install permission's state is shared across all users. if (mSettings.mPermissionReviewRequired && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M && bp.isRuntime()) { return; } final PackageSetting ps = (PackageSetting) pkg.mExtras; final PermissionsState permissionsState = ps.getPermissionsState(); final int flags = permissionsState.getPermissionFlags(permName, userId); // Only the system may revoke SYSTEM_FIXED permissions. if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0 && UserHandle.getCallingAppId() != Process.SYSTEM_UID) { throw new SecurityException("Non-System UID cannot revoke system fixed permission " + permName + " for package " + packageName); } if (!overridePolicy && (flags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != 0) { throw new SecurityException("Cannot revoke policy fixed permission " + permName + " for package " + packageName); } if (bp.isDevelopment()) { // Development permissions must be handled specially, since they are not // normal runtime permissions. For now they apply to all users. if (permissionsState.revokeInstallPermission(bp) != PermissionsState.PERMISSION_OPERATION_FAILURE) { if (callback != null) { callback.onInstallPermissionRevoked(); } } return; } if (permissionsState.revokeRuntimePermission(bp, userId) == PermissionsState.PERMISSION_OPERATION_FAILURE) { return; } if (bp.isRuntime()) { logPermission(MetricsEvent.ACTION_PERMISSION_REVOKED, permName, packageName); } if (callback != null) { final int uid = UserHandle.getUid(userId, pkg.applicationInfo.uid); callback.onPermissionRevoked(pkg.applicationInfo.uid, userId); } }