diff options
| author | Geoffrey Pitsch <gpitsch@google.com> | 2018-01-24 17:33:59 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-01-24 17:33:59 +0000 |
| commit | d997d191edf668de177496e4e00e69d7d3c6b001 (patch) | |
| tree | be5a840ffca8dfd73067b0500e8c1b182fa06fb1 /core/java | |
| parent | 1387aaecc03855b16b96c7c4192321da852350e1 (diff) | |
| parent | 88f3d4dbe1dbc08316d8a9e25edce1ad16fe2eab (diff) | |
Merge "Security model for moving sharesheet to systemui"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/Activity.java | 6 | ||||
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 25 | ||||
| -rw-r--r-- | core/java/android/app/IActivityManager.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/app/Instrumentation.java | 7 | ||||
| -rw-r--r-- | core/java/com/android/internal/app/ChooserActivity.java | 5 | ||||
| -rw-r--r-- | core/java/com/android/internal/app/IntentForwarderActivity.java | 2 | ||||
| -rw-r--r-- | core/java/com/android/internal/app/ResolverActivity.java | 38 |
7 files changed, 72 insertions, 14 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 0a5b848e6220..73fbb1933943 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -17,6 +17,7 @@ package android.app; import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; + import static java.lang.Character.MIN_VALUE; import android.annotation.CallSuper; @@ -4671,6 +4672,7 @@ public class Activity extends ContextThemeWrapper * their launch had come from the original activity. * @param intent The Intent to start. * @param options ActivityOptions or null. + * @param permissionToken Token received from the system that permits this call to be made. * @param ignoreTargetSecurity If true, the activity manager will not check whether the * caller it is doing the start is, is actually allowed to start the target activity. * If you set this to true, you must set an explicit component in the Intent and do any @@ -4679,7 +4681,7 @@ public class Activity extends ContextThemeWrapper * @hide */ public void startActivityAsCaller(Intent intent, @Nullable Bundle options, - boolean ignoreTargetSecurity, int userId) { + IBinder permissionToken, boolean ignoreTargetSecurity, int userId) { if (mParent != null) { throw new RuntimeException("Can't be called from a child"); } @@ -4687,7 +4689,7 @@ public class Activity extends ContextThemeWrapper Instrumentation.ActivityResult ar = mInstrumentation.execStartActivityAsCaller( this, mMainThread.getApplicationThread(), mToken, this, - intent, -1, options, ignoreTargetSecurity, userId); + intent, -1, options, permissionToken, ignoreTargetSecurity, userId); if (ar != null) { mMainThread.sendActivityResult( mToken, mEmbeddedID, -1, ar.getResultCode(), diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 455458436c2f..b5a941283184 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -443,6 +443,31 @@ public class ActivityManager { */ public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5; + /** + * Extra included on intents that are delegating the call to + * ActivityManager#startActivityAsCaller to another app. This token is necessary for that call + * to succeed. Type is IBinder. + * @hide + */ + public static final String EXTRA_PERMISSION_TOKEN = "android.app.extra.PERMISSION_TOKEN"; + + /** + * Extra included on intents that contain an EXTRA_INTENT, with options that the contained + * intent may want to be started with. Type is Bundle. + * TODO: remove once the ChooserActivity moves to systemui + * @hide + */ + public static final String EXTRA_OPTIONS = "android.app.extra.OPTIONS"; + + /** + * Extra included on intents that contain an EXTRA_INTENT, use this boolean value for the + * parameter of the same name when starting the contained intent. + * TODO: remove once the ChooserActivity moves to systemui + * @hide + */ + public static final String EXTRA_IGNORE_TARGET_SECURITY = + "android.app.extra.EXTRA_IGNORE_TARGET_SECURITY"; + /** @hide User operation call: success! */ public static final int USER_OP_SUCCESS = 0; diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 04ee77d764aa..5f5d834425b6 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -438,10 +438,11 @@ interface IActivityManager { boolean isTopOfTask(in IBinder token); void notifyLaunchTaskBehindComplete(in IBinder token); void notifyEnterAnimationComplete(in IBinder token); + IBinder requestStartActivityPermissionToken(in IBinder delegatorToken); int startActivityAsCaller(in IApplicationThread caller, in String callingPackage, in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, - boolean ignoreTargetSecurity, int userId); + in IBinder permissionToken, boolean ignoreTargetSecurity, int userId); int addAppTask(in IBinder activityToken, in Intent intent, in ActivityManager.TaskDescription description, in Bitmap thumbnail); Point getAppTaskThumbnailSize(); diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java index c5a58f2eef30..3c38a4ec5fe4 100644 --- a/core/java/android/app/Instrumentation.java +++ b/core/java/android/app/Instrumentation.java @@ -1874,8 +1874,8 @@ public class Instrumentation { */ public ActivityResult execStartActivityAsCaller( Context who, IBinder contextThread, IBinder token, Activity target, - Intent intent, int requestCode, Bundle options, boolean ignoreTargetSecurity, - int userId) { + Intent intent, int requestCode, Bundle options, IBinder permissionToken, + boolean ignoreTargetSecurity, int userId) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { @@ -1906,7 +1906,8 @@ public class Instrumentation { .startActivityAsCaller(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, - requestCode, 0, null, options, ignoreTargetSecurity, userId); + requestCode, 0, null, options, permissionToken, + ignoreTargetSecurity, userId); checkStartActivityResult(result, intent); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 6e0ba3413e8c..997d47fe8cf0 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -841,7 +841,7 @@ public class ChooserActivity extends ResolverActivity { } @Override - public boolean startAsCaller(Activity activity, Bundle options, int userId) { + public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { final Intent intent = getBaseIntentToSend(); if (intent == null) { return false; @@ -860,8 +860,7 @@ public class ChooserActivity extends ResolverActivity { final boolean ignoreTargetSecurity = mSourceInfo != null && mSourceInfo.getResolvedComponentName().getPackageName() .equals(mChooserTarget.getComponentName().getPackageName()); - activity.startActivityAsCaller(intent, options, ignoreTargetSecurity, userId); - return true; + return activity.startAsCallerImpl(intent, options, ignoreTargetSecurity, userId); } @Override diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index 398d08791b5c..86731bcb4bf6 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -107,7 +107,7 @@ public class IntentForwarderActivity extends Activity { || ChooserActivity.class.getName().equals(ri.activityInfo.name)); try { - startActivityAsCaller(newIntent, null, false, targetUserId); + startActivityAsCaller(newIntent, null, null, false, targetUserId); } catch (RuntimeException e) { int launchedFromUid = -1; String launchedFromPackage = "?"; diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index ceb06f511108..d6d44908a15b 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -43,6 +43,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.IBinder; import android.os.PatternMatcher; import android.os.RemoteException; import android.os.StrictMode; @@ -857,6 +858,36 @@ public class ResolverActivity extends Activity { } } + public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, + int userId) { + // Pass intent to delegate chooser activity with permission token. + // TODO: This should move to a trampoline Activity in the system when the ChooserActivity + // moves into systemui + try { + // TODO: Once this is a small springboard activity, it can move off the UI process + // and we can move the request method to ActivityManagerInternal. + IBinder permissionToken = ActivityManager.getService() + .requestStartActivityPermissionToken(getActivityToken()); + final Intent chooserIntent = new Intent(); + final ComponentName delegateActivity = ComponentName.unflattenFromString( + Resources.getSystem().getString(R.string.config_chooserActivity)); + chooserIntent.setClassName(delegateActivity.getPackageName(), + delegateActivity.getClassName()); + chooserIntent.putExtra(ActivityManager.EXTRA_PERMISSION_TOKEN, permissionToken); + + // TODO: These extras will change as chooser activity moves into systemui + chooserIntent.putExtra(Intent.EXTRA_INTENT, intent); + chooserIntent.putExtra(ActivityManager.EXTRA_OPTIONS, options); + chooserIntent.putExtra(ActivityManager.EXTRA_IGNORE_TARGET_SECURITY, + ignoreTargetSecurity); + chooserIntent.putExtra(Intent.EXTRA_USER_ID, userId); + startActivity(chooserIntent); + } catch (RemoteException e) { + Log.e(TAG, e.toString()); + } + return true; + } + public void onActivityStarted(TargetInfo cti) { // Do nothing } @@ -1181,9 +1212,8 @@ public class ResolverActivity extends Activity { } @Override - public boolean startAsCaller(Activity activity, Bundle options, int userId) { - activity.startActivityAsCaller(mResolvedIntent, options, false, userId); - return true; + public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { + return activity.startAsCallerImpl(mResolvedIntent, options, false, userId); } @Override @@ -1242,7 +1272,7 @@ public class ResolverActivity extends Activity { * @param userId userId to start as or {@link UserHandle#USER_NULL} for activity's caller * @return true if the start completed successfully */ - boolean startAsCaller(Activity activity, Bundle options, int userId); + boolean startAsCaller(ResolverActivity activity, Bundle options, int userId); /** * Start the activity referenced by this target as a given user. |
