Merge into jb-mr1-dev

Change-Id: Ifc2328e30a52c2baebc1322c9b161104dcf21618
This commit is contained in:
Jean-Baptiste Queru
2012-09-25 09:36:28 -07:00
9 changed files with 95 additions and 14 deletions

View File

@@ -1530,8 +1530,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
IBinder resultTo = data.readStrongBinder();
Bundle options = data.readInt() != 0
? Bundle.CREATOR.createFromParcel(data) : null;
int userId = data.readInt();
int result = startActivities(app, intents, resolvedTypes, resultTo,
options);
options, userId);
reply.writeNoException();
reply.writeInt(result);
return true;
@@ -3708,7 +3709,7 @@ class ActivityManagerProxy implements IActivityManager
public int startActivities(IApplicationThread caller,
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
Bundle options) throws RemoteException {
Bundle options, int userId) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
@@ -3722,6 +3723,7 @@ class ActivityManagerProxy implements IActivityManager
} else {
data.writeInt(0);
}
data.writeInt(userId);
mRemote.transact(START_ACTIVITIES_TRANSACTION, data, reply, 0);
reply.readException();
int result = reply.readInt();

View File

@@ -965,6 +965,20 @@ class ContextImpl extends Context {
startActivities(intents, null);
}
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
throw new AndroidRuntimeException(
"Calling startActivities() from outside of an Activity "
+ " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
+ " Is this really what you want?");
}
mMainThread.getInstrumentation().execStartActivitiesAsUser(
getOuterContext(), mMainThread.getApplicationThread(), null,
(Activity)null, intents, options, userHandle.getIdentifier());
}
@Override
public void startActivities(Intent[] intents, Bundle options) {
if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {

View File

@@ -311,7 +311,7 @@ public interface IActivityManager extends IInterface {
public int startActivities(IApplicationThread caller,
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
Bundle options) throws RemoteException;
Bundle options, int userId) throws RemoteException;
public int getFrontActivityScreenCompatMode() throws RemoteException;
public void setFrontActivityScreenCompatMode(int mode) throws RemoteException;

View File

@@ -1430,6 +1430,21 @@ public class Instrumentation {
*/
public void execStartActivities(Context who, IBinder contextThread,
IBinder token, Activity target, Intent[] intents, Bundle options) {
execStartActivitiesAsUser(who, contextThread, token, target, intents, options,
UserHandle.myUserId());
}
/**
* Like {@link #execStartActivity(Context, IBinder, IBinder, Activity, Intent, int)},
* but accepts an array of activities to be started. Note that active
* {@link ActivityMonitor} objects only match against the first activity in
* the array.
*
* {@hide}
*/
public void execStartActivitiesAsUser(Context who, IBinder contextThread,
IBinder token, Activity target, Intent[] intents, Bundle options,
int userId) {
IApplicationThread whoThread = (IApplicationThread) contextThread;
if (mActivityMonitors != null) {
synchronized (mSync) {
@@ -1453,7 +1468,8 @@ public class Instrumentation {
resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver());
}
int result = ActivityManagerNative.getDefault()
.startActivities(whoThread, intents, resolvedTypes, token, options);
.startActivities(whoThread, intents, resolvedTypes, token, options,
userId);
checkStartActivityResult(result, intents[0]);
} catch (RemoteException e) {
}

View File

@@ -23,6 +23,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import java.util.ArrayList;
@@ -207,6 +208,19 @@ public class TaskStackBuilder {
startActivities(null);
}
/**
* Start the task stack constructed by this builder.
* @hide
*/
public void startActivities(Bundle options, UserHandle userHandle) {
if (mIntents.isEmpty()) {
throw new IllegalStateException(
"No intents added to TaskStackBuilder; cannot startActivities");
}
mSourceContext.startActivitiesAsUser(getIntents(), options, userHandle);
}
/**
* Start the task stack constructed by this builder.
*
@@ -215,12 +229,7 @@ public class TaskStackBuilder {
* Context.startActivity(Intent, Bundle)} for more details.
*/
public void startActivities(Bundle options) {
if (mIntents.isEmpty()) {
throw new IllegalStateException(
"No intents added to TaskStackBuilder; cannot startActivities");
}
mSourceContext.startActivities(getIntents(), options);
startActivities(options, new UserHandle(UserHandle.myUserId()));
}
/**

View File

@@ -973,6 +973,36 @@ public abstract class Context {
*/
public abstract void startActivities(Intent[] intents, Bundle options);
/**
* @hide
* Launch multiple new activities. This is generally the same as calling
* {@link #startActivity(Intent)} for the first Intent in the array,
* that activity during its creation calling {@link #startActivity(Intent)}
* for the second entry, etc. Note that unlike that approach, generally
* none of the activities except the last in the array will be created
* at this point, but rather will be created when the user first visits
* them (due to pressing back from the activity on top).
*
* <p>This method throws {@link ActivityNotFoundException}
* if there was no Activity found for <em>any</em> given Intent. In this
* case the state of the activity stack is undefined (some Intents in the
* list may be on it, some not), so you probably want to avoid such situations.
*
* @param intents An array of Intents to be started.
* @param options Additional options for how the Activity should be started.
* @param userHandle The user for whom to launch the activities
* See {@link android.content.Context#startActivity(Intent, Bundle)
* Context.startActivity(Intent, Bundle)} for more details.
*
* @throws ActivityNotFoundException
*
* @see {@link #startActivities(Intent[])}
* @see PackageManager#resolveActivity
*/
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
throw new RuntimeException("Not implemented. Must override in a subclass.");
}
/**
* Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
* with no options specified.

View File

@@ -311,6 +311,12 @@ public class ContextWrapper extends Context {
mBase.startActivities(intents, options);
}
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
mBase.startActivitiesAsUser(intents, options, userHandle);
}
@Override
public void startIntentSender(IntentSender intent,
Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)

View File

@@ -342,7 +342,8 @@ public abstract class BaseStatusBar extends SystemUI implements
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", packageName, null));
intent.setComponent(intent.resolveActivity(mContext.getPackageManager()));
TaskStackBuilder.create(mContext).addNextIntentWithParentStack(intent).startActivities();
TaskStackBuilder.create(mContext).addNextIntentWithParentStack(intent).startActivities(
null, UserHandle.CURRENT);
}
protected View.OnLongClickListener getNotificationLongClicker() {

View File

@@ -2623,10 +2623,13 @@ public final class ActivityManagerService extends ActivityManagerNative
}
public final int startActivities(IApplicationThread caller,
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options) {
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options,
int userId) {
enforceNotIsolatedCaller("startActivities");
userId = handleIncomingUserLocked(Binder.getCallingPid(), Binder.getCallingUid(), userId,
false, true, "startActivity", null);
int ret = mMainStack.startActivities(caller, -1, intents, resolvedTypes, resultTo,
options, UserHandle.getCallingUserId());
options, userId);
return ret;
}
@@ -12412,7 +12415,7 @@ public final class ActivityManagerService extends ActivityManagerNative
} else {
try {
ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
destIntent.getComponent(), 0, UserHandle.getCallingUserId());
destIntent.getComponent(), 0, srec.userId);
int res = mMainStack.startActivityLocked(srec.app.thread, destIntent,
null, aInfo, parent.appToken, null,
0, -1, parent.launchedFromUid, 0, null, true, null);