Search in sources :

Example 21 with UserHandle

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

the class AccountManagerService method showCantAddAccount.

private void showCantAddAccount(int errorCode, int userId) {
    Intent cantAddAccount = new Intent(mContext, CantAddAccountActivity.class);
    cantAddAccount.putExtra(CantAddAccountActivity.EXTRA_ERROR_CODE, errorCode);
    cantAddAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    long identityToken = clearCallingIdentity();
    try {
        mContext.startActivityAsUser(cantAddAccount, new UserHandle(userId));
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 22 with UserHandle

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

the class Telecom method getPhoneAccountHandleFromArgs.

private PhoneAccountHandle getPhoneAccountHandleFromArgs() throws RemoteException {
    final ComponentName component = parseComponentName(nextArgRequired());
    final String accountId = nextArgRequired();
    final String userSnInStr = nextArgRequired();
    UserHandle userHandle;
    try {
        final int userSn = Integer.parseInt(userSnInStr);
        userHandle = UserHandle.of(mUserManager.getUserHandle(userSn));
    } catch (NumberFormatException ex) {
        throw new IllegalArgumentException("Invalid user serial number " + userSnInStr);
    }
    return new PhoneAccountHandle(component, accountId, userHandle);
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName)

Example 23 with UserHandle

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

the class NfcActivityManager method createBeamShareData.

/** Callback from NFC service, usually on binder thread */
@Override
public BeamShareData createBeamShareData(byte peerLlcpVersion) {
    NfcAdapter.CreateNdefMessageCallback ndefCallback;
    NfcAdapter.CreateBeamUrisCallback urisCallback;
    NdefMessage message;
    Activity activity;
    Uri[] uris;
    int flags;
    NfcEvent event = new NfcEvent(mAdapter, peerLlcpVersion);
    synchronized (NfcActivityManager.this) {
        NfcActivityState state = findResumedActivityState();
        if (state == null)
            return null;
        ndefCallback = state.ndefMessageCallback;
        urisCallback = state.uriCallback;
        message = state.ndefMessage;
        uris = state.uris;
        flags = state.flags;
        activity = state.activity;
    }
    final long ident = Binder.clearCallingIdentity();
    try {
        // Make callbacks without lock
        if (ndefCallback != null) {
            message = ndefCallback.createNdefMessage(event);
        }
        if (urisCallback != null) {
            uris = urisCallback.createBeamUris(event);
            if (uris != null) {
                ArrayList<Uri> validUris = new ArrayList<Uri>();
                for (Uri uri : uris) {
                    if (uri == null) {
                        Log.e(TAG, "Uri not allowed to be null.");
                        continue;
                    }
                    String scheme = uri.getScheme();
                    if (scheme == null || (!scheme.equalsIgnoreCase("file") && !scheme.equalsIgnoreCase("content"))) {
                        Log.e(TAG, "Uri needs to have " + "either scheme file or scheme content");
                        continue;
                    }
                    uri = ContentProvider.maybeAddUserId(uri, UserHandle.myUserId());
                    validUris.add(uri);
                }
                uris = validUris.toArray(new Uri[validUris.size()]);
            }
        }
        if (uris != null && uris.length > 0) {
            for (Uri uri : uris) {
                // Grant the NFC process permission to read these URIs
                activity.grantUriPermission("com.android.nfc", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    return new BeamShareData(message, uris, new UserHandle(UserHandle.myUserId()), flags);
}
Also used : ArrayList(java.util.ArrayList) Activity(android.app.Activity) Uri(android.net.Uri) UserHandle(android.os.UserHandle)

Example 24 with UserHandle

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

the class JobServiceContext method executeRunnableJob.

/**
     * Give a job to this context for execution. Callers must first check {@link #getRunningJob()}
     * and ensure it is null to make sure this is a valid context.
     * @param job The status of the job that we are going to run.
     * @return True if the job is valid and is running. False if the job cannot be executed.
     */
boolean executeRunnableJob(JobStatus job) {
    synchronized (mLock) {
        if (!mAvailable) {
            Slog.e(TAG, "Starting new runnable but context is unavailable > Error.");
            return false;
        }
        mPreferredUid = NO_PREFERRED_UID;
        mRunningJob = job;
        final boolean isDeadlineExpired = job.hasDeadlineConstraint() && (job.getLatestRunTimeElapsed() < SystemClock.elapsedRealtime());
        Uri[] triggeredUris = null;
        if (job.changedUris != null) {
            triggeredUris = new Uri[job.changedUris.size()];
            job.changedUris.toArray(triggeredUris);
        }
        String[] triggeredAuthorities = null;
        if (job.changedAuthorities != null) {
            triggeredAuthorities = new String[job.changedAuthorities.size()];
            job.changedAuthorities.toArray(triggeredAuthorities);
        }
        mParams = new JobParameters(this, job.getJobId(), job.getExtras(), isDeadlineExpired, triggeredUris, triggeredAuthorities);
        mExecutionStartTimeElapsed = SystemClock.elapsedRealtime();
        mVerb = VERB_BINDING;
        scheduleOpTimeOut();
        final Intent intent = new Intent().setComponent(job.getServiceComponent());
        boolean binding = mContext.bindServiceAsUser(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND, new UserHandle(job.getUserId()));
        if (!binding) {
            if (DEBUG) {
                Slog.d(TAG, job.getServiceComponent().getShortClassName() + " unavailable.");
            }
            mRunningJob = null;
            mParams = null;
            mExecutionStartTimeElapsed = 0L;
            mVerb = VERB_FINISHED;
            removeOpTimeOut();
            return false;
        }
        try {
            mBatteryStats.noteJobStart(job.getBatteryName(), job.getSourceUid());
        } catch (RemoteException e) {
        // Whatever.
        }
        mJobPackageTracker.noteActive(job);
        mAvailable = false;
        return true;
    }
}
Also used : UserHandle(android.os.UserHandle) Intent(android.content.Intent) JobParameters(android.app.job.JobParameters) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 25 with UserHandle

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

the class PackageManagerService method movePackage.

@Override
public int movePackage(final String packageName, final String volumeUuid) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
    final UserHandle user = new UserHandle(UserHandle.getCallingUserId());
    final int moveId = mNextMoveId.getAndIncrement();
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                movePackageInternal(packageName, volumeUuid, moveId, user);
            } catch (PackageManagerException e) {
                Slog.w(TAG, "Failed to move " + packageName, e);
                mMoveCallbacks.notifyStatusChanged(moveId, PackageManager.MOVE_FAILED_INTERNAL_ERROR);
            }
        }
    });
    return moveId;
}
Also used : UserHandle(android.os.UserHandle)

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