Loading core/java/com/android/internal/app/ChooserActivity.java +1 −105 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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)); } Loading Loading @@ -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(); } Loading core/java/com/android/internal/app/ChooserFlags.java +0 −12 Original line number Diff line number Diff line Loading @@ -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}. Loading core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +0 −24 Original line number Diff line number Diff line Loading @@ -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"); Loading @@ -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 Loading @@ -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"); Loading @@ -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 Loading Loading @@ -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"); Loading @@ -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 Loading core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +0 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -290,7 +281,6 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; onQueryDirectShareTargets = null; onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null; Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +1 −105 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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)); } Loading Loading @@ -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(); } Loading
core/java/com/android/internal/app/ChooserFlags.java +0 −12 Original line number Diff line number Diff line Loading @@ -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}. Loading
core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +0 −24 Original line number Diff line number Diff line Loading @@ -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"); Loading @@ -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 Loading @@ -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"); Loading @@ -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 Loading Loading @@ -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"); Loading @@ -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 Loading
core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +0 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -290,7 +281,6 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; onQueryDirectShareTargets = null; onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null; Loading