From ebc0b9c32331acaaddaec45a1f099e13ee8b1620 Mon Sep 17 00:00:00 2001 From: Vania Januar Date: Mon, 3 Jul 2023 14:44:59 +0100 Subject: [PATCH] Do not show a summary in Tail button preferences if no app found Bug: 289054758 Test: StylusDevicesControllerTest Change-Id: I985194b2e64d36844a9b88f19394db2728ea70e4 --- .../stylus/StylusDevicesController.java | 2 +- .../stylus/StylusDevicesControllerTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java index ec9f4c6eb51..0a0e2081a8f 100644 --- a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +++ b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java @@ -124,7 +124,7 @@ public class StylusDevicesController extends AbstractPreferenceController implem try { ApplicationInfo ai = pm.getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(0)); - appName = ai == null ? packageName : pm.getApplicationLabel(ai).toString(); + appName = ai == null ? "" : pm.getApplicationLabel(ai).toString(); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Notes role package not found."); } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java index 1fcf396f31c..3c459de3792 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java @@ -272,6 +272,20 @@ public class StylusDevicesControllerTest { NOTES_APP_LABEL.toString())); } + @Test + public void defaultNotesPreference_noApplicationInfo_showsBlankSummary() + throws PackageManager.NameNotFoundException { + when(mPm.getApplicationInfo(eq(NOTES_PACKAGE_NAME), + any(PackageManager.ApplicationInfoFlags.class))).thenReturn(null); + + showScreen(mController); + + Preference defaultNotesPref = mPreferenceContainer.getPreference(0); + assertThat(defaultNotesPref.getTitle().toString()).isEqualTo( + mContext.getString(R.string.stylus_default_notes_app)); + assertThat(defaultNotesPref.getSummary().toString()).isEqualTo(""); + } + @Test public void defaultNotesPreference_roleHolderChanges_updatesPreference() { showScreen(mController);