Java Code Examples for android.os.UserHandle#USER_NULL

The following examples show how to use android.os.UserHandle#USER_NULL . 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: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: ApplicationPackageManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 3
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 4
Source File: BluetoothManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 6
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 7
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 8
Source File: NetworkScoreService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: KeyguardServiceDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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()));
}
 
Example 11
Source File: ProtectedPackages.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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()));
}
 
Example 13
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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()));
}
 
Example 14
Source File: KeyguardServiceDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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()));
}
 
Example 16
Source File: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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()));
}
 
Example 17
Source File: SyncManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 18
Source File: UserController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
int getCurrentOrTargetUserIdLU() {
    return mTargetUserId != UserHandle.USER_NULL ? mTargetUserId : mCurrentUserId;
}
 
Example 19
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 20
Source File: ActivityStarter.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}