Loading src/com/android/settings/localepicker/AppLocalePickerActivity.java +3 −2 Original line number Diff line number Diff line Loading @@ -158,13 +158,14 @@ public class AppLocalePickerActivity extends SettingsBaseActivity private void broadcastAppLocaleChange(LocaleStore.LocaleInfo localeInfo) { if (!localeNotificationEnabled()) { Log.w(TAG, "Locale notification is not enabled"); return; } String localeTag = localeInfo.getLocale().toLanguageTag(); if (LocaleUtils.isInSystemLocale(localeTag) || localeInfo.isAppCurrentLocale()) { if (localeInfo.isAppCurrentLocale()) { return; } try { String localeTag = localeInfo.getLocale().toLanguageTag(); int uid = getPackageManager().getApplicationInfo(mPackageName, PackageManager.GET_META_DATA).uid; boolean launchNotification = mNotificationController.shouldTriggerNotification( Loading src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java +2 −0 Original line number Diff line number Diff line Loading @@ -270,12 +270,14 @@ class LocaleDragAndDropAdapter void removeChecked() { int itemCount = mFeedItemList.size(); LocaleStore.LocaleInfo localeInfo; NotificationController controller = NotificationController.getInstance(mContext); for (int i = itemCount - 1; i >= 0; i--) { localeInfo = mFeedItemList.get(i); if (localeInfo.getChecked()) { FeatureFactory.getFeatureFactory().getMetricsFeatureProvider() .action(mContext, SettingsEnums.ACTION_REMOVE_LANGUAGE); mFeedItemList.remove(i); controller.removeNotificationInfo(localeInfo.getLocale().toLanguageTag()); } } notifyDataSetChanged(); Loading src/com/android/settings/localepicker/LocaleNotificationDataManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,17 @@ public class LocaleNotificationDataManager { editor.apply(); } /** * Removes one entry with the corresponding locale from the {@link SharedPreferences}. * * @param locale A locale which the application sets to */ public void removeNotificationInfo(String locale) { SharedPreferences.Editor editor = getSharedPreferences(mContext).edit(); editor.remove(locale); editor.apply(); } /** * Gets the {@link NotificationInfo} with the associated locale from the * {@link SharedPreferences}. Loading src/com/android/settings/localepicker/NotificationController.java +22 −13 Original line number Diff line number Diff line Loading @@ -110,6 +110,15 @@ public class NotificationController { return (info != null) ? info.getNotificationId() : -1; } /** * Remove the {@link NotificationInfo} with the corresponding locale * * @param locale The locale which the application sets to */ public void removeNotificationInfo(@NonNull String locale) { mDataManager.removeNotificationInfo(locale); } private boolean updateLocaleNotificationInfo(int uid, String locale) { NotificationInfo info = mDataManager.getNotificationInfo(locale); if (info == null) { Loading @@ -135,13 +144,12 @@ public class NotificationController { int notificationCount = info.getNotificationCount(); long lastNotificationTime = info.getLastNotificationTimeMs(); int notificationId = info.getNotificationId(); if (dismissCount < DISMISS_COUNT_THRESHOLD && notificationCount < NOTIFICATION_COUNT_THRESHOLD) { // Add the uid into the locale's uid list uidSet.add(uid); if (dismissCount < DISMISS_COUNT_THRESHOLD && notificationCount < NOTIFICATION_COUNT_THRESHOLD // Notification should fire on multiples of 2 apps using the locale. && uidSet.size() % MULTIPLE_BASE == 0 if (uidSet.size() % MULTIPLE_BASE == 0 && !isNotificationFrequent(lastNotificationTime)) { // Increment the count because the notification can be triggered. notificationCount = info.getNotificationCount() + 1; Loading @@ -151,6 +159,7 @@ public class NotificationController { notificationId = (int) SystemClock.uptimeMillis(); } } } return new NotificationInfo(uidSet, notificationCount, dismissCount, lastNotificationTime, notificationId); } Loading tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -369,7 +369,7 @@ public class AppLocalePickerActivityTest { // In the proto file, en-US's uid list contains 103, the notificationCount equals 1, and // LastNotificationTime > 0. NotificationInfo info = mDataManager.getNotificationInfo(EN_US); assertThat(info.getUidCollection().contains(sUid)).isTrue(); assertThat(info.getUidCollection()).contains(sUid); assertThat(info.getNotificationCount()).isEqualTo(1); assertThat(info.getDismissCount()).isEqualTo(0); assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0); Loading Loading @@ -440,7 +440,7 @@ public class AppLocalePickerActivityTest { @Test @RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED) public void testEvaluateLocaleNotification_localeUpdateReachThreshold_uidAddedNoNotification() public void testEvaluateLocaleNotification_localeUpdateReachThreshold_noUidNorNotification() throws Exception { // App with uid 106 changed its locale from System to en-US. sUid = 106; Loading @@ -460,7 +460,7 @@ public class AppLocalePickerActivityTest { // In the proto file, en-US's uid list contains 106, the notificationCount equals 2, and // LastNotificationTime > 0. NotificationInfo info = mDataManager.getNotificationInfo(EN_US); assertThat(info.getUidCollection()).contains(sUid); assertThat(info.getUidCollection().contains(sUid)).isFalse(); assertThat(info.getNotificationCount()).isEqualTo(2); assertThat(info.getDismissCount()).isEqualTo(0); assertThat(info.getLastNotificationTimeMs()).isEqualTo(lastNotificationTime); Loading Loading
src/com/android/settings/localepicker/AppLocalePickerActivity.java +3 −2 Original line number Diff line number Diff line Loading @@ -158,13 +158,14 @@ public class AppLocalePickerActivity extends SettingsBaseActivity private void broadcastAppLocaleChange(LocaleStore.LocaleInfo localeInfo) { if (!localeNotificationEnabled()) { Log.w(TAG, "Locale notification is not enabled"); return; } String localeTag = localeInfo.getLocale().toLanguageTag(); if (LocaleUtils.isInSystemLocale(localeTag) || localeInfo.isAppCurrentLocale()) { if (localeInfo.isAppCurrentLocale()) { return; } try { String localeTag = localeInfo.getLocale().toLanguageTag(); int uid = getPackageManager().getApplicationInfo(mPackageName, PackageManager.GET_META_DATA).uid; boolean launchNotification = mNotificationController.shouldTriggerNotification( Loading
src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java +2 −0 Original line number Diff line number Diff line Loading @@ -270,12 +270,14 @@ class LocaleDragAndDropAdapter void removeChecked() { int itemCount = mFeedItemList.size(); LocaleStore.LocaleInfo localeInfo; NotificationController controller = NotificationController.getInstance(mContext); for (int i = itemCount - 1; i >= 0; i--) { localeInfo = mFeedItemList.get(i); if (localeInfo.getChecked()) { FeatureFactory.getFeatureFactory().getMetricsFeatureProvider() .action(mContext, SettingsEnums.ACTION_REMOVE_LANGUAGE); mFeedItemList.remove(i); controller.removeNotificationInfo(localeInfo.getLocale().toLanguageTag()); } } notifyDataSetChanged(); Loading
src/com/android/settings/localepicker/LocaleNotificationDataManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,17 @@ public class LocaleNotificationDataManager { editor.apply(); } /** * Removes one entry with the corresponding locale from the {@link SharedPreferences}. * * @param locale A locale which the application sets to */ public void removeNotificationInfo(String locale) { SharedPreferences.Editor editor = getSharedPreferences(mContext).edit(); editor.remove(locale); editor.apply(); } /** * Gets the {@link NotificationInfo} with the associated locale from the * {@link SharedPreferences}. Loading
src/com/android/settings/localepicker/NotificationController.java +22 −13 Original line number Diff line number Diff line Loading @@ -110,6 +110,15 @@ public class NotificationController { return (info != null) ? info.getNotificationId() : -1; } /** * Remove the {@link NotificationInfo} with the corresponding locale * * @param locale The locale which the application sets to */ public void removeNotificationInfo(@NonNull String locale) { mDataManager.removeNotificationInfo(locale); } private boolean updateLocaleNotificationInfo(int uid, String locale) { NotificationInfo info = mDataManager.getNotificationInfo(locale); if (info == null) { Loading @@ -135,13 +144,12 @@ public class NotificationController { int notificationCount = info.getNotificationCount(); long lastNotificationTime = info.getLastNotificationTimeMs(); int notificationId = info.getNotificationId(); if (dismissCount < DISMISS_COUNT_THRESHOLD && notificationCount < NOTIFICATION_COUNT_THRESHOLD) { // Add the uid into the locale's uid list uidSet.add(uid); if (dismissCount < DISMISS_COUNT_THRESHOLD && notificationCount < NOTIFICATION_COUNT_THRESHOLD // Notification should fire on multiples of 2 apps using the locale. && uidSet.size() % MULTIPLE_BASE == 0 if (uidSet.size() % MULTIPLE_BASE == 0 && !isNotificationFrequent(lastNotificationTime)) { // Increment the count because the notification can be triggered. notificationCount = info.getNotificationCount() + 1; Loading @@ -151,6 +159,7 @@ public class NotificationController { notificationId = (int) SystemClock.uptimeMillis(); } } } return new NotificationInfo(uidSet, notificationCount, dismissCount, lastNotificationTime, notificationId); } Loading
tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -369,7 +369,7 @@ public class AppLocalePickerActivityTest { // In the proto file, en-US's uid list contains 103, the notificationCount equals 1, and // LastNotificationTime > 0. NotificationInfo info = mDataManager.getNotificationInfo(EN_US); assertThat(info.getUidCollection().contains(sUid)).isTrue(); assertThat(info.getUidCollection()).contains(sUid); assertThat(info.getNotificationCount()).isEqualTo(1); assertThat(info.getDismissCount()).isEqualTo(0); assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0); Loading Loading @@ -440,7 +440,7 @@ public class AppLocalePickerActivityTest { @Test @RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED) public void testEvaluateLocaleNotification_localeUpdateReachThreshold_uidAddedNoNotification() public void testEvaluateLocaleNotification_localeUpdateReachThreshold_noUidNorNotification() throws Exception { // App with uid 106 changed its locale from System to en-US. sUid = 106; Loading @@ -460,7 +460,7 @@ public class AppLocalePickerActivityTest { // In the proto file, en-US's uid list contains 106, the notificationCount equals 2, and // LastNotificationTime > 0. NotificationInfo info = mDataManager.getNotificationInfo(EN_US); assertThat(info.getUidCollection()).contains(sUid); assertThat(info.getUidCollection().contains(sUid)).isFalse(); assertThat(info.getNotificationCount()).isEqualTo(2); assertThat(info.getDismissCount()).isEqualTo(0); assertThat(info.getLastNotificationTimeMs()).isEqualTo(lastNotificationTime); Loading