Merge "Simplify app prediction service check" into tm-dev
This commit is contained in:
@@ -771,11 +771,6 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
delegationIntent.setComponent(delegateActivity);
|
delegationIntent.setComponent(delegateActivity);
|
||||||
delegationIntent.putExtra(Intent.EXTRA_INTENT, getIntent());
|
delegationIntent.putExtra(Intent.EXTRA_INTENT, getIntent());
|
||||||
delegationIntent.putExtra(ActivityTaskManager.EXTRA_PERMISSION_TOKEN, permissionToken);
|
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);
|
delegationIntent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
|
||||||
|
|
||||||
// Don't close until the delegate finishes, or the token will be invalidated.
|
// 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.
|
* Returns true if app prediction service is defined and the component exists on device.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
private boolean isAppPredictionServiceAvailable() {
|
||||||
public boolean isAppPredictionServiceAvailable() {
|
return getPackageManager().getAppPredictionServicePackageName() != null;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1307,55 +1307,6 @@ public class ChooserActivityTest {
|
|||||||
is(testBaseScore * SHORTCUT_TARGET_SCORE_BOOST));
|
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
|
@Test
|
||||||
public void testConvertToChooserTarget_predictionService() {
|
public void testConvertToChooserTarget_predictionService() {
|
||||||
Intent sendIntent = createSendTextIntent();
|
Intent sendIntent = createSendTextIntent();
|
||||||
|
|||||||
Reference in New Issue
Block a user