Merge "Fix Settings button visibility on autofill" into pi-car-dev
diff --git a/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceController.java b/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceController.java
index f61a16f..60bffa8 100644
--- a/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceController.java
+++ b/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceController.java
@@ -19,7 +19,6 @@
import android.car.drivingstate.CarUxRestrictions;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
import androidx.annotation.Nullable;
@@ -48,27 +47,22 @@
protected void updateState(ButtonPreference preference) {
super.updateState(preference);
+ // If activity does not exist, return. Otherwise allow intenting to the activity.
Intent intent = getSettingIntent(getCurrentDefaultAppInfo());
- boolean isSafeIntent = false;
- if (intent != null) {
- ActivityInfo info = intent.resolveActivityInfo(
- getContext().getPackageManager(), intent.getFlags());
- // If activity exists and is visible to Car Settings, allow intenting to the activity.
- if (info != null && info.exported) {
- isSafeIntent = true;
- }
+ if (intent == null || intent.resolveActivityInfo(
+ getContext().getPackageManager(), intent.getFlags()) == null) {
+ preference.showAction(false);
+ return;
}
- preference.showAction(isSafeIntent);
- if (isSafeIntent) {
- // Use startActivityForResult because some apps need to check the identity of the
- // caller.
- preference.setOnButtonClickListener(p -> getContext().startActivityForResult(
- getContext().getBasePackageName(),
- intent,
- /* requestCode= */ 0,
- /* options= */ null
- ));
- }
+
+ // Use startActivityForResult because some apps need to check the identity of the caller.
+ preference.setOnButtonClickListener(p -> getContext().startActivityForResult(
+ getContext().getBasePackageName(),
+ intent,
+ /* requestCode= */ 0,
+ /* options= */ null
+ ));
+ preference.showAction(true);
}
/**
diff --git a/tests/robotests/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceControllerTest.java
index 55179a7..73db10b 100644
--- a/tests/robotests/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/car/settings/applications/defaultapps/DefaultAppsPickerEntryBasePreferenceControllerTest.java
@@ -121,7 +121,7 @@
}
@Test
- public void refreshUi_hasSettingIntentButNoVisibleActivity_actionButtonIsNotVisible() {
+ public void refreshUi_hasSettingIntentButNoVisibleActivity_actionButtonIsVisible() {
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.exported = false;
ResolveInfo resolveInfo = new ResolveInfo();
@@ -132,7 +132,7 @@
mControllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
mController.refreshUi();
- assertThat(mButtonPreference.isActionShown()).isFalse();
+ assertThat(mButtonPreference.isActionShown()).isTrue();
}
@Test