From 554dcb5a72bbcdc508e6b753d52ab2fb1aae2f83 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Fri, 19 Nov 2021 14:34:16 -0500 Subject: [PATCH] System->Unbundled, AppPrediction availability bit. The current logic in ChooserActivity depends on checking for the presence of a particular AppPredictionService component in AiAi, but that check always fails in the unbundled Chooser. Instead, only check when we're running on the system side, and hand off the bit in an extra on the delegation intent. Test: trivial (needs other changes for meaningful behavior) Bug: 206831012 Change-Id: I86919d962ac25fc1a4dd4a25d672d400abc64ff2 --- .../android/internal/app/ChooserActivity.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index fd9ad0d9bcfd1..359c382f51bc6 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -185,6 +185,17 @@ public class ChooserActivity extends ResolverActivity implements public static final String EXTRA_PRIVATE_RETAIN_IN_ON_STOP = "com.android.internal.app.ChooserActivity.EXTRA_PRIVATE_RETAIN_IN_ON_STOP"; + /** + * Boolean extra added to "unbundled Sharesheet" delegation intents to signal whether the app + * prediction service is available. Our query of the service availability depends on + * privileges that are only available in the system, even though the service itself would then + * be available to the unbundled component. For now, we just include the query result as part of + * the handover intent. + * TODO: investigate whether the privileged query is necessary to determine the availability. + */ + protected static final String EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE = + "com.android.internal.app.ChooserActivity.EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE"; + /** * Transition name for the first image preview. * To be used for shared element transition into this activity. @@ -757,6 +768,11 @@ public class ChooserActivity extends ResolverActivity implements delegationIntent.setComponent(delegateActivity); delegationIntent.putExtra(Intent.EXTRA_INTENT, getIntent()); delegationIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, permissionToken); + + // Query prediction availability; mIsAppPredictorComponentAvailable isn't initialized. + delegationIntent.putExtra( + EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE, isAppPredictionServiceAvailable()); + delegationIntent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); // Don't close until the delegate finishes, or the token will be invalidated. @@ -971,7 +987,8 @@ public class ChooserActivity extends ResolverActivity implements return false; } - // Check if the app prediction component actually exists on the device. + // Check if the app prediction component actually exists on the device. The component is + // only visible when this is running in a system activity; otherwise this check will fail. Intent intent = new Intent(); intent.setComponent(appPredictionComponentName); if (getPackageManager().resolveService(intent, PackageManager.MATCH_ALL) == null) {