Loading services/core/java/com/android/server/notification/PreferencesHelper.java +18 −10 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__DENIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_PROMOTABLE; import android.annotation.FlaggedApi; Loading Loading @@ -155,6 +156,7 @@ public class PreferencesHelper implements RankingConfig { private static final String ATT_VERSION = "version"; private static final String ATT_NAME = "name"; private static final String ATT_UID = "uid"; private static final String ATT_LAST_BUBBLES_VERSION_UPGRADE = "last_bubbles_version_upgrade"; private static final String ATT_USERID = "userid"; private static final String ATT_ID = "id"; Loading Loading @@ -286,7 +288,8 @@ public class PreferencesHelper implements RankingConfig { if (!TAG_RANKING.equals(tag)) return; final int xmlVersion = parser.getAttributeInt(null, ATT_VERSION, -1); boolean upgradeForBubbles = xmlVersion == XML_VERSION_BUBBLES_UPGRADE; boolean upgradeForBubbles = parser.getAttributeInt(null, ATT_LAST_BUBBLES_VERSION_UPGRADE, -1) < Build.VERSION.SDK_INT; boolean migrateToPermission = (xmlVersion < XML_VERSION_NOTIF_PERMISSION); if (mShowReviewPermissionsNotification && (xmlVersion < XML_VERSION_REVIEW_PERMISSIONS_NOTIFICATION)) { Loading Loading @@ -337,15 +340,19 @@ public class PreferencesHelper implements RankingConfig { } boolean skipWarningLogged = false; boolean skipGroupWarningLogged = false; boolean hasSAWPermission = false; if (upgradeForBubbles && uid != UNKNOWN_UID) { hasSAWPermission = mAppOps.noteOpNoThrow( OP_SYSTEM_ALERT_WINDOW, uid, name, null, "check-notif-bubble") == AppOpsManager.MODE_ALLOWED; } int bubblePref = hasSAWPermission ? BUBBLE_PREFERENCE_ALL : parser.getAttributeInt(null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE); int bubblePref = parser.getAttributeInt(null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE); boolean bubbleLocked = (parser.getAttributeInt(null, ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS) & USER_LOCKED_BUBBLE) != 0; if (!bubbleLocked && upgradeForBubbles && uid != UNKNOWN_UID && mAppOps.noteOpNoThrow(OP_SYSTEM_ALERT_WINDOW, uid, name, null, "check-notif-bubble") == AppOpsManager.MODE_ALLOWED) { // User hasn't changed bubble pref & the app has SAW, so allow all bubbles. bubblePref = BUBBLE_PREFERENCE_ALL; } int appImportance = parser.getAttributeInt(null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE); // when data is loaded from disk it's loaded as USER_ALL, but restored data that Loading Loading @@ -684,6 +691,7 @@ public class PreferencesHelper implements RankingConfig { public void writeXml(TypedXmlSerializer out, boolean forBackup, int userId) throws IOException { out.startTag(null, TAG_RANKING); out.attributeInt(null, ATT_VERSION, XML_VERSION); out.attributeInt(null, ATT_LAST_BUBBLES_VERSION_UPGRADE, Build.VERSION.SDK_INT); if (mHideSilentStatusBarIcons != DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS) { out.startTag(null, TAG_STATUS_ICONS); out.attributeBoolean(null, ATT_HIDE_SILENT, mHideSilentStatusBarIcons); Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +54 −5 Original line number Diff line number Diff line Loading @@ -1219,7 +1219,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, false, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"com.example.o\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" Loading Loading @@ -1303,7 +1304,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " Loading Loading @@ -1389,7 +1391,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " Loading Loading @@ -1440,7 +1443,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Packages that exist solely in permissionhelper + "<package name=\"" + PKG_P + "\" importance=\"3\" />\n" + "<package name=\"" + PKG_O + "\" importance=\"0\" />\n" Loading Loading @@ -4474,7 +4478,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test public void testBubblePreference_upgradeWithSAWPermission() throws Exception { public void testBubblePreference_noLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); Loading @@ -4494,6 +4498,51 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); } @Test public void testBubblePreference_differentLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); final String xml = "<ranking version=\"4\" last_bubbles_version_upgrade=\"34\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n" + "<channel id=\"someId\" name=\"hi\"" + " importance=\"3\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertEquals(BUBBLE_PREFERENCE_ALL, mHelper.getBubblePreference(PKG_O, UID_O)); assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); } @Test public void testBubblePreference_sameLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); final String xml = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n" + "<channel id=\"someId\" name=\"hi\"" + " importance=\"3\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertEquals(DEFAULT_BUBBLE_PREFERENCE, mHelper.getBubblePreference(PKG_O, UID_O)); assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); // Version was the same SAW check should not have happened verify(mAppOpsManager, never()).noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString()); } @Test public void testBubblePreference_upgradeWithSAWThenUserOverride() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), Loading Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +18 −10 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__DENIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_PROMOTABLE; import android.annotation.FlaggedApi; Loading Loading @@ -155,6 +156,7 @@ public class PreferencesHelper implements RankingConfig { private static final String ATT_VERSION = "version"; private static final String ATT_NAME = "name"; private static final String ATT_UID = "uid"; private static final String ATT_LAST_BUBBLES_VERSION_UPGRADE = "last_bubbles_version_upgrade"; private static final String ATT_USERID = "userid"; private static final String ATT_ID = "id"; Loading Loading @@ -286,7 +288,8 @@ public class PreferencesHelper implements RankingConfig { if (!TAG_RANKING.equals(tag)) return; final int xmlVersion = parser.getAttributeInt(null, ATT_VERSION, -1); boolean upgradeForBubbles = xmlVersion == XML_VERSION_BUBBLES_UPGRADE; boolean upgradeForBubbles = parser.getAttributeInt(null, ATT_LAST_BUBBLES_VERSION_UPGRADE, -1) < Build.VERSION.SDK_INT; boolean migrateToPermission = (xmlVersion < XML_VERSION_NOTIF_PERMISSION); if (mShowReviewPermissionsNotification && (xmlVersion < XML_VERSION_REVIEW_PERMISSIONS_NOTIFICATION)) { Loading Loading @@ -337,15 +340,19 @@ public class PreferencesHelper implements RankingConfig { } boolean skipWarningLogged = false; boolean skipGroupWarningLogged = false; boolean hasSAWPermission = false; if (upgradeForBubbles && uid != UNKNOWN_UID) { hasSAWPermission = mAppOps.noteOpNoThrow( OP_SYSTEM_ALERT_WINDOW, uid, name, null, "check-notif-bubble") == AppOpsManager.MODE_ALLOWED; } int bubblePref = hasSAWPermission ? BUBBLE_PREFERENCE_ALL : parser.getAttributeInt(null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE); int bubblePref = parser.getAttributeInt(null, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE); boolean bubbleLocked = (parser.getAttributeInt(null, ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS) & USER_LOCKED_BUBBLE) != 0; if (!bubbleLocked && upgradeForBubbles && uid != UNKNOWN_UID && mAppOps.noteOpNoThrow(OP_SYSTEM_ALERT_WINDOW, uid, name, null, "check-notif-bubble") == AppOpsManager.MODE_ALLOWED) { // User hasn't changed bubble pref & the app has SAW, so allow all bubbles. bubblePref = BUBBLE_PREFERENCE_ALL; } int appImportance = parser.getAttributeInt(null, ATT_IMPORTANCE, DEFAULT_IMPORTANCE); // when data is loaded from disk it's loaded as USER_ALL, but restored data that Loading Loading @@ -684,6 +691,7 @@ public class PreferencesHelper implements RankingConfig { public void writeXml(TypedXmlSerializer out, boolean forBackup, int userId) throws IOException { out.startTag(null, TAG_RANKING); out.attributeInt(null, ATT_VERSION, XML_VERSION); out.attributeInt(null, ATT_LAST_BUBBLES_VERSION_UPGRADE, Build.VERSION.SDK_INT); if (mHideSilentStatusBarIcons != DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS) { out.startTag(null, TAG_STATUS_ICONS); out.attributeBoolean(null, ATT_HIDE_SILENT, mHideSilentStatusBarIcons); Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +54 −5 Original line number Diff line number Diff line Loading @@ -1219,7 +1219,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, false, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"com.example.o\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" Loading Loading @@ -1303,7 +1304,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " Loading Loading @@ -1389,7 +1391,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " Loading Loading @@ -1440,7 +1443,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\">\n" String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" // Packages that exist solely in permissionhelper + "<package name=\"" + PKG_P + "\" importance=\"3\" />\n" + "<package name=\"" + PKG_O + "\" importance=\"0\" />\n" Loading Loading @@ -4474,7 +4478,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test public void testBubblePreference_upgradeWithSAWPermission() throws Exception { public void testBubblePreference_noLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); Loading @@ -4494,6 +4498,51 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); } @Test public void testBubblePreference_differentLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); final String xml = "<ranking version=\"4\" last_bubbles_version_upgrade=\"34\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n" + "<channel id=\"someId\" name=\"hi\"" + " importance=\"3\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertEquals(BUBBLE_PREFERENCE_ALL, mHelper.getBubblePreference(PKG_O, UID_O)); assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); } @Test public void testBubblePreference_sameLastVersionWithSAWPermission() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED); final String xml = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n" + "<channel id=\"someId\" name=\"hi\"" + " importance=\"3\"/>" + "</package>" + "</ranking>"; TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())), null); parser.nextTag(); mHelper.readXml(parser, false, UserHandle.USER_ALL); assertEquals(DEFAULT_BUBBLE_PREFERENCE, mHelper.getBubblePreference(PKG_O, UID_O)); assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O)); // Version was the same SAW check should not have happened verify(mAppOpsManager, never()).noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), anyString(), eq(null), anyString()); } @Test public void testBubblePreference_upgradeWithSAWThenUserOverride() throws Exception { when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(), Loading