Search in sources :

Example 76 with UserHandle

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

the class DevicePolicyManagerService method setPermissionGrantState.

@Override
public boolean setPermissionGrantState(ComponentName admin, String packageName, String permission, int grantState) throws RemoteException {
    UserHandle user = mInjector.binderGetCallingUserHandle();
    synchronized (this) {
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
        long ident = mInjector.binderClearCallingIdentity();
        try {
            if (getTargetSdk(packageName, user.getIdentifier()) < android.os.Build.VERSION_CODES.M) {
                return false;
            }
            final PackageManager packageManager = mContext.getPackageManager();
            switch(grantState) {
                case DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED:
                    {
                        packageManager.grantRuntimePermission(packageName, permission, user);
                        packageManager.updatePermissionFlags(permission, packageName, PackageManager.FLAG_PERMISSION_POLICY_FIXED, PackageManager.FLAG_PERMISSION_POLICY_FIXED, user);
                    }
                    break;
                case DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED:
                    {
                        packageManager.revokeRuntimePermission(packageName, permission, user);
                        packageManager.updatePermissionFlags(permission, packageName, PackageManager.FLAG_PERMISSION_POLICY_FIXED, PackageManager.FLAG_PERMISSION_POLICY_FIXED, user);
                    }
                    break;
                case DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT:
                    {
                        packageManager.updatePermissionFlags(permission, packageName, PackageManager.FLAG_PERMISSION_POLICY_FIXED, 0, user);
                    }
                    break;
            }
            return true;
        } catch (SecurityException se) {
            return false;
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle)

Example 77 with UserHandle

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

the class DevicePolicyManagerService method setDeviceOwner.

@Override
public boolean setDeviceOwner(ComponentName admin, String ownerName, int userId) {
    if (!mHasFeature) {
        return false;
    }
    if (admin == null || !isPackageInstalledForUser(admin.getPackageName(), userId)) {
        throw new IllegalArgumentException("Invalid component " + admin + " for device owner");
    }
    final boolean hasIncompatibleAccountsOrNonAdb = hasIncompatibleAccountsOrNonAdbNoLock(userId, admin);
    synchronized (this) {
        enforceCanSetDeviceOwnerLocked(admin, userId, hasIncompatibleAccountsOrNonAdb);
        if (getActiveAdminUncheckedLocked(admin, userId) == null || getUserData(userId).mRemovingAdmins.contains(admin)) {
            throw new IllegalArgumentException("Not active admin: " + admin);
        }
        // Shutting down backup manager service permanently.
        long ident = mInjector.binderClearCallingIdentity();
        try {
            if (mInjector.getIBackupManager() != null) {
                mInjector.getIBackupManager().setBackupServiceActive(UserHandle.USER_SYSTEM, false);
            }
        } catch (RemoteException e) {
            throw new IllegalStateException("Failed deactivating backup service.", e);
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
        mOwners.setDeviceOwner(admin, ownerName, userId);
        mOwners.writeDeviceOwner();
        updateDeviceOwnerLocked();
        setDeviceOwnerSystemPropertyLocked();
        Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED);
        ident = mInjector.binderClearCallingIdentity();
        try {
            // TODO Send to system too?
            mContext.sendBroadcastAsUser(intent, new UserHandle(userId));
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
        Slog.i(LOG_TAG, "Device owner set: " + admin + " on user " + userId);
        return true;
    }
}
Also used : UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 78 with UserHandle

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

the class DevicePolicyManagerService method removeKeyPair.

@Override
public boolean removeKeyPair(ComponentName who, String alias) {
    enforceCanManageInstalledKeys(who);
    final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId());
    final long id = Binder.clearCallingIdentity();
    try {
        final KeyChainConnection keyChainConnection = KeyChain.bindAsUser(mContext, userHandle);
        try {
            IKeyChainService keyChain = keyChainConnection.getService();
            return keyChain.removeKeyPair(alias);
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "Removing keypair", e);
        } finally {
            keyChainConnection.close();
        }
    } catch (InterruptedException e) {
        Log.w(LOG_TAG, "Interrupted while removing keypair", e);
        Thread.currentThread().interrupt();
    } finally {
        Binder.restoreCallingIdentity(id);
    }
    return false;
}
Also used : IKeyChainService(android.security.IKeyChainService) UserHandle(android.os.UserHandle) KeyChainConnection(android.security.KeyChain.KeyChainConnection) RemoteException(android.os.RemoteException)

Example 79 with UserHandle

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

the class RemoteViews method getApplicationInfo.

private static ApplicationInfo getApplicationInfo(String packageName, int userId) {
    if (packageName == null) {
        return null;
    }
    // Get the application for the passed in package and user.
    Application application = ActivityThread.currentApplication();
    if (application == null) {
        throw new IllegalStateException("Cannot create remote views out of an aplication.");
    }
    ApplicationInfo applicationInfo = application.getApplicationInfo();
    if (UserHandle.getUserId(applicationInfo.uid) != userId || !applicationInfo.packageName.equals(packageName)) {
        try {
            Context context = application.getBaseContext().createPackageContextAsUser(packageName, 0, new UserHandle(userId));
            applicationInfo = context.getApplicationInfo();
        } catch (NameNotFoundException nnfe) {
            throw new IllegalArgumentException("No such package " + packageName);
        }
    }
    return applicationInfo;
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo) Application(android.app.Application)

Example 80 with UserHandle

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

the class RecentsActivity method onBusEvent.

public final void onBusEvent(ShowApplicationInfoEvent event) {
    // Create a new task stack with the application info details activity
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", event.task.key.getComponent().getPackageName(), null));
    intent.setComponent(intent.resolveActivity(getPackageManager()));
    TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities(null, new UserHandle(event.task.key.userId));
    // Keep track of app-info invocations
    MetricsLogger.count(this, "overview_app_info", 1);
}
Also used : UserHandle(android.os.UserHandle) Intent(android.content.Intent)

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