Search in sources :

Example 41 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class LockSettingsStorageTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mStorageDir = new File(getContext().getFilesDir(), "locksettings");
    mDb = getContext().getDatabasePath("locksettings.db");
    assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
    assertTrue(FileUtils.deleteContents(mStorageDir));
    assertTrue(!mDb.exists() || mDb.delete());
    final Context ctx = getContext();
    setContext(new ContextWrapper(ctx) {

        @Override
        public Object getSystemService(String name) {
            if (USER_SERVICE.equals(name)) {
                return new UserManager(ctx, null) {

                    @Override
                    public UserInfo getProfileParent(int userHandle) {
                        if (userHandle == 2) {
                            // User 2 is a profile of user 1.
                            return new UserInfo(1, "name", 0);
                        }
                        if (userHandle == 3) {
                            // User 3 is a profile of user 0.
                            return new UserInfo(0, "name", 0);
                        }
                        return null;
                    }
                };
            }
            return super.getSystemService(name);
        }
    });
    mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {

        @Override
        public void initialize(SQLiteDatabase db) {
            mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
        }
    }) {

        @Override
        String getLockPatternFilename(int userId) {
            return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getLockPasswordFilename(int userId) {
            return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
        }

        @Override
        String getChildProfileLockFile(int userId) {
            return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Example 42 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class ResolverActivity method setProfileSwitchMessageId.

private void setProfileSwitchMessageId(int contentUserHint) {
    if (contentUserHint != UserHandle.USER_CURRENT && contentUserHint != UserHandle.myUserId()) {
        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
        UserInfo originUserInfo = userManager.getUserInfo(contentUserHint);
        boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() : false;
        boolean targetIsManaged = userManager.isManagedProfile();
        if (originIsManaged && !targetIsManaged) {
            mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner;
        } else if (!originIsManaged && targetIsManaged) {
            mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work;
        }
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 43 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class IntentForwarderActivity method getProfileParent.

/**
     * Returns the userId of the profile parent or UserHandle.USER_NULL if there is
     * no parent.
     */
private int getProfileParent() {
    UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
    UserInfo parent = userManager.getProfileParent(UserHandle.myUserId());
    if (parent == null) {
        Slog.wtf(TAG, FORWARD_INTENT_TO_PARENT + " has been called, but there is no parent");
        return UserHandle.USER_NULL;
    }
    return parent.id;
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 44 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

the class SettingsProviderTest method testPerUserSettings.

@MediumTest
public void testPerUserSettings() {
    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 user = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
    assertTrue(user != null);
    try {
        // Write some settings for that user as well as the current user
        final String TEST_KEY = "test_setting";
        final int SELF_VALUE = 40;
        final int OTHER_VALUE = 27;
        Settings.Secure.putInt(r, TEST_KEY, SELF_VALUE);
        Settings.Secure.putIntForUser(r, TEST_KEY, OTHER_VALUE, user.id);
        // Verify that they read back as intended
        int myValue = Settings.Secure.getInt(r, TEST_KEY, 0);
        int otherValue = Settings.Secure.getIntForUser(r, TEST_KEY, 0, user.id);
        assertTrue("Running as user " + UserHandle.myUserId() + " and reading/writing as user " + user.id + ", expected to read " + SELF_VALUE + " but got " + myValue, myValue == SELF_VALUE);
        assertTrue("Running as user " + UserHandle.myUserId() + " and reading/writing as user " + user.id + ", expected to read " + OTHER_VALUE + " but got " + otherValue, otherValue == OTHER_VALUE);
    } finally {
        // Tidy up
        um.removeUser(user.id);
    }
}
Also used : UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) ContentResolver(android.content.ContentResolver) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 45 with UserManager

use of android.os.UserManager in project android_frameworks_base by DirtyUnicorns.

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)

Aggregations

UserManager (android.os.UserManager)271 UserInfo (android.content.pm.UserInfo)146 UserHandle (android.os.UserHandle)44 RemoteException (android.os.RemoteException)40 Intent (android.content.Intent)30 DevicePolicyManager (android.app.admin.DevicePolicyManager)29 ComponentName (android.content.ComponentName)29 Context (android.content.Context)25 PackageManager (android.content.pm.PackageManager)25 ArrayList (java.util.ArrayList)21 PendingIntent (android.app.PendingIntent)16 LockPatternUtils (com.android.internal.widget.LockPatternUtils)16 ApplicationInfo (android.content.pm.ApplicationInfo)15 File (java.io.File)15 ContentResolver (android.content.ContentResolver)14 ResolveInfo (android.content.pm.ResolveInfo)13 IPackageManager (android.content.pm.IPackageManager)12 Drawable (android.graphics.drawable.Drawable)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Resources (android.content.res.Resources)11