/** * Perform the operation associated with this PendingIntent, allowing the caller to specify * information about the Intent to use and be notified when the send has completed. * * <p>For the intent parameter, a PendingIntent often has restrictions on which fields can be * supplied here, based on how the PendingIntent was retrieved in {@link #getActivity}, {@link * #getBroadcast}, or {@link #getService}. * * @param context The Context of the caller. This may be null if <var>intent</var> is also null. * @param code Result code to supply back to the PendingIntent's target. * @param intent Additional Intent data. See {@link Intent#fillIn Intent.fillIn()} for information * on how this is applied to the original Intent. Use null to not modify the original Intent. * If flag {@link #FLAG_IMMUTABLE} was set when this pending intent was created, this argument * will be ignored. * @param onFinished The object to call back on when the send has completed, or null for no * callback. * @param handler Handler identifying the thread on which the callback should happen. If null, the * callback will happen from the thread pool of the process. * @param requiredPermission Name of permission that a recipient of the PendingIntent is required * to hold. This is only valid for broadcast intents, and corresponds to the permission * argument in {@link Context#sendBroadcast(Intent, String) * Context.sendOrderedBroadcast(Intent, String)}. If null, no permission is required. * @param options Additional options the caller would like to provide to modify the sending * behavior. May be built from an {@link ActivityOptions} to apply to an activity start. * @see #send() * @see #send(int) * @see #send(Context, int, Intent) * @see #send(int, android.app.PendingIntent.OnFinished, Handler) * @see #send(Context, int, Intent, OnFinished, Handler) * @throws CanceledException Throws CanceledException if the PendingIntent is no longer allowing * more intents to be sent through it. */ public void send( Context context, int code, @Nullable Intent intent, @Nullable OnFinished onFinished, @Nullable Handler handler, @Nullable String requiredPermission, @Nullable Bundle options) throws CanceledException { try { String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; int res = mTarget.send( code, intent, resolvedType, onFinished != null ? new FinishedDispatcher(this, onFinished, handler) : null, requiredPermission, options); if (res < 0) { throw new CanceledException(); } } catch (RemoteException e) { throw new CanceledException(e); } }
/** * Retrieve a PendingIntent that will start a service, like calling {@link Context#startService * Context.startService()}. The start arguments given to the service will come from the extras of * the Intent. * * <p class="note">For security reasons, the {@link android.content.Intent} you supply here should * almost always be an <em>explicit intent</em>, that is specify an explicit component to be * delivered to through {@link Intent#setClass(android.content.Context, Class) Intent.setClass} * * @param context The Context in which this PendingIntent should start the service. * @param requestCode Private request code for the sender * @param intent An Intent describing the service to be started. * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE}, {@link * #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT}, or any of the flags as supported by * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts of the intent that * can be supplied when the actual send happens. * @return Returns an existing or new PendingIntent matching the given parameters. May return null * only if {@link #FLAG_NO_CREATE} has been supplied. */ public static PendingIntent getService( Context context, int requestCode, @NonNull Intent intent, @Flags int flags) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_SERVICE, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, null, UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
/** * @hide Note that UserHandle.CURRENT will be interpreted at the time the broadcast is sent, not * when the pending intent is created. */ public static PendingIntent getBroadcastAsUser( Context context, int requestCode, Intent intent, int flags, UserHandle userHandle) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_BROADCAST, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, null, userHandle.getIdentifier()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
/** * @hide Note that UserHandle.CURRENT will be interpreted at the time the activity is started, not * when the pending intent is created. */ public static PendingIntent getActivityAsUser( Context context, int requestCode, @NonNull Intent intent, int flags, Bundle options, UserHandle user) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_ACTIVITY, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, options, user.getIdentifier()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
@Override public ServiceInfo selectStubServiceInfoByIntent(Intent intent) throws RemoteException { ServiceInfo ai = null; if (intent.getComponent() != null) { ai = getServiceInfo(intent.getComponent(), 0); } else { ResolveInfo resolveInfo = resolveIntent(intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), 0); if (resolveInfo.serviceInfo != null) { ai = resolveInfo.serviceInfo; } } if (ai != null) { return selectStubServiceInfo(ai); } return null; }
/** * Broadcast the given intent to all interested BroadcastReceivers. This call is asynchronous; it * returns immediately, and you will continue executing while the receivers are run. * * @param intent The Intent to broadcast; all receivers matching this Intent will receive the * broadcast. * @see #registerReceiver */ public boolean sendBroadcast(Intent intent) { synchronized (mReceivers) { final String action = intent.getAction(); final String type = intent.resolveTypeIfNeeded(mAppContext.getContentResolver()); final Uri data = intent.getData(); final String scheme = intent.getScheme(); final Set<String> categories = intent.getCategories(); final boolean debug = DEBUG || ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); if (debug) Log.v(TAG, "Resolving type " + type + " scheme " + scheme + " of intent " + intent); ArrayList<ReceiverRecord> entries = mActions.get(intent.getAction()); if (entries != null) { if (debug) Log.v(TAG, "Action list: " + entries); ArrayList<ReceiverRecord> receivers = null; for (int i = 0; i < entries.size(); i++) { ReceiverRecord receiver = entries.get(i); if (debug) Log.v(TAG, "Matching against filter " + receiver.filter); if (receiver.broadcasting) { if (debug) { Log.v(TAG, " Filter's target already added"); } continue; } int match = receiver.filter.match( action, type, scheme, data, categories, "LocalBroadcastManager"); if (match >= 0) { if (debug) Log.v(TAG, " Filter matched! match=0x" + Integer.toHexString(match)); if (receivers == null) { receivers = new ArrayList<ReceiverRecord>(); } receivers.add(receiver); receiver.broadcasting = true; } else { if (debug) { String reason; switch (match) { case IntentFilter.NO_MATCH_ACTION: reason = "action"; break; case IntentFilter.NO_MATCH_CATEGORY: reason = "category"; break; case IntentFilter.NO_MATCH_DATA: reason = "data"; break; case IntentFilter.NO_MATCH_TYPE: reason = "type"; break; default: reason = "unknown reason"; break; } Log.v(TAG, " Filter did not match: " + reason); } } } if (receivers != null) { for (int i = 0; i < receivers.size(); i++) { receivers.get(i).broadcasting = false; } mPendingBroadcasts.add(new BroadcastRecord(intent, receivers)); if (!mHandler.hasMessages(MSG_EXEC_PENDING_BROADCASTS)) { mHandler.sendEmptyMessage(MSG_EXEC_PENDING_BROADCASTS); } return true; } } } return false; }
public boolean sendBroadcast(Intent paramIntent) { int i; label57: int j; label162: int l; ArrayList localArrayList2; synchronized (this.mReceivers) { String str1 = paramIntent.getAction(); String str2 = paramIntent.resolveTypeIfNeeded(this.mAppContext.getContentResolver()); Uri localUri = paramIntent.getData(); String str3 = paramIntent.getScheme(); Set localSet = paramIntent.getCategories(); if ((0x8 & paramIntent.getFlags()) == 0) break label500; i = 1; if (i != 0) Log.v("LocalBroadcastManager", "Resolving type " + str2 + " scheme " + str3 + " of intent " + paramIntent); ArrayList localArrayList1 = (ArrayList)this.mActions.get(paramIntent.getAction()); if (localArrayList1 == null) break label481; if (i == 0) break label485; Log.v("LocalBroadcastManager", "Action list: " + localArrayList1); break label485: if (j >= localArrayList1.size()) break label534; ReceiverRecord localReceiverRecord = (ReceiverRecord)localArrayList1.get(j); if (i != 0) Log.v("LocalBroadcastManager", "Matching against filter " + localReceiverRecord.filter); if (localReceiverRecord.broadcasting) { if (i != 0) Log.v("LocalBroadcastManager", " Filter's target already added"); } else { l = localReceiverRecord.filter.match(str1, str2, str3, localUri, localSet, "LocalBroadcastManager"); if (l >= 0) { if (i != 0) Log.v("LocalBroadcastManager", " Filter matched! match=0x" + Integer.toHexString(l)); if (localArrayList2 == null) localArrayList2 = new ArrayList(); localArrayList2.add(localReceiverRecord); localReceiverRecord.broadcasting = true; } } } String str4; if (i != 0) switch (l) { default: str4 = "unknown reason"; label380: Log.v("LocalBroadcastManager", " Filter did not match: " + str4); break; case -3: case -4: case -2: case -1: } while (true) { if (k < localArrayList2.size()) { ((ReceiverRecord)localArrayList2.get(k)).broadcasting = false; ++k; } this.mPendingBroadcasts.add(new BroadcastRecord(paramIntent, localArrayList2)); if (!this.mHandler.hasMessages(1)) this.mHandler.sendEmptyMessage(1); monitorexit; return true; do { label481: monitorexit; return false; label485: j = 0; localArrayList2 = null; break label162: ++j; break label162: label500: i = 0; break label57: str4 = "action"; break label380: str4 = "category"; break label380: str4 = "data"; break label380: str4 = "type"; label534: break label380: } while (localArrayList2 == null); int k = 0; } }