From 90b62ac16496de554c039e09e507f65a2024c7d3 Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Sat, 19 Feb 2022 15:16:00 -0500 Subject: Remove permission token Bug: 222082547 Test: atest UnbundledChooserActivityTest Change-Id: I70585e158bea2341fc753aee4d382ae2e21b9f30 --- .../android/intentresolver/ChooserActivity.java | 29 +++------ .../com/android/intentresolver/ChooserHelper.java | 75 ---------------------- .../android/intentresolver/ChooserHelperTest.java | 58 ----------------- .../UnbundledChooserActivityTest.java | 4 -- 4 files changed, 9 insertions(+), 157 deletions(-) delete mode 100644 java/src/com/android/intentresolver/ChooserHelper.java delete mode 100644 java/tests/src/com/android/intentresolver/ChooserHelperTest.java (limited to 'java') diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index d5dff9ff..d221c491 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -16,11 +16,9 @@ package com.android.intentresolver; -import android.app.ActivityTaskManager; import android.content.Intent; import android.os.Bundle; -import android.os.IBinder; -import android.util.Log; +import android.os.StrictMode; /** * Activity for selecting which application ought to handle an ACTION_SEND intent. @@ -28,27 +26,18 @@ import android.util.Log; public class ChooserActivity extends com.android.internal.app.ChooserActivity { private static final String TAG = "ChooserActivity"; - private IBinder mPermissionToken; - @Override public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, int userId) { - ChooserHelper.onTargetSelected( - this, intent, options, mPermissionToken, ignoreTargetSecurity, userId); - return true; - } - @Override - protected void onCreate(Bundle savedInstanceState) { - mPermissionToken = getIntent().getExtras().getBinder( - ActivityTaskManager.EXTRA_PERMISSION_TOKEN); - - if (mPermissionToken != null) { - super.onCreate(savedInstanceState); - } else { - Log.e(TAG, "No permission token to launch activities from chooser"); - super_onCreate(savedInstanceState); // Skip up to Activity::onCreate(). - finish(); + // We're dispatching intents that might be coming from legacy apps, so + // (as in com.android.internal.app.ResolverActivity) exempt ourselves from death. + StrictMode.disableDeathOnFileUriExposure(); + try { + startActivityAsCaller(intent, options, ignoreTargetSecurity, userId); + } finally { + StrictMode.enableDeathOnFileUriExposure(); } + return true; } } diff --git a/java/src/com/android/intentresolver/ChooserHelper.java b/java/src/com/android/intentresolver/ChooserHelper.java deleted file mode 100644 index 0edaf595..00000000 --- a/java/src/com/android/intentresolver/ChooserHelper.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.intentresolver; - -import android.app.Activity; -import android.app.ActivityTaskManager; -import android.content.Intent; -import android.os.Bundle; -import android.os.IBinder; -import android.os.StrictMode; - -import androidx.annotation.VisibleForTesting; - -/** Utilities for executing the action that the user selected from a Chooser UI. */ -public class ChooserHelper { - - private static final String TAG = "ChooserHelper"; - - /** Launch the user's selected target. */ - static void onTargetSelected( - Activity activity, - Intent chosenIntent, - Bundle options, - IBinder permissionToken, - boolean ignoreTargetSecurity, - int userId) { - - // We're dispatching intents that might be coming from legacy apps, so - // (as in com.android.internal.app.ResolverActivity) exempt ourselves from death. - StrictMode.disableDeathOnFileUriExposure(); - try { - activity.startActivityAsCaller( - chosenIntent, options, permissionToken, ignoreTargetSecurity, userId); - } finally { - StrictMode.enableDeathOnFileUriExposure(); - } - } - - /** - * Launch a pre-selected target. In the earliest versions of the unbundled chooser, the user - * has already selected their target from a system-side ChooserActivity UI, and the selection - * was delegated to the current Activity to dispatch immediately. Unpack the arguments from the - * Intent that was sent from the system-side ChooserActivity for this kind of delegated - * dispatch, and launch the user's selected target using the startActivityAsCaller API. - */ - @VisibleForTesting - public static void onChoose(Activity activity) { - final Intent thisIntent = activity.getIntent(); - final Bundle thisExtras = thisIntent.getExtras(); - final Intent chosenIntent = thisIntent.getParcelableExtra(Intent.EXTRA_INTENT); - final Bundle options = thisIntent.getParcelableExtra(ActivityTaskManager.EXTRA_OPTIONS); - final IBinder permissionToken = - thisExtras.getBinder(ActivityTaskManager.EXTRA_PERMISSION_TOKEN); - final boolean ignoreTargetSecurity = - thisIntent.getBooleanExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY, false); - final int userId = thisIntent.getIntExtra(Intent.EXTRA_USER_ID, -1); - - onTargetSelected( - activity, chosenIntent, options, permissionToken, ignoreTargetSecurity, userId); - } -} diff --git a/java/tests/src/com/android/intentresolver/ChooserHelperTest.java b/java/tests/src/com/android/intentresolver/ChooserHelperTest.java deleted file mode 100644 index d791cd4b..00000000 --- a/java/tests/src/com/android/intentresolver/ChooserHelperTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.intentresolver.tests; - -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.app.Activity; -import android.app.ActivityTaskManager; -import android.content.Intent; -import android.os.Binder; -import android.test.suitebuilder.annotation.SmallTest; - -import androidx.test.runner.AndroidJUnit4; - -import com.android.intentresolver.ChooserHelper; - -import org.junit.Test; -import org.junit.runner.RunWith; - -@SmallTest -@RunWith(AndroidJUnit4.class) -public class ChooserHelperTest { - - @Test - public void testOnChoose_CallsStartActivityAsCallerWithToken() { - final Intent intent = new Intent(); - final Binder token = new Binder(); - intent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, token); - - final Activity mockActivity = mock(Activity.class); - when(mockActivity.getIntent()).thenReturn(intent); - - ChooserHelper.onChoose(mockActivity); - verify(mockActivity, times(1)).startActivityAsCaller( - any(), any(), eq(token), anyBoolean(), anyInt()); - } -} diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index c88fc53d..ebd04d4c 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -20,11 +20,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; -import android.app.ActivityTaskManager; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.os.Binder; import androidx.test.platform.app.InstrumentationRegistry; @@ -64,8 +62,6 @@ public class UnbundledChooserActivityTest extends ChooserActivityTest { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); clientIntent.setClass(context, com.android.intentresolver.ChooserWrapperActivity.class); - clientIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, new Binder()); - PackageManager pm = ChooserActivityOverrideData.getInstance().createPackageManager .apply(context.getPackageManager()); clientIntent.putExtra( -- cgit v1.2.3-59-g8ed1b