Search in sources :

Example 56 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class AppWidgetServiceImpl method maskWidgetsViewsLocked.

/**
     * Mask the target widget belonging to the specified provider, or all active widgets
     * of the provider if target widget == null.
     */
private void maskWidgetsViewsLocked(Provider provider, Widget targetWidget) {
    final int widgetCount = provider.widgets.size();
    if (widgetCount == 0) {
        return;
    }
    final String providerPackage = provider.info.provider.getPackageName();
    final int providerUserId = provider.getUserId();
    Bitmap iconBitmap = createMaskedWidgetBitmap(providerPackage, providerUserId);
    if (iconBitmap == null) {
        return;
    }
    final boolean showBadge;
    final Intent onClickIntent;
    final long identity = Binder.clearCallingIdentity();
    try {
        if (provider.maskedBySuspendedPackage) {
            UserInfo userInfo = mUserManager.getUserInfo(providerUserId);
            showBadge = userInfo.isManagedProfile();
            onClickIntent = mDevicePolicyManagerInternal.createPackageSuspendedDialogIntent(providerPackage, providerUserId);
        } else if (provider.maskedByQuietProfile) {
            showBadge = true;
            onClickIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(providerUserId);
        } else /* provider.maskedByLockedProfile */
        {
            showBadge = true;
            onClickIntent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null, providerUserId);
            if (onClickIntent != null) {
                onClickIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            }
        }
        for (int j = 0; j < widgetCount; j++) {
            Widget widget = provider.widgets.get(j);
            if (targetWidget != null && targetWidget != widget)
                continue;
            PendingIntent intent = null;
            if (onClickIntent != null) {
                intent = PendingIntent.getActivity(mContext, widget.appWidgetId, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            }
            RemoteViews views = createMaskedWidgetRemoteViews(iconBitmap, showBadge, intent);
            if (widget.replaceWithMaskedViewsLocked(views)) {
                scheduleNotifyUpdateAppWidgetLocked(widget, widget.getEffectiveViewsLocked());
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : Bitmap(android.graphics.Bitmap) RemoteViews(android.widget.RemoteViews) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) UserInfo(android.content.pm.UserInfo) PendingIntent(android.app.PendingIntent) Point(android.graphics.Point)

Example 57 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class SettingsProviderTest method testSettingsChangeForOtherUser.

@MediumTest
public void testSettingsChangeForOtherUser() {
    UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    ContentResolver r = getContext().getContentResolver();
    // Make sure there's an owner
    assertTrue(findUser(um, UserHandle.USER_SYSTEM));
    // create a new user to use for testing
    UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
    assertTrue(otherUser != null);
    try {
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
        final String testKey = "testSettingsChangeForOtherUser";
        final String testValue1 = "value1";
        final String testValue2 = "value2";
        Settings.Secure.putString(r, testKey, testValue1);
        Settings.Secure.putStringForUser(r, testKey, testValue2, otherUser.id);
        assertEquals(testValue1, Settings.Secure.getString(r, testKey));
        assertEquals(testValue2, Settings.Secure.getStringForUser(r, testKey, otherUser.id));
        assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId());
    } finally {
        // Tidy up
        um.removeUser(otherUser.id);
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 58 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UsageStatsService method cleanUpRemovedUsersLocked.

private void cleanUpRemovedUsersLocked() {
    final List<UserInfo> users = mUserManager.getUsers(true);
    if (users == null || users.size() == 0) {
        throw new IllegalStateException("There can't be no users");
    }
    ArraySet<String> toDelete = new ArraySet<>();
    String[] fileNames = mUsageStatsDir.list();
    if (fileNames == null) {
        // No users to delete.
        return;
    }
    toDelete.addAll(Arrays.asList(fileNames));
    final int userCount = users.size();
    for (int i = 0; i < userCount; i++) {
        final UserInfo userInfo = users.get(i);
        toDelete.remove(Integer.toString(userInfo.id));
    }
    final int deleteCount = toDelete.size();
    for (int i = 0; i < deleteCount; i++) {
        deleteRecursively(new File(mUsageStatsDir, toDelete.valueAt(i)));
    }
}
Also used : ArraySet(android.util.ArraySet) UserInfo(android.content.pm.UserInfo) File(java.io.File)

Example 59 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testRemoveUser.

public void testRemoveUser() throws Exception {
    UserInfo userInfo = createUser("Guest 1", UserInfo.FLAG_GUEST);
    removeUser(userInfo.id);
    assertFalse(findUser(userInfo.id));
}
Also used : UserInfo(android.content.pm.UserInfo)

Example 60 with UserInfo

use of android.content.pm.UserInfo in project platform_frameworks_base by android.

the class UserManagerTest method testGetSerialNumbersOfUsers.

public void testGetSerialNumbersOfUsers() {
    UserInfo user1 = createUser("User 1", 0);
    UserInfo user2 = createUser("User 2", 0);
    long[] serialNumbersOfUsers = mUserManager.getSerialNumbersOfUsers(false);
    String errMsg = "Array " + Arrays.toString(serialNumbersOfUsers) + " should contain ";
    assertTrue(errMsg + user1.serialNumber, ArrayUtils.contains(serialNumbersOfUsers, user1.serialNumber));
    assertTrue(errMsg + user2.serialNumber, ArrayUtils.contains(serialNumbersOfUsers, user2.serialNumber));
}
Also used : UserInfo(android.content.pm.UserInfo)

Aggregations

UserInfo (android.content.pm.UserInfo)814 UserManager (android.os.UserManager)156 RemoteException (android.os.RemoteException)144 ArrayList (java.util.ArrayList)73 UserHandle (android.os.UserHandle)66 Intent (android.content.Intent)58 IOException (java.io.IOException)52 File (java.io.File)47 Bundle (android.os.Bundle)43 ApplicationInfo (android.content.pm.ApplicationInfo)40 PackageManager (android.content.pm.PackageManager)39 ComponentName (android.content.ComponentName)32 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)29 AtomicFile (android.util.AtomicFile)28 PackageInfo (android.content.pm.PackageInfo)26 DevicePolicyManager (android.app.admin.DevicePolicyManager)25 LockPatternUtils (com.android.internal.widget.LockPatternUtils)24 PendingIntent (android.app.PendingIntent)23