Do not show a summary in Tail button preferences if no app found

Bug: 289054758
Test: StylusDevicesControllerTest
Change-Id: I985194b2e64d36844a9b88f19394db2728ea70e4
diff --git a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java
index ec9f4c6..0a0e208 100644
--- a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java
+++ b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java
@@ -124,7 +124,7 @@
         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 1fcf396..3c459de 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java
@@ -273,6 +273,20 @@
     }
 
     @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);
         Preference defaultNotesPref = mPreferenceContainer.getPreference(0);