Add feature flag for LocaleNotification
Bug: 248514263 Test: atest AppLocalePickerActivityTest LocaleListEditorTest Change-Id: I0e2160d75bbac83a161c73c90624b0e7af5b0a8e
This commit is contained in:
@@ -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