下面列出了android.os.UserHandle#USER_NULL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@VisibleForTesting
void saveDirtyInfo() {
if (DEBUG) {
Slog.d(TAG, "saveDirtyInfo");
}
try {
synchronized (mLock) {
for (int i = mDirtyUserIds.size() - 1; i >= 0; i--) {
final int userId = mDirtyUserIds.get(i);
if (userId == UserHandle.USER_NULL) { // USER_NULL for base state.
saveBaseStateLocked();
} else {
saveUserLocked(userId);
}
}
mDirtyUserIds.clear();
}
} catch (Exception e) {
wtf("Exception in saveDirtyInfo", e);
}
}
/**
* @hide
*/
public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
if (bitmap == null) {
return UserIcons.getDefaultUserIcon(
mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
}
return new BitmapDrawable(bitmap);
}
Drawable dr = null;
if (itemInfo.packageName != null) {
dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
}
if (dr == null) {
dr = itemInfo.loadDefaultIcon(this);
}
return dr;
}
private boolean checkIfCallerIsForegroundUser() {
int foregroundUser;
int callingUser = UserHandle.getCallingUserId();
int callingUid = Binder.getCallingUid();
long callingIdentity = Binder.clearCallingIdentity();
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
UserInfo ui = um.getProfileParent(callingUser);
int parentUser = (ui != null) ? ui.id : UserHandle.USER_NULL;
int callingAppId = UserHandle.getAppId(callingUid);
boolean valid = false;
try {
foregroundUser = ActivityManager.getCurrentUser();
valid = (callingUser == foregroundUser) || parentUser == foregroundUser
|| callingAppId == Process.NFC_UID || callingAppId == mSystemUiUid;
if (DBG && !valid) {
Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid + " callingUser="
+ callingUser + " parentUser=" + parentUser + " foregroundUser="
+ foregroundUser);
}
} finally {
Binder.restoreCallingIdentity(callingIdentity);
}
return valid;
}
/**
* @hide
*/
public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
if (bitmap == null) {
return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
}
return new BitmapDrawable(bitmap);
}
Drawable dr = null;
if (itemInfo.packageName != null) {
dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
}
if (dr == null) {
dr = itemInfo.loadDefaultIcon(this);
}
return dr;
}
/**
* @hide
*/
public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
if (bitmap == null) {
return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
}
return new BitmapDrawable(bitmap);
}
Drawable dr = null;
if (itemInfo.packageName != null) {
dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
}
if (dr == null) {
dr = itemInfo.loadDefaultIcon(this);
}
return dr;
}
@Override
public void onReceive(Context context, Intent intent) {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
if (userId == UserHandle.USER_NULL) {
Slog.w(TAG, "Intent broadcast does not contain user handle: " + intent);
return;
}
Uri data = intent.getData();
String pkg = data != null ? data.getSchemeSpecificPart() : null;
if (pkg == null) {
Slog.w(TAG, "Intent broadcast does not contain package name: " + intent);
return;
}
switch (intent.getAction()) {
case Intent.ACTION_PACKAGE_REMOVED:
final boolean replacing =
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
if (!replacing) {
mPermissions.removePkg(pkg, userId);
}
break;
case Intent.ACTION_PACKAGE_DATA_CLEARED:
mPermissions.removePkg(pkg, userId);
break;
}
}
/**
* @hide
*/
public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
if (bitmap == null) {
return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
}
return new BitmapDrawable(bitmap);
}
Drawable dr = null;
if (itemInfo.packageName != null) {
dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
}
if (dr == null) {
dr = itemInfo.loadDefaultIcon(this);
}
return dr;
}
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
if (DBG) Log.d(TAG, "Received " + action + " for userId " + userId);
if (userId == UserHandle.USER_NULL) return;
if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
onUserUnlocked(userId);
}
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
if (userId == UserHandle.USER_NULL) return;
if (Intent.ACTION_USER_REMOVED.equals(action)) {
onUserRemoved(userId);
} else if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
onUserUnlocked(userId);
} else if (Intent.ACTION_USER_STOPPED.equals(action)) {
onUserStopped(userId);
}
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (DEBUG) Log.v(TAG, "*** Keyguard connected (yay!)");
mKeyguardService = new KeyguardServiceWrapper(mContext,
IKeyguardService.Stub.asInterface(service), mCallback);
if (mKeyguardState.systemIsReady) {
// If the system is ready, it means keyguard crashed and restarted.
mKeyguardService.onSystemReady();
if (mKeyguardState.currentUser != UserHandle.USER_NULL) {
// There has been a user switch earlier
mKeyguardService.setCurrentUser(mKeyguardState.currentUser);
}
// This is used to hide the scrim once keyguard displays.
if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE
|| mKeyguardState.interactiveState == INTERACTIVE_STATE_WAKING) {
mKeyguardService.onStartedWakingUp();
}
if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE) {
mKeyguardService.onFinishedWakingUp();
}
if (mKeyguardState.screenState == SCREEN_STATE_ON
|| mKeyguardState.screenState == SCREEN_STATE_TURNING_ON) {
mKeyguardService.onScreenTurningOn(
new KeyguardShowDelegate(mDrawnListenerWhenConnect));
}
if (mKeyguardState.screenState == SCREEN_STATE_ON) {
mKeyguardService.onScreenTurnedOn();
}
mDrawnListenerWhenConnect = null;
}
if (mKeyguardState.bootCompleted) {
mKeyguardService.onBootCompleted();
}
if (mKeyguardState.occluded) {
mKeyguardService.setOccluded(mKeyguardState.occluded, false /* animate */);
}
if (!mKeyguardState.enabled) {
mKeyguardService.setKeyguardEnabled(mKeyguardState.enabled);
}
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(getUserId()));
}
/**
* Sets the device/profile owner information.
*/
public synchronized void setDeviceAndProfileOwnerPackages(
int deviceOwnerUserId, String deviceOwnerPackage,
SparseArray<String> profileOwnerPackages) {
mDeviceOwnerUserId = deviceOwnerUserId;
mDeviceOwnerPackage =
(deviceOwnerUserId == UserHandle.USER_NULL) ? null : deviceOwnerPackage;
mProfileOwnerPackages = (profileOwnerPackages == null) ? null
: profileOwnerPackages.clone();
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
}
private void reset() {
// Assume keyguard is showing and secure until we know for sure. This is here in
// the event something checks before the service is actually started.
// KeyguardService itself should default to this state until the real state is known.
showing = true;
showingAndNotOccluded = true;
secure = true;
deviceHasKeyguard = true;
enabled = true;
currentUser = UserHandle.USER_NULL;
}
/**
* See {@link UserManagerInternal#setDevicePolicyUserRestrictions}
*/
private void setDevicePolicyUserRestrictionsInner(int userId, @Nullable Bundle restrictions,
boolean isDeviceOwner, int cameraRestrictionScope) {
final Bundle global = new Bundle();
final Bundle local = new Bundle();
// Sort restrictions into local and global ensuring they don't overlap.
UserRestrictionsUtils.sortToGlobalAndLocal(restrictions, isDeviceOwner,
cameraRestrictionScope, global, local);
boolean globalChanged, localChanged;
synchronized (mRestrictionsLock) {
// Update global and local restrictions if they were changed.
globalChanged = updateRestrictionsIfNeededLR(
userId, global, mDevicePolicyGlobalUserRestrictions);
localChanged = updateRestrictionsIfNeededLR(
userId, local, mDevicePolicyLocalUserRestrictions);
if (isDeviceOwner) {
// Remember the global restriction owner userId to be able to make a distinction
// in getUserRestrictionSource on who set local policies.
mDeviceOwnerUserId = userId;
} else {
if (mDeviceOwnerUserId == userId) {
// When profile owner sets restrictions it passes null global bundle and we
// reset global restriction owner userId.
// This means this user used to have DO, but now the DO is gone and the user
// instead has PO.
mDeviceOwnerUserId = UserHandle.USER_NULL;
}
}
}
if (DBG) {
Log.d(LOG_TAG, "setDevicePolicyUserRestrictions: userId=" + userId
+ " global=" + global + (globalChanged ? " (changed)" : "")
+ " local=" + local + (localChanged ? " (changed)" : "")
);
}
// Don't call them within the mRestrictionsLock.
synchronized (mPackagesLock) {
if (localChanged || globalChanged) {
writeUserLP(getUserDataNoChecks(userId));
}
}
synchronized (mRestrictionsLock) {
if (globalChanged) {
applyUserRestrictionsForAllUsersLR();
} else if (localChanged) {
applyUserRestrictionsLR(userId);
}
}
}
int getCurrentOrTargetUserIdLU() {
return mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId;
}
/**
* Compute the logical UID based on which the package manager would filter
* app components i.e. based on which the instant app policy would be applied
* because it is the logical calling UID.
*
* @param customCallingUid The UID on whose behalf to make the call.
* @param actualCallingUid The UID actually making the call.
* @param filterCallingUid The UID to be used to filter for instant apps.
* @return The logical UID making the call.
*/
static int computeResolveFilterUid(int customCallingUid, int actualCallingUid,
int filterCallingUid) {
return filterCallingUid != UserHandle.USER_NULL
? filterCallingUid
: (customCallingUid >= 0 ? customCallingUid : actualCallingUid);
}