Merge "Fix Calls/SMS default SIM selector" into qt-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b2306de..ec15bdf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3075,8 +3075,8 @@
<string name="kernel_version">Kernel version</string>
<!-- About phone screen, setting option name [CHAR LIMIT=40] -->
<string name="build_number">Build number</string>
- <!-- About phone screen, mainline module versions [CHAR LIMIT=40] -->
- <string name="module_version">Mainline module versions</string>
+ <!-- About phone screen, tapping this button will take user to a seperate UI to check Google Play system update [CHAR LIMIT=60] -->
+ <string name="module_version">Google Play system update</string>
<!-- About phone screen, show when a value of some status item is unavailable. -->
<string name="device_info_not_available">Not available</string>
@@ -5108,7 +5108,7 @@
<!-- Title for a warning about security implications of enabling an accessibility
service. [CHAR LIMIT=NONE] -->
<string name="enable_service_title">Allow
- <xliff:g id="service" example="TalkBack">%1$s</xliff:g> to have full contol of your
+ <xliff:g id="service" example="TalkBack">%1$s</xliff:g> to have full control of your
device?</string>
<!-- Title for the list of capabilities of an accessibility service. -->
<string name="capabilities_list_title"><xliff:g id="service" example="TalkBack">%1$s</xliff:g>
@@ -5165,7 +5165,7 @@
</string>
<!-- Title for the action perform in accessibility dialog. [CHAR LIMIT=NONE] -->
- <string name="accessibility_service_action_perform_title">View and platform actions</string>
+ <string name="accessibility_service_action_perform_title">View and perform actions</string>
<!-- Description for the action perform in accessibility dialog. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_action_perform_description">It can track your interactions
@@ -6079,10 +6079,6 @@
<string name="sms_access_restriction_enabled">Restrict SMS & call log access</string>
<!-- Summary for whether to enable SMS access restriction [CHAR LIMIT=NONE]-->
<string name="sms_access_restriction_enabled_summary">Only default phone and messaging apps have SMS & call log permissions</string>
- <!-- Title for the new device identifier access restrictions [CHAR LIMIT=50]-->
- <string name="device_identifier_access_restrictions_title">Disable device identifier restrictions</string>
- <!-- Summary for the new device identifier access restrictions [CHAR LIMIT=NONE]-->
- <string name="device_identifier_access_restrictions_summary">Disable the new access restrictions for device identifiers</string>
<!-- Message when there are no available trust agents to display -->
@@ -10652,12 +10648,15 @@
<string name="game_driver_app_preference_default">Default</string>
<!-- The game driver value for Game Driver app preference [CHAR LIMIT=50] -->
<string name="game_driver_app_preference_game_driver">Game Driver</string>
+ <!-- The game driver value for Prerelease Game Driver app preference [CHAR LIMIT=50] -->
+ <string name="game_driver_app_preference_prerelease_driver">Prerelease Driver</string>
<!-- The system value for Game Driver app preference [CHAR LIMIT=50] -->
<string name="game_driver_app_preference_system">System Graphics Driver</string>
<!-- All the values for Game Driver app preference [CHAR LIMIT=50] -->
<string-array name="game_driver_app_preference_values">
<item>@string/game_driver_app_preference_default</item>
<item>@string/game_driver_app_preference_game_driver</item>
+ <item>@string/game_driver_app_preference_prerelease_driver</item>
<item>@string/game_driver_app_preference_system</item>
</string-array>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 5a7d194..d1eff34 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -562,11 +562,6 @@
android:summary="@string/sms_access_restriction_enabled_summary" />
<SwitchPreference
- android:key="device_identifier_access_restrictions"
- android:title="@string/device_identifier_access_restrictions_title"
- android:summary="@string/device_identifier_access_restrictions_summary" />
-
- <SwitchPreference
android:key="notification_bubbles"
android:title="@string/notification_bubbles_title"
android:summary="@string/notification_bubbles_developer_setting_summary"/>
diff --git a/res/xml/mobile_network_settings_v2.xml b/res/xml/mobile_network_settings_v2.xml
index 20ed1c7..506b354 100644
--- a/res/xml/mobile_network_settings_v2.xml
+++ b/res/xml/mobile_network_settings_v2.xml
@@ -203,4 +203,14 @@
android:title="@string/mobile_network_erase_sim"
settings:controller="com.android.settings.network.telephony.DeleteSimProfilePreferenceController" />
+ <PreferenceCategory
+ android:key="footer_container"
+ android:title="@string/summary_placeholder"
+ android:layout="@layout/preference_category_no_label"
+ settings:controller="com.android.settings.network.telephony.DisableSimFooterPreferenceController">
+ <com.android.settingslib.widget.FooterPreference
+ android:key="disable_sim_explanation"
+ android:title="@string/mobile_network_disable_sim_explanation" />
+ </PreferenceCategory>
+
</PreferenceScreen>
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 8e0db2f..aba95c8 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -480,7 +480,6 @@
controllers.add(new ResizableActivityPreferenceController(context));
controllers.add(new FreeformWindowsPreferenceController(context));
controllers.add(new DesktopModePreferenceController(context));
- controllers.add(new DeviceIdentifierAccessRestrictionsPreferenceController(context));
controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
controllers.add(new BubbleGlobalPreferenceController(context));
controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
diff --git a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java b/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
deleted file mode 100644
index f4e5953..0000000
--- a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
+++ /dev/null
@@ -1,97 +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.development;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.DeviceConfig;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-
-public class DeviceIdentifierAccessRestrictionsPreferenceController
- extends DeveloperOptionsPreferenceController
- implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
-
- private static final String DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY =
- "device_identifier_access_restrictions";
-
- // The settings that should be set when the new device identifier access restrictions are
- // disabled.
- private static final String[] RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS = {
- Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED,
- Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED,
- Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED
- };
-
- private ContentResolver mContentResolver;
-
- public DeviceIdentifierAccessRestrictionsPreferenceController(Context context) {
- super(context);
- mContentResolver = context.getContentResolver();
- }
-
- @Override
- public boolean isAvailable() {
- // If the new access restrictions have been disabled from the server side then do not
- // display the option.
- boolean disabledFromServerSide = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED, false);
- return !disabledFromServerSide;
- }
-
- @Override
- public String getPreferenceKey() {
- return DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY;
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- writeSetting((boolean) newValue);
- return true;
- }
-
- private void writeSetting(boolean isEnabled) {
- for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
- Settings.Global.putInt(mContentResolver, relaxCheckSetting, isEnabled ? 1 : 0);
- }
- }
-
- @Override
- public void updateState(Preference preference) {
- boolean isEnabled = true;
- for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
- if (Settings.Global.getInt(mContentResolver, relaxCheckSetting, 0) == 0) {
- isEnabled = false;
- break;
- }
- }
- ((SwitchPreference) mPreference).setChecked(isEnabled);
- }
-
- @Override
- protected void onDeveloperOptionsSwitchDisabled() {
- super.onDeveloperOptionsSwitchDisabled();
- writeSetting(false);
- ((SwitchPreference) mPreference).setChecked(false);
- }
-}
diff --git a/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
index 09659be..489408d 100644
--- a/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
+++ b/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceController.java
@@ -64,12 +64,14 @@
private final String mPreferenceTitle;
private final String mPreferenceDefault;
private final String mPreferenceGameDriver;
+ private final String mPreferencePrereleaseDriver;
private final String mPreferenceSystem;
@VisibleForTesting
GameDriverContentObserver mGameDriverContentObserver;
private final List<AppInfo> mAppInfos;
private final Set<String> mDevOptInApps;
+ private final Set<String> mDevPrereleaseOptInApps;
private final Set<String> mDevOptOutApps;
private PreferenceGroup mPreferenceGroup;
@@ -88,6 +90,8 @@
mPreferenceDefault = resources.getString(R.string.game_driver_app_preference_default);
mPreferenceGameDriver =
resources.getString(R.string.game_driver_app_preference_game_driver);
+ mPreferencePrereleaseDriver =
+ resources.getString(R.string.game_driver_app_preference_prerelease_driver);
mPreferenceSystem = resources.getString(R.string.game_driver_app_preference_system);
// TODO: Move this task to background if there's potential ANR/Jank.
@@ -96,6 +100,8 @@
mDevOptInApps =
getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS);
+ mDevPrereleaseOptInApps = getGlobalSettingsString(
+ mContentResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS);
mDevOptOutApps =
getGlobalSettingsString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS);
}
@@ -147,21 +153,31 @@
// opt-in and opt-out apps. Then set the new summary text.
if (value.equals(mPreferenceSystem)) {
mDevOptInApps.remove(packageName);
+ mDevPrereleaseOptInApps.remove(packageName);
mDevOptOutApps.add(packageName);
} else if (value.equals(mPreferenceGameDriver)) {
mDevOptInApps.add(packageName);
+ mDevPrereleaseOptInApps.remove(packageName);
+ mDevOptOutApps.remove(packageName);
+ } else if (value.equals(mPreferencePrereleaseDriver)) {
+ mDevOptInApps.remove(packageName);
+ mDevPrereleaseOptInApps.add(packageName);
mDevOptOutApps.remove(packageName);
} else {
mDevOptInApps.remove(packageName);
+ mDevPrereleaseOptInApps.remove(packageName);
mDevOptOutApps.remove(packageName);
}
listPref.setValue(value);
listPref.setSummary(value);
- // Push the updated Sets for opt-in and opt-out apps to
- // corresponding Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
+ // Push the updated Sets for stable/prerelease opt-in and opt-out apps to
+ // corresponding Settings.Global.GAME_DRIVER(_PRERELEASE)?_OPT_(IN|OUT)_APPS
Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS,
String.join(",", mDevOptInApps));
+ Settings.Global.putString(mContentResolver,
+ Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS,
+ String.join(",", mDevPrereleaseOptInApps));
Settings.Global.putString(mContentResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS,
String.join(",", mDevOptOutApps));
@@ -233,10 +249,13 @@
listPreference.setEntryValues(mEntryList);
// Initialize preference default and summary with the opt in/out choices
- // from Settings.Global.GAME_DRIVER_OPT_(IN|OUT)_APPS
+ // from Settings.Global.GAME_DRIVER(_PRERELEASE)?_OPT_(IN|OUT)_APPS
if (mDevOptOutApps.contains(packageName)) {
listPreference.setValue(mPreferenceSystem);
listPreference.setSummary(mPreferenceSystem);
+ } else if (mDevPrereleaseOptInApps.contains(packageName)) {
+ listPreference.setValue(mPreferencePrereleaseDriver);
+ listPreference.setSummary(mPreferencePrereleaseDriver);
} else if (mDevOptInApps.contains(packageName)) {
listPreference.setValue(mPreferenceGameDriver);
listPreference.setSummary(mPreferenceGameDriver);
diff --git a/src/com/android/settings/network/MobileNetworkListController.java b/src/com/android/settings/network/MobileNetworkListController.java
index d0e14ce..ab41fad 100644
--- a/src/com/android/settings/network/MobileNetworkListController.java
+++ b/src/com/android/settings/network/MobileNetworkListController.java
@@ -118,14 +118,19 @@
if (mSubscriptionManager.isActiveSubscriptionId(subId)) {
pref.setSummary(R.string.mobile_network_active_sim);
} else {
- pref.setSummary(R.string.mobile_network_inactive_sim);
+ pref.setSummary(mContext.getString(R.string.mobile_network_tap_to_activate,
+ SubscriptionUtil.getDisplayName(info)));
}
}
pref.setOnPreferenceClickListener(clickedPref -> {
- final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
- intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
- mContext.startActivity(intent);
+ if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
+ mSubscriptionManager.setSubscriptionEnabled(subId, true);
+ } else {
+ final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
+ intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
+ mContext.startActivity(intent);
+ }
return true;
});
mPreferences.put(subId, pref);
diff --git a/src/com/android/settings/network/MobileNetworkSummaryController.java b/src/com/android/settings/network/MobileNetworkSummaryController.java
index 9498c4e..0f76f24 100644
--- a/src/com/android/settings/network/MobileNetworkSummaryController.java
+++ b/src/com/android/settings/network/MobileNetworkSummaryController.java
@@ -108,7 +108,14 @@
}
return null;
} else if (subs.size() == 1) {
- return subs.get(0).getDisplayName();
+ final SubscriptionInfo info = subs.get(0);
+ final int subId = info.getSubscriptionId();
+ if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
+ return mContext.getString(R.string.mobile_network_tap_to_activate,
+ SubscriptionUtil.getDisplayName(info));
+ } else {
+ return subs.get(0).getDisplayName();
+ }
} else {
final int count = subs.size();
return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count,
@@ -154,9 +161,15 @@
if (subs.size() == 1) {
mPreference.setOnPreferenceClickListener((Preference pref) -> {
- final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
- intent.putExtra(Settings.EXTRA_SUB_ID, subs.get(0).getSubscriptionId());
- mContext.startActivity(intent);
+ final SubscriptionInfo info = subs.get(0);
+ final int subId = info.getSubscriptionId();
+ if (!info.isEmbedded() && !mSubscriptionManager.isActiveSubscriptionId(subId)) {
+ mSubscriptionManager.setSubscriptionEnabled(subId, true);
+ } else {
+ final Intent intent = new Intent(mContext, MobileNetworkActivity.class);
+ intent.putExtra(Settings.EXTRA_SUB_ID, subs.get(0).getSubscriptionId());
+ mContext.startActivity(intent);
+ }
return true;
});
} else {
diff --git a/src/com/android/settings/network/SubscriptionUtil.java b/src/com/android/settings/network/SubscriptionUtil.java
index ebac51f..f723575 100644
--- a/src/com/android/settings/network/SubscriptionUtil.java
+++ b/src/com/android/settings/network/SubscriptionUtil.java
@@ -25,12 +25,10 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
-import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
public class SubscriptionUtil {
@@ -107,4 +105,12 @@
}
return subscriptions;
}
+
+ public static String getDisplayName(SubscriptionInfo info) {
+ final CharSequence name = info.getDisplayName();
+ if (name != null) {
+ return name.toString();
+ }
+ return "";
+ }
}
diff --git a/src/com/android/settings/network/telephony/DisableSimFooterPreferenceController.java b/src/com/android/settings/network/telephony/DisableSimFooterPreferenceController.java
new file mode 100644
index 0000000..ab01b9d
--- /dev/null
+++ b/src/com/android/settings/network/telephony/DisableSimFooterPreferenceController.java
@@ -0,0 +1,54 @@
+/*
+ * 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.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.SubscriptionUtil;
+
+public class DisableSimFooterPreferenceController extends BasePreferenceController {
+ private int mSubId;
+
+ public DisableSimFooterPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
+
+ public void init(int subId) {
+ mSubId = subId;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) {
+ if (info.getSubscriptionId() == mSubId) {
+ if (info.isEmbedded()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ break;
+ }
+ }
+ return AVAILABLE;
+ }
+}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index aa63b74..c8e2247 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -142,6 +142,7 @@
use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
use(DeleteSimProfilePreferenceController.class).init(mSubId, this,
REQUEST_CODE_DELETE_SUBSCRIPTION);
+ use(DisableSimFooterPreferenceController.class).init(mSubId);
}
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
index 2037adc..e6422f0 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
@@ -93,23 +93,23 @@
if (mSwitchBar == null) {
return;
}
- final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(
- mContext);
- if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ||
- mSubscriptionManager.isSubscriptionEnabled(mSubId) && subs.size() < 2) {
- mSwitchBar.hide();
- return;
- }
- for (SubscriptionInfo info : subs) {
+ SubscriptionInfo subInfo = null;
+ for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) {
if (info.getSubscriptionId() == mSubId) {
- mSwitchBar.show();
- mSwitchBar.setChecked(mSubscriptionManager.isSubscriptionEnabled(mSubId));
- return;
+ subInfo = info;
+ break;
}
}
- // This subscription was not found in the available list.
- mSwitchBar.hide();
+
+ // For eSIM, we always want the toggle. The telephony stack doesn't currently support
+ // disabling a pSIM directly (b/133379187), so we for now we don't include this on pSIM.
+ if (subInfo == null || !subInfo.isEmbedded()) {
+ mSwitchBar.hide();
+ } else {
+ mSwitchBar.show();
+ mSwitchBar.setChecked(mSubscriptionManager.isSubscriptionEnabled(mSubId));
+ }
}
@Override
diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java
index d942113..be5f45e 100644
--- a/src/com/android/settings/notification/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/HeaderPreferenceController.java
@@ -25,13 +25,14 @@
import android.text.TextUtils;
import android.view.View;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
-import androidx.preference.PreferenceFragmentCompat;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.LayoutPreference;
@@ -39,11 +40,11 @@
public class HeaderPreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin, LifecycleObserver {
- private final PreferenceFragmentCompat mFragment;
+ private final DashboardFragment mFragment;
private EntityHeaderController mHeaderController;
private boolean mStarted = false;
- public HeaderPreferenceController(Context context, PreferenceFragmentCompat fragment) {
+ public HeaderPreferenceController(Context context, DashboardFragment fragment) {
super(context, null);
mFragment = fragment;
}
@@ -83,18 +84,12 @@
.setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
EntityHeaderController.ActionType.ACTION_NONE)
.setHasAppInfoLink(true)
+ .setRecyclerView(mFragment.getListView(), mFragment.getSettingsLifecycle())
.done(activity, mContext);
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
}
}
- CharSequence getLabel() {
- return (mChannel != null && !isDefaultChannel()) ? mChannel.getName()
- : mChannelGroup != null
- ? mChannelGroup.getName()
- : mAppRow.label;
- }
-
@Override
public CharSequence getSummary() {
if (mChannel != null && !isDefaultChannel()) {
@@ -124,4 +119,12 @@
mHeaderController.styleActionBar(mFragment.getActivity());
}
}
+
+ @VisibleForTesting
+ CharSequence getLabel() {
+ return (mChannel != null && !isDefaultChannel()) ? mChannel.getName()
+ : mChannelGroup != null
+ ? mChannelGroup.getName()
+ : mAppRow.label;
+ }
}
diff --git a/src/com/android/settings/notification/ZenModeAutomaticRulesPreferenceController.java b/src/com/android/settings/notification/ZenModeAutomaticRulesPreferenceController.java
index 499bfbc..2f62f45 100644
--- a/src/com/android/settings/notification/ZenModeAutomaticRulesPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeAutomaticRulesPreferenceController.java
@@ -69,7 +69,7 @@
for (int i = 0; i < sortedRules.length; i++) {
ZenRulePreference pref = (ZenRulePreference) mPreferenceCategory.getPreference(i);
// we are either:
- // 1. updating the enabled state or name of the rule
+ // 1. updating everything about the rule
// 2. rule was added or deleted, so reload the entire list
if (Objects.equals(pref.mId, sortedRules[i].getKey())) {
AutomaticZenRule rule = sortedRules[i].getValue();
diff --git a/src/com/android/settings/notification/ZenRulePreference.java b/src/com/android/settings/notification/ZenRulePreference.java
index 8bc602a..fb6e92a 100644
--- a/src/com/android/settings/notification/ZenRulePreference.java
+++ b/src/com/android/settings/notification/ZenRulePreference.java
@@ -49,7 +49,7 @@
final ZenServiceListing mServiceListing;
final PackageManager mPm;
final MetricsFeatureProvider mMetricsFeatureProvider;
- final AutomaticZenRule mRule;
+ AutomaticZenRule mRule;
CharSequence mName;
private Intent mIntent;
@@ -122,14 +122,14 @@
if (!mRule.getName().equals(rule.getName())) {
mName = rule.getName();
setTitle(mName);
- mRule.setName(mName.toString());
}
if (mRule.isEnabled() != rule.isEnabled()) {
- mRule.setEnabled(rule.isEnabled());
setChecked(mRule.isEnabled());
setSummary(computeRuleSummary(mRule));
}
+
+ mRule = rule;
}
@Override
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
index f6fa8e0..f007ce2 100644
--- a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverAppPreferenceControllerTest.java
@@ -56,7 +56,8 @@
private static final int DEFAULT = 0;
private static final int GAME_DRIVER = 1;
- private static final int SYSTEM = 2;
+ private static final int PRERELEASE_DRIVER = 2;
+ private static final int SYSTEM = 3;
private static final String TEST_APP_NAME = "testApp";
private static final String TEST_PKG_NAME = "testPkg";
@@ -181,7 +182,7 @@
@Test
public void createPreference_configGAME_DRIVER_shouldSetGameDriverAttributes() {
- loadConfig(TEST_PKG_NAME, "");
+ loadConfig(TEST_PKG_NAME, "", "");
final ListPreference preference =
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
@@ -196,8 +197,24 @@
}
@Test
+ public void createPreference_configPRERELEASE_DRIVER_shouldSetPrereleaseDriverAttributes() {
+ loadConfig("", TEST_PKG_NAME, "");
+ final ListPreference preference =
+ mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
+
+ assertThat(preference.getKey()).isEqualTo(TEST_PKG_NAME);
+ assertThat(preference.getTitle()).isEqualTo(TEST_APP_NAME);
+ assertThat(preference.getDialogTitle()).isEqualTo(mDialogTitle);
+ assertThat(preference.getEntries()).isEqualTo(mValueList);
+ assertThat(preference.getEntryValues()).isEqualTo(mValueList);
+ assertThat(preference.getEntry()).isEqualTo(mValueList[PRERELEASE_DRIVER]);
+ assertThat(preference.getValue()).isEqualTo(mValueList[PRERELEASE_DRIVER]);
+ assertThat(preference.getSummary()).isEqualTo(mValueList[PRERELEASE_DRIVER]);
+ }
+
+ @Test
public void createPreference_configSystem_shouldSetSystemAttributes() {
- loadConfig("", TEST_PKG_NAME);
+ loadConfig("", "", TEST_PKG_NAME);
final ListPreference preference =
mController.createListPreference(mContext, TEST_PKG_NAME, TEST_APP_NAME);
@@ -274,10 +291,12 @@
when(mContext.getPackageManager()).thenReturn(mPackageManager);
}
- private void loadDefaultConfig() { loadConfig("", ""); }
+ private void loadDefaultConfig() { loadConfig("", "", ""); }
- private void loadConfig(String optIn, String optOut) {
+ private void loadConfig(String optIn, String prereleaseOptIn, String optOut) {
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_IN_APPS, optIn);
+ Settings.Global.putString(
+ mResolver, Settings.Global.GAME_DRIVER_PRERELEASE_OPT_IN_APPS, prereleaseOptIn);
Settings.Global.putString(mResolver, Settings.Global.GAME_DRIVER_OPT_OUT_APPS, optOut);
mController = new GameDriverAppPreferenceController(mContext, "testKey");
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkListControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkListControllerTest.java
index 342fed5..4a98753 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkListControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkListControllerTest.java
@@ -21,6 +21,8 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -32,6 +34,7 @@
import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
@@ -54,9 +57,11 @@
@RunWith(RobolectricTestRunner.class)
public class MobileNetworkListControllerTest {
@Mock
- TelephonyManager mTelephonyManager;
+ private TelephonyManager mTelephonyManager;
@Mock
- EuiccManager mEuiccManager;
+ private EuiccManager mEuiccManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
@Mock
private Lifecycle mLifecycle;
@@ -74,6 +79,7 @@
mContext = spy(Robolectric.setupActivity(Activity.class));
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
when(mPreferenceScreen.getContext()).thenReturn(mContext);
mAddMorePreference = new Preference(mContext);
@@ -114,6 +120,8 @@
public void displayPreference_twoSubscriptions_correctlySetup() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(1));
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(2));
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
@@ -139,6 +147,33 @@
}
@Test
+ public void displayPreference_oneActiveESimOneInactivePSim_correctlySetup() {
+ final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
+ final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
+ when(sub1.isEmbedded()).thenReturn(true);
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(1));
+ doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(eq(2));
+
+ when(sub2.isEmbedded()).thenReturn(false);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+
+ mController.displayPreference(mPreferenceScreen);
+ mController.onResume();
+
+ // Check that the preferences get created with the correct summaries.
+ final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(
+ Preference.class);
+ verify(mPreferenceScreen, times(2)).addPreference(preferenceCaptor.capture());
+ final Preference pref1 = preferenceCaptor.getAllValues().get(0);
+ final Preference pref2 = preferenceCaptor.getAllValues().get(1);
+ assertThat(pref1.getSummary()).isEqualTo("Active / Downloaded SIM");
+ assertThat(pref2.getSummary()).isEqualTo("Tap to activate sub2");
+
+ pref2.getOnPreferenceClickListener().onPreferenceClick(pref2);
+ verify(mSubscriptionManager).setSubscriptionEnabled(eq(2), eq(true));
+ }
+
+ @Test
public void onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
index a623850..99c9134 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.atLeastOnce;
@@ -64,6 +65,8 @@
@Mock
private TelephonyManager mTelephonyManager;
@Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
private EuiccManager mEuiccManager;
@Mock
private PreferenceScreen mPreferenceScreen;
@@ -79,9 +82,11 @@
MockitoAnnotations.initMocks(this);
mContext = spy(Robolectric.setupActivity(Activity.class));
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
+ when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
when(mEuiccManager.isEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
@@ -160,6 +165,24 @@
}
@Test
+ public void getSummary_oneInactivePSim_correctSummaryAndClickHandler() {
+ final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
+ when(sub1.getSubscriptionId()).thenReturn(1);
+ when(sub1.getDisplayName()).thenReturn("sub1");
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
+ when(mSubscriptionManager.isActiveSubscriptionId(eq(1))).thenReturn(false);
+
+ mController.displayPreference(mPreferenceScreen);
+ mController.onResume();
+
+ assertThat(mController.getSummary()).isEqualTo("Tap to activate sub1");
+
+ assertThat(mPreference.getFragment()).isNull();
+ mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
+ verify(mSubscriptionManager).setSubscriptionEnabled(eq(sub1.getSubscriptionId()), eq(true));
+ }
+
+ @Test
public void getSummary_twoSubscriptions_correctSummaryAndFragment() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java
new file mode 100644
index 0000000..a0a4f00
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.telephony.SubscriptionInfo;
+
+import com.android.settings.network.SubscriptionUtil;
+
+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;
+
+import java.util.Arrays;
+
+@RunWith(RobolectricTestRunner.class)
+public class DisableSimFooterPreferenceControllerTest {
+ private static final String PREF_KEY = "pref_key";
+ private static final int SUB_ID = 111;
+
+ @Mock
+ private SubscriptionInfo mInfo;
+
+ private Context mContext;
+ private DisableSimFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ when(mInfo.getSubscriptionId()).thenReturn(SUB_ID);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mInfo));
+ mController = new DisableSimFooterPreferenceController(mContext, PREF_KEY);
+ }
+
+ @Test
+ public void isAvailable_noInit_notAvailable() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_eSIM_notAvailable() {
+ when(mInfo.isEmbedded()).thenReturn(true);
+ mController.init(SUB_ID);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_pSIM_available() {
+ when(mInfo.isEmbedded()).thenReturn(false);
+ mController.init(SUB_ID);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
index a10227f..86c380e 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
@@ -79,13 +79,14 @@
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
+ when(mSubscription.isEmbedded()).thenReturn(true);
when(mSubscription.getSubscriptionId()).thenReturn(mSubId);
// Most tests want to have 2 available subscriptions so that the switch bar will show.
- SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
+ final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub2.getSubscriptionId()).thenReturn(456);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription, sub2));
- String key = "prefKey";
+ final String key = "prefKey";
mController = new MobileNetworkSwitchController(mContext, key);
mController.init(mLifecycle, mSubscription.getSubscriptionId());
@@ -100,11 +101,18 @@
}
@Test
- public void displayPreference_oneEnabledSubscription_switchBarHidden() {
+ public void isAvailable_pSIM_isNotAvailable() {
+ when(mSubscription.isEmbedded()).thenReturn(false);
+ mController.displayPreference(mScreen);
+ assertThat(mSwitchBar.isShowing()).isFalse();
+ }
+
+ @Test
+ public void displayPreference_oneEnabledSubscription_switchBarNotHidden() {
doReturn(true).when(mSubscriptionManager).isSubscriptionEnabled(mSubId);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
mController.displayPreference(mScreen);
- assertThat(mSwitchBar.isShowing()).isFalse();
+ assertThat(mSwitchBar.isShowing()).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
index de84f07..7f6ecae 100644
--- a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
@@ -21,7 +21,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -35,8 +34,8 @@
import android.view.View;
import androidx.fragment.app.FragmentActivity;
-import androidx.preference.PreferenceFragmentCompat;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
@@ -70,7 +69,7 @@
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
- PreferenceFragmentCompat fragment = mock(PreferenceFragmentCompat.class);
+ DashboardFragment fragment = mock(DashboardFragment.class);
when(fragment.getContext()).thenReturn(mContext);
FragmentActivity activity = mock(FragmentActivity.class);
when(activity.getApplicationContext()).thenReturn(mContext);