Skip to content

Commit c56e560

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Construct a task stack for picking a wifi network from notification" into jb-mr1-dev
2 parents bfbf6e1 + d56b4d1 commit c56e560

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

core/java/android/app/PendingIntent.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,31 @@ public static PendingIntent getActivities(Context context, int requestCode,
394394
return null;
395395
}
396396

397+
/**
398+
* @hide
399+
* Note that UserHandle.CURRENT will be interpreted at the time the
400+
* activity is started, not when the pending intent is created.
401+
*/
402+
public static PendingIntent getActivitiesAsUser(Context context, int requestCode,
403+
Intent[] intents, int flags, Bundle options, UserHandle user) {
404+
String packageName = context.getPackageName();
405+
String[] resolvedTypes = new String[intents.length];
406+
for (int i=0; i<intents.length; i++) {
407+
intents[i].setAllowFds(false);
408+
resolvedTypes[i] = intents[i].resolveTypeIfNeeded(context.getContentResolver());
409+
}
410+
try {
411+
IIntentSender target =
412+
ActivityManagerNative.getDefault().getIntentSender(
413+
ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
414+
null, null, requestCode, intents, resolvedTypes,
415+
flags, options, user.getIdentifier());
416+
return target != null ? new PendingIntent(target) : null;
417+
} catch (RemoteException e) {
418+
}
419+
return null;
420+
}
421+
397422
/**
398423
* Retrieve a PendingIntent that will perform a broadcast, like calling
399424
* {@link Context#sendBroadcast(Intent) Context.sendBroadcast()}.

core/java/android/app/TaskStackBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options
273273
flags, options);
274274
}
275275

276+
/**
277+
* @hide
278+
*/
279+
public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options,
280+
UserHandle user) {
281+
if (mIntents.isEmpty()) {
282+
throw new IllegalStateException(
283+
"No intents added to TaskStackBuilder; cannot getPendingIntent");
284+
}
285+
286+
return PendingIntent.getActivitiesAsUser(mSourceContext, requestCode, getIntents(), flags,
287+
options, user);
288+
}
289+
276290
/**
277291
* Return an array containing the intents added to this builder. The intent at the
278292
* root of the task stack will appear as the first item in the array and the

services/java/com/android/server/WifiService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.app.Notification;
2222
import android.app.NotificationManager;
2323
import android.app.PendingIntent;
24+
import android.app.TaskStackBuilder;
2425
import android.bluetooth.BluetoothAdapter;
2526
import android.content.BroadcastReceiver;
2627
import android.content.ContentResolver;
@@ -1766,9 +1767,10 @@ private void setNotificationVisible(boolean visible, int numNetworks, boolean fo
17661767
mNotification.when = 0;
17671768
mNotification.icon = ICON_NETWORKS_AVAILABLE;
17681769
mNotification.flags = Notification.FLAG_AUTO_CANCEL;
1769-
mNotification.contentIntent = PendingIntent.getActivityAsUser(mContext, 0,
1770-
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK), 0,
1771-
null, UserHandle.CURRENT);
1770+
mNotification.contentIntent = TaskStackBuilder.create(mContext)
1771+
.addNextIntentWithParentStack(
1772+
new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK))
1773+
.getPendingIntent(0, 0, null, UserHandle.CURRENT);
17721774
}
17731775

17741776
CharSequence title = mContext.getResources().getQuantityText(

0 commit comments

Comments
 (0)