summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2022-02-19 15:16:00 -0500
committer Mark Renouf <mrenouf@google.com> 2022-03-09 16:24:47 -0500
commit90b62ac16496de554c039e09e507f65a2024c7d3 (patch)
tree323cde5ef496497ac1b6c6787f1b74b0f3be3088 /java
parentbbd66a16f80d38764b5ff38ae0f3356d52b6335b (diff)
Remove permission token
Bug: 222082547 Test: atest UnbundledChooserActivityTest Change-Id: I70585e158bea2341fc753aee4d382ae2e21b9f30
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/intentresolver/ChooserActivity.java29
-rw-r--r--java/src/com/android/intentresolver/ChooserHelper.java75
-rw-r--r--java/tests/src/com/android/intentresolver/ChooserHelperTest.java58
-rw-r--r--java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java4
4 files changed, 9 insertions, 157 deletions
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(