Merge "Make work challenge pattern resizeable." into qt-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f4ff282..fc3888b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -102,8 +102,6 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
- <protected-broadcast android:name="com.android.settings.DELETE_SIM_PROFILE_RESULT"/>
-
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
android:theme="@style/Theme.Settings"
diff --git a/res/layout/master_clear.xml b/res/layout/master_clear.xml
index bf22b88..04c8f8d 100644
--- a/res/layout/master_clear.xml
+++ b/res/layout/master_clear.xml
@@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:theme="@style/SudThemeGlifV3.DayNight"
+ android:theme="@style/GlifV3Theme.Footer"
android:icon="@drawable/ic_delete_accent"
app:sucHeaderText="@string/master_clear_title">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 171fe42..250078e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7335,7 +7335,7 @@
<string name="keywords_assist_gesture_launch">gesture</string>
<string name="keywords_face_unlock">face, unlock, auth, sign in</string>
<string name="keywords_imei_info">imei, meid, min, prl version, imei sv</string>
- <string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid</string>
+ <string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid, eid</string>
<string name="keywords_model_and_hardware">serial number, hardware version</string>
<string name="keywords_android_version">android security patch level, baseband version, kernel version</string>
<!-- Search keywords for dark mode settings [CHAR LIMIT=NONE] -->
@@ -7889,8 +7889,8 @@
<!-- Configure Notifications: section header for prioritizer settings [CHAR LIMIT=80] -->
<string name="smart_notifications_title">Adaptive notifications</string>
- <!-- Configure Notifications: setting title [CHAR LIMIT=80] -->
- <string name="asst_capability_prioritizer_title">Automatic Prioritization</string>
+ <!-- Configure Notifications: setting title [CHAR LIMIT=80 BACKUP_MESSAGE_ID=6691908606916292167] -->
+ <string name="asst_capability_prioritizer_title">Adaptive notification priority</string>
<!-- Configure Notifications: setting summary [CHAR LIMIT=200] -->
<string name="asst_capability_prioritizer_summary">Automatically set lower priority notifications to Gentle</string>
@@ -7901,6 +7901,9 @@
<!-- Configure Notifications: setting summary [CHAR LIMIT=200] -->
<string name="asst_capabilities_actions_replies_summary">Automatically show suggested actions & replies</string>
+ <!-- Configure Notifications: setting title, whether the snooze menu is shown on notifications [CHAR LIMIT=80] -->
+ <string name="snooze_options_title">Allow notification snoozing</string>
+
<!-- Configure Notifications: setting title [CHAR LIMIT=80] -->
<string name="hide_silent_icons_title">Hide icons from gentle notifications</string>
@@ -8101,7 +8104,7 @@
<string name="notification_silence_title">Silent</string>
<!-- [CHAR LIMIT=100] Notification Importance title -->
- <string name="notification_alert_title">Prioritized</string>
+ <string name="notification_alert_title">Alerting</string>
<!-- [CHAR LIMIT=40] Notification importance title. This setting controls how notifications in older apps may alert the user (eg, sound, visual, vibrate). -->
<string name="allow_interruption">Allow interruptions</string>
@@ -10197,6 +10200,15 @@
<!-- Search keywords for System Navigation settings. [CHAR_LIMIT=NONE]-->
<string name="keywords_system_navigation">system navigation, 2 button navigation, 3 button navigation, gesture navigation</string>
+ <!-- Message for the alert dialog which says that the current default home app does not support gesture navigation. [CHAR LIMIT=NONE] -->
+ <string name="gesture_not_supported_dialog_message">Not supported by your default home app, <xliff:g id="default_home_app" example="Pixel Launcher">%s</xliff:g></string>
+
+ <!-- Positive button for the alert dialog when gesture nav not supported by launcher [CHAR LIMIT=40] -->
+ <string name="gesture_not_supported_positive_button">Switch default home app</string>
+
+ <!-- Content description for the Information icon [CHAR LIMIT=30] -->
+ <string name="information_label">Information</string>
+
<!-- Preference and settings suggestion title text for ambient display double tap (phone) [CHAR LIMIT=60]-->
<string name="ambient_display_title" product="default">Double-tap to check phone</string>
<!-- Preference and settings suggestion title text for ambient display double tap (tablet) [CHAR LIMIT=60]-->
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 8316971..3eda345 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -126,6 +126,8 @@
<style name="Theme.AlertDialog" parent="Theme.AlertDialog.Base">
<item name="android:windowSoftInputMode">adjustResize</item>
+ <item name="android:clipToPadding">true</item>
+ <item name="android:clipChildren">true</item>
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
diff --git a/res/values/themes_suw.xml b/res/values/themes_suw.xml
index add2fed..f7f1d16 100644
--- a/res/values/themes_suw.xml
+++ b/res/values/themes_suw.xml
@@ -112,6 +112,11 @@
<item name="*android:lockPatternStyle">@style/LockPatternStyle.Setup</item>
</style>
+ <style name="GlifV3Theme.Footer" parent="@style/SudThemeGlifV3.DayNight">
+ <item name="android:clipChildren">true</item>
+ <item name="android:clipToPadding">true</item>
+ </style>
+
<style name="GlifV3Theme.Light" parent="SudThemeGlifV3.Light">
<!-- For all AndroidX Alert Dialogs -->
<item name="alertDialogTheme">@style/GlifV2ThemeAlertDialog.Light</item>
@@ -209,4 +214,4 @@
<item name="colorAccent">@*android:color/accent_device_default_light</item>
<item name="dialogCornerRadius">@*android:dimen/config_dialogCornerRadius</item>
</style>
-</resources>
\ No newline at end of file
+</resources>
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index 224a910..63f6751 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -80,6 +80,11 @@
settings:initialExpandedChildrenCount="0">
<SwitchPreference
+ android:key="show_snooze_options"
+ android:title="@string/snooze_options_title"
+ settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
+
+ <SwitchPreference
android:key="asst_capabilities_actions_replies"
android:title="@string/asst_capabilities_actions_replies_title"
android:summary="@string/asst_capabilities_actions_replies_summary"
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index c537f3f..25982fe8 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -248,6 +248,11 @@
android:summary="@string/wifi_verbose_logging_summary" />
<SwitchPreference
+ android:key="wifi_scan_throttling"
+ android:title="@string/wifi_scan_throttling"
+ android:summary="@string/wifi_scan_throttling_summary" />
+
+ <SwitchPreference
android:key="mobile_data_always_on"
android:title="@string/mobile_data_always_on"
android:summary="@string/mobile_data_always_on_summary" />
@@ -522,6 +527,11 @@
android:title="@string/show_notification_channel_warnings"
android:summary="@string/show_notification_channel_warnings_summary" />
+ <SwitchPreference
+ android:key="asst_capability_prioritizer"
+ android:title="@string/asst_capability_prioritizer_title"
+ settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
+
<Preference
android:key="inactive_apps"
android:title="@string/inactive_apps_title"
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 9dcc222..bca5ded 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -432,6 +432,7 @@
controllers.add(new CameraLaserSensorPreferenceController(context));
controllers.add(new WifiDisplayCertificationPreferenceController(context));
controllers.add(new WifiVerboseLoggingPreferenceController(context));
+ controllers.add(new WifiScanThrottlingPreferenceController(context));
controllers.add(new MobileDataAlwaysOnPreferenceController(context));
controllers.add(new TetheringHardwareAccelPreferenceController(context));
controllers.add(new BluetoothDeviceNoNamePreferenceController(context));
diff --git a/src/com/android/settings/development/WifiScanThrottlingPreferenceController.java b/src/com/android/settings/development/WifiScanThrottlingPreferenceController.java
new file mode 100644
index 0000000..a069827
--- /dev/null
+++ b/src/com/android/settings/development/WifiScanThrottlingPreferenceController.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class WifiScanThrottlingPreferenceController extends DeveloperOptionsPreferenceController
+ implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+ private static final String WIFI_SCAN_THROTTLING_KEY = "wifi_scan_throttling";
+ @VisibleForTesting
+ static final int SETTING_THROTTLING_ENABLE_VALUE_ON = 1; // default is throttling enabled.
+ @VisibleForTesting
+ static final int SETTING_THROTTLING_ENABLE_VALUE_OFF = 0;
+
+ public WifiScanThrottlingPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return WIFI_SCAN_THROTTLING_KEY;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isEnabled = (Boolean) newValue;
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
+ isEnabled
+ ? SETTING_THROTTLING_ENABLE_VALUE_ON
+ : SETTING_THROTTLING_ENABLE_VALUE_OFF);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int scanThrottleEnabled = Settings.Global.getInt(
+ mContext.getContentResolver(), Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
+ SETTING_THROTTLING_ENABLE_VALUE_ON);
+ ((SwitchPreference) mPreference).setChecked(
+ scanThrottleEnabled == SETTING_THROTTLING_ENABLE_VALUE_ON);
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchDisabled() {
+ super.onDeveloperOptionsSwitchDisabled();
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, SETTING_THROTTLING_ENABLE_VALUE_ON);
+ ((SwitchPreference) mPreference).setChecked(true);
+ }
+}
diff --git a/src/com/android/settings/network/MobileNetworkListFragment.java b/src/com/android/settings/network/MobileNetworkListFragment.java
index c90827e..4690a28 100644
--- a/src/com/android/settings/network/MobileNetworkListFragment.java
+++ b/src/com/android/settings/network/MobileNetworkListFragment.java
@@ -18,6 +18,7 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.os.UserManager;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
@@ -66,5 +67,10 @@
result.add(sir);
return result;
}
+
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return context.getSystemService(UserManager.class).isAdminUser();
+ }
};
}
diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java
index ae31b56..e9cdb46 100644
--- a/src/com/android/settings/network/SubscriptionsPreferenceController.java
+++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java
@@ -19,16 +19,22 @@
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
+import static com.android.settings.network.telephony.MobileNetworkUtils.NO_CELL_DATA_TYPE_ICON;
+
import android.content.Context;
import android.content.Intent;
+import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.provider.Settings;
+import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.util.ArraySet;
+import androidx.annotation.VisibleForTesting;
import androidx.collection.ArrayMap;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
@@ -40,9 +46,14 @@
import com.android.settings.R;
import com.android.settings.network.telephony.DataConnectivityListener;
import com.android.settings.network.telephony.MobileNetworkActivity;
+import com.android.settings.network.telephony.MobileNetworkUtils;
+import com.android.settings.network.telephony.SignalStrengthListener;
import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.net.SignalStrengthUtil;
+import java.util.Collections;
import java.util.Map;
+import java.util.Set;
/**
* This manages a set of Preferences it places into a PreferenceGroup owned by some parent
@@ -51,7 +62,8 @@
*/
public class SubscriptionsPreferenceController extends AbstractPreferenceController implements
LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient,
- MobileDataEnabledListener.Client, DataConnectivityListener.Client {
+ MobileDataEnabledListener.Client, DataConnectivityListener.Client,
+ SignalStrengthListener.Callback {
private static final String TAG = "SubscriptionsPrefCntrlr";
private UpdateListener mUpdateListener;
@@ -62,6 +74,8 @@
private SubscriptionsChangeListener mSubscriptionsListener;
private MobileDataEnabledListener mDataEnabledListener;
private DataConnectivityListener mConnectivityListener;
+ private SignalStrengthListener mSignalStrengthListener;
+
// Map of subscription id to Preference
private Map<Integer, Preference> mSubscriptionPreferences;
@@ -102,6 +116,7 @@
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
mDataEnabledListener = new MobileDataEnabledListener(context, this);
mConnectivityListener = new DataConnectivityListener(context, this);
+ mSignalStrengthListener = new SignalStrengthListener(context, this);
lifecycle.addObserver(this);
}
@@ -110,6 +125,7 @@
mSubscriptionsListener.start();
mDataEnabledListener.start(SubscriptionManager.getDefaultDataSubscriptionId());
mConnectivityListener.start();
+ mSignalStrengthListener.resume();
update();
}
@@ -118,6 +134,7 @@
mSubscriptionsListener.stop();
mDataEnabledListener.stop();
mConnectivityListener.stop();
+ mSignalStrengthListener.pause();
}
@Override
@@ -136,6 +153,7 @@
mPreferenceGroup.removePreference(pref);
}
mSubscriptionPreferences.clear();
+ mSignalStrengthListener.updateSubscriptionIds(Collections.emptySet());
mUpdateListener.onChildrenUpdated();
return;
}
@@ -144,16 +162,20 @@
mSubscriptionPreferences = new ArrayMap<>();
int order = mStartOrder;
+ final Set<Integer> activeSubIds = new ArraySet<>();
+ final int dataDefaultSubId = SubscriptionManager.getDefaultDataSubscriptionId();
for (SubscriptionInfo info : SubscriptionUtil.getActiveSubscriptions(mManager)) {
final int subId = info.getSubscriptionId();
+ activeSubIds.add(subId);
Preference pref = existingPrefs.remove(subId);
if (pref == null) {
pref = new Preference(mPreferenceGroup.getContext());
mPreferenceGroup.addPreference(pref);
}
pref.setTitle(info.getDisplayName());
- pref.setSummary(getSummary(subId));
- pref.setIcon(R.drawable.ic_network_cell);
+ final boolean isDefaultForData = (subId == dataDefaultSubId);
+ pref.setSummary(getSummary(subId, isDefaultForData));
+ setIcon(pref, subId, isDefaultForData);
pref.setOrder(order++);
pref.setOnPreferenceClickListener(clickedPref -> {
@@ -165,6 +187,7 @@
mSubscriptionPreferences.put(subId, pref);
}
+ mSignalStrengthListener.updateSubscriptionIds(activeSubIds);
// Remove any old preferences that no longer map to a subscription.
for (Preference pref : existingPrefs.values()) {
@@ -173,6 +196,32 @@
mUpdateListener.onChildrenUpdated();
}
+ @VisibleForTesting
+ boolean shouldInflateSignalStrength(int subId) {
+ return SignalStrengthUtil.shouldInflateSignalStrength(mContext, subId);
+ }
+
+ @VisibleForTesting
+ void setIcon(Preference pref, int subId, boolean isDefaultForData) {
+ final TelephonyManager mgr = mContext.getSystemService(
+ TelephonyManager.class).createForSubscriptionId(subId);
+ final SignalStrength strength = mgr.getSignalStrength();
+ int level = (strength == null) ? 0 : strength.getLevel();
+ int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
+ if (shouldInflateSignalStrength(subId)) {
+ level += 1;
+ numLevels += 1;
+ }
+ final boolean showCutOut = !isDefaultForData || !mgr.isDataEnabled();
+ pref.setIcon(getIcon(level, numLevels, showCutOut));
+ }
+
+ @VisibleForTesting
+ Drawable getIcon(int level, int numLevels, boolean cutOut) {
+ return MobileNetworkUtils.getSignalStrengthIcon(mContext, level, numLevels,
+ NO_CELL_DATA_TYPE_ICON, cutOut);
+ }
+
private boolean activeNetworkIsCellular() {
final Network activeNetwork = mConnectivityManager.getActiveNetwork();
if (activeNetwork == null) {
@@ -197,10 +246,9 @@
*
* If a subscription isn't the default for anything, we just say it is available.
*/
- protected String getSummary(int subId) {
+ protected String getSummary(int subId, boolean isDefaultForData) {
final int callsDefaultSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
final int smsDefaultSubId = SubscriptionManager.getDefaultSmsSubscriptionId();
- final int dataDefaultSubId = SubscriptionManager.getDefaultDataSubscriptionId();
String line1 = null;
if (subId == callsDefaultSubId && subId == smsDefaultSubId) {
@@ -212,10 +260,10 @@
}
String line2 = null;
- if (subId == dataDefaultSubId) {
+ if (isDefaultForData) {
final TelephonyManager telMgrForSub = mContext.getSystemService(
TelephonyManager.class).createForSubscriptionId(subId);
- boolean dataEnabled = telMgrForSub.isDataEnabled();
+ final boolean dataEnabled = telMgrForSub.isDataEnabled();
if (dataEnabled && activeNetworkIsCellular()) {
line2 = mContext.getString(R.string.mobile_data_active);
} else if (!dataEnabled) {
@@ -277,4 +325,9 @@
public void onDataConnectivityChange() {
update();
}
+
+ @Override
+ public void onSignalStrengthChanged() {
+ update();
+ }
}
diff --git a/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialog.java b/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialog.java
deleted file mode 100644
index 13bfa92..0000000
--- a/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialog.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2019 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
- */
-
-package com.android.settings.network.telephony;
-
-import android.app.Dialog;
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.telephony.SubscriptionInfo;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-import androidx.appcompat.app.AlertDialog;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class DeleteSimProfileConfirmationDialog extends InstrumentedDialogFragment implements
- DialogInterface.OnClickListener {
- public static final String TAG = "confirm_delete_sim";
- public static final String KEY_SUBSCRIPTION_INFO = "subscription_info";
- private SubscriptionInfo mInfo;
-
- public static DeleteSimProfileConfirmationDialog newInstance(SubscriptionInfo info) {
- final DeleteSimProfileConfirmationDialog dialog =
- new DeleteSimProfileConfirmationDialog();
- final Bundle args = new Bundle();
- args.putParcelable(KEY_SUBSCRIPTION_INFO, info);
- dialog.setArguments(args);
- return dialog;
- }
-
- @NonNull
- @Override
- public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
- mInfo = getArguments().getParcelable(KEY_SUBSCRIPTION_INFO);
- Context context = getContext();
- final String message = context.getString(R.string.mobile_network_erase_sim_dialog_body,
- mInfo.getCarrierName(), mInfo.getCarrierName());
- return new AlertDialog.Builder(context)
- .setTitle(R.string.mobile_network_erase_sim_dialog_title)
- .setMessage(message)
- .setNegativeButton(R.string.cancel, null)
- .setPositiveButton(R.string.mobile_network_erase_sim_dialog_ok, this)
- .create();
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- beginDeletionWithProgress();
- }
- }
-
- @VisibleForTesting
- void beginDeletionWithProgress() {
- final DeleteSimProfileProgressDialog progress =
- DeleteSimProfileProgressDialog.newInstance(mInfo.getSubscriptionId());
- progress.setTargetFragment(getTargetFragment(), 0);
- progress.show(getFragmentManager(), DeleteSimProfileProgressDialog.TAG);
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DIALOG_DELETE_SIM_CONFIRMATION;
- }
-}
diff --git a/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceController.java b/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceController.java
index 22ff2b6..daabf8b 100644
--- a/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceController.java
+++ b/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceController.java
@@ -17,7 +17,9 @@
package com.android.settings.network.telephony;
import android.content.Context;
+import android.content.Intent;
import android.telephony.SubscriptionInfo;
+import android.telephony.euicc.EuiccManager;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
@@ -31,12 +33,13 @@
private SubscriptionInfo mSubscriptionInfo;
private Fragment mParentFragment;
+ private int mRequestCode;
public DeleteSimProfilePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
- public void init(int subscriptionId, Fragment parentFragment) {
+ public void init(int subscriptionId, Fragment parentFragment, int requestCode) {
mParentFragment = parentFragment;
for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(
@@ -46,6 +49,7 @@
break;
}
}
+ mRequestCode = requestCode;
}
@Override
@@ -53,11 +57,10 @@
super.displayPreference(screen);
final Preference pref = screen.findPreference(getPreferenceKey());
pref.setOnPreferenceClickListener(p -> {
- final DeleteSimProfileConfirmationDialog dialogFragment =
- DeleteSimProfileConfirmationDialog.newInstance(mSubscriptionInfo);
- dialogFragment.setTargetFragment(mParentFragment, 0);
- dialogFragment.show(mParentFragment.getFragmentManager(),
- DeleteSimProfileConfirmationDialog.TAG);
+ final Intent intent = new Intent(EuiccManager.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED);
+ intent.putExtra(EuiccManager.EXTRA_SUBSCRIPTION_ID,
+ mSubscriptionInfo.getSubscriptionId());
+ mParentFragment.startActivityForResult(intent, mRequestCode);
return true;
});
}
diff --git a/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialog.java b/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialog.java
deleted file mode 100644
index c176f3c..0000000
--- a/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialog.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2019 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
- */
-
-package com.android.settings.network.telephony;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.app.PendingIntent;
-import android.app.ProgressDialog;
-import android.app.settings.SettingsEnums;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.telephony.euicc.EuiccManager;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class DeleteSimProfileProgressDialog extends InstrumentedDialogFragment {
- public static final String TAG = "delete_sim_progress";
-
- // Note that this must be listed in AndroidManfiest.xml in a <protected-broadcast> tag
- @VisibleForTesting
- static final String PENDING_INTENT =
- "com.android.settings.DELETE_SIM_PROFILE_RESULT";
- private static final int PENDING_INTENT_REQUEST_CODE = 1;
- private static final String KEY_SUBSCRIPTION_ID = "subscription_id";
- @VisibleForTesting
- static final String KEY_DELETE_STARTED = "delete_started";
-
- private boolean mDeleteStarted;
- private BroadcastReceiver mReceiver;
-
- public static DeleteSimProfileProgressDialog newInstance(int subscriptionId) {
- final DeleteSimProfileProgressDialog dialog = new DeleteSimProfileProgressDialog();
- final Bundle args = new Bundle();
- args.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
- dialog.setArguments(args);
- return dialog;
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(KEY_DELETE_STARTED, mDeleteStarted);
- }
-
- @NonNull
- @Override
- public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
- if (savedInstanceState != null) {
- mDeleteStarted = savedInstanceState.getBoolean(KEY_DELETE_STARTED, false);
- }
- final Context context = getContext();
- final ProgressDialog progressDialog = new ProgressDialog(context);
- progressDialog.setMessage(
- context.getString(R.string.mobile_network_erase_sim_dialog_progress));
-
- mReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- dismiss();
- final Activity activity = getActivity();
- if (activity != null && !activity.isFinishing()) {
- activity.finish();
- }
- }
- };
- context.registerReceiver(mReceiver, new IntentFilter(PENDING_INTENT));
-
- if (!mDeleteStarted) {
- final PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
- PENDING_INTENT_REQUEST_CODE, new Intent(PENDING_INTENT),
- PendingIntent.FLAG_ONE_SHOT);
-
- final EuiccManager euiccManager = context.getSystemService(EuiccManager.class);
- final int subId = getArguments().getInt(KEY_SUBSCRIPTION_ID);
- euiccManager.deleteSubscription(subId, pendingIntent);
- mDeleteStarted = true;
- }
-
- return progressDialog;
- }
-
- @Override
- public void onDismiss(@NonNull DialogInterface dialog) {
- if (mReceiver != null) {
- final Context context = getContext();
- if (context != null) {
- context.unregisterReceiver(mReceiver);
- }
- mReceiver = null;
- }
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DIALOG_DELETE_SIM_PROGRESS;
- }
-}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index e18971d..838aa12 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -61,6 +61,7 @@
private static final String LOG_TAG = "NetworkSettings";
public static final int REQUEST_CODE_EXIT_ECM = 17;
+ public static final int REQUEST_CODE_DELETE_SUBSCRIPTION = 18;
@VisibleForTesting
static final String KEY_CLICKED_PREF = "key_clicked_pref";
@@ -138,7 +139,8 @@
use(BillingCyclePreferenceController.class).init(mSubId);
use(MmsMessagePreferenceController.class).init(mSubId);
use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
- use(DeleteSimProfilePreferenceController.class).init(mSubId, this);
+ use(DeleteSimProfilePreferenceController.class).init(mSubId, this,
+ REQUEST_CODE_DELETE_SUBSCRIPTION);
}
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
@@ -226,6 +228,13 @@
}
break;
+ case REQUEST_CODE_DELETE_SUBSCRIPTION:
+ final Activity activity = getActivity();
+ if (activity != null && !activity.isFinishing()) {
+ activity.finish();
+ }
+ break;
+
default:
break;
}
@@ -268,5 +277,11 @@
result.add(sir);
return result;
}
+
+ /** suppress full page if user is not admin */
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return context.getSystemService(UserManager.class).isAdminUser();
+ }
};
}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index c0b4590..0e5eaa8 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -24,6 +24,10 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.provider.Settings;
@@ -37,6 +41,7 @@
import android.telephony.ims.feature.ImsFeature;
import android.text.TextUtils;
import android.util.Log;
+import android.view.Gravity;
import androidx.annotation.VisibleForTesting;
@@ -45,7 +50,10 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.util.ArrayUtils;
+import com.android.settings.R;
+import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.graph.SignalDrawable;
import java.util.Arrays;
import java.util.List;
@@ -65,6 +73,10 @@
private static final String LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT =
"android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
+ // The following constants are used to draw signal icon.
+ public static final int NO_CELL_DATA_TYPE_ICON = 0;
+ public static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
+
/**
* Returns if DPC APNs are enforced.
*/
@@ -495,4 +507,32 @@
return false;
}
+
+ public static Drawable getSignalStrengthIcon(Context context, int level, int numLevels,
+ int iconType, boolean cutOut) {
+ SignalDrawable signalDrawable = new SignalDrawable(context);
+ signalDrawable.setLevel(
+ SignalDrawable.getState(level, numLevels, cutOut));
+
+ // Make the network type drawable
+ Drawable networkDrawable =
+ iconType == NO_CELL_DATA_TYPE_ICON
+ ? EMPTY_DRAWABLE
+ : context
+ .getResources().getDrawable(iconType, context.getTheme());
+
+ // Overlay the two drawables
+ final Drawable[] layers = {networkDrawable, signalDrawable};
+ final int iconSize =
+ context.getResources().getDimensionPixelSize(R.dimen.signal_strength_icon_size);
+
+ LayerDrawable icons = new LayerDrawable(layers);
+ // Set the network type icon at the top left
+ icons.setLayerGravity(0 /* index of networkDrawable */, Gravity.TOP | Gravity.LEFT);
+ // Set the signal strength icon at the bottom right
+ icons.setLayerGravity(1 /* index of SignalDrawable */, Gravity.BOTTOM | Gravity.RIGHT);
+ icons.setLayerSize(1 /* index of SignalDrawable */, iconSize, iconSize);
+ icons.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal));
+ return icons;
+ }
}
diff --git a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
index 2359399..77f40da 100644
--- a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
+++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
@@ -16,22 +16,17 @@
package com.android.settings.network.telephony;
+import static android.telephony.SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
+
import android.content.Context;
-import android.graphics.Color;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.LayerDrawable;
import android.telephony.CellInfo;
import android.telephony.CellSignalStrength;
-import android.telephony.SignalStrength;
import android.util.Log;
-import android.view.Gravity;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.graph.SignalDrawable;
import java.util.List;
@@ -45,18 +40,12 @@
private static final int LEVEL_NONE = -1;
- // number of signal strength level
- public static final int NUMBER_OF_LEVELS = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
private CellInfo mCellInfo;
private List<String> mForbiddenPlmns;
private int mLevel = LEVEL_NONE;
private boolean mShow4GForLTE;
private boolean mUseNewApi;
- // The following constants are used to draw signal icon.
- private static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
- private static final int NO_CELL_DATA_CONNECTED_ICON = 0;
-
public NetworkOperatorPreference(
CellInfo cellinfo, Context context, List<String> forbiddenPlmns, boolean show4GForLTE) {
super(context);
@@ -113,39 +102,16 @@
case CellInfo.TYPE_CDMA:
return R.drawable.signal_strength_1x;
default:
- return 0;
+ return MobileNetworkUtils.NO_CELL_DATA_TYPE_ICON;
}
}
private void updateIcon(int level) {
- if (!mUseNewApi || level < 0 || level >= NUMBER_OF_LEVELS) {
+ if (!mUseNewApi || level < 0 || level >= NUM_SIGNAL_STRENGTH_BINS) {
return;
}
Context context = getContext();
- SignalDrawable signalDrawable = new SignalDrawable(getContext());
- signalDrawable.setLevel(
- SignalDrawable.getState(level, NUMBER_OF_LEVELS, false /* cutOut */));
-
- // Make the network type drawable
- int iconType = getIconIdForCell(mCellInfo);
- Drawable networkDrawable =
- iconType == NO_CELL_DATA_CONNECTED_ICON
- ? EMPTY_DRAWABLE
- : getContext()
- .getResources().getDrawable(iconType, getContext().getTheme());
-
- // Overlay the two drawables
- final Drawable[] layers = {networkDrawable, signalDrawable};
- final int iconSize =
- context.getResources().getDimensionPixelSize(R.dimen.signal_strength_icon_size);
-
- LayerDrawable icons = new LayerDrawable(layers);
- // Set the network type icon at the top left
- icons.setLayerGravity(0 /* index of networkDrawable */, Gravity.TOP | Gravity.LEFT);
- // Set the signal strength icon at the bottom right
- icons.setLayerGravity(1 /* index of SignalDrawable */, Gravity.BOTTOM | Gravity.RIGHT);
- icons.setLayerSize(1 /* index of SignalDrawable */, iconSize, iconSize);
- icons.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal));
- setIcon(icons);
+ setIcon(MobileNetworkUtils.getSignalStrengthIcon(context, level, NUM_SIGNAL_STRENGTH_BINS,
+ getIconIdForCell(mCellInfo), false));
}
}
diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
index 98bfc0d..62947d1 100644
--- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
@@ -29,6 +29,7 @@
import android.telephony.CellInfo;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
+import android.telephony.SignalStrength;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -336,7 +337,7 @@
pref.setSummary(R.string.network_connected);
// Update the signal strength icon, since the default signalStrength value would be
// zero (it would be quite confusing why the connected network has no signal)
- pref.setIcon(NetworkOperatorPreference.NUMBER_OF_LEVELS - 1);
+ pref.setIcon(SignalStrength.NUM_SIGNAL_STRENGTH_BINS - 1);
mConnectedPreferenceCategory.addPreference(pref);
} else {
// Remove the connected network operators category
diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
index f7e7de5..82554c2 100644
--- a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
+++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
@@ -95,13 +95,9 @@
builder.setTitle(R.string.mobile_network_sim_name)
.setView(view)
.setPositiveButton(R.string.mobile_network_sim_name_rename, (dialog, which) -> {
- SubscriptionInfo currentInfo = mSubscriptionManager.getActiveSubscriptionInfo(
- mSubId);
String newName = mNameView.getText().toString();
- if (currentInfo != null && !currentInfo.getDisplayName().equals(newName)) {
- mSubscriptionManager.setDisplayName(newName, mSubId,
- SubscriptionManager.NAME_SOURCE_USER_INPUT);
- }
+ mSubscriptionManager.setDisplayName(newName, mSubId,
+ SubscriptionManager.NAME_SOURCE_USER_INPUT);
})
.setNegativeButton(android.R.string.cancel, null);
return builder.create();
diff --git a/src/com/android/settings/network/telephony/SignalStrengthListener.java b/src/com/android/settings/network/telephony/SignalStrengthListener.java
new file mode 100644
index 0000000..0e29a45
--- /dev/null
+++ b/src/com/android/settings/network/telephony/SignalStrengthListener.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2019 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
+ */
+
+package com.android.settings.network.telephony;
+
+import android.content.Context;
+import android.telephony.PhoneStateListener;
+import android.telephony.SignalStrength;
+import android.telephony.TelephonyManager;
+import android.util.ArraySet;
+
+import com.google.common.collect.Sets;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+/** Helper class to manage listening to signal strength changes on a set of mobile network
+ * subscriptions */
+public class SignalStrengthListener {
+
+ private TelephonyManager mBaseTelephonyManager;
+ private Callback mCallback;
+ private Map<Integer, PhoneStateListener> mListeners;
+
+ public interface Callback {
+ void onSignalStrengthChanged();
+ }
+
+ public SignalStrengthListener(Context context, Callback callback) {
+ mBaseTelephonyManager = context.getSystemService(TelephonyManager.class);
+ mCallback = callback;
+ mListeners = new TreeMap<>();
+ }
+
+ /** Resumes listening for signal strength changes for the set of ids from the last call to
+ * {@link #updateSubscriptionIds(Set)} */
+ public void resume() {
+ for (int subId : mListeners.keySet()) {
+ startListening(subId);
+ }
+ }
+
+ /** Pauses listening for signal strength changes */
+ public void pause() {
+ for (int subId : mListeners.keySet()) {
+ stopListening(subId);
+ }
+ }
+
+ /** Updates the set of ids we want to be listening for, beginning to listen for any new ids and
+ * stopping listening for any ids not contained in the new set */
+ public void updateSubscriptionIds(Set<Integer> ids) {
+ Set<Integer> currentIds = new ArraySet<>(mListeners.keySet());
+ for (int idToRemove : Sets.difference(currentIds, ids)) {
+ stopListening(idToRemove);
+ mListeners.remove(idToRemove);
+ }
+ for (int idToAdd : Sets.difference(ids, currentIds)) {
+ PhoneStateListener listener = new PhoneStateListener() {
+ @Override
+ public void onSignalStrengthsChanged(SignalStrength signalStrength) {
+ mCallback.onSignalStrengthChanged();
+ }
+ };
+ mListeners.put(idToAdd, listener);
+ startListening(idToAdd);
+ }
+ }
+
+ private void startListening(int subId) {
+ TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
+ mgr.listen(mListeners.get(subId), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
+ }
+
+ private void stopListening(int subId) {
+ TelephonyManager mgr = mBaseTelephonyManager.createForSubscriptionId(subId);
+ mgr.listen(mListeners.get(subId), PhoneStateListener.LISTEN_NONE);
+ }
+}
diff --git a/src/com/android/settings/notification/AudioHelper.java b/src/com/android/settings/notification/AudioHelper.java
index d178113..01945fd 100644
--- a/src/com/android/settings/notification/AudioHelper.java
+++ b/src/com/android/settings/notification/AudioHelper.java
@@ -22,6 +22,7 @@
import android.media.AudioSystem;
import android.os.UserHandle;
import android.os.UserManager;
+import android.util.Log;
import com.android.settings.Utils;
@@ -30,6 +31,7 @@
*/
public class AudioHelper {
+ private static final String TAG = "AudioHelper";
private Context mContext;
private AudioManager mAudioManager;
@@ -76,6 +78,15 @@
}
public int getMinVolume(int stream) {
- return mAudioManager.getStreamMinVolume(stream);
+ int minVolume;
+ try {
+ minVolume = mAudioManager.getStreamMinVolume(stream);
+ } catch (IllegalArgumentException e) {
+ Log.w(TAG, "Invalid stream type " + stream);
+ // Fallback to STREAM_VOICE_CALL because CallVolumePreferenceController.java default
+ // return STREAM_VOICE_CALL in getAudioStream
+ minVolume = mAudioManager.getStreamMinVolume(AudioManager.STREAM_VOICE_CALL);
+ }
+ return minVolume;
}
}
diff --git a/src/com/android/settings/notification/SnoozeNotificationPreferenceController.java b/src/com/android/settings/notification/SnoozeNotificationPreferenceController.java
new file mode 100644
index 0000000..03170e4
--- /dev/null
+++ b/src/com/android/settings/notification/SnoozeNotificationPreferenceController.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+import androidx.annotation.VisibleForTesting;
+
+public class SnoozeNotificationPreferenceController extends TogglePreferenceController {
+
+ private static final String TAG = "SnoozeNotifPrefContr";
+ @VisibleForTesting
+ static final int ON = 1;
+ @VisibleForTesting
+ static final int OFF = 0;
+
+ public SnoozeNotificationPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ SHOW_NOTIFICATION_SNOOZE, OFF) == ON;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putInt(mContext.getContentResolver(),
+ SHOW_NOTIFICATION_SNOOZE, isChecked ? ON : OFF);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/WifiScanThrottlingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/WifiScanThrottlingPreferenceControllerTest.java
new file mode 100644
index 0000000..605bd0d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/WifiScanThrottlingPreferenceControllerTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.settings.development;
+
+import static com.android.settings.development.WifiScanThrottlingPreferenceController.SETTING_THROTTLING_ENABLE_VALUE_OFF;
+import static com.android.settings.development.WifiScanThrottlingPreferenceController.SETTING_THROTTLING_ENABLE_VALUE_ON;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiScanThrottlingPreferenceControllerTest {
+
+ @Mock
+ private SwitchPreference mPreference;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ private Context mContext;
+ private WifiScanThrottlingPreferenceController mController;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new WifiScanThrottlingPreferenceController(mContext);
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
+ .thenReturn(mPreference);
+ mController.displayPreference(mPreferenceScreen);
+ }
+
+ @Test
+ public void onPreferenceChanged_turnOnScanThrottling() {
+ mController.onPreferenceChange(mPreference, true /* new value */);
+
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
+
+ assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_ON);
+ }
+
+ @Test
+ public void onPreferenceChanged_turnOffScanThrottling() {
+ mController.onPreferenceChange(mPreference, false /* new value */);
+
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
+
+ assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_OFF);
+ }
+
+ @Test
+ public void updateState_preferenceShouldBeChecked() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
+ SETTING_THROTTLING_ENABLE_VALUE_ON);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_preferenceShouldNotBeChecked() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
+ SETTING_THROTTLING_ENABLE_VALUE_OFF);
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onDeveloperOptionsDisabled_shouldDisablePreference() {
+ mController.onDeveloperOptionsDisabled();
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
+
+ assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_ON);
+ verify(mPreference).setEnabled(false);
+ verify(mPreference).setChecked(true);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkListFragmentTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkListFragmentTest.java
new file mode 100644
index 0000000..a65ff24
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkListFragmentTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.settings.network;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserManager;
+
+import com.android.settings.search.BaseSearchIndexProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.util.ReflectionHelpers;
+
+
+@RunWith(RobolectricTestRunner.class)
+public class MobileNetworkListFragmentTest {
+ @Mock
+ private Context mContext;
+ @Mock
+ private UserManager mUserManager;
+
+ private MobileNetworkListFragment mFragment;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mFragment = new MobileNetworkListFragment();
+ }
+
+ @Test
+ public void isPageSearchEnabled_adminUser_shouldReturnTrue() {
+ when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+ when(mUserManager.isAdminUser()).thenReturn(true);
+ final BaseSearchIndexProvider provider =
+ (BaseSearchIndexProvider) mFragment.SEARCH_INDEX_DATA_PROVIDER;
+
+ final Object obj = ReflectionHelpers.callInstanceMethod(provider, "isPageSearchEnabled",
+ ReflectionHelpers.ClassParameter.from(Context.class, mContext));
+ final boolean isEnabled = (Boolean) obj;
+
+ assertThat(isEnabled).isTrue();
+ }
+
+ @Test
+ public void isPageSearchEnabled_nonAdminUser_shouldReturnFalse() {
+ when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+ when(mUserManager.isAdminUser()).thenReturn(false);
+ final BaseSearchIndexProvider provider =
+ (BaseSearchIndexProvider) mFragment.SEARCH_INDEX_DATA_PROVIDER;
+
+ final Object obj = ReflectionHelpers.callInstanceMethod(provider, "isPageSearchEnabled",
+ ReflectionHelpers.ClassParameter.from(Context.class, mContext));
+ final boolean isEnabled = (Boolean) obj;
+
+ assertThat(isEnabled).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
index d6edcc7..51f8ec0 100644
--- a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
@@ -16,11 +16,17 @@
package com.android.settings.network;
+import static android.telephony.SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
+import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GOOD;
+import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GREAT;
+import static android.telephony.SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
+import static android.telephony.SignalStrength.SIGNAL_STRENGTH_POOR;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -33,16 +39,20 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.provider.Settings;
+import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.graph.SignalDrawable;
import org.junit.After;
import org.junit.Before;
@@ -84,6 +94,8 @@
private Network mActiveNetwork;
@Mock
private NetworkCapabilities mCapabilities;
+ @Mock
+ private Drawable mSignalStrengthIcon;
private Context mContext;
private LifecycleOwner mLifecycleOwner;
@@ -109,8 +121,10 @@
mOnChildUpdatedCount = 0;
mUpdateListener = () -> mOnChildUpdatedCount++;
- mController = new SubscriptionsPreferenceController(mContext, mLifecycle, mUpdateListener,
- KEY, 5);
+ mController = spy(
+ new SubscriptionsPreferenceController(mContext, mLifecycle, mUpdateListener,
+ KEY, 5));
+ doReturn(mSignalStrengthIcon).when(mController).getIcon(anyInt(), anyInt(), anyBoolean());
}
@After
@@ -120,32 +134,25 @@
@Test
public void isAvailable_oneSubscription_availableFalse() {
- SubscriptionUtil.setActiveSubscriptionsForTesting(
- Arrays.asList(mock(SubscriptionInfo.class)));
+ setupMockSubscriptions(1);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_twoSubscriptions_availableTrue() {
- SubscriptionUtil.setActiveSubscriptionsForTesting(
- Arrays.asList(mock(SubscriptionInfo.class), mock(SubscriptionInfo.class)));
+ setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_fiveSubscriptions_availableTrue() {
- final ArrayList<SubscriptionInfo> subs = new ArrayList<>();
- for (int i = 0; i < 5; i++) {
- subs.add(mock(SubscriptionInfo.class));
- }
- SubscriptionUtil.setActiveSubscriptionsForTesting(subs);
+ setupMockSubscriptions(5);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_airplaneModeOn_availableFalse() {
- SubscriptionUtil.setActiveSubscriptionsForTesting(
- Arrays.asList(mock(SubscriptionInfo.class), mock(SubscriptionInfo.class)));
+ setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
assertThat(mController.isAvailable()).isFalse();
@@ -153,8 +160,7 @@
@Test
public void onAirplaneModeChanged_airplaneModeTurnedOn_eventFired() {
- SubscriptionUtil.setActiveSubscriptionsForTesting(
- Arrays.asList(mock(SubscriptionInfo.class), mock(SubscriptionInfo.class)));
+ setupMockSubscriptions(2);
mController.onResume();
mController.displayPreference(mScreen);
assertThat(mController.isAvailable()).isTrue();
@@ -169,8 +175,7 @@
@Test
public void onAirplaneModeChanged_airplaneModeTurnedOff_eventFired() {
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
- SubscriptionUtil.setActiveSubscriptionsForTesting(
- Arrays.asList(mock(SubscriptionInfo.class), mock(SubscriptionInfo.class)));
+ setupMockSubscriptions(2);
mController.onResume();
mController.displayPreference(mScreen);
assertThat(mController.isAvailable()).isFalse();
@@ -184,15 +189,14 @@
@Test
public void onSubscriptionsChanged_countBecameTwo_eventFired() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
+ SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 1));
mController.onResume();
mController.displayPreference(mScreen);
assertThat(mController.isAvailable()).isFalse();
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ SubscriptionUtil.setActiveSubscriptionsForTesting(subs);
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isTrue();
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
@@ -200,18 +204,14 @@
@Test
public void onSubscriptionsChanged_countBecameOne_eventFiredAndPrefsRemoved() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub2.getSubscriptionId()).thenReturn(2);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
mController.onResume();
mController.displayPreference(mScreen);
assertThat(mController.isAvailable()).isTrue();
verify(mPreferenceCategory, times(2)).addPreference(any(Preference.class));
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
+ SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 1));
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isFalse();
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
@@ -219,21 +219,12 @@
verify(mPreferenceCategory, times(2)).removePreference(any(Preference.class));
}
-
@Test
public void onSubscriptionsChanged_subscriptionReplaced_preferencesChanged() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub3 = mock(SubscriptionInfo.class);
- when(sub1.getDisplayName()).thenReturn("sub1");
- when(sub2.getDisplayName()).thenReturn("sub2");
- when(sub3.getDisplayName()).thenReturn("sub3");
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub2.getSubscriptionId()).thenReturn(2);
- when(sub3.getSubscriptionId()).thenReturn(3);
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(3);
// Start out with only sub1 and sub2.
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 2));
mController.onResume();
mController.displayPreference(mScreen);
final ArgumentCaptor<Preference> captor = ArgumentCaptor.forClass(Preference.class);
@@ -245,7 +236,7 @@
// Now replace sub2 with sub3, and make sure the old preference was removed and the new
// preference was added.
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub3));
+ SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(subs.get(0), subs.get(2)));
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isTrue();
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
@@ -264,14 +255,8 @@
* @param subscriptionCount the number of subscriptions
* @param selectedPrefIndex index of the subscription to click on
*/
- private void runPreferenceClickTest(int subscriptionCount, int selectedPrefIndex) {
- final ArrayList<SubscriptionInfo> subscriptions = new ArrayList<>();
- for (int i = 0; i < subscriptionCount; i++) {
- final SubscriptionInfo sub = mock(SubscriptionInfo.class);
- doReturn(i + 1).when(sub).getSubscriptionId();
- subscriptions.add(sub);
- }
- SubscriptionUtil.setActiveSubscriptionsForTesting(subscriptions);
+ private void runPreferenceClickTest(final int subscriptionCount, final int selectedPrefIndex) {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(subscriptionCount);
mController.displayPreference(mScreen);
final ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mPreferenceCategory, times(subscriptionCount)).addPreference(prefCaptor.capture());
@@ -286,7 +271,7 @@
final int subIdFromIntent = intent.getIntExtra(Settings.EXTRA_SUB_ID,
INVALID_SUBSCRIPTION_ID);
assertThat(subIdFromIntent).isEqualTo(
- subscriptions.get(selectedPrefIndex).getSubscriptionId());
+ subs.get(selectedPrefIndex).getSubscriptionId());
}
@Test
@@ -311,86 +296,248 @@
@Test
public void getSummary_twoSubsOneDefaultForEverythingDataActive() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(11);
- when(sub2.getSubscriptionId()).thenReturn(22);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ setupMockSubscriptions(2);
- ShadowSubscriptionManager.setDefaultDataSubscriptionId(11);
ShadowSubscriptionManager.setDefaultSmsSubscriptionId(11);
ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(11);
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
when(mCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)).thenReturn(true);
- assertThat(mController.getSummary(11)).isEqualTo(
+ assertThat(mController.getSummary(11, true)).isEqualTo(
mContext.getString(R.string.default_for_calls_and_sms) + System.lineSeparator()
+ mContext.getString(R.string.mobile_data_active));
- assertThat(mController.getSummary(22)).isEqualTo(
+ assertThat(mController.getSummary(22, false)).isEqualTo(
mContext.getString(R.string.subscription_available));
}
@Test
public void getSummary_twoSubsOneDefaultForEverythingDataNotActive() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(11);
- when(sub2.getSubscriptionId()).thenReturn(22);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ setupMockSubscriptions(2, 1, true);
- ShadowSubscriptionManager.setDefaultDataSubscriptionId(11);
- ShadowSubscriptionManager.setDefaultSmsSubscriptionId(11);
- ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(11);
- when(mTelephonyManager.isDataEnabled()).thenReturn(true);
+ ShadowSubscriptionManager.setDefaultSmsSubscriptionId(1);
+ ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(1);
- assertThat(mController.getSummary(11)).isEqualTo(
+ assertThat(mController.getSummary(1, true)).isEqualTo(
mContext.getString(R.string.default_for_calls_and_sms) + System.lineSeparator()
+ mContext.getString(R.string.default_for_mobile_data));
- assertThat(mController.getSummary(22)).isEqualTo(
+ assertThat(mController.getSummary(2, false)).isEqualTo(
mContext.getString(R.string.subscription_available));
}
@Test
public void getSummary_twoSubsOneDefaultForEverythingDataDisabled() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(11);
- when(sub2.getSubscriptionId()).thenReturn(22);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ setupMockSubscriptions(2);
- ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(11);
- ShadowSubscriptionManager.setDefaultSmsSubscriptionId(11);
- ShadowSubscriptionManager.setDefaultDataSubscriptionId(11);
- when(mTelephonyManager.isDataEnabled()).thenReturn(false);
+ ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(1);
+ ShadowSubscriptionManager.setDefaultSmsSubscriptionId(1);
- assertThat(mController.getSummary(11)).isEqualTo(
+ assertThat(mController.getSummary(1, true)).isEqualTo(
mContext.getString(R.string.default_for_calls_and_sms) + System.lineSeparator()
+ mContext.getString(R.string.mobile_data_off));
- assertThat(mController.getSummary(22)).isEqualTo(
+ assertThat(mController.getSummary(2, false)).isEqualTo(
mContext.getString(R.string.subscription_available));
}
@Test
public void getSummary_twoSubsOneForCallsAndDataOneForSms() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(11);
- when(sub2.getSubscriptionId()).thenReturn(22);
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ setupMockSubscriptions(2, 1, true);
- ShadowSubscriptionManager.setDefaultDataSubscriptionId(11);
- ShadowSubscriptionManager.setDefaultSmsSubscriptionId(22);
- ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(11);
- when(mTelephonyManager.isDataEnabled()).thenReturn(true);
+ ShadowSubscriptionManager.setDefaultSmsSubscriptionId(2);
+ ShadowSubscriptionManager.setDefaultVoiceSubscriptionId(1);
- assertThat(mController.getSummary(11)).isEqualTo(
+ assertThat(mController.getSummary(1, true)).isEqualTo(
mContext.getString(R.string.default_for_calls) + System.lineSeparator()
+ mContext.getString(R.string.default_for_mobile_data));
- assertThat(mController.getSummary(22)).isEqualTo(
+ assertThat(mController.getSummary(2, false)).isEqualTo(
mContext.getString(R.string.default_for_sms));
}
+
+ @Test
+ public void setIcon_nullStrength_noCrash() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
+ setMockSubSignalStrength(subs, 0, -1);
+ final Preference pref = mock(Preference.class);
+
+ mController.setIcon(pref, 1, true /* isDefaultForData */);
+ verify(mController).getIcon(eq(0), eq(NUM_SIGNAL_STRENGTH_BINS), eq(true));
+ }
+
+ @Test
+ public void setIcon_noSignal_correctLevels() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
+ setMockSubSignalStrength(subs, 0, SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
+ setMockSubDataEnabled(subs, 0, true);
+ final Preference pref = mock(Preference.class);
+
+ mController.setIcon(pref, 1, true /* isDefaultForData */);
+ verify(mController).getIcon(eq(0), eq(NUM_SIGNAL_STRENGTH_BINS), eq(false));
+
+ mController.setIcon(pref, 2, false /* isDefaultForData */);
+ verify(mController).getIcon(eq(0), eq(NUM_SIGNAL_STRENGTH_BINS), eq(true));
+ }
+
+ @Test
+ public void setIcon_noSignal_withInflation_correctLevels() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
+ setMockSubSignalStrength(subs, 0, SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_NONE_OR_UNKNOWN);
+ final Preference pref = mock(Preference.class);
+ doReturn(true).when(mController).shouldInflateSignalStrength(anyInt());
+
+ mController.setIcon(pref, 1, true /* isDefaultForData */);
+ verify(mController).getIcon(eq(1), eq(NUM_SIGNAL_STRENGTH_BINS + 1), eq(false));
+
+ mController.setIcon(pref, 2, false /* isDefaultForData */);
+ verify(mController).getIcon(eq(1), eq(NUM_SIGNAL_STRENGTH_BINS + 1), eq(true));
+ }
+
+ @Test
+ public void setIcon_greatSignal_correctLevels() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
+ setMockSubSignalStrength(subs, 0, SIGNAL_STRENGTH_GREAT);
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_GREAT);
+ final Preference pref = mock(Preference.class);
+
+ mController.setIcon(pref, 1, true /* isDefaultForData */);
+ verify(mController).getIcon(eq(4), eq(NUM_SIGNAL_STRENGTH_BINS), eq(false));
+
+ mController.setIcon(pref, 2, false /* isDefaultForData */);
+ verify(mController).getIcon(eq(4), eq(NUM_SIGNAL_STRENGTH_BINS), eq(true));
+ }
+
+ @Test
+ public void onSignalStrengthChanged_subTwoGoesFromGoodToGreat_correctLevels() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
+ setMockSubSignalStrength(subs, 0, SIGNAL_STRENGTH_POOR);
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_GOOD);
+
+ mController.onResume();
+ mController.displayPreference(mScreen);
+
+ // Now change the signal strength for the 2nd subscription from Good to Great
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_GREAT);
+ mController.onSignalStrengthChanged();
+
+ final ArgumentCaptor<Integer> level = ArgumentCaptor.forClass(Integer.class);
+ verify(mController, times(4)).getIcon(level.capture(), eq(NUM_SIGNAL_STRENGTH_BINS),
+ eq(true));
+ assertThat(level.getAllValues().get(0)).isEqualTo(1);
+ assertThat(level.getAllValues().get(1)).isEqualTo(3); // sub2, first time
+ assertThat(level.getAllValues().get(2)).isEqualTo(1);
+ assertThat(level.getAllValues().get(3)).isEqualTo(4); // sub2, after change
+ }
+
+ @Test
+ public void displayPreference_mobileDataOff_bothSubsHaveCutOut() {
+ setupMockSubscriptions(2, 1, false);
+
+ mController.onResume();
+ mController.displayPreference(mScreen);
+
+ verify(mController, times(2)).getIcon(eq(SIGNAL_STRENGTH_GOOD),
+ eq(NUM_SIGNAL_STRENGTH_BINS), eq(true));
+ }
+
+ @Test
+ public void displayPreference_mobileDataOn_onlyNonDefaultSubHasCutOut() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
+ setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_POOR);
+
+ mController.onResume();
+ mController.displayPreference(mScreen);
+
+ verify(mController).getIcon(eq(SIGNAL_STRENGTH_GOOD), eq(NUM_SIGNAL_STRENGTH_BINS),
+ eq(false));
+ verify(mController).getIcon(eq(SIGNAL_STRENGTH_POOR), eq(NUM_SIGNAL_STRENGTH_BINS),
+ eq(true));
+ }
+
+
+ @Test
+ public void onMobileDataEnabledChange_mobileDataTurnedOff_bothSubsHaveCutOut() {
+ final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
+
+ mController.onResume();
+ mController.displayPreference(mScreen);
+
+ setMockSubDataEnabled(subs, 0, false);
+ mController.onMobileDataEnabledChange();
+
+ final ArgumentCaptor<Boolean> cutOutCaptor = ArgumentCaptor.forClass(Boolean.class);
+ verify(mController, times(4)).getIcon(eq(SIGNAL_STRENGTH_GOOD),
+ eq(NUM_SIGNAL_STRENGTH_BINS), cutOutCaptor.capture());
+ assertThat(cutOutCaptor.getAllValues().get(0)).isEqualTo(false); // sub1, first time
+ assertThat(cutOutCaptor.getAllValues().get(1)).isEqualTo(true);
+ assertThat(cutOutCaptor.getAllValues().get(2)).isEqualTo(true); // sub1, second time
+ assertThat(cutOutCaptor.getAllValues().get(3)).isEqualTo(true);
+ }
+
+ private List<SubscriptionInfo> setupMockSubscriptions(int count) {
+ return setupMockSubscriptions(count, 0, true);
+ }
+
+ /** Helper method to setup several mock active subscriptions. The generated subscription id's
+ * start at 1.
+ *
+ * @param count How many subscriptions to create
+ * @param defaultDataSubId The subscription id of the default data subscription - pass
+ * INVALID_SUBSCRIPTION_ID if there should not be one
+ * @param mobileDataEnabled Whether mobile data should be considered enabled for the default
+ * data subscription
+ */
+ private List<SubscriptionInfo> setupMockSubscriptions(int count, int defaultDataSubId,
+ boolean mobileDataEnabled) {
+ if (defaultDataSubId != INVALID_SUBSCRIPTION_ID) {
+ ShadowSubscriptionManager.setDefaultDataSubscriptionId(defaultDataSubId);
+ }
+ final ArrayList<SubscriptionInfo> infos = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ final int subscriptionId = i + 1;
+ final SubscriptionInfo info = mock(SubscriptionInfo.class);
+ final TelephonyManager mgrForSub = mock(TelephonyManager.class);
+ final SignalStrength signalStrength = mock(SignalStrength.class);
+
+ if (subscriptionId == defaultDataSubId) {
+ when(mgrForSub.isDataEnabled()).thenReturn(mobileDataEnabled);
+ }
+ when(info.getSubscriptionId()).thenReturn(i + 1);
+ when(info.getDisplayName()).thenReturn("sub" + (i + 1));
+ doReturn(mgrForSub).when(mTelephonyManager).createForSubscriptionId(eq(subscriptionId));
+ when(mgrForSub.getSignalStrength()).thenReturn(signalStrength);
+ when(signalStrength.getLevel()).thenReturn(SIGNAL_STRENGTH_GOOD);
+
+ infos.add(info);
+ }
+ SubscriptionUtil.setActiveSubscriptionsForTesting(infos);
+ return infos;
+ }
+
+ /**
+ * Helper method to set the signal strength returned for a mock subscription
+ * @param subs The list of subscriptions
+ * @param index The index in of the subscription in |subs| to change
+ * @param level The signal strength level to return for the subscription. Pass -1 to force
+ * return of a null SignalStrength object for the subscription.
+ */
+ private void setMockSubSignalStrength(List<SubscriptionInfo> subs, int index, int level) {
+ final TelephonyManager mgrForSub =
+ mTelephonyManager.createForSubscriptionId(subs.get(index).getSubscriptionId());
+ if (level == -1) {
+ when(mgrForSub.getSignalStrength()).thenReturn(null);
+ } else {
+ final SignalStrength signalStrength = mgrForSub.getSignalStrength();
+ when(signalStrength.getLevel()).thenReturn(level);
+ }
+ }
+
+ private void setMockSubDataEnabled(List<SubscriptionInfo> subs, int index, boolean enabled) {
+ final TelephonyManager mgrForSub =
+ mTelephonyManager.createForSubscriptionId(subs.get(index).getSubscriptionId());
+ when(mgrForSub.isDataEnabled()).thenReturn(enabled);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialogTest.java b/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialogTest.java
deleted file mode 100644
index 9b6f551..0000000
--- a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileConfirmationDialogTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2019 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
- */
-
-package com.android.settings.network.telephony;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.telephony.SubscriptionInfo;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.fragment.app.FragmentActivity;
-
-import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadows.androidx.fragment.FragmentController;
-
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowAlertDialogCompat.class)
-public class DeleteSimProfileConfirmationDialogTest {
- @Mock
- private SubscriptionInfo mSubscriptionInfo;
-
- private DeleteSimProfileConfirmationDialog mDialogFragment;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mDialogFragment = spy(DeleteSimProfileConfirmationDialog.newInstance(mSubscriptionInfo));
- doNothing().when(mDialogFragment).beginDeletionWithProgress();
- }
-
- @Test
- public void showDialog_dialogCancelled_deleteNotCalled() {
- FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
- 0 /* containerViewId */,
- null /* bundle */);
- final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
- dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
- verify(mDialogFragment, never()).beginDeletionWithProgress();
- }
-
- @Test
- public void showDialog_dialogOk_deleteWasCalled() {
- FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
- 0 /* containerViewId */,
- null /* bundle */);
- final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
- dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
- verify(mDialogFragment).beginDeletionWithProgress();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceControllerTest.java
index 21fd19b..ca8fcf8 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfilePreferenceControllerTest.java
@@ -18,11 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.euicc.EuiccManager;
import androidx.fragment.app.Fragment;
@@ -35,6 +39,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -46,12 +51,12 @@
@RunWith(RobolectricTestRunner.class)
public class DeleteSimProfilePreferenceControllerTest {
private static final String PREF_KEY = "delete_profile_key";
+ private static final int REQUEST_CODE = 4321;
private static final int SUB_ID = 1234;
private static final int OTHER_ID = 5678;
@Mock
private Fragment mFragment;
-
@Mock
private SubscriptionInfo mSubscriptionInfo;
@Mock
@@ -85,27 +90,42 @@
@Test
public void getAvailabilityStatus_noSubs_notAvailable() {
SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>());
- mController.init(SUB_ID, mFragment);
+ mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_physicalSim_notAvailable() {
when(mSubscriptionInfo.isEmbedded()).thenReturn(false);
- mController.init(SUB_ID, mFragment);
+ mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_unknownSim_notAvailable() {
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(OTHER_ID);
- mController.init(SUB_ID, mFragment);
+ mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_knownEsim_isAvailable() {
- mController.init(SUB_ID, mFragment);
+ mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isTrue();
}
+
+ @Test
+ public void onPreferenceClick_startsIntent() {
+ mController.init(SUB_ID, mFragment, REQUEST_CODE);
+ mController.displayPreference(mScreen);
+ mPreference.performClick();
+
+ final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mFragment).startActivityForResult(intentCaptor.capture(), eq(REQUEST_CODE));
+ final Intent intent = intentCaptor.getValue();
+ assertThat(intent.getAction()).isEqualTo(
+ EuiccManager.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED);
+ assertThat(intent.getIntExtra(EuiccManager.EXTRA_SUBSCRIPTION_ID,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(SUB_ID);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialogTest.java b/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialogTest.java
deleted file mode 100644
index aebcc46..0000000
--- a/tests/robotests/src/com/android/settings/network/telephony/DeleteSimProfileProgressDialogTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2019 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
- */
-
-package com.android.settings.network.telephony;
-
-import static com.android.settings.network.telephony.DeleteSimProfileProgressDialog.KEY_DELETE_STARTED;
-import static com.android.settings.network.telephony.DeleteSimProfileProgressDialog.PENDING_INTENT;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.notNull;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.Dialog;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.telephony.euicc.EuiccManager;
-
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentActivity;
-
-import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-@RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowAlertDialogCompat.class)
-public class DeleteSimProfileProgressDialogTest {
- private static final int SUB_ID = 111;
-
- @Mock
- private FragmentActivity mActivity;
- @Mock
- private Fragment mTargetFragment;
- @Mock
- private EuiccManager mEuiccManager;
-
- private Context mContext;
- private DeleteSimProfileProgressDialog mDialogFragment;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
-
- when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
- mDialogFragment = spy(DeleteSimProfileProgressDialog.newInstance(SUB_ID));
- when(mDialogFragment.getContext()).thenReturn(mContext);
- when(mDialogFragment.getTargetFragment()).thenReturn(mTargetFragment);
- when(mDialogFragment.getActivity()).thenReturn(mActivity);
- }
-
- @Test
- public void onCreateDialog_firstShowing_deleteStartedAndRecordedInOutState() {
- mDialogFragment.onCreateDialog(null);
- verify(mEuiccManager).deleteSubscription(eq(SUB_ID), notNull());
-
- final Bundle outState = new Bundle();
- mDialogFragment.onSaveInstanceState(outState);
- assertThat(outState.containsKey(KEY_DELETE_STARTED)).isTrue();
- assertThat(outState.getBoolean(KEY_DELETE_STARTED)).isTrue();
- }
-
- @Test
- public void showDialog_secondShowing_deleteNotStarted() {
- final Bundle inState = new Bundle();
- inState.putBoolean(KEY_DELETE_STARTED, true);
- mDialogFragment.onCreateDialog(inState);
-
- verify(mEuiccManager, never()).deleteSubscription(anyInt(), any());
-
- final Bundle outState = new Bundle();
- mDialogFragment.onSaveInstanceState(outState);
- assertThat(outState.containsKey(KEY_DELETE_STARTED)).isTrue();
- assertThat(outState.getBoolean(KEY_DELETE_STARTED)).isTrue();
- }
-
- @Test
- public void showDialog_pendingIntentReceiverFired_activityFinished() {
- mDialogFragment.onCreateDialog(null);
-
- final ArgumentCaptor<PendingIntent> intentCaptor = ArgumentCaptor.forClass(
- PendingIntent.class);
- verify(mEuiccManager).deleteSubscription(eq(SUB_ID), intentCaptor.capture());
- assertThat(intentCaptor.getValue()).isNotNull();
-
- final ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(
- BroadcastReceiver.class);
- verify(mContext).registerReceiver(receiverCaptor.capture(), any(IntentFilter.class));
-
- doNothing().when(mDialogFragment).dismiss();
- receiverCaptor.getValue().onReceive(mContext, new Intent(PENDING_INTENT));
- verify(mDialogFragment).dismiss();
- verify(mActivity).finish();
- }
-
- @Test
- public void onDismiss_receiverUnregistered() {
- Dialog dialog = mDialogFragment.onCreateDialog(null);
- final ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(
- BroadcastReceiver.class);
- verify(mContext).registerReceiver(receiverCaptor.capture(), any(IntentFilter.class));
-
- mDialogFragment.onDismiss(dialog);
- verify(mContext).unregisterReceiver(eq(receiverCaptor.getValue()));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
index 011bca5..4afe0fc 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSettingsTest.java
@@ -16,17 +16,21 @@
package com.android.settings.network.telephony;
+import static com.android.settings.network.telephony.MobileNetworkSettings.REQUEST_CODE_DELETE_SUBSCRIPTION;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.net.NetworkPolicyManager;
import android.os.Bundle;
+import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@@ -35,6 +39,7 @@
import com.android.settings.core.FeatureFlags;
import com.android.settings.datausage.DataUsageSummaryPreferenceController;
import com.android.settings.development.featureflags.FeatureFlagPersistent;
+import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -47,6 +52,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
import java.util.List;
@@ -80,6 +86,7 @@
args.putInt(Settings.EXTRA_SUB_ID, subscriptionId);
mFragment.setArguments(args);
when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mActivity.isFinishing()).thenReturn(false);
when(mActivity.getSystemService(NetworkPolicyManager.class)).thenReturn(
mNetworkPolicyManager);
}
@@ -118,4 +125,47 @@
.count())
.isEqualTo(1);
}
+
+ @Test
+ public void onActivityResult_noActivity_noCrash() {
+ when(mFragment.getActivity()).thenReturn(null);
+ // this should not crash
+ mFragment.onActivityResult(REQUEST_CODE_DELETE_SUBSCRIPTION, 0, null);
+ }
+
+ @Test
+ public void onActivityResult_deleteSubscription_activityFinishes() {
+ mFragment.onActivityResult(REQUEST_CODE_DELETE_SUBSCRIPTION, 0, null);
+ verify(mActivity).finish();
+ }
+
+ @Test
+ public void isPageSearchEnabled_adminUser_shouldReturnTrue() {
+ final UserManager userManager = mock(UserManager.class);
+ when(mContext.getSystemService(UserManager.class)).thenReturn(userManager);
+ when(userManager.isAdminUser()).thenReturn(true);
+ final BaseSearchIndexProvider provider =
+ (BaseSearchIndexProvider) mFragment.SEARCH_INDEX_DATA_PROVIDER;
+
+ final Object obj = ReflectionHelpers.callInstanceMethod(provider, "isPageSearchEnabled",
+ ReflectionHelpers.ClassParameter.from(Context.class, mContext));
+ final boolean isEnabled = (Boolean) obj;
+
+ assertThat(isEnabled).isTrue();
+ }
+
+ @Test
+ public void isPageSearchEnabled_nonAdminUser_shouldReturnFalse() {
+ final UserManager userManager = mock(UserManager.class);
+ when(mContext.getSystemService(UserManager.class)).thenReturn(userManager);
+ when(userManager.isAdminUser()).thenReturn(false);
+ final BaseSearchIndexProvider provider =
+ (BaseSearchIndexProvider) mFragment.SEARCH_INDEX_DATA_PROVIDER;
+
+ final Object obj = ReflectionHelpers.callInstanceMethod(provider, "isPageSearchEnabled",
+ ReflectionHelpers.ClassParameter.from(Context.class, mContext));
+ final boolean isEnabled = (Boolean) obj;
+
+ assertThat(isEnabled).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/SignalStrengthListenerTest.java b/tests/robotests/src/com/android/settings/network/telephony/SignalStrengthListenerTest.java
new file mode 100644
index 0000000..406f360
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/SignalStrengthListenerTest.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2019 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
+ */
+
+package com.android.settings.network.telephony;
+
+import static android.telephony.PhoneStateListener.LISTEN_NONE;
+import static android.telephony.PhoneStateListener.LISTEN_SIGNAL_STRENGTHS;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.telephony.PhoneStateListener;
+import android.telephony.TelephonyManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.internal.util.collections.Sets;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class SignalStrengthListenerTest {
+ private static final int SUB_ID_1 = 111;
+ private static final int SUB_ID_2 = 222;
+ private static final int SUB_ID_3 = 333;
+
+ @Mock
+ private SignalStrengthListener.Callback mCallback;
+ @Mock
+ private TelephonyManager mBaseManager;
+ @Mock
+ private TelephonyManager mManager1;
+ @Mock
+ private TelephonyManager mManager2;
+ @Mock
+ private TelephonyManager mManager3;
+
+ private Context mContext;
+ private SignalStrengthListener mListener;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mBaseManager);
+ when(mBaseManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mManager1);
+ when(mBaseManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mManager2);
+ when(mBaseManager.createForSubscriptionId(SUB_ID_3)).thenReturn(mManager3);
+ mListener = new SignalStrengthListener(mContext, mCallback);
+ }
+
+ @Test
+ public void resume_noIds_noCrash() {
+ mListener.resume();
+ }
+
+ @Test
+ public void pause_noIds_noCrash() {
+ mListener.resume();
+ }
+
+ @Test
+ public void updateSubscriptionIds_beforeResume_startedListening() {
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
+ ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+ ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager2).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager3, never()).listen(any(), anyInt());
+ assertThat(captor1.getValue()).isNotNull();
+ assertThat(captor2.getValue()).isNotNull();
+
+ // Make sure the two listeners are separate objects.
+ assertThat(captor1.getValue() != captor2.getValue()).isTrue();
+ }
+
+ @Test
+ public void updateSubscriptionIds_twoCalls_oneIdAdded() {
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
+ verify(mManager1).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager2).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
+
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2, SUB_ID_3));
+ verify(mManager1, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
+ verify(mManager2, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
+ verify(mManager3).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
+ }
+
+ @Test
+ public void updateSubscriptionIds_twoCalls_oneIdRemoved() {
+ ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager2).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
+
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_2));
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
+ verify(mManager2, never()).listen(any(PhoneStateListener.class), eq(LISTEN_NONE));
+ // Make sure the correct listener was removed.
+ assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
+ }
+
+ @Test
+ public void updateSubscriptionIds_twoCalls_twoIdsRemovedOneAdded() {
+ ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+ ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager2).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_3));
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
+ verify(mManager2).listen(captor2.capture(), eq(LISTEN_NONE));
+ verify(mManager3).listen(any(PhoneStateListener.class), eq(LISTEN_SIGNAL_STRENGTHS));
+ // Make sure the correct listeners were removed.
+ assertThat(captor1.getValue() != captor2.getValue()).isTrue();
+ assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
+ assertThat(captor2.getAllValues().get(0) == captor2.getAllValues().get(1)).isTrue();
+ }
+
+ @Test
+ public void updateSubscriptionIds_thenPauseResume_correctlyStartsAndStops() {
+ mListener.updateSubscriptionIds(Sets.newSet(SUB_ID_1, SUB_ID_2));
+ mListener.pause();
+ mListener.resume();
+
+ ArgumentCaptor<PhoneStateListener> captor1 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+ ArgumentCaptor<PhoneStateListener> captor2 = ArgumentCaptor.forClass(
+ PhoneStateListener.class);
+ verify(mManager1, times(2)).listen(captor1.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager1).listen(captor1.capture(), eq(LISTEN_NONE));
+
+ verify(mManager2, times(2)).listen(captor2.capture(), eq(LISTEN_SIGNAL_STRENGTHS));
+ verify(mManager2).listen(captor2.capture(), eq(LISTEN_NONE));
+
+ assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(1)).isTrue();
+ assertThat(captor1.getAllValues().get(0) == captor1.getAllValues().get(2)).isTrue();
+
+ assertThat(captor2.getAllValues().get(0) == captor2.getAllValues().get(1)).isTrue();
+ assertThat(captor2.getAllValues().get(0) == captor2.getAllValues().get(2)).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/AudioHelperTest.java b/tests/robotests/src/com/android/settings/notification/AudioHelperTest.java
new file mode 100644
index 0000000..79d0198
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/AudioHelperTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2019 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
+ */
+
+package com.android.settings.notification;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class AudioHelperTest {
+
+ private static final int START = -10;
+ private static final int END = 10;
+ private static final int DEFAULT = -100;
+
+ private Context mContext;
+ private AudioHelper mAudioHelper;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mAudioHelper = new AudioHelper(mContext);
+ }
+
+ @Test
+ public void getMaxVolume_anyStreamType_getValue() {
+ int volume = DEFAULT;
+
+ for (int i = START; i < END; i++) {
+ volume = mAudioHelper.getMaxVolume(i);
+ assertThat(volume).isNotEqualTo(DEFAULT);
+ }
+ }
+
+ @Test
+ public void getMinVolume_anyStreamType_getValue() {
+ int volume = DEFAULT;
+
+ for (int i = START; i < END; i++) {
+ volume = mAudioHelper.getMinVolume(i);
+ assertThat(volume).isNotEqualTo(DEFAULT);
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/SnoozeNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SnoozeNotificationPreferenceControllerTest.java
new file mode 100644
index 0000000..6779ff1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/SnoozeNotificationPreferenceControllerTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
+import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
+
+import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
+import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.TwoStatePreference;
+
+@RunWith(RobolectricTestRunner.class)
+public class SnoozeNotificationPreferenceControllerTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private SnoozeNotificationPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mController = new SnoozeNotificationPreferenceController(mContext,
+ "key");
+ mPreference = new Preference(RuntimeEnvironment.application);
+ mPreference.setKey(mController.getPreferenceKey());
+ when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void display_configIsTrue_shouldDisplay() {
+ mController.displayPreference(mScreen);
+ assertThat(mPreference.isVisible()).isTrue();
+ }
+
+ @Test
+ public void isChecked_settingIsOff_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, OFF);
+
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_settingIsOn_shouldReturnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, ON);
+
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void setChecked_setFalse_disablesSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, ON);
+
+ mController.setChecked(false);
+ int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
+ SHOW_NOTIFICATION_SNOOZE, -1);
+
+ assertThat(updatedValue).isEqualTo(OFF);
+ }
+
+ @Test
+ public void setChecked_setTrue_enablesSetting() {
+ Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, OFF);
+
+ mController.setChecked(true);
+ int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
+ SHOW_NOTIFICATION_SNOOZE, -1);
+
+ assertThat(updatedValue).isEqualTo(ON);
+ }
+}