Search in sources :

Example 16 with IntentSender

use of android.content.IntentSender in project android_frameworks_base by crdroidandroid.

the class ActivityStarter method showConfirmDeviceCredential.

void showConfirmDeviceCredential(int userId) {
    // First, retrieve the stack that we want to resume after credential is confirmed.
    ActivityStack targetStack;
    ActivityStack fullscreenStack = mSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID);
    ActivityStack freeformStack = mSupervisor.getStack(FREEFORM_WORKSPACE_STACK_ID);
    if (fullscreenStack != null && fullscreenStack.getStackVisibilityLocked(null) != ActivityStack.STACK_INVISIBLE) {
        // Single window case and the case that the docked stack is shown with fullscreen stack.
        targetStack = fullscreenStack;
    } else if (freeformStack != null && freeformStack.getStackVisibilityLocked(null) != ActivityStack.STACK_INVISIBLE) {
        targetStack = freeformStack;
    } else {
        // The case that the docked stack is shown with recent.
        targetStack = mSupervisor.getStack(HOME_STACK_ID);
    }
    if (targetStack == null) {
        return;
    }
    final KeyguardManager km = (KeyguardManager) mService.mContext.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent credential = km.createConfirmDeviceCredentialIntent(null, null, userId);
    // For safety, check null here in case users changed the setting after the checking.
    if (credential == null) {
        return;
    }
    final ActivityRecord activityRecord = targetStack.topRunningActivityLocked();
    if (activityRecord != null) {
        final IIntentSender target = mService.getIntentSenderLocked(ActivityManager.INTENT_SENDER_ACTIVITY, activityRecord.launchedFromPackage, activityRecord.launchedFromUid, activityRecord.userId, null, null, 0, new Intent[] { activityRecord.intent }, new String[] { activityRecord.resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE, null);
        credential.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
        // Show confirm credentials activity.
        startConfirmCredentialIntent(credential);
    }
}
Also used : IIntentSender(android.content.IIntentSender) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IntentSender(android.content.IntentSender) IIntentSender(android.content.IIntentSender) KeyguardManager(android.app.KeyguardManager)

Example 17 with IntentSender

use of android.content.IntentSender in project android_frameworks_base by crdroidandroid.

the class ActiveServices method requestStartTargetPermissionsReviewIfNeededLocked.

private boolean requestStartTargetPermissionsReviewIfNeededLocked(ServiceRecord r, String callingPackage, int callingUid, Intent service, boolean callerFg, final int userId) {
    if (mAm.getPackageManagerInternalLocked().isPermissionsReviewRequired(r.packageName, r.userId)) {
        // Show a permission review UI only for starting from a foreground app
        if (!callerFg) {
            Slog.w(TAG, "u" + r.userId + " Starting a service in package" + r.packageName + " requires a permissions review");
            return false;
        }
        IIntentSender target = mAm.getIntentSenderLocked(ActivityManager.INTENT_SENDER_SERVICE, callingPackage, callingUid, userId, null, null, 0, new Intent[] { service }, new String[] { service.resolveType(mAm.mContext.getContentResolver()) }, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE, null);
        final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, r.packageName);
        intent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
        if (DEBUG_PERMISSIONS_REVIEW) {
            Slog.i(TAG, "u" + r.userId + " Launching permission review for package " + r.packageName);
        }
        mAm.mHandler.post(new Runnable() {

            @Override
            public void run() {
                mAm.mContext.startActivityAsUser(intent, new UserHandle(userId));
            }
        });
        return false;
    }
    return true;
}
Also used : IIntentSender(android.content.IIntentSender) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IIntentSender(android.content.IIntentSender) IntentSender(android.content.IntentSender)

Example 18 with IntentSender

use of android.content.IntentSender in project android_frameworks_base by DirtyUnicorns.

the class PrintManager method print.

/**
     * Creates a print job for printing a {@link PrintDocumentAdapter} with
     * default print attributes.
     * <p>
     * Calling this method brings the print UI allowing the user to customize
     * the print job and returns a {@link PrintJob} object without waiting for the
     * user to customize or confirm the print job. The returned print job instance
     * is in a {@link PrintJobInfo#STATE_CREATED created} state.
     * <p>
     * This method can be called only from an {@link Activity}. The rationale is that
     * printing from a service will create an inconsistent user experience as the print
     * UI would appear without any context.
     * </p>
     * <p>
     * Also the passed in {@link PrintDocumentAdapter} will be considered invalid if
     * your activity is finished. The rationale is that once the activity that
     * initiated printing is finished, the provided adapter may be in an inconsistent
     * state as it may depend on the UI presented by the activity.
     * </p>
     * <p>
     * The default print attributes are a hint to the system how the data is to
     * be printed. For example, a photo editor may look at the photo aspect ratio
     * to determine the default orientation and provide a hint whether the printing
     * should be in portrait or landscape. The system will do a best effort to
     * selected the hinted options in the print dialog, given the current printer
     * supports them.
     * </p>
     * <p>
     * <strong>Note:</strong> Calling this method will bring the print dialog and
     * the system will connect to the provided {@link PrintDocumentAdapter}. If a
     * configuration change occurs that you application does not handle, for example
     * a rotation change, the system will drop the connection to the adapter as the
     * activity has to be recreated and the old adapter may be invalid in this context,
     * hence a new adapter instance is required. As a consequence, if your activity
     * does not handle configuration changes (default behavior), you have to save the
     * state that you were printing and call this method again when your activity
     * is recreated.
     * </p>
     *
     * @param printJobName A name for the new print job which is shown to the user.
     * @param documentAdapter An adapter that emits the document to print.
     * @param attributes The default print job attributes or <code>null</code>.
     * @return The created print job on success or null on failure.
     * @throws IllegalStateException If not called from an {@link Activity}.
     * @throws IllegalArgumentException If the print job name is empty or the
     * document adapter is null.
     *
     * @see PrintJob
     */
@NonNull
public PrintJob print(@NonNull String printJobName, @NonNull PrintDocumentAdapter documentAdapter, @Nullable PrintAttributes attributes) {
    if (mService == null) {
        Log.w(LOG_TAG, "Feature android.software.print not available");
        return null;
    }
    if (!(mContext instanceof Activity)) {
        throw new IllegalStateException("Can print only from an activity");
    }
    if (TextUtils.isEmpty(printJobName)) {
        throw new IllegalArgumentException("printJobName cannot be empty");
    }
    if (documentAdapter == null) {
        throw new IllegalArgumentException("documentAdapter cannot be null");
    }
    PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate((Activity) mContext, documentAdapter);
    try {
        Bundle result = mService.print(printJobName, delegate, attributes, mContext.getPackageName(), mAppId, mUserId);
        if (result != null) {
            PrintJobInfo printJob = result.getParcelable(EXTRA_PRINT_JOB);
            IntentSender intent = result.getParcelable(EXTRA_PRINT_DIALOG_INTENT);
            if (printJob == null || intent == null) {
                return null;
            }
            try {
                mContext.startIntentSender(intent, null, 0, 0, 0);
                return new PrintJob(printJob, this);
            } catch (SendIntentException sie) {
                Log.e(LOG_TAG, "Couldn't start print job config activity.", sie);
            }
        }
    } catch (RemoteException re) {
        throw re.rethrowFromSystemServer();
    }
    return null;
}
Also used : Bundle(android.os.Bundle) Activity(android.app.Activity) IntentSender(android.content.IntentSender) RemoteException(android.os.RemoteException) SendIntentException(android.content.IntentSender.SendIntentException) NonNull(android.annotation.NonNull)

Example 19 with IntentSender

use of android.content.IntentSender in project TinyKeePass by sorz.

the class TinyAutofillService method onFillRequest.

@Override
public void onFillRequest(@NonNull FillRequest request, @NonNull CancellationSignal cancellationSignal, @NonNull FillCallback callback) {
    cancellationSignal.setOnCancelListener(() -> Log.d(TAG, "autofill canceled."));
    if (!hasDatabaseConfigured(this)) {
        callback.onSuccess(null);
        return;
    }
    AssistStructure structure = request.getFillContexts().get(request.getFillContexts().size() - 1).getStructure();
    StructureParser.Result parseResult = new StructureParser(structure).parse();
    if (parseResult.password.isEmpty()) {
        Log.d(TAG, "no password field found");
        callback.onSuccess(null);
        return;
    }
    FillResponse.Builder responseBuilder = new FillResponse.Builder();
    RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_unlock_db), android.R.drawable.ic_lock_lock);
    IntentSender sender = AuthActivity.getAuthIntentSenderForResponse(this);
    AutofillId[] autofillIds = parseResult.allAutofillIds().toArray(AutofillId[]::new);
    responseBuilder.setAuthentication(autofillIds, sender, presentation);
    callback.onSuccess(responseBuilder.build());
}
Also used : RemoteViews(android.widget.RemoteViews) FillResponse(android.service.autofill.FillResponse) AssistStructure(android.app.assist.AssistStructure) IntentSender(android.content.IntentSender) AutofillId(android.view.autofill.AutofillId)

Example 20 with IntentSender

use of android.content.IntentSender in project android_packages_apps_Settings by LineageOS.

the class AccountSyncSettings method requestAccountAccessIfNeeded.

private boolean requestAccountAccessIfNeeded(String packageName) {
    if (packageName == null) {
        return false;
    }
    final int uid;
    try {
        uid = getContext().getPackageManager().getPackageUidAsUser(packageName, mUserHandle.getIdentifier());
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Invalid sync ", e);
        return false;
    }
    AccountManager accountManager = getContext().getSystemService(AccountManager.class);
    if (!accountManager.hasAccountAccess(mAccount, packageName, mUserHandle)) {
        IntentSender intent = accountManager.createRequestAccountAccessIntentSenderAsUser(mAccount, packageName, mUserHandle);
        if (intent != null) {
            try {
                startIntentSenderForResult(intent, uid, null, 0, 0, 0, null);
                return true;
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "Error requesting account access", e);
            }
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) AccountManager(android.accounts.AccountManager) IntentSender(android.content.IntentSender)

Aggregations

IntentSender (android.content.IntentSender)94 Intent (android.content.Intent)48 IIntentSender (android.content.IIntentSender)46 PendingIntent (android.app.PendingIntent)40 RemoteException (android.os.RemoteException)30 UserHandle (android.os.UserHandle)14 ActivityOptions (android.app.ActivityOptions)13 KeyguardManager (android.app.KeyguardManager)10 UserInfo (android.content.pm.UserInfo)10 Bundle (android.os.Bundle)10 IActivityManager (android.app.IActivityManager)8 ComponentName (android.content.ComponentName)8 ActivityInfo (android.content.pm.ActivityInfo)8 ResolveInfo (android.content.pm.ResolveInfo)8 HeavyWeightSwitcherActivity (com.android.internal.app.HeavyWeightSwitcherActivity)8 AccountManager (android.accounts.AccountManager)7 Activity (android.app.Activity)7 PackageManager (android.content.pm.PackageManager)7 Point (android.graphics.Point)7 SpannableStringBuilder (android.text.SpannableStringBuilder)7