Search in sources :

Example 91 with UserHandle

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

the class DevicePolicyManagerService method choosePrivateKeyAlias.

@Override
public void choosePrivateKeyAlias(final int uid, final Uri uri, final String alias, final IBinder response) {
    // Caller UID needs to be trusted, so we restrict this method to SYSTEM_UID callers.
    if (!isCallerWithSystemUid()) {
        return;
    }
    final UserHandle caller = mInjector.binderGetCallingUserHandle();
    // If there is a profile owner, redirect to that; otherwise query the device owner.
    ComponentName aliasChooser = getProfileOwner(caller.getIdentifier());
    if (aliasChooser == null && caller.isSystem()) {
        ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
        if (deviceOwnerAdmin != null) {
            aliasChooser = deviceOwnerAdmin.info.getComponent();
        }
    }
    if (aliasChooser == null) {
        sendPrivateKeyAliasResponse(null, response);
        return;
    }
    Intent intent = new Intent(DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS);
    intent.setComponent(aliasChooser);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, uid);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_URI, uri);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_ALIAS, alias);
    intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_RESPONSE, response);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    final long id = mInjector.binderClearCallingIdentity();
    try {
        mContext.sendOrderedBroadcastAsUser(intent, caller, null, new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                final String chosenAlias = getResultData();
                sendPrivateKeyAliasResponse(chosenAlias, response);
            }
        }, null, Activity.RESULT_OK, null, null);
    } finally {
        mInjector.binderRestoreCallingIdentity(id);
    }
}
Also used : Context(android.content.Context) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ParcelableString(com.android.internal.util.ParcelableString) BroadcastReceiver(android.content.BroadcastReceiver)

Example 92 with UserHandle

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

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 93 with UserHandle

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

the class DevicePolicyManagerService method sendChangedNotification.

private void sendChangedNotification(int userHandle) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    long ident = mInjector.binderClearCallingIdentity();
    try {
        mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle));
    } finally {
        mInjector.binderRestoreCallingIdentity(ident);
    }
}
Also used : UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 94 with UserHandle

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

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 95 with UserHandle

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

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)

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