Search in sources :

Example 66 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class ResolveInfo method loadIcon.

/**
     * Retrieve the current graphical icon associated with this resolution.  This
     * will call back on the given PackageManager to load the icon from
     * the application.
     *
     * @param pm A PackageManager from which the icon can be loaded; usually
     * the PackageManager from which you originally retrieved this item.
     *
     * @return Returns a Drawable containing the resolution's icon.  If the
     * item does not have an icon, the default activity icon is returned.
     */
public Drawable loadIcon(PackageManager pm) {
    Drawable dr = null;
    if (resolvePackageName != null && iconResourceId != 0) {
        dr = pm.getDrawable(resolvePackageName, iconResourceId, null);
    }
    ComponentInfo ci = getComponentInfo();
    if (dr == null && iconResourceId != 0) {
        ApplicationInfo ai = ci.applicationInfo;
        dr = pm.getDrawable(ci.packageName, iconResourceId, ai);
    }
    if (dr != null) {
        return pm.getUserBadgedIcon(dr, new UserHandle(UserHandle.myUserId()));
    }
    return ci.loadIcon(pm);
}
Also used : UserHandle(android.os.UserHandle) Drawable(android.graphics.drawable.Drawable)

Example 67 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Object o = l.getAdapter().getItem(position);
    DeviceAdminInfo dpi = (DeviceAdminInfo) o;
    final UserHandle user = new UserHandle(getUserId(dpi));
    final Activity activity = getActivity();
    Intent intent = new Intent(activity, DeviceAdminAdd.class);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
    activity.startActivityAsUser(intent, user);
}
Also used : DeviceAdminInfo(android.app.admin.DeviceAdminInfo) UserHandle(android.os.UserHandle) Activity(android.app.Activity) Intent(android.content.Intent)

Example 68 with UserHandle

use of android.os.UserHandle in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
    getActivity().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
    final ComponentName deviceOwnerComponent = mDPM.getDeviceOwnerComponentOnAnyUser();
    mDeviceOwnerPkg = deviceOwnerComponent != null ? deviceOwnerComponent.getPackageName() : null;
    mProfileOwnerComponents.clear();
    final List<UserHandle> profiles = mUm.getUserProfiles();
    final int profilesSize = profiles.size();
    for (int i = 0; i < profilesSize; ++i) {
        final int profileId = profiles.get(i).getIdentifier();
        mProfileOwnerComponents.put(profileId, mDPM.getProfileOwnerAsUser(profileId));
    }
    updateList();
}
Also used : IntentFilter(android.content.IntentFilter) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName)

Example 69 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class UserManagerTest method testGetUserCreationTime.

public void testGetUserCreationTime() throws Exception {
    final int primaryUserId = mUserManager.getPrimaryUser().id;
    UserInfo profile = createProfileForUser("Managed 1", UserInfo.FLAG_MANAGED_PROFILE, primaryUserId);
    assertNotNull(profile);
    assertTrue("creationTime must be set when the profile is created", profile.creationTime > 0);
    assertEquals(profile.creationTime, mUserManager.getUserCreationTime(new UserHandle(profile.id)));
    long ownerCreationTime = mUserManager.getUserInfo(primaryUserId).creationTime;
    assertEquals(ownerCreationTime, mUserManager.getUserCreationTime(new UserHandle(primaryUserId)));
    try {
        int noSuchUserId = 100500;
        mUserManager.getUserCreationTime(new UserHandle(noSuchUserId));
        fail("SecurityException should be thrown for nonexistent user");
    } catch (Exception e) {
        assertTrue("SecurityException should be thrown for nonexistent user, but was: " + e, e instanceof SecurityException);
    }
    UserInfo user = createUser("User 1", 0);
    try {
        mUserManager.getUserCreationTime(new UserHandle(user.id));
        fail("SecurityException should be thrown for other user");
    } catch (Exception e) {
        assertTrue("SecurityException should be thrown for other user, but was: " + e, e instanceof SecurityException);
    }
}
Also used : UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo)

Example 70 with UserHandle

use of android.os.UserHandle in project android_frameworks_base by ResurrectionRemix.

the class UserManagerTest method testRestrictions.

public void testRestrictions() {
    UserInfo testUser = createUser("User 1", 0);
    mUserManager.setUserRestriction(UserManager.DISALLOW_INSTALL_APPS, true, new UserHandle(testUser.id));
    mUserManager.setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, false, new UserHandle(testUser.id));
    Bundle stored = mUserManager.getUserRestrictions(new UserHandle(testUser.id));
    // Note this will fail if DO already sets those restrictions.
    assertEquals(stored.getBoolean(UserManager.DISALLOW_CONFIG_WIFI), false);
    assertEquals(stored.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS), false);
    assertEquals(stored.getBoolean(UserManager.DISALLOW_INSTALL_APPS), true);
}
Also used : Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo)

Aggregations

UserHandle (android.os.UserHandle)1087 Intent (android.content.Intent)306 RemoteException (android.os.RemoteException)205 Test (org.junit.Test)165 UserInfo (android.content.pm.UserInfo)152 PendingIntent (android.app.PendingIntent)134 Bundle (android.os.Bundle)127 Context (android.content.Context)126 ApplicationInfo (android.content.pm.ApplicationInfo)93 ArrayList (java.util.ArrayList)91 PackageManager (android.content.pm.PackageManager)86 UserManager (android.os.UserManager)85 ComponentName (android.content.ComponentName)82 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)82 Drawable (android.graphics.drawable.Drawable)61 IBinder (android.os.IBinder)49 IOException (java.io.IOException)45 Config (org.robolectric.annotation.Config)41 Account (android.accounts.Account)39 ResolveInfo (android.content.pm.ResolveInfo)37