diff options
| author | Joshua Trask <joshtrask@google.com> | 2021-08-25 17:43:13 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-08-25 17:43:13 +0000 |
| commit | e2e8cefe30db8b323ecaca18e28c8ecfc6319f45 (patch) | |
| tree | c6c8961d7a122085d631401bb1ac70b412be496b | |
| parent | 0e6105e0f6216c6d4b1e4089cbfaf2f79b74ac5d (diff) | |
| parent | 1e781efd02c0db80a0d0161bb001d0fc59e2897a (diff) | |
Merge "Remove ChooserTargetService flow entrypoints."
4 files changed, 1 insertions, 151 deletions
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 35d25caead0b..e47181f4a0e7 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<ComponentName, UserHandle> 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 <service> 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 1a93f1bc947f..ab6b0f89c2fa 100644 --- a/core/java/com/android/internal/app/ChooserFlags.java +++ b/core/java/com/android/internal/app/ChooserFlags.java @@ -17,9 +17,6 @@ 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}. @@ -27,15 +24,6 @@ import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; 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 b5ab2825ae41..cfcbc7dec7d1 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 9fcab0923f2d..6b3d657f9450 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java @@ -229,14 +229,6 @@ public class ChooserWrapperActivity extends ChooserActivity { } @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<PackageManager, PackageManager> createPackageManager; public Function<TargetInfo, Boolean> onSafelyStartCallback; public Function<ChooserListAdapter, Void> onQueryDirectShareTargets; - public Function<ChooserListAdapter, Void> 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; |
