Search in sources :

Example 41 with UserHandle

use of android.os.UserHandle in project platform_frameworks_base by android.

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

use of android.os.UserHandle in project platform_frameworks_base by android.

the class ManagedApplicationService method connect.

/**
     * Asynchronously bind to the application service if not bound.
     */
public void connect() {
    synchronized (mLock) {
        if (mConnection != null || mPendingConnection != null) {
            // We're already connected or are trying to connect
            return;
        }
        final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mSettingsAction), 0);
        final Intent intent = new Intent().setComponent(mComponent).putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
        final ServiceConnection serviceConnection = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                IInterface iface = null;
                PendingEvent pendingEvent = null;
                synchronized (mLock) {
                    if (mPendingConnection == this) {
                        // No longer pending, remove from pending connection
                        mPendingConnection = null;
                        mConnection = this;
                    } else {
                        // Service connection wasn't pending, must have been disconnected
                        mContext.unbindService(this);
                        return;
                    }
                    try {
                        iBinder.linkToDeath(mDeathRecipient, 0);
                        mBoundInterface = mChecker.asInterface(iBinder);
                        if (!mChecker.checkType(mBoundInterface)) {
                            // Received an invalid binder, disconnect
                            mContext.unbindService(this);
                            mBoundInterface = null;
                        }
                        iface = mBoundInterface;
                        pendingEvent = mPendingEvent;
                        mPendingEvent = null;
                    } catch (RemoteException e) {
                        // DOA
                        Slog.w(TAG, "Unable to bind service: " + intent, e);
                        mBoundInterface = null;
                    }
                }
                if (iface != null && pendingEvent != null) {
                    try {
                        pendingEvent.runEvent(iface);
                    } catch (RuntimeException | RemoteException ex) {
                        Slog.e(TAG, "Received exception from user service: ", ex);
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
                Slog.w(TAG, "Service disconnected: " + intent);
                mConnection = null;
                mBoundInterface = null;
            }
        };
        mPendingConnection = serviceConnection;
        try {
            if (!mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId))) {
                Slog.w(TAG, "Unable to bind service: " + intent);
            }
        } catch (SecurityException e) {
            Slog.w(TAG, "Unable to bind service: " + intent, e);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IInterface(android.os.IInterface) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Example 43 with UserHandle

use of android.os.UserHandle in project platform_frameworks_base by android.

the class TvRemoteProviderWatcher method start.

public void start() {
    if (DEBUG)
        Slog.d(TAG, "start()");
    if (!mRunning) {
        mRunning = true;
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
        filter.addDataScheme("package");
        mContext.registerReceiverAsUser(mScanPackagesReceiver, new UserHandle(mUserId), filter, null, mHandler);
        // Scan packages.
        // Also has the side-effect of restarting providers if needed.
        mHandler.post(mScanPackagesRunnable);
    }
}
Also used : IntentFilter(android.content.IntentFilter) UserHandle(android.os.UserHandle)

Example 44 with UserHandle

use of android.os.UserHandle in project platform_frameworks_base by android.

the class RemotePrintService method ensureBound.

private void ensureBound() {
    if (isBound() || mBinding) {
        return;
    }
    if (DEBUG) {
        Slog.i(LOG_TAG, "[user: " + mUserId + "] ensureBound()");
    }
    mBinding = true;
    mContext.bindServiceAsUser(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId));
}
Also used : UserHandle(android.os.UserHandle)

Example 45 with UserHandle

use of android.os.UserHandle in project platform_frameworks_base by android.

the class VoiceInteractionManagerServiceImpl method startLocked.

void startLocked() {
    Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
    intent.setComponent(mComponent);
    mBound = mContext.bindServiceAsUser(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUser));
    if (!mBound) {
        Slog.w(TAG, "Failed binding to voice interaction service " + mComponent);
    }
}
Also used : UserHandle(android.os.UserHandle) Intent(android.content.Intent)

Aggregations

UserHandle (android.os.UserHandle)568 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)163 PendingIntent (android.app.PendingIntent)132 ComponentName (android.content.ComponentName)69 Context (android.content.Context)68 UserInfo (android.content.pm.UserInfo)66 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)62 Bundle (android.os.Bundle)50 IBinder (android.os.IBinder)49 UserManager (android.os.UserManager)44 PackageManager (android.content.pm.PackageManager)40 ApplicationInfo (android.content.pm.ApplicationInfo)30 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)30 ActivityNotFoundException (android.content.ActivityNotFoundException)28 Notification (android.app.Notification)27 ServiceConnection (android.content.ServiceConnection)27 IPackageManager (android.content.pm.IPackageManager)27 Pair (android.util.Pair)23