From a4972e951bf2bdb7afdafee95b3ab0c15b8bacae Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 14 Mar 2012 10:38:05 -0700 Subject: [PATCH] Add new "options" argument to all startActivity APIs. This will be used to allow new features to be requested... such as, say, a special kind of animation. Right now there are no options defined. Change-Id: I4eb6f27275cdd4bf186f6da316ab93a2372ad4b7 --- api/current.txt | 18 ++ cmds/am/src/com/android/commands/am/Am.java | 42 +-- core/java/android/app/Activity.java | 306 +++++++++++++++--- core/java/android/app/ActivityManager.java | 148 +++++++++ .../android/app/ActivityManagerNative.java | 166 ++++++---- core/java/android/app/ActivityThread.java | 2 +- core/java/android/app/ContextImpl.java | 25 +- core/java/android/app/Fragment.java | 36 ++- core/java/android/app/IActivityManager.java | 69 +--- core/java/android/app/Instrumentation.java | 30 +- core/java/android/app/PendingIntent.java | 8 +- core/java/android/content/Context.java | 67 +++- core/java/android/content/ContextWrapper.java | 18 ++ .../policy/impl/PhoneWindowManager.java | 18 +- .../android/server/UiModeManagerService.java | 4 +- .../server/am/ActivityManagerService.java | 95 +++--- .../com/android/server/am/ActivityStack.java | 130 +++----- .../server/am/PendingIntentRecord.java | 29 +- .../src/android/test/mock/MockContext.java | 17 + .../bridge/android/BridgeContext.java | 17 + 20 files changed, 871 insertions(+), 374 deletions(-) diff --git a/api/current.txt b/api/current.txt index 6056bf785f567..0e3fee64c6671 100644 --- a/api/current.txt +++ b/api/current.txt @@ -2688,13 +2688,20 @@ package android.app { method public final deprecated boolean showDialog(int, android.os.Bundle); method public android.view.ActionMode startActionMode(android.view.ActionMode.Callback); method public void startActivityForResult(android.content.Intent, int); + method public void startActivityForResult(android.content.Intent, int, android.os.Bundle); method public void startActivityFromChild(android.app.Activity, android.content.Intent, int); + method public void startActivityFromChild(android.app.Activity, android.content.Intent, int, android.os.Bundle); method public void startActivityFromFragment(android.app.Fragment, android.content.Intent, int); + method public void startActivityFromFragment(android.app.Fragment, android.content.Intent, int, android.os.Bundle); method public boolean startActivityIfNeeded(android.content.Intent, int); + method public boolean startActivityIfNeeded(android.content.Intent, int, android.os.Bundle); method public void startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException; + method public void startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException; method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException; + method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException; method public deprecated void startManagingCursor(android.database.Cursor); method public boolean startNextMatchingActivity(android.content.Intent); + method public boolean startNextMatchingActivity(android.content.Intent, android.os.Bundle); method public void startSearch(java.lang.String, boolean, android.os.Bundle, boolean); method public deprecated void stopManagingCursor(android.database.Cursor); method public void takeKeyEvents(boolean); @@ -3320,7 +3327,9 @@ package android.app { method public void setTargetFragment(android.app.Fragment, int); method public void setUserVisibleHint(boolean); method public void startActivity(android.content.Intent); + method public void startActivity(android.content.Intent, android.os.Bundle); method public void startActivityForResult(android.content.Intent, int); + method public void startActivityForResult(android.content.Intent, int, android.os.Bundle); method public void unregisterForContextMenu(android.view.View); } @@ -5149,9 +5158,12 @@ package android.content { method public abstract deprecated void setWallpaper(android.graphics.Bitmap) throws java.io.IOException; method public abstract deprecated void setWallpaper(java.io.InputStream) throws java.io.IOException; method public abstract void startActivities(android.content.Intent[]); + method public abstract void startActivities(android.content.Intent[], android.os.Bundle); method public abstract void startActivity(android.content.Intent); + method public abstract void startActivity(android.content.Intent, android.os.Bundle); method public abstract boolean startInstrumentation(android.content.ComponentName, java.lang.String, android.os.Bundle); method public abstract void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException; + method public abstract void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException; method public abstract android.content.ComponentName startService(android.content.Intent); method public abstract boolean stopService(android.content.Intent); method public abstract void unbindService(android.content.ServiceConnection); @@ -5274,9 +5286,12 @@ package android.content { method public void setWallpaper(android.graphics.Bitmap) throws java.io.IOException; method public void setWallpaper(java.io.InputStream) throws java.io.IOException; method public void startActivities(android.content.Intent[]); + method public void startActivities(android.content.Intent[], android.os.Bundle); method public void startActivity(android.content.Intent); + method public void startActivity(android.content.Intent, android.os.Bundle); method public boolean startInstrumentation(android.content.ComponentName, java.lang.String, android.os.Bundle); method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException; + method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException; method public android.content.ComponentName startService(android.content.Intent); method public boolean stopService(android.content.Intent); method public void unbindService(android.content.ServiceConnection); @@ -19926,9 +19941,12 @@ package android.test.mock { method public void setWallpaper(android.graphics.Bitmap) throws java.io.IOException; method public void setWallpaper(java.io.InputStream) throws java.io.IOException; method public void startActivities(android.content.Intent[]); + method public void startActivities(android.content.Intent[], android.os.Bundle); method public void startActivity(android.content.Intent); + method public void startActivity(android.content.Intent, android.os.Bundle); method public boolean startInstrumentation(android.content.ComponentName, java.lang.String, android.os.Bundle); method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException; + method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException; method public android.content.ComponentName startService(android.content.Intent); method public boolean stopService(android.content.Intent); method public void unbindService(android.content.ServiceConnection); diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index da38df13ae81e..c15c49f9d0869 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -57,16 +57,13 @@ public class Am { private int mNextArg; private String mCurArgData; - private boolean mDebugOption = false; + private int mStartFlags = 0; private boolean mWaitOption = false; private boolean mStopOption = false; - private boolean mOpenglTraceOption = false; - private int mRepeat = 0; private String mProfileFile; - private boolean mProfileAutoStop; // These are magic strings understood by the Eclipse plugin. private static final String FATAL_ERROR_CODE = "Error type 1"; @@ -150,10 +147,9 @@ public class Am { Intent baseIntent = intent; boolean hasIntentInfo = false; - mDebugOption = false; + mStartFlags = 0; mWaitOption = false; mStopOption = false; - mOpenglTraceOption = false; mRepeat = 0; mProfileFile = null; Uri data = null; @@ -297,21 +293,21 @@ public class Am { intent.setDataAndType(data, type); intent = new Intent(); } else if (opt.equals("-D")) { - mDebugOption = true; + mStartFlags |= ActivityManager.START_FLAG_DEBUG; } else if (opt.equals("-W")) { mWaitOption = true; } else if (opt.equals("-P")) { mProfileFile = nextArgRequired(); - mProfileAutoStop = true; + mStartFlags |= ActivityManager.START_FLAG_AUTO_STOP_PROFILER; } else if (opt.equals("--start-profiler")) { mProfileFile = nextArgRequired(); - mProfileAutoStop = false; + mStartFlags &= ~ActivityManager.START_FLAG_AUTO_STOP_PROFILER; } else if (opt.equals("-R")) { mRepeat = Integer.parseInt(nextArgRequired()); } else if (opt.equals("-S")) { mStopOption = true; } else if (opt.equals("--opengl-trace")) { - mOpenglTraceOption = true; + mStartFlags |= ActivityManager.START_FLAG_OPENGL_TRACES; } else { System.err.println("Error: Unknown option: " + opt); showUsage(); @@ -450,64 +446,60 @@ public class Am { int res; if (mWaitOption) { result = mAm.startActivityAndWait(null, intent, mimeType, - null, 0, null, null, 0, false, - mDebugOption, mOpenglTraceOption, - mProfileFile, fd, mProfileAutoStop); + null, null, 0, mStartFlags, mProfileFile, fd, null); res = result.result; } else { res = mAm.startActivity(null, intent, mimeType, - null, 0, null, null, 0, false, - mDebugOption, mOpenglTraceOption, - mProfileFile, fd, mProfileAutoStop); + null, null, 0, mStartFlags, mProfileFile, fd, null); } PrintStream out = mWaitOption ? System.out : System.err; boolean launched = false; switch (res) { - case IActivityManager.START_SUCCESS: + case ActivityManager.START_SUCCESS: launched = true; break; - case IActivityManager.START_SWITCHES_CANCELED: + case ActivityManager.START_SWITCHES_CANCELED: launched = true; out.println( "Warning: Activity not started because the " + " current activity is being kept for the user."); break; - case IActivityManager.START_DELIVERED_TO_TOP: + case ActivityManager.START_DELIVERED_TO_TOP: launched = true; out.println( "Warning: Activity not started, intent has " + "been delivered to currently running " + "top-most instance."); break; - case IActivityManager.START_RETURN_INTENT_TO_CALLER: + case ActivityManager.START_RETURN_INTENT_TO_CALLER: launched = true; out.println( "Warning: Activity not started because intent " + "should be handled by the caller"); break; - case IActivityManager.START_TASK_TO_FRONT: + case ActivityManager.START_TASK_TO_FRONT: launched = true; out.println( "Warning: Activity not started, its current " + "task has been brought to the front"); break; - case IActivityManager.START_INTENT_NOT_RESOLVED: + case ActivityManager.START_INTENT_NOT_RESOLVED: out.println( "Error: Activity not started, unable to " + "resolve " + intent.toString()); break; - case IActivityManager.START_CLASS_NOT_FOUND: + case ActivityManager.START_CLASS_NOT_FOUND: out.println(NO_CLASS_ERROR_CODE); out.println("Error: Activity class " + intent.getComponent().toShortString() + " does not exist."); break; - case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: + case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: out.println( "Error: Activity not started, you requested to " + "both forward and receive its result"); break; - case IActivityManager.START_PERMISSION_DENIED: + case ActivityManager.START_PERMISSION_DENIED: out.println( "Error: Activity not started, you do not " + "have permission to access it."); diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 0f2aa4608f6fc..dc12acd51c0f4 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -3165,43 +3165,61 @@ public class Activity extends ContextThemeWrapper } } + /** + * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} + * with no options. + * + * @param intent The intent to start. + * @param requestCode If >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivity + */ + public void startActivityForResult(Intent intent, int requestCode) { + startActivityForResult(intent, requestCode, null); + } + /** * Launch an activity for which you would like a result when it finished. * When this activity exits, your * onActivityResult() method will be called with the given requestCode. * Using a negative requestCode is the same as calling * {@link #startActivity} (the activity is not launched as a sub-activity). - * + * *

Note that this method should only be used with Intent protocols * that are defined to return a result. In other protocols (such as * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may * not get the result when you expect. For example, if the activity you * are launching uses the singleTask launch mode, it will not run in your * task and thus you will immediately receive a cancel result. - * + * *

As a special case, if you call startActivityForResult() with a requestCode * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your * activity, then your window will not be displayed until a result is * returned back from the started activity. This is to avoid visible * flickering when redirecting to another activity. - * + * *

This method throws {@link android.content.ActivityNotFoundException} * if there was no Activity found to run the given Intent. - * + * * @param intent The intent to start. * @param requestCode If >= 0, this code will be returned in * onActivityResult() when the activity exits. - * + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. + * * @throws android.content.ActivityNotFoundException - * + * * @see #startActivity */ - public void startActivityForResult(Intent intent, int requestCode) { + public void startActivityForResult(Intent intent, int requestCode, Bundle options) { if (mParent == null) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, this, - intent, requestCode); + intent, requestCode, options); if (ar != null) { mMainThread.sendActivityResult( mToken, mEmbeddedID, requestCode, ar.getResultCode(), @@ -3218,10 +3236,38 @@ public class Activity extends ContextThemeWrapper mStartedActivity = true; } } else { - mParent.startActivityFromChild(this, intent, requestCode); + if (options != null) { + mParent.startActivityFromChild(this, intent, requestCode, options); + } else { + // Note we want to go through this method for compatibility with + // existing applications that may have overridden it. + mParent.startActivityFromChild(this, intent, requestCode); + } } } + /** + * Same as calling {@link #startIntentSenderForResult(IntentSender, int, + * Intent, int, int, int, Bundle)} with no options. + * + * @param intent The IntentSender to launch. + * @param requestCode If >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param fillInIntent If non-null, this will be provided as the + * intent parameter to {@link IntentSender#sendIntent}. + * @param flagsMask Intent flags in the original IntentSender that you + * would like to change. + * @param flagsValues Desired values for any bits set in + * flagsMask + * @param extraFlags Always set to 0. + */ + public void startIntentSenderForResult(IntentSender intent, int requestCode, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) + throws IntentSender.SendIntentException { + startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, + flagsValues, extraFlags, null); + } + /** * Like {@link #startActivityForResult(Intent, int)}, but allowing you * to use a IntentSender to describe the activity to be started. If @@ -3241,21 +3287,29 @@ public class Activity extends ContextThemeWrapper * @param flagsValues Desired values for any bits set in * flagsMask * @param extraFlags Always set to 0. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. */ public void startIntentSenderForResult(IntentSender intent, int requestCode, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) - throws IntentSender.SendIntentException { + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { if (mParent == null) { startIntentSenderForResultInner(intent, requestCode, fillInIntent, - flagsMask, flagsValues, this); + flagsMask, flagsValues, this, options); + } else if (options != null) { + mParent.startIntentSenderFromChild(this, intent, requestCode, + fillInIntent, flagsMask, flagsValues, extraFlags, options); } else { + // Note we want to go through this call for compatibility with + // existing applications that may have overridden the method. mParent.startIntentSenderFromChild(this, intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags); } } private void startIntentSenderForResultInner(IntentSender intent, int requestCode, - Intent fillInIntent, int flagsMask, int flagsValues, Activity activity) + Intent fillInIntent, int flagsMask, int flagsValues, Activity activity, + Bundle options) throws IntentSender.SendIntentException { try { String resolvedType = null; @@ -3266,8 +3320,8 @@ public class Activity extends ContextThemeWrapper int result = ActivityManagerNative.getDefault() .startActivityIntentSender(mMainThread.getApplicationThread(), intent, fillInIntent, resolvedType, mToken, activity.mEmbeddedID, - requestCode, flagsMask, flagsValues); - if (result == IActivityManager.START_CANCELED) { + requestCode, flagsMask, flagsValues, options); + if (result == ActivityManager.START_CANCELED) { throw new IntentSender.SendIntentException(); } Instrumentation.checkStartActivityResult(result, null); @@ -3285,6 +3339,22 @@ public class Activity extends ContextThemeWrapper } } + /** + * Same as {@link #startActivity(Intent, Bundle)} with no options + * specified. + * + * @param intent The intent to start. + * + * @throws android.content.ActivityNotFoundException + * + * @see {@link #startActivity(Intent, Bundle)} + * @see #startActivityForResult + */ + @Override + public void startActivity(Intent intent) { + startActivity(intent, null); + } + /** * Launch a new activity. You will not receive any information about when * the activity exits. This implementation overrides the base version, @@ -3298,14 +3368,39 @@ public class Activity extends ContextThemeWrapper * if there was no Activity found to run the given Intent. * * @param intent The intent to start. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @throws android.content.ActivityNotFoundException - * + * + * @see {@link #startActivity(Intent)} * @see #startActivityForResult */ @Override - public void startActivity(Intent intent) { - startActivityForResult(intent, -1); + public void startActivity(Intent intent, Bundle options) { + if (options != null) { + startActivityForResult(intent, -1, options); + } else { + // Note we want to go through this call for compatibility with + // applications that may have overridden the method. + startActivityForResult(intent, -1); + } + } + + /** + * Same as {@link #startActivities(Intent[], Bundle)} with no options + * specified. + * + * @param intents The intents to start. + * + * @throws android.content.ActivityNotFoundException + * + * @see {@link #startActivities(Intent[], Bundle)} + * @see #startActivityForResult + */ + @Override + public void startActivities(Intent[] intents) { + startActivities(intents, null); } /** @@ -3321,22 +3416,23 @@ public class Activity extends ContextThemeWrapper * if there was no Activity found to run the given Intent. * * @param intents The intents to start. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @throws android.content.ActivityNotFoundException * + * @see {@link #startActivities(Intent[])} * @see #startActivityForResult */ @Override - public void startActivities(Intent[] intents) { + public void startActivities(Intent[] intents, Bundle options) { mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), - mToken, this, intents); + mToken, this, intents, options); } /** - * Like {@link #startActivity(Intent)}, but taking a IntentSender - * to start; see - * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int)} - * for more information. + * Same as calling {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} + * with no options. * * @param intent The IntentSender to launch. * @param fillInIntent If non-null, this will be provided as the @@ -3350,8 +3446,58 @@ public class Activity extends ContextThemeWrapper public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException { - startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, - flagsValues, extraFlags); + startIntentSender(intent, fillInIntent, flagsMask, flagsValues, + extraFlags, null); + } + + /** + * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender + * to start; see + * {@link #startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle)} + * for more information. + * + * @param intent The IntentSender to launch. + * @param fillInIntent If non-null, this will be provided as the + * intent parameter to {@link IntentSender#sendIntent}. + * @param flagsMask Intent flags in the original IntentSender that you + * would like to change. + * @param flagsValues Desired values for any bits set in + * flagsMask + * @param extraFlags Always set to 0. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. + */ + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { + if (options != null) { + startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, + flagsValues, extraFlags, options); + } else { + // Note we want to go through this call for compatibility with + // applications that may have overridden the method. + startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, + flagsValues, extraFlags); + } + } + + /** + * Same as calling {@link #startActivityIfNeeded(Intent, int, Bundle)} + * with no options. + * + * @param intent The intent to start. + * @param requestCode If >= 0, this code will be returned in + * onActivityResult() when the activity exits, as described in + * {@link #startActivityForResult}. + * + * @return If a new activity was launched then true is returned; otherwise + * false is returned and you must handle the Intent yourself. + * + * @see #startActivity + * @see #startActivityForResult + */ + public boolean startActivityIfNeeded(Intent intent, int requestCode) { + return startActivityIfNeeded(intent, requestCode, null); } /** @@ -3374,6 +3520,8 @@ public class Activity extends ContextThemeWrapper * @param requestCode If >= 0, this code will be returned in * onActivityResult() when the activity exits, as described in * {@link #startActivityForResult}. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @return If a new activity was launched then true is returned; otherwise * false is returned and you must handle the Intent yourself. @@ -3381,17 +3529,17 @@ public class Activity extends ContextThemeWrapper * @see #startActivity * @see #startActivityForResult */ - public boolean startActivityIfNeeded(Intent intent, int requestCode) { + public boolean startActivityIfNeeded(Intent intent, int requestCode, Bundle options) { if (mParent == null) { - int result = IActivityManager.START_RETURN_INTENT_TO_CALLER; + int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; try { intent.setAllowFds(false); result = ActivityManagerNative.getDefault() .startActivity(mMainThread.getApplicationThread(), intent, intent.resolveTypeIfNeeded(getContentResolver()), - null, 0, - mToken, mEmbeddedID, requestCode, true /* onlyIfNeeded */, - false, false, null, null, false); + mToken, mEmbeddedID, requestCode, + ActivityManager.START_FLAG_ONLY_IF_NEEDED, null, null, + options); } catch (RemoteException e) { // Empty } @@ -3408,13 +3556,31 @@ public class Activity extends ContextThemeWrapper // activity is finished, no matter what happens to it. mStartedActivity = true; } - return result != IActivityManager.START_RETURN_INTENT_TO_CALLER; + return result != ActivityManager.START_RETURN_INTENT_TO_CALLER; } throw new UnsupportedOperationException( "startActivityIfNeeded can only be called from a top-level activity"); } + /** + * Same as calling {@link #startNextMatchingActivity(Intent, Bundle)} with + * no options. + * + * @param intent The intent to dispatch to the next activity. For + * correct behavior, this must be the same as the Intent that started + * your own activity; the only changes you can make are to the extras + * inside of it. + * + * @return Returns a boolean indicating whether there was another Activity + * to start: true if there was a next activity to start, false if there + * wasn't. In general, if true is returned you will then want to call + * finish() on yourself. + */ + public boolean startNextMatchingActivity(Intent intent) { + return startNextMatchingActivity(intent, null); + } + /** * Special version of starting an activity, for use when you are replacing * other activity components. You can use this to hand the Intent off @@ -3425,18 +3591,20 @@ public class Activity extends ContextThemeWrapper * correct behavior, this must be the same as the Intent that started * your own activity; the only changes you can make are to the extras * inside of it. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @return Returns a boolean indicating whether there was another Activity * to start: true if there was a next activity to start, false if there * wasn't. In general, if true is returned you will then want to call * finish() on yourself. */ - public boolean startNextMatchingActivity(Intent intent) { + public boolean startNextMatchingActivity(Intent intent, Bundle options) { if (mParent == null) { try { intent.setAllowFds(false); return ActivityManagerNative.getDefault() - .startNextMatchingActivity(mToken, intent); + .startNextMatchingActivity(mToken, intent, options); } catch (RemoteException e) { // Empty } @@ -3446,7 +3614,25 @@ public class Activity extends ContextThemeWrapper throw new UnsupportedOperationException( "startNextMatchingActivity can only be called from a top-level activity"); } - + + /** + * Same as calling {@link #startActivityFromChild(Activity, Intent, int, Bundle)} + * with no options. + * + * @param child The activity making the call. + * @param intent The intent to start. + * @param requestCode Reply request code. < 0 if reply is not requested. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivity + * @see #startActivityForResult + */ + public void startActivityFromChild(Activity child, Intent intent, + int requestCode) { + startActivityFromChild(child, intent, requestCode); + } + /** * This is called when a child activity of this one calls its * {@link #startActivity} or {@link #startActivityForResult} method. @@ -3456,7 +3642,9 @@ public class Activity extends ContextThemeWrapper * * @param child The activity making the call. * @param intent The intent to start. - * @param requestCode Reply request code. < 0 if reply is not requested. + * @param requestCode Reply request code. < 0 if reply is not requested. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @throws android.content.ActivityNotFoundException * @@ -3464,11 +3652,11 @@ public class Activity extends ContextThemeWrapper * @see #startActivityForResult */ public void startActivityFromChild(Activity child, Intent intent, - int requestCode) { + int requestCode, Bundle options) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, child, - intent, requestCode); + intent, requestCode, options); if (ar != null) { mMainThread.sendActivityResult( mToken, child.mEmbeddedID, requestCode, @@ -3476,6 +3664,24 @@ public class Activity extends ContextThemeWrapper } } + /** + * Same as calling {@link #startActivityFromFragment(Fragment, Intent, int, Bundle)} + * with no options. + * + * @param fragment The fragment making the call. + * @param intent The intent to start. + * @param requestCode Reply request code. < 0 if reply is not requested. + * + * @throws android.content.ActivityNotFoundException + * + * @see Fragment#startActivity + * @see Fragment#startActivityForResult + */ + public void startActivityFromFragment(Fragment fragment, Intent intent, + int requestCode) { + startActivityFromFragment(fragment, intent, requestCode, null); + } + /** * This is called when a Fragment in this activity calls its * {@link Fragment#startActivity} or {@link Fragment#startActivityForResult} @@ -3487,6 +3693,8 @@ public class Activity extends ContextThemeWrapper * @param fragment The fragment making the call. * @param intent The intent to start. * @param requestCode Reply request code. < 0 if reply is not requested. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @throws android.content.ActivityNotFoundException * @@ -3494,11 +3702,11 @@ public class Activity extends ContextThemeWrapper * @see Fragment#startActivityForResult */ public void startActivityFromFragment(Fragment fragment, Intent intent, - int requestCode) { + int requestCode, Bundle options) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, fragment, - intent, requestCode); + intent, requestCode, options); if (ar != null) { mMainThread.sendActivityResult( mToken, fragment.mWho, requestCode, @@ -3506,6 +3714,18 @@ public class Activity extends ContextThemeWrapper } } + /** + * Same as calling {@link #startIntentSenderFromChild(Activity, IntentSender, + * int, Intent, int, int, int, Bundle)} with no options. + */ + public void startIntentSenderFromChild(Activity child, IntentSender intent, + int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, + int extraFlags) + throws IntentSender.SendIntentException { + startIntentSenderFromChild(child, intent, requestCode, fillInIntent, + flagsMask, flagsValues, extraFlags, null); + } + /** * Like {@link #startActivityFromChild(Activity, Intent, int)}, but * taking a IntentSender; see @@ -3514,10 +3734,10 @@ public class Activity extends ContextThemeWrapper */ public void startIntentSenderFromChild(Activity child, IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, - int extraFlags) + int extraFlags, Bundle options) throws IntentSender.SendIntentException { startIntentSenderForResultInner(intent, requestCode, fillInIntent, - flagsMask, flagsValues, child); + flagsMask, flagsValues, child, options); } /** @@ -3843,7 +4063,7 @@ public class Activity extends ContextThemeWrapper data.setAllowFds(false); IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( - IActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, + ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, mParent == null ? mToken : mParent.mToken, mEmbeddedID, requestCode, new Intent[] { data }, null, flags); return target != null ? new PendingIntent(target) : null; diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 59c803e0a5c8b..d056b171d4535 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -59,6 +59,154 @@ public class ActivityManager { private final Context mContext; private final Handler mHandler; + /** + * Result for IActivityManager.startActivity: an error where the + * start had to be canceled. + * @hide + */ + public static final int START_CANCELED = -6; + + /** + * Result for IActivityManager.startActivity: an error where the + * thing being started is not an activity. + * @hide + */ + public static final int START_NOT_ACTIVITY = -5; + + /** + * Result for IActivityManager.startActivity: an error where the + * caller does not have permission to start the activity. + * @hide + */ + public static final int START_PERMISSION_DENIED = -4; + + /** + * Result for IActivityManager.startActivity: an error where the + * caller has requested both to forward a result and to receive + * a result. + * @hide + */ + public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; + + /** + * Result for IActivityManager.startActivity: an error where the + * requested class is not found. + * @hide + */ + public static final int START_CLASS_NOT_FOUND = -2; + + /** + * Result for IActivityManager.startActivity: an error where the + * given Intent could not be resolved to an activity. + * @hide + */ + public static final int START_INTENT_NOT_RESOLVED = -1; + + /** + * Result for IActivityManaqer.startActivity: the activity was started + * successfully as normal. + * @hide + */ + public static final int START_SUCCESS = 0; + + /** + * Result for IActivityManaqer.startActivity: the caller asked that the Intent not + * be executed if it is the recipient, and that is indeed the case. + * @hide + */ + public static final int START_RETURN_INTENT_TO_CALLER = 1; + + /** + * Result for IActivityManaqer.startActivity: activity wasn't really started, but + * a task was simply brought to the foreground. + * @hide + */ + public static final int START_TASK_TO_FRONT = 2; + + /** + * Result for IActivityManaqer.startActivity: activity wasn't really started, but + * the given Intent was given to the existing top activity. + * @hide + */ + public static final int START_DELIVERED_TO_TOP = 3; + + /** + * Result for IActivityManaqer.startActivity: request was canceled because + * app switches are temporarily canceled to ensure the user's last request + * (such as pressing home) is performed. + * @hide + */ + public static final int START_SWITCHES_CANCELED = 4; + + /** + * Flag for IActivityManaqer.startActivity: do special start mode where + * a new activity is launched only if it is needed. + * @hide + */ + public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; + + /** + * Flag for IActivityManaqer.startActivity: launch the app for + * debugging. + * @hide + */ + public static final int START_FLAG_DEBUG = 1<<1; + + /** + * Flag for IActivityManaqer.startActivity: launch the app for + * OpenGL tracing. + * @hide + */ + public static final int START_FLAG_OPENGL_TRACES = 1<<2; + + /** + * Flag for IActivityManaqer.startActivity: if the app is being + * launched for profiling, automatically stop the profiler once done. + * @hide + */ + public static final int START_FLAG_AUTO_STOP_PROFILER = 1<<3; + + /** + * Result for IActivityManaqer.broadcastIntent: success! + * @hide + */ + public static final int BROADCAST_SUCCESS = 0; + + /** + * Result for IActivityManaqer.broadcastIntent: attempt to broadcast + * a sticky intent without appropriate permission. + * @hide + */ + public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; + + /** + * Type for IActivityManaqer.getIntentSender: this PendingIntent is + * for a sendBroadcast operation. + * @hide + */ + public static final int INTENT_SENDER_BROADCAST = 1; + + /** + * Type for IActivityManaqer.getIntentSender: this PendingIntent is + * for a startActivity operation. + * @hide + */ + public static final int INTENT_SENDER_ACTIVITY = 2; + + /** + * Type for IActivityManaqer.getIntentSender: this PendingIntent is + * for an activity result operation. + * @hide + */ + public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; + + /** + * Type for IActivityManaqer.getIntentSender: this PendingIntent is + * for a startService operation. + * @hide + */ + public static final int INTENT_SENDER_SERVICE = 4; + /*package*/ ActivityManager(Context context, Handler handler) { mContext = context; mHandler = handler; diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index 7daaf7da88e99..732d211233ea7 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -117,22 +117,18 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM IApplicationThread app = ApplicationThreadNative.asInterface(b); Intent intent = Intent.CREATOR.createFromParcel(data); String resolvedType = data.readString(); - Uri[] grantedUriPermissions = data.createTypedArray(Uri.CREATOR); - int grantedMode = data.readInt(); IBinder resultTo = data.readStrongBinder(); String resultWho = data.readString(); int requestCode = data.readInt(); - boolean onlyIfNeeded = data.readInt() != 0; - boolean debug = data.readInt() != 0; - boolean openglTrace = data.readInt() != 0; + int startFlags = data.readInt(); String profileFile = data.readString(); ParcelFileDescriptor profileFd = data.readInt() != 0 ? data.readFileDescriptor() : null; - boolean autoStopProfiler = data.readInt() != 0; + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; int result = startActivity(app, intent, resolvedType, - grantedUriPermissions, grantedMode, resultTo, resultWho, - requestCode, onlyIfNeeded, debug, openglTrace, - profileFile, profileFd, autoStopProfiler); + resultTo, resultWho, requestCode, startFlags, + profileFile, profileFd, options); reply.writeNoException(); reply.writeInt(result); return true; @@ -145,22 +141,18 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM IApplicationThread app = ApplicationThreadNative.asInterface(b); Intent intent = Intent.CREATOR.createFromParcel(data); String resolvedType = data.readString(); - Uri[] grantedUriPermissions = data.createTypedArray(Uri.CREATOR); - int grantedMode = data.readInt(); IBinder resultTo = data.readStrongBinder(); String resultWho = data.readString(); int requestCode = data.readInt(); - boolean onlyIfNeeded = data.readInt() != 0; - boolean debug = data.readInt() != 0; - boolean openglTrace = data.readInt() != 0; + int startFlags = data.readInt(); String profileFile = data.readString(); ParcelFileDescriptor profileFd = data.readInt() != 0 ? data.readFileDescriptor() : null; - boolean autoStopProfiler = data.readInt() != 0; + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; WaitResult result = startActivityAndWait(app, intent, resolvedType, - grantedUriPermissions, grantedMode, resultTo, resultWho, - requestCode, onlyIfNeeded, debug, openglTrace, - profileFile, profileFd, autoStopProfiler); + resultTo, resultWho, requestCode, startFlags, + profileFile, profileFd, options); reply.writeNoException(); result.writeToParcel(reply, 0); return true; @@ -173,17 +165,15 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM IApplicationThread app = ApplicationThreadNative.asInterface(b); Intent intent = Intent.CREATOR.createFromParcel(data); String resolvedType = data.readString(); - Uri[] grantedUriPermissions = data.createTypedArray(Uri.CREATOR); - int grantedMode = data.readInt(); IBinder resultTo = data.readStrongBinder(); String resultWho = data.readString(); int requestCode = data.readInt(); - boolean onlyIfNeeded = data.readInt() != 0; - boolean debug = data.readInt() != 0; + int startFlags = data.readInt(); Configuration config = Configuration.CREATOR.createFromParcel(data); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; int result = startActivityWithConfig(app, intent, resolvedType, - grantedUriPermissions, grantedMode, resultTo, resultWho, - requestCode, onlyIfNeeded, debug, config); + resultTo, resultWho, requestCode, startFlags, config, options); reply.writeNoException(); reply.writeInt(result); return true; @@ -205,9 +195,11 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM int requestCode = data.readInt(); int flagsMask = data.readInt(); int flagsValues = data.readInt(); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; int result = startActivityIntentSender(app, intent, fillInIntent, resolvedType, resultTo, resultWho, - requestCode, flagsMask, flagsValues); + requestCode, flagsMask, flagsValues, options); reply.writeNoException(); reply.writeInt(result); return true; @@ -218,7 +210,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM data.enforceInterface(IActivityManager.descriptor); IBinder callingActivity = data.readStrongBinder(); Intent intent = Intent.CREATOR.createFromParcel(data); - boolean result = startNextMatchingActivity(callingActivity, intent); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; + boolean result = startNextMatchingActivity(callingActivity, intent, options); reply.writeNoException(); reply.writeInt(result ? 1 : 0); return true; @@ -1231,9 +1225,11 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM IBinder resultTo = data.readStrongBinder(); String resultWho = data.readString(); int requestCode = data.readInt(); - boolean onlyIfNeeded = data.readInt() != 0; + int startFlags = data.readInt(); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; int result = startActivityInPackage(uid, intent, resolvedType, - resultTo, resultWho, requestCode, onlyIfNeeded); + resultTo, resultWho, requestCode, startFlags, options); reply.writeNoException(); reply.writeInt(result); return true; @@ -1412,7 +1408,10 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM Intent[] intents = data.createTypedArray(Intent.CREATOR); String[] resolvedTypes = data.createStringArray(); IBinder resultTo = data.readStrongBinder(); - int result = startActivitiesInPackage(uid, intents, resolvedTypes, resultTo); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; + int result = startActivitiesInPackage(uid, intents, resolvedTypes, + resultTo, options); reply.writeNoException(); reply.writeInt(result); return true; @@ -1426,7 +1425,10 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM Intent[] intents = data.createTypedArray(Intent.CREATOR); String[] resolvedTypes = data.createStringArray(); IBinder resultTo = data.readStrongBinder(); - int result = startActivities(app, intents, resolvedTypes, resultTo); + Bundle options = data.readInt() != 0 + ? Bundle.CREATOR.createFromParcel(data) : null; + int result = startActivities(app, intents, resolvedTypes, resultTo, + options); reply.writeNoException(); reply.writeInt(result); return true; @@ -1618,25 +1620,19 @@ class ActivityManagerProxy implements IActivityManager } public int startActivity(IApplicationThread caller, Intent intent, - String resolvedType, Uri[] grantedUriPermissions, int grantedMode, - IBinder resultTo, String resultWho, - int requestCode, boolean onlyIfNeeded, - boolean debug, boolean openglTrace, String profileFile, ParcelFileDescriptor profileFd, - boolean autoStopProfiler) throws RemoteException { + String resolvedType, IBinder resultTo, String resultWho, int requestCode, + int startFlags, String profileFile, + ParcelFileDescriptor profileFd, Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(caller != null ? caller.asBinder() : null); intent.writeToParcel(data, 0); data.writeString(resolvedType); - data.writeTypedArray(grantedUriPermissions, 0); - data.writeInt(grantedMode); data.writeStrongBinder(resultTo); data.writeString(resultWho); data.writeInt(requestCode); - data.writeInt(onlyIfNeeded ? 1 : 0); - data.writeInt(debug ? 1 : 0); - data.writeInt(openglTrace ? 1 : 0); + data.writeInt(startFlags); data.writeString(profileFile); if (profileFd != null) { data.writeInt(1); @@ -1644,7 +1640,12 @@ class ActivityManagerProxy implements IActivityManager } else { data.writeInt(0); } - data.writeInt(autoStopProfiler ? 1 : 0); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -1653,25 +1654,19 @@ class ActivityManagerProxy implements IActivityManager return result; } public WaitResult startActivityAndWait(IApplicationThread caller, Intent intent, - String resolvedType, Uri[] grantedUriPermissions, int grantedMode, - IBinder resultTo, String resultWho, - int requestCode, boolean onlyIfNeeded, - boolean debug, boolean openglTrace, String profileFile, ParcelFileDescriptor profileFd, - boolean autoStopProfiler) throws RemoteException { + String resolvedType, IBinder resultTo, String resultWho, + int requestCode, int startFlags, String profileFile, + ParcelFileDescriptor profileFd, Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(caller != null ? caller.asBinder() : null); intent.writeToParcel(data, 0); data.writeString(resolvedType); - data.writeTypedArray(grantedUriPermissions, 0); - data.writeInt(grantedMode); data.writeStrongBinder(resultTo); data.writeString(resultWho); data.writeInt(requestCode); - data.writeInt(onlyIfNeeded ? 1 : 0); - data.writeInt(debug ? 1 : 0); - data.writeInt(openglTrace ? 1 : 0); + data.writeInt(startFlags); data.writeString(profileFile); if (profileFd != null) { data.writeInt(1); @@ -1679,7 +1674,12 @@ class ActivityManagerProxy implements IActivityManager } else { data.writeInt(0); } - data.writeInt(autoStopProfiler ? 1 : 0); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITY_AND_WAIT_TRANSACTION, data, reply, 0); reply.readException(); WaitResult result = WaitResult.CREATOR.createFromParcel(reply); @@ -1688,24 +1688,26 @@ class ActivityManagerProxy implements IActivityManager return result; } public int startActivityWithConfig(IApplicationThread caller, Intent intent, - String resolvedType, Uri[] grantedUriPermissions, int grantedMode, - IBinder resultTo, String resultWho, - int requestCode, boolean onlyIfNeeded, - boolean debug, Configuration config) throws RemoteException { + String resolvedType, IBinder resultTo, String resultWho, + int requestCode, int startFlags, Configuration config, + Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(caller != null ? caller.asBinder() : null); intent.writeToParcel(data, 0); data.writeString(resolvedType); - data.writeTypedArray(grantedUriPermissions, 0); - data.writeInt(grantedMode); data.writeStrongBinder(resultTo); data.writeString(resultWho); data.writeInt(requestCode); - data.writeInt(onlyIfNeeded ? 1 : 0); - data.writeInt(debug ? 1 : 0); + data.writeInt(startFlags); config.writeToParcel(data, 0); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -1716,7 +1718,7 @@ class ActivityManagerProxy implements IActivityManager public int startActivityIntentSender(IApplicationThread caller, IntentSender intent, Intent fillInIntent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int flagsMask, int flagsValues) throws RemoteException { + int flagsMask, int flagsValues, Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -1734,6 +1736,12 @@ class ActivityManagerProxy implements IActivityManager data.writeInt(requestCode); data.writeInt(flagsMask); data.writeInt(flagsValues); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITY_INTENT_SENDER_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -1742,12 +1750,18 @@ class ActivityManagerProxy implements IActivityManager return result; } public boolean startNextMatchingActivity(IBinder callingActivity, - Intent intent) throws RemoteException { + Intent intent, Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(callingActivity); intent.writeToParcel(data, 0); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_NEXT_MATCHING_ACTIVITY_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -3075,7 +3089,7 @@ class ActivityManagerProxy implements IActivityManager public int startActivityInPackage(int uid, Intent intent, String resolvedType, IBinder resultTo, - String resultWho, int requestCode, boolean onlyIfNeeded) + String resultWho, int requestCode, int startFlags, Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); @@ -3086,7 +3100,13 @@ class ActivityManagerProxy implements IActivityManager data.writeStrongBinder(resultTo); data.writeString(resultWho); data.writeInt(requestCode); - data.writeInt(onlyIfNeeded ? 1 : 0); + data.writeInt(startFlags); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITY_IN_PACKAGE_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -3339,7 +3359,8 @@ class ActivityManagerProxy implements IActivityManager } public int startActivities(IApplicationThread caller, - Intent[] intents, String[] resolvedTypes, IBinder resultTo) throws RemoteException { + Intent[] intents, String[] resolvedTypes, IBinder resultTo, + Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -3347,6 +3368,12 @@ class ActivityManagerProxy implements IActivityManager data.writeTypedArray(intents, 0); data.writeStringArray(resolvedTypes); data.writeStrongBinder(resultTo); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITIES_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); @@ -3356,7 +3383,8 @@ class ActivityManagerProxy implements IActivityManager } public int startActivitiesInPackage(int uid, - Intent[] intents, String[] resolvedTypes, IBinder resultTo) throws RemoteException { + Intent[] intents, String[] resolvedTypes, IBinder resultTo, + Bundle options) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); @@ -3364,6 +3392,12 @@ class ActivityManagerProxy implements IActivityManager data.writeTypedArray(intents, 0); data.writeStringArray(resolvedTypes); data.writeStrongBinder(resultTo); + if (options != null) { + data.writeInt(1); + options.writeToParcel(data, 0); + } else { + data.writeInt(0); + } mRemote.transact(START_ACTIVITIES_IN_PACKAGE_TRANSACTION, data, reply, 0); reply.readException(); int result = reply.readInt(); diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 2610d8772de6b..2a3e213c5003b 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1802,7 +1802,7 @@ public final class ActivityThread { if (aInfo == null) { // Throw an exception. Instrumentation.checkStartActivityResult( - IActivityManager.START_CLASS_NOT_FOUND, intent); + ActivityManager.START_CLASS_NOT_FOUND, intent); } return aInfo; } diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index e348b87c49651..7043a73dc47ac 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -852,6 +852,11 @@ class ContextImpl extends Context { @Override public void startActivity(Intent intent) { + startActivity(intent, null); + } + + @Override + public void startActivity(Intent intent, Bundle options) { if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { throw new AndroidRuntimeException( "Calling startActivity() from outside of an Activity " @@ -860,11 +865,16 @@ class ContextImpl extends Context { } mMainThread.getInstrumentation().execStartActivity( getOuterContext(), mMainThread.getApplicationThread(), null, - (Activity)null, intent, -1); + (Activity)null, intent, -1, options); } @Override public void startActivities(Intent[] intents) { + startActivities(intents, null); + } + + @Override + public void startActivities(Intent[] intents, Bundle options) { if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) { throw new AndroidRuntimeException( "Calling startActivities() from outside of an Activity " @@ -873,13 +883,20 @@ class ContextImpl extends Context { } mMainThread.getInstrumentation().execStartActivities( getOuterContext(), mMainThread.getApplicationThread(), null, - (Activity)null, intents); + (Activity)null, intents, options); } @Override public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException { + startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null); + } + + @Override + public void startIntentSender(IntentSender intent, Intent fillInIntent, + int flagsMask, int flagsValues, int extraFlags, Bundle options) + throws IntentSender.SendIntentException { try { String resolvedType = null; if (fillInIntent != null) { @@ -889,8 +906,8 @@ class ContextImpl extends Context { int result = ActivityManagerNative.getDefault() .startActivityIntentSender(mMainThread.getApplicationThread(), intent, fillInIntent, resolvedType, null, null, - 0, flagsMask, flagsValues); - if (result == IActivityManager.START_CANCELED) { + 0, flagsMask, flagsValues, options); + if (result == ActivityManager.START_CANCELED) { throw new IntentSender.SendIntentException(); } Instrumentation.checkStartActivityResult(result, null); diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index 492fcc73540cd..dadc4e5ff593e 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -961,27 +961,55 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, true); return mLoaderManager; } - + /** * Call {@link Activity#startActivity(Intent)} on the fragment's * containing Activity. */ public void startActivity(Intent intent) { + startActivity(intent, null); + } + + /** + * Call {@link Activity#startActivity(Intent, Bundle)} on the fragment's + * containing Activity. + */ + public void startActivity(Intent intent, Bundle options) { if (mActivity == null) { throw new IllegalStateException("Fragment " + this + " not attached to Activity"); } - mActivity.startActivityFromFragment(this, intent, -1); + if (options != null) { + mActivity.startActivityFromFragment(this, intent, -1, options); + } else { + // Note we want to go through this call for compatibility with + // applications that may have overridden the method. + mActivity.startActivityFromFragment(this, intent, -1); + } } - + /** * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's * containing Activity. */ public void startActivityForResult(Intent intent, int requestCode) { + startActivityForResult(intent, requestCode, null); + } + + /** + * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} on the fragment's + * containing Activity. + */ + public void startActivityForResult(Intent intent, int requestCode, Bundle options) { if (mActivity == null) { throw new IllegalStateException("Fragment " + this + " not attached to Activity"); } - mActivity.startActivityFromFragment(this, intent, requestCode); + if (options != null) { + mActivity.startActivityFromFragment(this, intent, requestCode, options); + } else { + // Note we want to go through this call for compatibility with + // applications that may have overridden the method. + mActivity.startActivityFromFragment(this, intent, requestCode, options); + } } /** diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index acebf58a71918..9306bd2a14169 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -50,57 +50,24 @@ import java.util.List; * {@hide} */ public interface IActivityManager extends IInterface { - /** - * Returned by startActivity() if the start request was canceled because - * app switches are temporarily canceled to ensure the user's last request - * (such as pressing home) is performed. - */ - public static final int START_SWITCHES_CANCELED = 4; - /** - * Returned by startActivity() if an activity wasn't really started, but - * the given Intent was given to the existing top activity. - */ - public static final int START_DELIVERED_TO_TOP = 3; - /** - * Returned by startActivity() if an activity wasn't really started, but - * a task was simply brought to the foreground. - */ - public static final int START_TASK_TO_FRONT = 2; - /** - * Returned by startActivity() if the caller asked that the Intent not - * be executed if it is the recipient, and that is indeed the case. - */ - public static final int START_RETURN_INTENT_TO_CALLER = 1; - /** - * Activity was started successfully as normal. - */ - public static final int START_SUCCESS = 0; - public static final int START_INTENT_NOT_RESOLVED = -1; - public static final int START_CLASS_NOT_FOUND = -2; - public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; - public static final int START_PERMISSION_DENIED = -4; - public static final int START_NOT_ACTIVITY = -5; - public static final int START_CANCELED = -6; public int startActivity(IApplicationThread caller, - Intent intent, String resolvedType, Uri[] grantedUriPermissions, - int grantedMode, IBinder resultTo, String resultWho, int requestCode, - boolean onlyIfNeeded, boolean debug, boolean openglTrace, String profileFile, - ParcelFileDescriptor profileFd, boolean autoStopProfiler) throws RemoteException; + Intent intent, String resolvedType, IBinder resultTo, String resultWho, + int requestCode, int flags, String profileFile, + ParcelFileDescriptor profileFd, Bundle options) throws RemoteException; public WaitResult startActivityAndWait(IApplicationThread caller, - Intent intent, String resolvedType, Uri[] grantedUriPermissions, - int grantedMode, IBinder resultTo, String resultWho, int requestCode, - boolean onlyIfNeeded, boolean debug, boolean openglTrace, String profileFile, - ParcelFileDescriptor profileFd, boolean autoStopProfiler) throws RemoteException; + Intent intent, String resolvedType, IBinder resultTo, String resultWho, + int requestCode, int flags, String profileFile, + ParcelFileDescriptor profileFd, Bundle options) throws RemoteException; public int startActivityWithConfig(IApplicationThread caller, - Intent intent, String resolvedType, Uri[] grantedUriPermissions, - int grantedMode, IBinder resultTo, String resultWho, int requestCode, - boolean onlyIfNeeded, boolean debug, Configuration newConfig) throws RemoteException; + Intent intent, String resolvedType, IBinder resultTo, String resultWho, + int requestCode, int startFlags, Configuration newConfig, + Bundle options) throws RemoteException; public int startActivityIntentSender(IApplicationThread caller, IntentSender intent, Intent fillInIntent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, - int flagsMask, int flagsValues) throws RemoteException; + int flagsMask, int flagsValues, Bundle options) throws RemoteException; public boolean startNextMatchingActivity(IBinder callingActivity, - Intent intent) throws RemoteException; + Intent intent, Bundle options) throws RemoteException; public boolean finishActivity(IBinder token, int code, Intent data) throws RemoteException; public void finishSubActivity(IBinder token, String resultWho, int requestCode) throws RemoteException; @@ -109,8 +76,6 @@ public interface IActivityManager extends IInterface { IIntentReceiver receiver, IntentFilter filter, String requiredPermission) throws RemoteException; public void unregisterReceiver(IIntentReceiver receiver) throws RemoteException; - public static final int BROADCAST_SUCCESS = 0; - public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; public int broadcastIntent(IApplicationThread caller, Intent intent, String resolvedType, IIntentReceiver resultTo, int resultCode, String resultData, Bundle map, String requiredPermission, @@ -201,10 +166,6 @@ public interface IActivityManager extends IInterface { public ComponentName getActivityClassForToken(IBinder token) throws RemoteException; public String getPackageForToken(IBinder token) throws RemoteException; - public static final int INTENT_SENDER_BROADCAST = 1; - public static final int INTENT_SENDER_ACTIVITY = 2; - public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; - public static final int INTENT_SENDER_SERVICE = 4; public IIntentSender getIntentSender(int type, String packageName, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, @@ -302,7 +263,7 @@ public interface IActivityManager extends IInterface { public int startActivityInPackage(int uid, Intent intent, String resolvedType, IBinder resultTo, - String resultWho, int requestCode, boolean onlyIfNeeded) + String resultWho, int requestCode, int startFlags, Bundle options) throws RemoteException; public void killApplicationWithUid(String pkg, int uid) throws RemoteException; @@ -342,9 +303,11 @@ public interface IActivityManager extends IInterface { ParcelFileDescriptor fd) throws RemoteException; public int startActivities(IApplicationThread caller, - Intent[] intents, String[] resolvedTypes, IBinder resultTo) throws RemoteException; + Intent[] intents, String[] resolvedTypes, IBinder resultTo, + Bundle options) throws RemoteException; public int startActivitiesInPackage(int uid, - Intent[] intents, String[] resolvedTypes, IBinder resultTo) throws RemoteException; + Intent[] intents, String[] resolvedTypes, IBinder resultTo, + Bundle options) throws RemoteException; public int getFrontActivityScreenCompatMode() throws RemoteException; public void setFrontActivityScreenCompatMode(int mode) throws RemoteException; diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java index a34e1d38064af..16299de6fa3cd 100644 --- a/core/java/android/app/Instrumentation.java +++ b/core/java/android/app/Instrumentation.java @@ -1346,6 +1346,7 @@ public class Instrumentation { * @param intent The actual Intent to start. * @param requestCode Identifier for this request's result; less than zero * if the caller is not expecting a result. + * @param options Addition options. * * @return To force the return of a particular result, return an * ActivityResult object containing the desired data; otherwise @@ -1361,7 +1362,7 @@ public class Instrumentation { */ public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, - Intent intent, int requestCode) { + Intent intent, int requestCode, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { @@ -1383,8 +1384,8 @@ public class Instrumentation { int result = ActivityManagerNative.getDefault() .startActivity(whoThread, intent, intent.resolveTypeIfNeeded(who.getContentResolver()), - null, 0, token, target != null ? target.mEmbeddedID : null, - requestCode, false, false, false, null, null, false); + token, target != null ? target.mEmbeddedID : null, + requestCode, 0, null, null, options); checkStartActivityResult(result, intent); } catch (RemoteException e) { } @@ -1400,7 +1401,7 @@ public class Instrumentation { * {@hide} */ public void execStartActivities(Context who, IBinder contextThread, - IBinder token, Activity target, Intent[] intents) { + IBinder token, Activity target, Intent[] intents, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { @@ -1424,7 +1425,7 @@ public class Instrumentation { resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver()); } int result = ActivityManagerNative.getDefault() - .startActivities(whoThread, intents, resolvedTypes, token); + .startActivities(whoThread, intents, resolvedTypes, token, options); checkStartActivityResult(result, intents[0]); } catch (RemoteException e) { } @@ -1459,7 +1460,7 @@ public class Instrumentation { */ public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Fragment target, - Intent intent, int requestCode) { + Intent intent, int requestCode, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { @@ -1481,9 +1482,8 @@ public class Instrumentation { int result = ActivityManagerNative.getDefault() .startActivity(whoThread, intent, intent.resolveTypeIfNeeded(who.getContentResolver()), - null, 0, token, target != null ? target.mWho : null, - requestCode, false, false /* debug */, false /* openglTrace */, - null, null, false); + token, target != null ? target.mWho : null, + requestCode, 0, null, null, options); checkStartActivityResult(result, intent); } catch (RemoteException e) { } @@ -1502,13 +1502,13 @@ public class Instrumentation { } /*package*/ static void checkStartActivityResult(int res, Object intent) { - if (res >= IActivityManager.START_SUCCESS) { + if (res >= ActivityManager.START_SUCCESS) { return; } switch (res) { - case IActivityManager.START_INTENT_NOT_RESOLVED: - case IActivityManager.START_CLASS_NOT_FOUND: + case ActivityManager.START_INTENT_NOT_RESOLVED: + case ActivityManager.START_CLASS_NOT_FOUND: if (intent instanceof Intent && ((Intent)intent).getComponent() != null) throw new ActivityNotFoundException( "Unable to find explicit activity class " @@ -1516,13 +1516,13 @@ public class Instrumentation { + "; have you declared this activity in your AndroidManifest.xml?"); throw new ActivityNotFoundException( "No Activity found to handle " + intent); - case IActivityManager.START_PERMISSION_DENIED: + case ActivityManager.START_PERMISSION_DENIED: throw new SecurityException("Not allowed to start activity " + intent); - case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: + case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: throw new AndroidRuntimeException( "FORWARD_RESULT_FLAG used while also requesting a result"); - case IActivityManager.START_NOT_ACTIVITY: + case ActivityManager.START_NOT_ACTIVITY: throw new IllegalArgumentException( "PendingIntent is not an activity"); default: diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index c95066cd61ba1..57192c3c45e39 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -195,7 +195,7 @@ public final class PendingIntent implements Parcelable { intent.setAllowFds(false); IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( - IActivityManager.INTENT_SENDER_ACTIVITY, packageName, + ActivityManager.INTENT_SENDER_ACTIVITY, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, flags); return target != null ? new PendingIntent(target) : null; @@ -256,7 +256,7 @@ public final class PendingIntent implements Parcelable { try { IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( - IActivityManager.INTENT_SENDER_ACTIVITY, packageName, + ActivityManager.INTENT_SENDER_ACTIVITY, packageName, null, null, requestCode, intents, resolvedTypes, flags); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { @@ -292,7 +292,7 @@ public final class PendingIntent implements Parcelable { intent.setAllowFds(false); IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( - IActivityManager.INTENT_SENDER_BROADCAST, packageName, + ActivityManager.INTENT_SENDER_BROADCAST, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, flags); return target != null ? new PendingIntent(target) : null; @@ -330,7 +330,7 @@ public final class PendingIntent implements Parcelable { intent.setAllowFds(false); IIntentSender target = ActivityManagerNative.getDefault().getIntentSender( - IActivityManager.INTENT_SENDER_SERVICE, packageName, + ActivityManager.INTENT_SENDER_SERVICE, packageName, null, null, requestCode, new Intent[] { intent }, resolvedType != null ? new String[] { resolvedType } : null, flags); return target != null ? new PendingIntent(target) : null; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 0e9e256af0b34..19a5bc0103fd8 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -817,6 +817,19 @@ public abstract class Context { @Deprecated public abstract void clearWallpaper() throws IOException; + /** + * Same as {@link #startActivity(Intent, Bundle)} with no options + * specified. + * + * @param intent The description of the activity to start. + * + * @throws ActivityNotFoundException + * + * @see {@link #startActivity(Intent, Bundle)} + * @see PackageManager#resolveActivity + */ + public abstract void startActivity(Intent intent); + /** * Launch a new activity. You will not receive any information about when * the activity exits. @@ -832,12 +845,28 @@ public abstract class Context { * if there was no Activity found to run the given Intent. * * @param intent The description of the activity to start. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. * * @throws ActivityNotFoundException * + * @see {@link #startActivity(Intent)} * @see PackageManager#resolveActivity */ - public abstract void startActivity(Intent intent); + public abstract void startActivity(Intent intent, Bundle options); + + /** + * Same as {@link #startActivities(Intent[], Bundle)} with no options + * specified. + * + * @param intents An array of Intents to be started. + * + * @throws ActivityNotFoundException + * + * @see {@link #startActivities(Intent[], Bundle)} + * @see PackageManager#resolveActivity + */ + public abstract void startActivities(Intent[] intents); /** * Launch multiple new activities. This is generally the same as calling @@ -854,15 +883,38 @@ public abstract class Context { * 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. + * May be null if there are no options. * * @throws ActivityNotFoundException * + * @see {@link #startActivities(Intent[])} * @see PackageManager#resolveActivity */ - public abstract void startActivities(Intent[] intents); + public abstract void startActivities(Intent[] intents, Bundle options); /** - * Like {@link #startActivity(Intent)}, but taking a IntentSender + * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} + * with no options specified. + * + * @param intent The IntentSender to launch. + * @param fillInIntent If non-null, this will be provided as the + * intent parameter to {@link IntentSender#sendIntent}. + * @param flagsMask Intent flags in the original IntentSender that you + * would like to change. + * @param flagsValues Desired values for any bits set in + * flagsMask + * @param extraFlags Always set to 0. + * + * @see #startActivity(Intent) + * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle) + */ + public abstract void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) + throws IntentSender.SendIntentException; + + /** + * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender * to start. If the IntentSender is for an activity, that activity will be started * as if you had called the regular {@link #startActivity(Intent)} * here; otherwise, its associated action will be executed (such as @@ -877,10 +929,15 @@ public abstract class Context { * @param flagsValues Desired values for any bits set in * flagsMask * @param extraFlags Always set to 0. + * @param options Additional options for how the Activity should be started. + * May be null if there are no options. + * + * @see #startActivity(Intent, Bundle) + * @see #startIntentSender(IntentSender, Intent, int, int, int) */ public abstract void startIntentSender(IntentSender intent, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) - throws IntentSender.SendIntentException; + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException; /** * Broadcast the given intent to all interested BroadcastReceivers. This diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 5ba9dccd36b37..6b950e0eaa396 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -276,11 +276,21 @@ public class ContextWrapper extends Context { mBase.startActivity(intent); } + @Override + public void startActivity(Intent intent, Bundle options) { + mBase.startActivity(intent, options); + } + @Override public void startActivities(Intent[] intents) { mBase.startActivities(intents); } + @Override + public void startActivities(Intent[] intents, Bundle options) { + mBase.startActivities(intents, options); + } + @Override public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) @@ -288,6 +298,14 @@ public class ContextWrapper extends Context { mBase.startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags); } + + @Override + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { + mBase.startIntentSender(intent, fillInIntent, flagsMask, + flagsValues, extraFlags, options); + } @Override public void sendBroadcast(Intent intent) { diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index e0a0d2df66431..a1f73160a7cd3 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -17,8 +17,8 @@ package com.android.internal.policy.impl; import android.app.Activity; +import android.app.ActivityManager; import android.app.ActivityManagerNative; -import android.app.IActivityManager; import android.app.IUiModeManager; import android.app.ProgressDialog; import android.app.UiModeManager; @@ -3832,10 +3832,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { int result = ActivityManagerNative.getDefault() .startActivity(null, dock, dock.resolveTypeIfNeeded(mContext.getContentResolver()), - null, 0, null, null, 0, true /* onlyIfNeeded*/, - false /* debug */, false /* openglTrace */, - null, null, false); - if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { + null, null, 0, + ActivityManager.START_FLAG_ONLY_IF_NEEDED, + null, null, null); + if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { return false; } } @@ -3843,10 +3843,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { int result = ActivityManagerNative.getDefault() .startActivity(null, mHomeIntent, mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), - null, 0, null, null, 0, true /* onlyIfNeeded*/, - false /* debug */, false /* openglTrace */, - null, null, false); - if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { + null, null, 0, + ActivityManager.START_FLAG_ONLY_IF_NEEDED, + null, null, null); + if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { return false; } } catch (RemoteException ex) { diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java index c5c2901745e49..84daeaddb3ce7 100644 --- a/services/java/com/android/server/UiModeManagerService.java +++ b/services/java/com/android/server/UiModeManagerService.java @@ -189,8 +189,8 @@ class UiModeManagerService extends IUiModeManager.Stub { } try { ActivityManagerNative.getDefault().startActivityWithConfig( - null, homeIntent, null, null, 0, null, null, 0, false, false, - newConfig); + null, homeIntent, null, null, null, 0, 0, + newConfig, null); mHoldingConfiguration = false; } catch (RemoteException e) { Slog.w(TAG, e.getCause()); diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 94b9e91dd6788..6f89f6eab6b31 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -286,9 +286,7 @@ public final class ActivityManagerService extends ActivityManagerNative static class PendingActivityLaunch { ActivityRecord r; ActivityRecord sourceRecord; - Uri[] grantedUriPermissions; - int grantedMode; - boolean onlyIfNeeded; + int startFlags; } final ArrayList mPendingActivityLaunches @@ -2095,8 +2093,8 @@ public final class ActivityManagerService extends ActivityManagerNative aInfo.applicationInfo.uid); if (app == null || app.instrumentationClass == null) { intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); - mMainStack.startActivityLocked(null, intent, null, null, 0, aInfo, - null, null, 0, 0, 0, false, false, null); + mMainStack.startActivityLocked(null, intent, null, aInfo, + null, null, 0, 0, 0, 0, null, false, null); } } @@ -2150,8 +2148,8 @@ public final class ActivityManagerService extends ActivityManagerNative intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(new ComponentName( ri.activityInfo.packageName, ri.activityInfo.name)); - mMainStack.startActivityLocked(null, intent, null, null, 0, ri.activityInfo, - null, null, 0, 0, 0, false, false, null); + mMainStack.startActivityLocked(null, intent, null, ri.activityInfo, + null, null, 0, 0, 0, 0, null, false, null); } } } @@ -2257,18 +2255,15 @@ public final class ActivityManagerService extends ActivityManagerNative for (int i=0; i= 0) { - return START_FORWARD_AND_REQUEST_CONFLICT; + return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT; } resultRecord = sourceRecord.resultTo; resultWho = sourceRecord.resultWho; @@ -2331,19 +2320,19 @@ final class ActivityStack { } } - if (err == START_SUCCESS && intent.getComponent() == null) { + if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) { // We couldn't find a class that can handle the given Intent. // That's the end of that! - err = START_INTENT_NOT_RESOLVED; + err = ActivityManager.START_INTENT_NOT_RESOLVED; } - if (err == START_SUCCESS && aInfo == null) { + if (err == ActivityManager.START_SUCCESS && aInfo == null) { // We couldn't find the specific class specified in the Intent. // Also the end of the line. - err = START_CLASS_NOT_FOUND; + err = ActivityManager.START_CLASS_NOT_FOUND; } - if (err != START_SUCCESS) { + if (err != ActivityManager.START_SUCCESS) { if (resultRecord != null) { sendActivityResultLocked(-1, resultRecord, resultWho, requestCode, @@ -2400,7 +2389,7 @@ final class ActivityStack { // We pretend to the caller that it was really started, but // they will just get a cancel result. mDismissKeyguardOnNextActivity = false; - return START_SUCCESS; + return ActivityManager.START_SUCCESS; } } } @@ -2419,12 +2408,10 @@ final class ActivityStack { PendingActivityLaunch pal = new PendingActivityLaunch(); pal.r = r; pal.sourceRecord = sourceRecord; - pal.grantedUriPermissions = grantedUriPermissions; - pal.grantedMode = grantedMode; - pal.onlyIfNeeded = onlyIfNeeded; + pal.startFlags = startFlags; mService.mPendingActivityLaunches.add(pal); mDismissKeyguardOnNextActivity = false; - return START_SWITCHES_CANCELED; + return ActivityManager.START_SWITCHES_CANCELED; } } @@ -2443,7 +2430,7 @@ final class ActivityStack { } err = startActivityUncheckedLocked(r, sourceRecord, - grantedUriPermissions, grantedMode, onlyIfNeeded, true); + startFlags, true); if (mDismissKeyguardOnNextActivity && mPausingActivity == null) { // Someone asked to have the keyguard dismissed on the next // activity start, but we are not actually doing an activity @@ -2466,8 +2453,7 @@ final class ActivityStack { } final int startActivityUncheckedLocked(ActivityRecord r, - ActivityRecord sourceRecord, Uri[] grantedUriPermissions, - int grantedMode, boolean onlyIfNeeded, boolean doResume) { + ActivityRecord sourceRecord, int startFlags, boolean doResume) { final Intent intent = r.intent; final int callingUid = r.launchedFromUid; final int userId = r.userId; @@ -2494,14 +2480,14 @@ final class ActivityStack { // being launched is the same as the one making the call... or, as // a special case, if we do not know the caller then we count the // current top activity as the caller. - if (onlyIfNeeded) { + if ((startFlags&ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) { ActivityRecord checkedCaller = sourceRecord; if (checkedCaller == null) { checkedCaller = topRunningNonDelayedActivityLocked(notTop); } if (!checkedCaller.realActivity.equals(r.realActivity)) { // Caller is not the same as launcher, so always needed. - onlyIfNeeded = false; + startFlags &= ~ActivityManager.START_FLAG_ONLY_IF_NEEDED; } } @@ -2586,7 +2572,7 @@ final class ActivityStack { if ((launchFlags&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { taskTop = resetTaskIfNeededLocked(taskTop, r); } - if (onlyIfNeeded) { + if ((startFlags&ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) { // We don't need to start a new activity, and // the client said not to do anything if that // is the case, so this is it! And for paranoia, make @@ -2594,7 +2580,7 @@ final class ActivityStack { if (doResume) { resumeTopActivityLocked(null); } - return START_RETURN_INTENT_TO_CALLER; + return ActivityManager.START_RETURN_INTENT_TO_CALLER; } if ((launchFlags & (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK)) @@ -2681,7 +2667,7 @@ final class ActivityStack { if (doResume) { resumeTopActivityLocked(null); } - return START_TASK_TO_FRONT; + return ActivityManager.START_TASK_TO_FRONT; } } } @@ -2710,14 +2696,14 @@ final class ActivityStack { if (doResume) { resumeTopActivityLocked(null); } - if (onlyIfNeeded) { + if ((startFlags&ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) { // We don't need to start a new activity, and // the client said not to do anything if that // is the case, so this is it! - return START_RETURN_INTENT_TO_CALLER; + return ActivityManager.START_RETURN_INTENT_TO_CALLER; } top.deliverNewIntentLocked(callingUid, r.intent); - return START_DELIVERED_TO_TOP; + return ActivityManager.START_DELIVERED_TO_TOP; } } } @@ -2729,7 +2715,7 @@ final class ActivityStack { r.resultTo, r.resultWho, r.requestCode, Activity.RESULT_CANCELED, null); } - return START_CLASS_NOT_FOUND; + return ActivityManager.START_CLASS_NOT_FOUND; } boolean newTask = false; @@ -2770,7 +2756,7 @@ final class ActivityStack { if (doResume) { resumeTopActivityLocked(null); } - return START_DELIVERED_TO_TOP; + return ActivityManager.START_DELIVERED_TO_TOP; } } else if (!addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) { @@ -2785,7 +2771,7 @@ final class ActivityStack { if (doResume) { resumeTopActivityLocked(null); } - return START_DELIVERED_TO_TOP; + return ActivityManager.START_DELIVERED_TO_TOP; } } // An existing activity is starting this new activity, so we want @@ -2809,13 +2795,6 @@ final class ActivityStack { + " in new guessed " + r.task); } - if (grantedUriPermissions != null && callingUid > 0) { - for (int i=0; i 1) { Intent[] allIntents = new Intent[key.allIntents.length]; @@ -227,22 +228,22 @@ class PendingIntentRecord extends IIntentSender.Stub { allIntents[allIntents.length-1] = finalIntent; allResolvedTypes[allResolvedTypes.length-1] = resolvedType; owner.startActivitiesInPackage(uid, allIntents, - allResolvedTypes, resultTo); + allResolvedTypes, resultTo, options); } else { owner.startActivityInPackage(uid, finalIntent, resolvedType, - resultTo, resultWho, requestCode, false); + resultTo, resultWho, requestCode, 0, options); } } catch (RuntimeException e) { Slog.w(ActivityManagerService.TAG, "Unable to send startActivity intent", e); } break; - case IActivityManager.INTENT_SENDER_ACTIVITY_RESULT: + case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT: key.activity.stack.sendActivityResultLocked(-1, key.activity, key.who, key.requestCode, code, finalIntent); break; - case IActivityManager.INTENT_SENDER_BROADCAST: + case ActivityManager.INTENT_SENDER_BROADCAST: try { // If a completion callback has been requested, require // that the broadcast be delivered synchronously @@ -257,7 +258,7 @@ class PendingIntentRecord extends IIntentSender.Stub { "Unable to send startActivity intent", e); } break; - case IActivityManager.INTENT_SENDER_SERVICE: + case ActivityManager.INTENT_SENDER_SERVICE: try { owner.startServiceInPackage(uid, finalIntent, resolvedType); @@ -281,7 +282,7 @@ class PendingIntentRecord extends IIntentSender.Stub { return 0; } } - return IActivityManager.START_CANCELED; + return ActivityManager.START_CANCELED; } protected void finalize() throws Throwable { diff --git a/test-runner/src/android/test/mock/MockContext.java b/test-runner/src/android/test/mock/MockContext.java index 5fab2bb2d65d2..bf583e1ca7746 100644 --- a/test-runner/src/android/test/mock/MockContext.java +++ b/test-runner/src/android/test/mock/MockContext.java @@ -250,17 +250,34 @@ public class MockContext extends Context { throw new UnsupportedOperationException(); } + @Override + public void startActivity(Intent intent, Bundle options) { + startActivity(intent); + } + @Override public void startActivities(Intent[] intents) { throw new UnsupportedOperationException(); } + @Override + public void startActivities(Intent[] intents, Bundle options) { + startActivities(intents); + } + @Override public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException { throw new UnsupportedOperationException(); } + + @Override + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { + startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags); + } @Override public void sendBroadcast(Intent intent) { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index 58dc2d4984e67..6c49bab861464 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -1234,7 +1234,11 @@ public final class BridgeContext extends Context { @Override public void startActivity(Intent arg0) { // TODO Auto-generated method stub + } + @Override + public void startActivity(Intent arg0, Bundle arg1) { + // TODO Auto-generated method stub } @Override @@ -1244,6 +1248,13 @@ public final class BridgeContext extends Context { // TODO Auto-generated method stub } + @Override + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { + // TODO Auto-generated method stub + } + @Override public boolean startInstrumentation(ComponentName arg0, String arg1, Bundle arg2) { @@ -1286,6 +1297,12 @@ public final class BridgeContext extends Context { } + @Override + public void startActivities(Intent[] arg0, Bundle arg1) { + // TODO Auto-generated method stub + + } + @Override public boolean isRestricted() { return false;