Java Code Examples for android.os.UserManager#getSerialNumberForUser()

The following examples show how to use android.os.UserManager#getSerialNumberForUser() . 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: IconCache.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
public BitmapDrawable getIcon(Context context, PackageManager pm, LauncherActivityInfo appInfo) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    String name = appInfo.getComponentName().flattenToString() + ":" + userManager.getSerialNumberForUser(appInfo.getUser());

    BitmapDrawable drawable;

    synchronized (drawables) {
        drawable = drawables.get(name);
        if(drawable == null) {
            Drawable loadedIcon = loadIcon(context, pm, appInfo);
            drawable = U.convertToBitmapDrawable(context, loadedIcon);

            drawables.put(name, drawable);
        }
    }

    return drawable;
}
 
Example 2
Source File: AppEntry.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
public long getUserId(Context context) {
    if(userId == null) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        return userManager.getSerialNumberForUser(Process.myUserHandle());
    } else
        return userId;
}
 
Example 3
Source File: AppEntryTest.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUserId() {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    long currentUser = userManager.getSerialNumberForUser(Process.myUserHandle());
    assertEquals(currentUser, appEntry.getUserId(context));
    appEntry.setUserId(currentUser + 1);
    assertEquals(currentUser + 1, appEntry.getUserId(context));
    appEntry.setUserId(currentUser);
}
 
Example 4
Source File: ClonedHiddenSystemApps.java    From island with Apache License 2.0 4 votes vote down vote up
private static SharedPreferences getStore(final Context context, final UserHandle user) {
	final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
	final long usn = um != null ? um.getSerialNumberForUser(user) : Users.toId(user);
	return SafeSharedPreferences.wrap(context.getSharedPreferences(SHARED_PREFS_PREFIX_ENABLED_SYSTEM_APPS + usn, Context.MODE_PRIVATE));
}
 
Example 5
Source File: DeviceAdminReceiver.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
@Override
public void onEnabled(Context context, Intent intent) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    long serialNumber = userManager.getSerialNumberForUser(Binder.getCallingUserHandle());
    Log.i(TAG, "Device admin enabled in user with serial number: " + serialNumber);
}