Simplify app prediction service check
In support of sharesheet unbundling: This code directly accesses private platform config resources and cannot be used outside of system_server. This was originally added during the Q->R transition as app prediction service was ramping up [See b/138595943]. Incorrect versions would cause increased latency in opening the sharesheet, app prediction missing but no crash. If there is a problem with AiAi version configuration, that should be addressed directly and not covered over by silently disabling functionality. At this time the package name returned from the system call PackageManager#getAppPredictionServicePackageName() is passed through the function "ensureSystemPackage" before being returned this is sufficient to satisfy and availability checks. Bug: 220895016 Test: manual; share content from app, verify share targets Change-Id: I11aebe4fba1d96b543ba89482313668ce55b8ca4
This commit is contained in:
@@ -771,11 +771,6 @@ 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.
|
||||
@@ -972,34 +967,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
/**
|
||||
* Returns true if app prediction service is defined and the component exists on device.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public boolean isAppPredictionServiceAvailable() {
|
||||
if (getPackageManager().getAppPredictionServicePackageName() == null) {
|
||||
// Default AppPredictionService is not defined.
|
||||
return false;
|
||||
}
|
||||
|
||||
final String appPredictionServiceName =
|
||||
getString(R.string.config_defaultAppPredictionService);
|
||||
if (appPredictionServiceName == null) {
|
||||
return false;
|
||||
}
|
||||
final ComponentName appPredictionComponentName =
|
||||
ComponentName.unflattenFromString(appPredictionServiceName);
|
||||
if (appPredictionComponentName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
Log.e(TAG, "App prediction service is defined, but does not exist: "
|
||||
+ appPredictionServiceName);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
private boolean isAppPredictionServiceAvailable() {
|
||||
return getPackageManager().getAppPredictionServicePackageName() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1307,55 +1307,6 @@ public class ChooserActivityTest {
|
||||
is(testBaseScore * SHORTCUT_TARGET_SCORE_BOOST));
|
||||
}
|
||||
|
||||
/**
|
||||
* The case when AppPrediction service is not defined in PackageManager is already covered
|
||||
* as a test parameter {@link ChooserActivityTest#packageManagers}. This test is checking the
|
||||
* case when the prediction service is defined but the component is not available on the device.
|
||||
*/
|
||||
@Test
|
||||
public void testIsAppPredictionServiceAvailable() {
|
||||
Intent sendIntent = createSendTextIntent();
|
||||
List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2);
|
||||
when(
|
||||
ChooserActivityOverrideData
|
||||
.getInstance()
|
||||
.resolverListController
|
||||
.getResolversForIntent(
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.anyBoolean(),
|
||||
Mockito.isA(List.class)))
|
||||
.thenReturn(resolvedComponentInfos);
|
||||
|
||||
final ChooserActivity activity =
|
||||
mActivityRule.launchActivity(Intent.createChooser(sendIntent, null));
|
||||
waitForIdle();
|
||||
if (activity.getPackageManager().getAppPredictionServicePackageName() == null) {
|
||||
assertThat(activity.isAppPredictionServiceAvailable(), is(false));
|
||||
} else {
|
||||
if (!shouldTestTogglingAppPredictionServiceAvailabilityAtRuntime()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This isn't a toggle per-se, but isAppPredictionServiceAvailable only works in
|
||||
// system (see comment in the method).
|
||||
assertThat(activity.isAppPredictionServiceAvailable(), is(true));
|
||||
|
||||
ChooserActivityOverrideData.getInstance().resources =
|
||||
Mockito.spy(activity.getResources());
|
||||
when(
|
||||
ChooserActivityOverrideData
|
||||
.getInstance()
|
||||
.resources
|
||||
.getString(
|
||||
getRuntimeResourceId(
|
||||
"config_defaultAppPredictionService",
|
||||
"string")))
|
||||
.thenReturn("ComponentNameThatDoesNotExist");
|
||||
|
||||
assertThat(activity.isAppPredictionServiceAvailable(), is(false));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToChooserTarget_predictionService() {
|
||||
Intent sendIntent = createSendTextIntent();
|
||||
|
||||
Reference in New Issue
Block a user