diff options
author | Xin Li <delphij@google.com> | 2021-11-10 08:05:55 +0000 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2021-11-10 08:05:55 +0000 |
commit | 3576c0edb5ce03b34992cd70f71e126f7afeb849 (patch) | |
tree | b40c3110b0c59de3ec54fb73be8de1bb88fe98bb | |
parent | 24adc4306225a052a74d7e424dcf467bcf437e54 (diff) | |
parent | db4612ed18336378735a849584d5cb221a95b001 (diff) | |
download | CellBroadcastReceiver-3576c0edb5ce03b34992cd70f71e126f7afeb849.tar.gz |
Merge sc-qpr1-dev-plus-aosp-without-vendor@7810918temp_sam_210511427temp-sc-sam
Bug: 205056467
Merged-In: I8c48ea817f34d5342ec27d09c25c183e3a011f7a
Change-Id: I3b51ca2fcf6e9960ecbc2f991eef2d4ad2641406
5 files changed, 36 insertions, 57 deletions
diff --git a/res/values-v31/strings.xml b/res/values-v31/strings.xml new file mode 100644 index 000000000..e9c33eb5f --- /dev/null +++ b/res/values-v31/strings.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2021 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <!-- Name of a font family to use for headlines in SettingsLib. This overrides the default value which points to a private resource. Setting it to an empty value allows it to fallback to the default on the device. --> + <string name="settingslib_config_headlineFontFamily" translatable="false"></string> +</resources> diff --git a/res/xml/watch_preferences.xml b/res/xml/watch_preferences.xml index 7296caeb3..6c8e4abb5 100644 --- a/res/xml/watch_preferences.xml +++ b/res/xml/watch_preferences.xml @@ -60,9 +60,6 @@ android:defaultValue="@string/alert_reminder_interval_in_min_default" android:dialogTitle="@string/alert_reminder_interval_title" /> - <SwitchPreference android:key="watch_alert_reminder" - android:title="@string/alert_reminder_interval_title" /> - <SwitchPreference android:defaultValue="true" android:key="enable_alert_vibrate" android:title="@string/enable_alert_vibrate_title" /> diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index c8eb50057..7b15c2da3 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -45,7 +45,6 @@ import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceManager; -import androidx.preference.PreferenceScreen; import androidx.preference.TwoStatePreference; import com.android.internal.annotations.VisibleForTesting; @@ -149,9 +148,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { // Preference key for emergency alerts history public static final String KEY_EMERGENCY_ALERT_HISTORY = "emergency_alert_history"; - // For watch layout - private static final String KEY_WATCH_ALERT_REMINDER = "watch_alert_reminder"; - // Whether to receive alert in second language code public static final String KEY_RECEIVE_CMAS_IN_SECOND_LANGUAGE = "receive_cmas_in_second_language"; @@ -177,9 +173,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { // Key for shared preference which represents whether user has changed any preference private static final String ANY_PREFERENCE_CHANGED_BY_USER = "any_preference_changed_by_user"; - // Test override for disabling the subId specific resources - private static boolean sUseResourcesForSubId = true; - @Override public void onCreate(Bundle savedInstanceState) { // for backward compatibility on R devices @@ -264,12 +257,9 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { Log.d(TAG, "In not test harness mode. reset main toggle."); e.remove(KEY_ENABLE_ALERTS_MASTER_TOGGLE); } - PackageManager pm = c.getPackageManager(); - if (pm.hasSystemFeature(PackageManager.FEATURE_WATCH)) { - e.remove(KEY_WATCH_ALERT_REMINDER); - } e.commit(); + PackageManager pm = c.getPackageManager(); if (pm.hasSystemFeature(PackageManager.FEATURE_WATCH)) { PreferenceManager.setDefaultValues(c, R.xml.watch_preferences, true); } else { @@ -320,9 +310,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { private PreferenceCategory mAlertPreferencesCategory; private boolean mDisableSevereWhenExtremeDisabled = true; - // WATCH - private TwoStatePreference mAlertReminder; - // Show checkbox for Presidential alerts in settings private TwoStatePreference mPresidentialCheckBox; @@ -381,27 +368,7 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { findPreference(KEY_ENABLE_CMAS_PRESIDENTIAL_ALERTS); PackageManager pm = getActivity().getPackageManager(); - if (pm.hasSystemFeature(PackageManager.FEATURE_WATCH)) { - mAlertReminder = (TwoStatePreference) - findPreference(KEY_WATCH_ALERT_REMINDER); - if (Integer.valueOf(mReminderInterval.getValue()) == 0) { - mAlertReminder.setChecked(false); - } else { - mAlertReminder.setChecked(true); - } - mAlertReminder.setOnPreferenceChangeListener((p, newVal) -> { - try { - mReminderInterval.setValueIndex((Boolean) newVal ? 1 : 3); - } catch (IndexOutOfBoundsException e) { - mReminderInterval.setValue(String.valueOf(0)); - Log.w(TAG, "Setting default value"); - } - return true; - }); - PreferenceScreen watchScreen = (PreferenceScreen) - findPreference(KEY_CATEGORY_ALERT_PREFERENCES); - watchScreen.removePreference(mReminderInterval); - } else { + if (!pm.hasSystemFeature(PackageManager.FEATURE_WATCH)) { mAlertPreferencesCategory = (PreferenceCategory) findPreference(KEY_CATEGORY_ALERT_PREFERENCES); mAlertCategory = (PreferenceCategory) @@ -845,16 +812,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { } /** - * Override used by tests so that we don't call - * SubscriptionManager.getResourcesForSubId, which is a static unmockable - * method. - */ - @VisibleForTesting - public static void setUseResourcesForSubId(boolean useResourcesForSubId) { - sUseResourcesForSubId = useResourcesForSubId; - } - - /** * Get the device resource based on SIM * * @param context Context @@ -863,14 +820,12 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { * @return The resource */ public static @NonNull Resources getResources(@NonNull Context context, int subId) { - // based on the latest design, subId can be valid earlier than mcc mnc is known to telephony - // check if sim is loaded to avoid caching the wrong resources. - TelephonyManager tm = context.getSystemService(TelephonyManager.class); - boolean isSimLoaded = tm.getSimApplicationState(SubscriptionManager.getSlotIndex(subId)) - == TelephonyManager.SIM_STATE_LOADED; if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID - || !SubscriptionManager.isValidSubscriptionId(subId) || !sUseResourcesForSubId - || !isSimLoaded) { + || !SubscriptionManager.isValidSubscriptionId(subId) + // based on the latest design, subId can be valid earlier than mcc mnc is known to + // telephony. check if sim is loaded to avoid caching the wrong resources. + || context.getSystemService(TelephonyManager.class).getSimApplicationState( + SubscriptionManager.getSlotIndex(subId)) != TelephonyManager.SIM_STATE_LOADED) { return context.getResources(); } diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java index a30c9c41d..9168d5bf7 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java @@ -35,6 +35,7 @@ import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.telephony.SmsCbMessage; +import android.telephony.TelephonyManager; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; @@ -68,6 +69,9 @@ public class CellBroadcastAlertDialogTest extends @Mock private IThermalService.Stub mMockedThermalService; + @Mock + TelephonyManager mTelephonyManager; + @Captor private ArgumentCaptor<Integer> mInt; @@ -111,7 +115,9 @@ public class CellBroadcastAlertDialogTest extends mPowerManager = new PowerManager(mContext, mMockedPowerManagerService, mMockedThermalService, null); injectSystemService(PowerManager.class, mPowerManager); - CellBroadcastSettings.setUseResourcesForSubId(false); + doReturn(TelephonyManager.SIM_STATE_UNKNOWN).when(mTelephonyManager) + .getSimApplicationState(anyInt()); + injectSystemService(TelephonyManager.class, mTelephonyManager); } @After diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java index 7609829c0..66ae7b10f 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java @@ -165,13 +165,14 @@ public abstract class CellBroadcastServiceTestCase<T extends Service> extends Se doReturn(mMockedTelephonyManager).when(mMockedTelephonyManager) .createForSubscriptionId(anyInt()); + doReturn(TelephonyManager.SIM_STATE_UNKNOWN).when(mMockedTelephonyManager) + .getSimApplicationState(anyInt()); mMockedServiceManager = new MockedServiceManager(); mMockedServiceManager.replaceService("isub", mSubService); mContext = new TestContextWrapper(getContext()); setContext(mContext); - CellBroadcastSettings.setUseResourcesForSubId(false); } @After |