Merge "Add feature flag for LocaleNotification" into main
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.localepicker;
|
||||
|
||||
import static com.android.settings.flags.Flags.localeNotificationEnabled;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.app.LocaleManager;
|
||||
import android.app.NotificationChannel;
|
||||
@@ -27,7 +29,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -53,10 +54,8 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||
private static final String CHANNEL_ID_SUGGESTION_TO_USER = "Locale suggestion";
|
||||
private static final String EXTRA_SYSTEM_LOCALE_DIALOG_TYPE = "system_locale_dialog_type";
|
||||
private static final String LOCALE_SUGGESTION = "locale_suggestion";
|
||||
static final boolean ENABLED = false;
|
||||
static final String EXTRA_APP_LOCALE = "app_locale";
|
||||
static final String EXTRA_NOTIFICATION_ID = "notification_id";
|
||||
static final String PROP_SYSTEM_LOCALE_SUGGESTION = "android.system.locale.suggestion";
|
||||
|
||||
private String mPackageName;
|
||||
private LocalePickerWithRegion mLocalePickerWithRegion;
|
||||
@@ -151,7 +150,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||
}
|
||||
|
||||
private void broadcastAppLocaleChange(LocaleStore.LocaleInfo localeInfo) {
|
||||
if (!SystemProperties.getBoolean(PROP_SYSTEM_LOCALE_SUGGESTION, ENABLED)) {
|
||||
if (!localeNotificationEnabled()) {
|
||||
return;
|
||||
}
|
||||
String localeTag = localeInfo.getLocale().toLanguageTag();
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.localepicker;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_LOCALE;
|
||||
|
||||
import static com.android.settings.flags.Flags.localeNotificationEnabled;
|
||||
import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_APP_LOCALE;
|
||||
import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_NOTIFICATION_ID;
|
||||
import static com.android.settings.localepicker.LocaleDialogFragment.DIALOG_ADD_SYSTEM_LOCALE;
|
||||
@@ -31,7 +32,6 @@ import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -283,7 +283,7 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
String dialogType = intent.getStringExtra(EXTRA_SYSTEM_LOCALE_DIALOG_TYPE);
|
||||
String localeTag = intent.getStringExtra(EXTRA_APP_LOCALE);
|
||||
int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, INVALID_NOTIFICATION_ID);
|
||||
if (!isDialogFeatureEnabled()
|
||||
if (!localeNotificationEnabled()
|
||||
|| !isValidNotificationId(localeTag, notificationId)
|
||||
|| !isValidDialogType(dialogType)
|
||||
|| !isValidLocale(localeTag)
|
||||
@@ -293,11 +293,6 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isDialogFeatureEnabled() {
|
||||
return SystemProperties.getBoolean(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION,
|
||||
AppLocalePickerActivity.ENABLED);
|
||||
}
|
||||
|
||||
private boolean isValidNotificationId(String localeTag, long id) {
|
||||
if (id == -1) {
|
||||
return false;
|
||||
|
@@ -39,8 +39,10 @@ import android.net.Uri;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.ArrayRes;
|
||||
@@ -48,6 +50,7 @@ import androidx.annotation.ArrayRes;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.applications.AppLocaleUtil;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -98,6 +101,9 @@ public class AppLocalePickerActivityTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule rule = MockitoJUnit.rule();
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule =
|
||||
DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
private ShadowPackageManager mPackageManager;
|
||||
@@ -223,6 +229,7 @@ public class AppLocalePickerActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void onLocaleSelected_evaluateNotification_simpleLocaleUpdate_localeCreatedWithUid()
|
||||
throws Exception {
|
||||
sUid = 100;
|
||||
@@ -244,11 +251,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isEqualTo(0);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void onLocaleSelected_evaluateNotification_twoLocaleUpdate_triggerNotification()
|
||||
throws Exception {
|
||||
// App with uid 101 changed its locale from System to en-US.
|
||||
@@ -269,11 +276,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void onLocaleSelected_evaluateNotification_oddLocaleUpdate_uidAddedWithoutNotification()
|
||||
throws Exception {
|
||||
// App with uid 102 changed its locale from System to en-US.
|
||||
@@ -298,11 +305,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0);
|
||||
assertThat(info.getNotificationId()).isEqualTo(notificationId);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void onLocaleSelected_evaluateNotification_frequentLocaleUpdate_uidAddedNoNotification()
|
||||
throws Exception {
|
||||
// App with uid 103 changed its locale from System to en-US.
|
||||
@@ -327,11 +334,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0);
|
||||
assertThat(info.getNotificationId()).isEqualTo(notificationId);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void onLocaleSelected_evaluateNotification_2ndOddLocaleUpdate_uidAddedNoNotification()
|
||||
throws Exception {
|
||||
// App with uid 104 changed its locale from System to en-US.
|
||||
@@ -356,11 +363,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isNotEqualTo(0);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void testEvaluateLocaleNotification_evenLocaleUpdate_trigger2ndNotification()
|
||||
throws Exception {
|
||||
sUid = 105;
|
||||
@@ -387,11 +394,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isGreaterThan(lastNotificationTime);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void testEvaluateLocaleNotification_localeUpdateReachThreshold_uidAddedNoNotification()
|
||||
throws Exception {
|
||||
// App with uid 106 changed its locale from System to en-US.
|
||||
@@ -417,11 +424,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isEqualTo(lastNotificationTime);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void testEvaluateLocaleNotification_appChangedLocales_newLocaleCreated()
|
||||
throws Exception {
|
||||
sUid = 100;
|
||||
@@ -448,13 +455,11 @@ public class AppLocalePickerActivityTest {
|
||||
assertThat(info.getDismissCount()).isEqualTo(0);
|
||||
assertThat(info.getLastNotificationTimeMs()).isEqualTo(0);
|
||||
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "false");
|
||||
mDataManager.clearLocaleNotificationMap();
|
||||
}
|
||||
|
||||
private void initLocaleNotificationEnvironment() throws Exception {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags(EN_CA));
|
||||
SystemProperties.set(AppLocalePickerActivity.PROP_SYSTEM_LOCALE_SUGGESTION, "true");
|
||||
|
||||
Locale locale = Locale.forLanguageTag("en-US");
|
||||
when(mLocaleInfo.getLocale()).thenReturn(locale);
|
||||
|
@@ -40,6 +40,9 @@ import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -56,6 +59,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowActivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
@@ -63,6 +67,7 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -136,6 +141,10 @@ public class LocaleListEditorTest {
|
||||
@Mock
|
||||
private NotificationController mNotificationController;
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule =
|
||||
DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -346,6 +355,7 @@ public class LocaleListEditorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_showConfirmDialog() {
|
||||
initIntentAndResourceForLocaleDialog();
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
@@ -355,6 +365,7 @@ public class LocaleListEditorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_clickAdd() {
|
||||
initIntentAndResourceForLocaleDialog();
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
@@ -363,12 +374,14 @@ public class LocaleListEditorTest {
|
||||
bundle.putInt(ARG_DIALOG_TYPE, DIALOG_ADD_SYSTEM_LOCALE);
|
||||
bundle.putSerializable(LocaleDialogFragment.ARG_TARGET_LOCALE, info);
|
||||
Intent intent = new Intent().putExtras(bundle);
|
||||
|
||||
mLocaleListEditor.onActivityResult(DIALOG_ADD_SYSTEM_LOCALE, Activity.RESULT_OK, intent);
|
||||
|
||||
verify(mAdapter).addLocale(any(LocaleStore.LocaleInfo.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_clickCancel() {
|
||||
initIntentAndResourceForLocaleDialog();
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
@@ -377,6 +390,7 @@ public class LocaleListEditorTest {
|
||||
bundle.putInt(ARG_DIALOG_TYPE, DIALOG_ADD_SYSTEM_LOCALE);
|
||||
bundle.putSerializable(LocaleDialogFragment.ARG_TARGET_LOCALE, info);
|
||||
Intent intent = new Intent().putExtras(bundle);
|
||||
|
||||
mLocaleListEditor.onActivityResult(DIALOG_ADD_SYSTEM_LOCALE, Activity.RESULT_CANCELED,
|
||||
intent);
|
||||
|
||||
@@ -384,6 +398,7 @@ public class LocaleListEditorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_invalidLocale_noDialog() {
|
||||
Intent intent = new Intent("ACTION")
|
||||
.putExtra(EXTRA_APP_LOCALE, "ab-CD") // invalid locale
|
||||
@@ -392,11 +407,12 @@ public class LocaleListEditorTest {
|
||||
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
verify(mFragmentTransaction, never()).add(any(LocaleDialogFragment.class),
|
||||
eq(TAG_DIALOG_ADD_SYSTEM_LOCALE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_noDialogType_noDialog() {
|
||||
Intent intent = new Intent("ACTION")
|
||||
.putExtra(EXTRA_APP_LOCALE, "ja-JP");
|
||||
@@ -405,11 +421,12 @@ public class LocaleListEditorTest {
|
||||
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
verify(mFragmentTransaction, never()).add(any(LocaleDialogFragment.class),
|
||||
eq(TAG_DIALOG_ADD_SYSTEM_LOCALE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_LOCALE_NOTIFICATION_ENABLED)
|
||||
public void showDiallogForAddedLocale_inSystemLocale_noDialog() {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,ar-AE-u-nu-arab"));
|
||||
Intent intent = new Intent("ACTION")
|
||||
@@ -419,8 +436,8 @@ public class LocaleListEditorTest {
|
||||
|
||||
mLocaleListEditor.onViewStateRestored(null);
|
||||
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNull();
|
||||
verify(mFragmentTransaction, never()).add(any(LocaleDialogFragment.class),
|
||||
eq(TAG_DIALOG_ADD_SYSTEM_LOCALE));
|
||||
}
|
||||
|
||||
private void initIntentAndResourceForLocaleDialog() {
|
||||
|
Reference in New Issue
Block a user