Search in sources :

Example 71 with UserHandle

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

the class DevicePolicyManagerService method createAndManageUser.

@Override
public UserHandle createAndManageUser(ComponentName admin, String name, ComponentName profileOwner, PersistableBundle adminExtras, int flags) {
    Preconditions.checkNotNull(admin, "admin is null");
    Preconditions.checkNotNull(profileOwner, "profileOwner is null");
    if (!admin.getPackageName().equals(profileOwner.getPackageName())) {
        throw new IllegalArgumentException("profileOwner " + profileOwner + " and admin " + admin + " are not in the same package");
    }
    // Only allow the system user to use this method
    if (!mInjector.binderGetCallingUserHandle().isSystem()) {
        throw new SecurityException("createAndManageUser was called from non-system user");
    }
    if (!mInjector.userManagerIsSplitSystemUser() && (flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0) {
        throw new IllegalArgumentException("Ephemeral users are only supported on systems with a split system user.");
    }
    // Create user.
    UserHandle user = null;
    synchronized (this) {
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
        final long id = mInjector.binderClearCallingIdentity();
        try {
            int userInfoFlags = 0;
            if ((flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0) {
                userInfoFlags |= UserInfo.FLAG_EPHEMERAL;
            }
            UserInfo userInfo = mUserManagerInternal.createUserEvenWhenDisallowed(name, userInfoFlags);
            if (userInfo != null) {
                user = userInfo.getUserHandle();
            }
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
        }
    }
    if (user == null) {
        return null;
    }
    // Set admin.
    final long id = mInjector.binderClearCallingIdentity();
    try {
        final String adminPkg = admin.getPackageName();
        final int userHandle = user.getIdentifier();
        try {
            // Install the profile owner if not present.
            if (!mIPackageManager.isPackageAvailable(adminPkg, userHandle)) {
                mIPackageManager.installExistingPackageAsUser(adminPkg, userHandle);
            }
        } catch (RemoteException e) {
            Slog.e(LOG_TAG, "Failed to make remote calls for createAndManageUser, " + "removing created user", e);
            mUserManager.removeUser(user.getIdentifier());
            return null;
        }
        setActiveAdmin(profileOwner, true, userHandle);
        // So we store adminExtras for broadcasting when the user starts for first time.
        synchronized (this) {
            DevicePolicyData policyData = getUserData(userHandle);
            policyData.mInitBundle = adminExtras;
            policyData.mAdminBroadcastPending = true;
            saveSettingsLocked(userHandle);
        }
        final String ownerName = getProfileOwnerName(Process.myUserHandle().getIdentifier());
        setProfileOwner(profileOwner, ownerName, userHandle);
        if ((flags & DevicePolicyManager.SKIP_SETUP_WIZARD) != 0) {
            Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1, userHandle);
        }
        return user;
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
}
Also used : UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo) ParcelableString(com.android.internal.util.ParcelableString) RemoteException(android.os.RemoteException)

Example 72 with UserHandle

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

the class DevicePolicyManagerService method setProfileEnabled.

@Override
public void setProfileEnabled(ComponentName who) {
    if (!mHasFeature) {
        return;
    }
    Preconditions.checkNotNull(who, "ComponentName is null");
    synchronized (this) {
        // Check if this is the profile owner who is calling
        getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
        final int userId = UserHandle.getCallingUserId();
        enforceManagedProfile(userId, "enable the profile");
        long id = mInjector.binderClearCallingIdentity();
        try {
            mUserManager.setUserEnabled(userId);
            UserInfo parent = mUserManager.getProfileParent(userId);
            Intent intent = new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED);
            intent.putExtra(Intent.EXTRA_USER, new UserHandle(userId));
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
            mContext.sendBroadcastAsUser(intent, new UserHandle(parent.id));
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
        }
    }
}
Also used : UserHandle(android.os.UserHandle) UserInfo(android.content.pm.UserInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 73 with UserHandle

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

the class DevicePolicyManagerService method getApplicationLabel.

/**
     * Canonical name for a given package.
     */
private String getApplicationLabel(String packageName, int userHandle) {
    long token = mInjector.binderClearCallingIdentity();
    try {
        final Context userContext;
        try {
            UserHandle handle = new UserHandle(userHandle);
            userContext = mContext.createPackageContextAsUser(packageName, 0, handle);
        } catch (PackageManager.NameNotFoundException nnfe) {
            Log.w(LOG_TAG, packageName + " is not installed for user " + userHandle, nnfe);
            return null;
        }
        ApplicationInfo appInfo = userContext.getApplicationInfo();
        CharSequence result = null;
        if (appInfo != null) {
            PackageManager pm = userContext.getPackageManager();
            result = pm.getApplicationLabel(appInfo);
        }
        return result != null ? result.toString() : null;
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 74 with UserHandle

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

the class DevicePolicyManagerService method notifyPendingSystemUpdate.

@Override
public void notifyPendingSystemUpdate(long updateReceivedTime) {
    mContext.enforceCallingOrSelfPermission(permission.NOTIFY_PENDING_SYSTEM_UPDATE, "Only the system update service can broadcast update information");
    if (UserHandle.getCallingUserId() != UserHandle.USER_SYSTEM) {
        Slog.w(LOG_TAG, "Only the system update service in the system user " + "can broadcast update information.");
        return;
    }
    Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
    intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, updateReceivedTime);
    synchronized (this) {
        final String deviceOwnerPackage = mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerComponent().getPackageName() : null;
        if (deviceOwnerPackage == null) {
            return;
        }
        final UserHandle deviceOwnerUser = new UserHandle(mOwners.getDeviceOwnerUserId());
        ActivityInfo[] receivers = null;
        try {
            receivers = mContext.getPackageManager().getPackageInfo(deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, "Cannot find device owner package", e);
        }
        if (receivers != null) {
            long ident = mInjector.binderClearCallingIdentity();
            try {
                for (int i = 0; i < receivers.length; i++) {
                    if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
                        intent.setComponent(new ComponentName(deviceOwnerPackage, receivers[i].name));
                        mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(ident);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ParcelableString(com.android.internal.util.ParcelableString)

Example 75 with UserHandle

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

the class DevicePolicyManagerService method getPermissionGrantState.

@Override
public int getPermissionGrantState(ComponentName admin, String packageName, String permission) throws RemoteException {
    PackageManager packageManager = mContext.getPackageManager();
    UserHandle user = mInjector.binderGetCallingUserHandle();
    synchronized (this) {
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
        long ident = mInjector.binderClearCallingIdentity();
        try {
            int granted = mIPackageManager.checkPermission(permission, packageName, user.getIdentifier());
            int permFlags = packageManager.getPermissionFlags(permission, packageName, user);
            if ((permFlags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != PackageManager.FLAG_PERMISSION_POLICY_FIXED) {
                // Not controlled by policy
                return DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT;
            } else {
                // Policy controlled so return result based on permission grant state
                return granted == PackageManager.PERMISSION_GRANTED ? DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED : DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED;
            }
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle)

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