use of android.content.IntentSender in project android_frameworks_base by crdroidandroid.
the class BroadcastQueue method requestStartTargetPermissionsReviewIfNeededLocked.
private boolean requestStartTargetPermissionsReviewIfNeededLocked(BroadcastRecord receiverRecord, String receivingPackageName, final int receivingUserId) {
if (!mService.getPackageManagerInternalLocked().isPermissionsReviewRequired(receivingPackageName, receivingUserId)) {
return true;
}
final boolean callerForeground = receiverRecord.callerApp != null ? receiverRecord.callerApp.setSchedGroup != ProcessList.SCHED_GROUP_BACKGROUND : true;
// Show a permission review UI only for explicit broadcast from a foreground app
if (callerForeground && receiverRecord.intent.getComponent() != null) {
IIntentSender target = mService.getIntentSenderLocked(ActivityManager.INTENT_SENDER_BROADCAST, receiverRecord.callerPackage, receiverRecord.callingUid, receiverRecord.userId, null, null, 0, new Intent[] { receiverRecord.intent }, new String[] { receiverRecord.intent.resolveType(mService.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, receivingPackageName);
intent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
if (DEBUG_PERMISSIONS_REVIEW) {
Slog.i(TAG, "u" + receivingUserId + " Launching permission review for package " + receivingPackageName);
}
mHandler.post(new Runnable() {
@Override
public void run() {
mService.mContext.startActivityAsUser(intent, new UserHandle(receivingUserId));
}
});
} else {
Slog.w(TAG, "u" + receivingUserId + " Receiving a broadcast in package" + receivingPackageName + " requires a permissions review");
}
return false;
}
use of android.content.IntentSender in project android_frameworks_base by crdroidandroid.
the class UserState method print.
@SuppressWarnings("deprecation")
public Bundle print(@NonNull String printJobName, @NonNull IPrintDocumentAdapter adapter, @Nullable PrintAttributes attributes, @NonNull String packageName, int appId) {
// Create print job place holder.
final PrintJobInfo printJob = new PrintJobInfo();
printJob.setId(new PrintJobId());
printJob.setAppId(appId);
printJob.setLabel(printJobName);
printJob.setAttributes(attributes);
printJob.setState(PrintJobInfo.STATE_CREATED);
printJob.setCopies(1);
printJob.setCreationTime(System.currentTimeMillis());
// Track this job so we can forget it when the creator dies.
if (!mPrintJobForAppCache.onPrintJobCreated(adapter.asBinder(), appId, printJob)) {
// Not adding a print job means the client is dead - done.
return null;
}
// Spin the spooler to add the job and show the config UI.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mSpooler.createPrintJob(printJob);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
final long identity = Binder.clearCallingIdentity();
try {
Intent intent = new Intent(PrintManager.ACTION_PRINT_DIALOG);
intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
intent.putExtra(PrintManager.EXTRA_PRINT_DOCUMENT_ADAPTER, adapter.asBinder());
intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);
IntentSender intentSender = PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, null, new UserHandle(mUserId)).getIntentSender();
Bundle result = new Bundle();
result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);
result.putParcelable(PrintManager.EXTRA_PRINT_DIALOG_INTENT, intentSender);
return result;
} finally {
Binder.restoreCallingIdentity(identity);
}
}
use of android.content.IntentSender in project android_frameworks_base by crdroidandroid.
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;
}
use of android.content.IntentSender in project android_packages_apps_Settings by LineageOS.
the class ChooseLockSettingsHelper method copyOptionalExtras.
private void copyOptionalExtras(Intent inIntent, Intent outIntent) {
IntentSender intentSender = inIntent.getParcelableExtra(Intent.EXTRA_INTENT);
if (intentSender != null) {
outIntent.putExtra(Intent.EXTRA_INTENT, intentSender);
}
int taskId = inIntent.getIntExtra(Intent.EXTRA_TASK_ID, -1);
if (taskId != -1) {
outIntent.putExtra(Intent.EXTRA_TASK_ID, taskId);
}
// TODO: Remove once that bug is fixed.
if (intentSender != null || taskId != -1) {
outIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
outIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
}
}
use of android.content.IntentSender in project android_packages_apps_Settings by LineageOS.
the class ConfirmDeviceCredentialBaseFragment method checkForPendingIntent.
protected void checkForPendingIntent() {
int taskId = getActivity().getIntent().getIntExtra(Intent.EXTRA_TASK_ID, -1);
if (taskId != -1) {
try {
IActivityManager activityManager = ActivityManager.getService();
final ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchStackId(ActivityManager.StackId.INVALID_STACK_ID);
activityManager.startActivityFromRecents(taskId, options.toBundle());
return;
} catch (RemoteException e) {
// Do nothing.
}
}
IntentSender intentSender = getActivity().getIntent().getParcelableExtra(Intent.EXTRA_INTENT);
if (intentSender != null) {
try {
getActivity().startIntentSenderForResult(intentSender, -1, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
/* ignore */
}
}
}
Aggregations