Search in sources :

Example 16 with UserHandle

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

the class LockscreenWallpaper method run.

@Override
public void run() {
    if (mLoader != null) {
        mLoader.cancel(false);
    }
    final int currentUser = mCurrentUserId;
    final UserHandle selectedUser = mSelectedUser;
    mLoader = new AsyncTask<Void, Void, LoaderResult>() {

        @Override
        protected LoaderResult doInBackground(Void... params) {
            return loadBitmap(currentUser, selectedUser);
        }

        @Override
        protected void onPostExecute(LoaderResult result) {
            super.onPostExecute(result);
            if (isCancelled()) {
                return;
            }
            if (result.success) {
                mCached = true;
                mCache = result.bitmap;
                mUpdateMonitor.setHasLockscreenWallpaper(result.bitmap != null);
                mBar.updateMediaMetaData(true, /* metaDataChanged */
                true);
            }
            mLoader = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : UserHandle(android.os.UserHandle) AsyncTask(android.os.AsyncTask)

Example 17 with UserHandle

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

the class KeyguardBottomAreaView method bindCameraPrewarmService.

public void bindCameraPrewarmService() {
    Intent intent = getCameraIntent();
    ActivityInfo targetInfo = PreviewInflater.getTargetActivityInfo(mContext, intent, KeyguardUpdateMonitor.getCurrentUser(), true);
    if (targetInfo != null && targetInfo.metaData != null) {
        String clazz = targetInfo.metaData.getString(MediaStore.META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE);
        if (clazz != null) {
            Intent serviceIntent = new Intent();
            serviceIntent.setClassName(targetInfo.packageName, clazz);
            serviceIntent.setAction(CameraPrewarmService.ACTION_PREWARM);
            try {
                if (getContext().bindServiceAsUser(serviceIntent, mPrewarmConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(UserHandle.USER_CURRENT))) {
                    mPrewarmBound = true;
                }
            } catch (SecurityException e) {
                Log.w(TAG, "Unable to bind to prewarm service package=" + targetInfo.packageName + " class=" + clazz, e);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) UserHandle(android.os.UserHandle) Intent(android.content.Intent)

Example 18 with UserHandle

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

the class UsbConfirmActivity method onClick.

public void onClick(DialogInterface dialog, int which) {
    if (which == AlertDialog.BUTTON_POSITIVE) {
        try {
            IBinder b = ServiceManager.getService(USB_SERVICE);
            IUsbManager service = IUsbManager.Stub.asInterface(b);
            final int uid = mResolveInfo.activityInfo.applicationInfo.uid;
            final int userId = UserHandle.myUserId();
            boolean alwaysUse = mAlwaysUse.isChecked();
            Intent intent = null;
            if (mDevice != null) {
                intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
                // grant permission for the device
                service.grantDevicePermission(mDevice, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setDevicePackage(mDevice, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setDevicePackage(mDevice, null, userId);
                }
            } else if (mAccessory != null) {
                intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
                // grant permission for the accessory
                service.grantAccessoryPermission(mAccessory, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setAccessoryPackage(mAccessory, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setAccessoryPackage(mAccessory, null, userId);
                }
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setComponent(new ComponentName(mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name));
            startActivityAsUser(intent, new UserHandle(userId));
        } catch (Exception e) {
            Log.e(TAG, "Unable to start activity", e);
        }
    }
    finish();
}
Also used : IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) Intent(android.content.Intent) ComponentName(android.content.ComponentName) IUsbManager(android.hardware.usb.IUsbManager)

Example 19 with UserHandle

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

the class UsbResolverActivity method onTargetSelected.

@Override
protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
    final ResolveInfo ri = target.getResolveInfo();
    try {
        IBinder b = ServiceManager.getService(USB_SERVICE);
        IUsbManager service = IUsbManager.Stub.asInterface(b);
        final int uid = ri.activityInfo.applicationInfo.uid;
        final int userId = UserHandle.myUserId();
        if (mDevice != null) {
            // grant permission for the device
            service.grantDevicePermission(mDevice, uid);
            // set or clear default setting
            if (alwaysCheck) {
                service.setDevicePackage(mDevice, ri.activityInfo.packageName, userId);
            } else {
                service.setDevicePackage(mDevice, null, userId);
            }
        } else if (mAccessory != null) {
            // grant permission for the accessory
            service.grantAccessoryPermission(mAccessory, uid);
            // set or clear default setting
            if (alwaysCheck) {
                service.setAccessoryPackage(mAccessory, ri.activityInfo.packageName, userId);
            } else {
                service.setAccessoryPackage(mAccessory, null, userId);
            }
        }
        try {
            target.startAsUser(this, null, new UserHandle(userId));
        } catch (ActivityNotFoundException e) {
            Log.e(TAG, "startActivity failed", e);
        }
    } catch (RemoteException e) {
        Log.e(TAG, "onIntentSelected failed", e);
    }
    return true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) IBinder(android.os.IBinder) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) IUsbManager(android.hardware.usb.IUsbManager)

Example 20 with UserHandle

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

the class AlarmManagerService method sendNextAlarmClockChanged.

/**
     * Updates NEXT_ALARM_FORMATTED and sends NEXT_ALARM_CLOCK_CHANGED_INTENT for all users
     * for which alarm clocks have changed since the last call to this.
     *
     * Do not call with a lock held. Only call from mHandler's thread.
     *
     * @see AlarmHandler#SEND_NEXT_ALARM_CLOCK_CHANGED
     */
private void sendNextAlarmClockChanged() {
    SparseArray<AlarmManager.AlarmClockInfo> pendingUsers = mHandlerSparseAlarmClockArray;
    pendingUsers.clear();
    synchronized (mLock) {
        final int N = mPendingSendNextAlarmClockChangedForUser.size();
        for (int i = 0; i < N; i++) {
            int userId = mPendingSendNextAlarmClockChangedForUser.keyAt(i);
            pendingUsers.append(userId, mNextAlarmClockForUser.get(userId));
        }
        mPendingSendNextAlarmClockChangedForUser.clear();
    }
    final int N = pendingUsers.size();
    for (int i = 0; i < N; i++) {
        int userId = pendingUsers.keyAt(i);
        AlarmManager.AlarmClockInfo alarmClock = pendingUsers.valueAt(i);
        Settings.System.putStringForUser(getContext().getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, formatNextAlarm(getContext(), alarmClock, userId), userId);
        getContext().sendBroadcastAsUser(NEXT_ALARM_CLOCK_CHANGED_INTENT, new UserHandle(userId));
    }
}
Also used : UserHandle(android.os.UserHandle) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager)

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