From 1e781efd02c0db80a0d0161bb001d0fc59e2897a Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Tue, 24 Aug 2021 20:12:25 -0400 Subject: [PATCH] Remove ChooserTargetService flow entrypoints. Despite the `USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS` flag being hard-coded to true and thus triggering the deprecated flow, the effects of that flow (modulo potential bugs) have been suppressed since the ChooserFlag was set to false. That is, the logic removed in this CL was a (somewhat misleading) no-op; the *intended* behavior was disabled, but there were possible unintended consequences of the vestigial code (which I believe were addressed as of ag/15662048). Test: presubmits Change-Id: I0a2aa6e8bd796e41f6ebc69a54a1f74f9eeebbd9 --- .../android/internal/app/ChooserActivity.java | 106 +----------------- .../android/internal/app/ChooserFlags.java | 12 -- .../internal/app/ChooserActivityTest.java | 24 ---- .../internal/app/ChooserWrapperActivity.java | 10 -- 4 files changed, 1 insertion(+), 151 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 35d25caead0b7..e47181f4a0e75 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -86,7 +86,6 @@ import android.provider.Downloads; import android.provider.OpenableColumns; import android.provider.Settings; import android.service.chooser.ChooserTarget; -import android.service.chooser.ChooserTargetService; import android.service.chooser.IChooserTargetResult; import android.service.chooser.IChooserTargetService; import android.text.TextUtils; @@ -227,8 +226,6 @@ public class ChooserActivity extends ResolverActivity implements // statsd logger wrapper protected ChooserActivityLogger mChooserActivityLogger; - private static final boolean USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS = true; - @IntDef(flag = false, prefix = { "TARGET_TYPE_" }, value = { TARGET_TYPE_DEFAULT, TARGET_TYPE_CHOOSER_TARGET, @@ -268,7 +265,6 @@ public class ChooserActivity extends ResolverActivity implements private long mChooserShownTime; protected boolean mIsSuccessfullySelected; - private long mQueriedTargetServicesTimeMs; private long mQueriedSharingShortcutsTimeMs; private int mChooserRowServiceSpacing; @@ -1887,96 +1883,6 @@ public class ChooserActivity extends ResolverActivity implements } } - @VisibleForTesting - protected void queryTargetServices(ChooserListAdapter adapter) { - - mQueriedTargetServicesTimeMs = System.currentTimeMillis(); - - Context selectedProfileContext = createContextAsUser( - adapter.getUserHandle(), 0 /* flags */); - final PackageManager pm = selectedProfileContext.getPackageManager(); - ShortcutManager sm = selectedProfileContext.getSystemService(ShortcutManager.class); - int targetsToQuery = 0; - - for (int i = 0, N = adapter.getDisplayResolveInfoCount(); i < N; i++) { - final DisplayResolveInfo dri = adapter.getDisplayResolveInfo(i); - if (adapter.getScore(dri) == 0) { - // A score of 0 means the app hasn't been used in some time; - // don't query it as it's not likely to be relevant. - continue; - } - final ActivityInfo ai = dri.getResolveInfo().activityInfo; - if (sm.hasShareTargets(ai.packageName)) { - // Share targets will be queried from ShortcutManager - continue; - } - final Bundle md = ai.metaData; - final String serviceName = md != null ? convertServiceName(ai.packageName, - md.getString(ChooserTargetService.META_DATA_NAME)) : null; - if (serviceName != null && ChooserFlags.USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS) { - final ComponentName serviceComponent = new ComponentName( - ai.packageName, serviceName); - - UserHandle userHandle = adapter.getUserHandle(); - Pair requestedItem = - new Pair<>(serviceComponent, userHandle); - if (mServicesRequested.contains(requestedItem)) { - continue; - } - mServicesRequested.add(requestedItem); - - final Intent serviceIntent = new Intent(ChooserTargetService.SERVICE_INTERFACE) - .setComponent(serviceComponent); - - if (DEBUG) { - Log.d(TAG, "queryTargets found target with service " + serviceComponent); - } - - try { - final String perm = pm.getServiceInfo(serviceComponent, 0).permission; - if (!ChooserTargetService.BIND_PERMISSION.equals(perm)) { - Log.w(TAG, "ChooserTargetService " + serviceComponent + " does not require" - + " permission " + ChooserTargetService.BIND_PERMISSION - + " - this service will not be queried for ChooserTargets." - + " add android:permission=\"" - + ChooserTargetService.BIND_PERMISSION + "\"" - + " to the tag for " + serviceComponent - + " in the manifest."); - continue; - } - } catch (NameNotFoundException e) { - Log.e(TAG, "Could not look up service " + serviceComponent - + "; component name not found"); - continue; - } - - final ChooserTargetServiceConnection conn = - new ChooserTargetServiceConnection(this, dri, - adapter.getUserHandle()); - - // Explicitly specify the user handle instead of calling bindService - // to avoid the warning from calling from the system process without an explicit - // user handle - if (bindServiceAsUser(serviceIntent, conn, BIND_AUTO_CREATE | BIND_NOT_FOREGROUND, - adapter.getUserHandle())) { - if (DEBUG) { - Log.d(TAG, "Binding service connection for target " + dri - + " intent " + serviceIntent); - } - mServiceConnections.add(conn); - targetsToQuery++; - } - } - if (targetsToQuery >= QUERY_TARGET_SERVICE_LIMIT) { - if (DEBUG) { - Log.d(TAG, "queryTargets hit query target limit " - + QUERY_TARGET_SERVICE_LIMIT); - } - break; - } - } - } - private IntentFilter getTargetIntentFilter() { try { final Intent intent = getTargetIntent(); @@ -2241,10 +2147,7 @@ public class ChooserActivity extends ResolverActivity implements } private void logDirectShareTargetReceived(int logCategory) { - final long queryTime = - logCategory == MetricsEvent.ACTION_DIRECT_SHARE_TARGETS_LOADED_SHORTCUT_MANAGER - ? mQueriedSharingShortcutsTimeMs : mQueriedTargetServicesTimeMs; - final int apiLatency = (int) (System.currentTimeMillis() - queryTime); + final int apiLatency = (int) (System.currentTimeMillis() - mQueriedSharingShortcutsTimeMs); getMetricsLogger().write(new LogMaker(logCategory).setSubtype(apiLatency)); } @@ -2850,13 +2753,6 @@ public class ChooserActivity extends ResolverActivity implements queryDirectShareTargets(chooserListAdapter, false); } - if (USE_CHOOSER_TARGET_SERVICE_FOR_DIRECT_TARGETS) { - if (DEBUG) { - Log.d(TAG, "List built querying services"); - } - - queryTargetServices(chooserListAdapter); - } getChooserActivityLogger().logSharesheetAppLoadComplete(); } diff --git a/core/java/com/android/internal/app/ChooserFlags.java b/core/java/com/android/internal/app/ChooserFlags.java index 1a93f1bc947f1..ab6b0f89c2fad 100644 --- a/core/java/com/android/internal/app/ChooserFlags.java +++ b/core/java/com/android/internal/app/ChooserFlags.java @@ -17,24 +17,12 @@ package com.android.internal.app; import android.app.prediction.AppPredictionManager; -import android.provider.DeviceConfig; - -import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; /** * Common flags for {@link ChooserListAdapter} and {@link ChooserActivity}. */ public class ChooserFlags { - /** - * Whether to use the deprecated {@link android.service.chooser.ChooserTargetService} API for - * direct share targets. If true, both CTS and Shortcuts will be used to find Direct Share - * targets. If false, only Shortcuts will be used. - */ - public static final boolean USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS = - DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI, - SystemUiDeviceConfigFlags.SHARE_USE_SERVICE_TARGETS, false); - /** * Whether to use {@link AppPredictionManager} to query for direct share targets (as opposed to * talking directly to {@link android.content.pm.ShortcutManager}. diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java index a064af95f48d9..65262b5539dc8 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -2243,12 +2243,6 @@ public class ChooserActivityTest { (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; - boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false }; - sOverrides.onQueryTargetServices = chooserListAdapter -> { - isQueryTargetServicesCalledOnWorkProfile[0] = - (chooserListAdapter.getUserHandle().getIdentifier() == 10); - return null; - }; Intent sendIntent = createSendTextIntent(); sendIntent.setType("TestType"); @@ -2261,8 +2255,6 @@ public class ChooserActivityTest { assertFalse("Direct share targets were queried on a paused work profile", isQueryDirectShareCalledOnWorkProfile[0]); - assertFalse("Target services were queried on a paused work profile", - isQueryTargetServicesCalledOnWorkProfile[0]); } @Test @@ -2282,12 +2274,6 @@ public class ChooserActivityTest { (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; - boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false }; - sOverrides.onQueryTargetServices = chooserListAdapter -> { - isQueryTargetServicesCalledOnWorkProfile[0] = - (chooserListAdapter.getUserHandle().getIdentifier() == 10); - return null; - }; Intent sendIntent = createSendTextIntent(); sendIntent.setType("TestType"); @@ -2300,8 +2286,6 @@ public class ChooserActivityTest { assertFalse("Direct share targets were queried on a locked work profile user", isQueryDirectShareCalledOnWorkProfile[0]); - assertFalse("Target services were queried on a locked work profile user", - isQueryTargetServicesCalledOnWorkProfile[0]); } @Test @@ -2346,12 +2330,6 @@ public class ChooserActivityTest { (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; - boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false }; - sOverrides.onQueryTargetServices = chooserListAdapter -> { - isQueryTargetServicesCalledOnWorkProfile[0] = - (chooserListAdapter.getUserHandle().getIdentifier() == 10); - return null; - }; Intent sendIntent = createSendTextIntent(); sendIntent.setType("TestType"); @@ -2364,8 +2342,6 @@ public class ChooserActivityTest { assertFalse("Direct share targets were queried on a locked work profile user", isQueryDirectShareCalledOnWorkProfile[0]); - assertFalse("Target services were queried on a locked work profile user", - isQueryTargetServicesCalledOnWorkProfile[0]); } @Test diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java index 9fcab0923f2d8..6b3d657f9450d 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java @@ -228,14 +228,6 @@ public class ChooserWrapperActivity extends ChooserActivity { super.queryDirectShareTargets(adapter, skipAppPredictionService); } - @Override - protected void queryTargetServices(ChooserListAdapter adapter) { - if (sOverrides.onQueryTargetServices != null) { - sOverrides.onQueryTargetServices.apply(adapter); - } - super.queryTargetServices(adapter); - } - @Override protected boolean isQuietModeEnabled(UserHandle userHandle) { return sOverrides.isQuietModeEnabled; @@ -267,7 +259,6 @@ public class ChooserWrapperActivity extends ChooserActivity { public Function createPackageManager; public Function onSafelyStartCallback; public Function onQueryDirectShareTargets; - public Function onQueryTargetServices; public ResolverListController resolverListController; public ResolverListController workResolverListController; public Boolean isVoiceInteraction; @@ -290,7 +281,6 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; onQueryDirectShareTargets = null; - onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null;