Skip to content

Commit 7951c45

Browse files
author
Jean-Baptiste Queru
committed
Merge into jb-mr1-dev
Change-Id: Ifc2328e30a52c2baebc1322c9b161104dcf21618
2 parents a5e1d21 + ea7e915 commit 7951c45

File tree

9 files changed

+95
-14
lines changed

9 files changed

+95
-14
lines changed

core/java/android/app/ActivityManagerNative.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,8 +1530,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
15301530
IBinder resultTo = data.readStrongBinder();
15311531
Bundle options = data.readInt() != 0
15321532
? Bundle.CREATOR.createFromParcel(data) : null;
1533+
int userId = data.readInt();
15331534
int result = startActivities(app, intents, resolvedTypes, resultTo,
1534-
options);
1535+
options, userId);
15351536
reply.writeNoException();
15361537
reply.writeInt(result);
15371538
return true;
@@ -3708,7 +3709,7 @@ public boolean dumpHeap(String process, int userId, boolean managed,
37083709

37093710
public int startActivities(IApplicationThread caller,
37103711
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
3711-
Bundle options) throws RemoteException {
3712+
Bundle options, int userId) throws RemoteException {
37123713
Parcel data = Parcel.obtain();
37133714
Parcel reply = Parcel.obtain();
37143715
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -3722,6 +3723,7 @@ public int startActivities(IApplicationThread caller,
37223723
} else {
37233724
data.writeInt(0);
37243725
}
3726+
data.writeInt(userId);
37253727
mRemote.transact(START_ACTIVITIES_TRANSACTION, data, reply, 0);
37263728
reply.readException();
37273729
int result = reply.readInt();

core/java/android/app/ContextImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,20 @@ public void startActivities(Intent[] intents) {
965965
startActivities(intents, null);
966966
}
967967

968+
/** @hide */
969+
@Override
970+
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
971+
if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
972+
throw new AndroidRuntimeException(
973+
"Calling startActivities() from outside of an Activity "
974+
+ " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
975+
+ " Is this really what you want?");
976+
}
977+
mMainThread.getInstrumentation().execStartActivitiesAsUser(
978+
getOuterContext(), mMainThread.getApplicationThread(), null,
979+
(Activity)null, intents, options, userHandle.getIdentifier());
980+
}
981+
968982
@Override
969983
public void startActivities(Intent[] intents, Bundle options) {
970984
if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {

core/java/android/app/IActivityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public boolean dumpHeap(String process, int userId, boolean managed, String path
311311

312312
public int startActivities(IApplicationThread caller,
313313
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
314-
Bundle options) throws RemoteException;
314+
Bundle options, int userId) throws RemoteException;
315315

316316
public int getFrontActivityScreenCompatMode() throws RemoteException;
317317
public void setFrontActivityScreenCompatMode(int mode) throws RemoteException;

core/java/android/app/Instrumentation.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,21 @@ public ActivityResult execStartActivity(
14301430
*/
14311431
public void execStartActivities(Context who, IBinder contextThread,
14321432
IBinder token, Activity target, Intent[] intents, Bundle options) {
1433+
execStartActivitiesAsUser(who, contextThread, token, target, intents, options,
1434+
UserHandle.myUserId());
1435+
}
1436+
1437+
/**
1438+
* Like {@link #execStartActivity(Context, IBinder, IBinder, Activity, Intent, int)},
1439+
* but accepts an array of activities to be started. Note that active
1440+
* {@link ActivityMonitor} objects only match against the first activity in
1441+
* the array.
1442+
*
1443+
* {@hide}
1444+
*/
1445+
public void execStartActivitiesAsUser(Context who, IBinder contextThread,
1446+
IBinder token, Activity target, Intent[] intents, Bundle options,
1447+
int userId) {
14331448
IApplicationThread whoThread = (IApplicationThread) contextThread;
14341449
if (mActivityMonitors != null) {
14351450
synchronized (mSync) {
@@ -1453,7 +1468,8 @@ public void execStartActivities(Context who, IBinder contextThread,
14531468
resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver());
14541469
}
14551470
int result = ActivityManagerNative.getDefault()
1456-
.startActivities(whoThread, intents, resolvedTypes, token, options);
1471+
.startActivities(whoThread, intents, resolvedTypes, token, options,
1472+
userId);
14571473
checkStartActivityResult(result, intents[0]);
14581474
} catch (RemoteException e) {
14591475
}

core/java/android/app/TaskStackBuilder.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.content.pm.PackageManager;
2424
import android.content.pm.PackageManager.NameNotFoundException;
2525
import android.os.Bundle;
26+
import android.os.UserHandle;
2627
import android.util.Log;
2728

2829
import java.util.ArrayList;
@@ -209,18 +210,26 @@ public void startActivities() {
209210

210211
/**
211212
* Start the task stack constructed by this builder.
212-
*
213-
* @param options Additional options for how the Activity should be started.
214-
* See {@link android.content.Context#startActivity(Intent, Bundle)
215-
* Context.startActivity(Intent, Bundle)} for more details.
213+
* @hide
216214
*/
217-
public void startActivities(Bundle options) {
215+
public void startActivities(Bundle options, UserHandle userHandle) {
218216
if (mIntents.isEmpty()) {
219217
throw new IllegalStateException(
220218
"No intents added to TaskStackBuilder; cannot startActivities");
221219
}
222220

223-
mSourceContext.startActivities(getIntents(), options);
221+
mSourceContext.startActivitiesAsUser(getIntents(), options, userHandle);
222+
}
223+
224+
/**
225+
* Start the task stack constructed by this builder.
226+
*
227+
* @param options Additional options for how the Activity should be started.
228+
* See {@link android.content.Context#startActivity(Intent, Bundle)
229+
* Context.startActivity(Intent, Bundle)} for more details.
230+
*/
231+
public void startActivities(Bundle options) {
232+
startActivities(options, new UserHandle(UserHandle.myUserId()));
224233
}
225234

226235
/**

core/java/android/content/Context.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,36 @@ public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId
973973
*/
974974
public abstract void startActivities(Intent[] intents, Bundle options);
975975

976+
/**
977+
* @hide
978+
* Launch multiple new activities. This is generally the same as calling
979+
* {@link #startActivity(Intent)} for the first Intent in the array,
980+
* that activity during its creation calling {@link #startActivity(Intent)}
981+
* for the second entry, etc. Note that unlike that approach, generally
982+
* none of the activities except the last in the array will be created
983+
* at this point, but rather will be created when the user first visits
984+
* them (due to pressing back from the activity on top).
985+
*
986+
* <p>This method throws {@link ActivityNotFoundException}
987+
* if there was no Activity found for <em>any</em> given Intent. In this
988+
* case the state of the activity stack is undefined (some Intents in the
989+
* list may be on it, some not), so you probably want to avoid such situations.
990+
*
991+
* @param intents An array of Intents to be started.
992+
* @param options Additional options for how the Activity should be started.
993+
* @param userHandle The user for whom to launch the activities
994+
* See {@link android.content.Context#startActivity(Intent, Bundle)
995+
* Context.startActivity(Intent, Bundle)} for more details.
996+
*
997+
* @throws ActivityNotFoundException
998+
*
999+
* @see {@link #startActivities(Intent[])}
1000+
* @see PackageManager#resolveActivity
1001+
*/
1002+
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1003+
throw new RuntimeException("Not implemented. Must override in a subclass.");
1004+
}
1005+
9761006
/**
9771007
* Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
9781008
* with no options specified.

core/java/android/content/ContextWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ public void startActivities(Intent[] intents, Bundle options) {
311311
mBase.startActivities(intents, options);
312312
}
313313

314+
/** @hide */
315+
@Override
316+
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
317+
mBase.startActivitiesAsUser(intents, options, userHandle);
318+
}
319+
314320
@Override
315321
public void startIntentSender(IntentSender intent,
316322
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ private void startApplicationDetailsActivity(String packageName) {
342342
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
343343
Uri.fromParts("package", packageName, null));
344344
intent.setComponent(intent.resolveActivity(mContext.getPackageManager()));
345-
TaskStackBuilder.create(mContext).addNextIntentWithParentStack(intent).startActivities();
345+
TaskStackBuilder.create(mContext).addNextIntentWithParentStack(intent).startActivities(
346+
null, UserHandle.CURRENT);
346347
}
347348

348349
protected View.OnLongClickListener getNotificationLongClicker() {

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,10 +2623,13 @@ final int startActivityInPackage(int uid,
26232623
}
26242624

26252625
public final int startActivities(IApplicationThread caller,
2626-
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options) {
2626+
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options,
2627+
int userId) {
26272628
enforceNotIsolatedCaller("startActivities");
2629+
userId = handleIncomingUserLocked(Binder.getCallingPid(), Binder.getCallingUid(), userId,
2630+
false, true, "startActivity", null);
26282631
int ret = mMainStack.startActivities(caller, -1, intents, resolvedTypes, resultTo,
2629-
options, UserHandle.getCallingUserId());
2632+
options, userId);
26302633
return ret;
26312634
}
26322635

@@ -12412,7 +12415,7 @@ public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
1241212415
} else {
1241312416
try {
1241412417
ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
12415-
destIntent.getComponent(), 0, UserHandle.getCallingUserId());
12418+
destIntent.getComponent(), 0, srec.userId);
1241612419
int res = mMainStack.startActivityLocked(srec.app.thread, destIntent,
1241712420
null, aInfo, parent.appToken, null,
1241812421
0, -1, parent.launchedFromUid, 0, null, true, null);

0 commit comments

Comments
 (0)