Merge "Fix broken tests."
diff --git a/proguard.flags b/proguard.flags
index d509dba..b66a786 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -9,7 +9,7 @@
-keep public class com.android.settings.** extends androidx.fragment.app.Fragment
# Keep all preference controllers needed by slice and DashboardFragment.
--keep class !com.google.android.settings.aware.*, * extends com.android.settings.core.BasePreferenceController {
+-keep class * extends com.android.settings.core.BasePreferenceController {
*;
}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 08c46d5..c891432 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4431,7 +4431,7 @@
<!-- Title of Languages & input settings screen -->
<string name="language_keyboard_settings_title">Languages & input</string>
<!-- Title of preference category that lists all settings about helping user text input such as spell checker [CHAR LIMIT=60]-->
- <string name="input_assistance">Input assistance</string>
+ <string name="input_assistance">Tools</string>
<!-- On Languages & input settings screen, heading. Inside the "Languages & input settings" screen, this is the header for settings that relate to keyboard (enable/disable each keyboard, settings for each keyboard). -->
<string name="keyboard_settings_category">Keyboard & input methods</string>
<!-- On Text & language settings screen, setting option name. title of the setting to take the user to a screen to select the locale. -->
@@ -4468,7 +4468,7 @@
<!-- Image button description for spell checker language. -->
<string name="spellchecker_language">Language</string>
<!-- Title for the 'keyboard and input methods' preference category. [CHAR LIMIT=45] -->
- <string name="keyboard_and_input_methods_category">Keyboard & inputs</string>
+ <string name="keyboard_and_input_methods_category">Keyboards</string>
<!-- Title for the 'virtual keyboard' preference sub-screen. [CHAR LIMIT=35] -->
<string name="virtual_keyboard_category">Virtual keyboard</string>
<!-- Title for the 'available virtual keyboard' preference sub-screen. [CHAR LIMIT=35] -->
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 4f38843..998234b 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -26,6 +26,7 @@
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.os.UserHandle;
+import android.telephony.SubscriptionManager;
import android.util.ArraySet;
import android.util.IconDrawableFactory;
import android.util.Log;
@@ -88,7 +89,8 @@
private CycleAdapter mCycleAdapter;
private List<NetworkCycleDataForUid> mUsageData;
- private NetworkTemplate mTemplate;
+ @VisibleForTesting
+ NetworkTemplate mTemplate;
private AppItem mAppItem;
private Intent mAppSettingsIntent;
private SpinnerPreference mCycle;
@@ -108,7 +110,7 @@
: null;
if (mTemplate == null) {
mTemplate = DataUsageUtils.getDefaultTemplate(mContext,
- DataUsageUtils.getDefaultSubscriptionId(mContext));
+ SubscriptionManager.getDefaultDataSubscriptionId());
}
if (mAppItem == null) {
int uid = (args != null) ? args.getInt(AppInfoBase.ARG_PACKAGE_UID, -1)
diff --git a/src/com/android/settings/display/NightDisplayPreference.java b/src/com/android/settings/display/NightDisplayPreference.java
index 82e2596..7020c49 100644
--- a/src/com/android/settings/display/NightDisplayPreference.java
+++ b/src/com/android/settings/display/NightDisplayPreference.java
@@ -16,26 +16,25 @@
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
+import android.hardware.display.NightDisplayListener;
import android.util.AttributeSet;
import androidx.preference.SwitchPreference;
-import com.android.internal.app.ColorDisplayController;
-
import java.time.LocalTime;
public class NightDisplayPreference extends SwitchPreference
- implements ColorDisplayController.Callback {
+ implements NightDisplayListener.Callback {
private ColorDisplayManager mColorDisplayManager;
- private ColorDisplayController mController;
+ private NightDisplayListener mNightDisplayListener;
private NightDisplayTimeFormatter mTimeFormatter;
public NightDisplayPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
- mController = new ColorDisplayController(context);
+ mNightDisplayListener = new NightDisplayListener(context);
mTimeFormatter = new NightDisplayTimeFormatter(context);
}
@@ -44,7 +43,7 @@
super.onAttached();
// Listen for changes only while attached.
- mController.setListener(this);
+ mNightDisplayListener.setCallback(this);
// Update the summary since the state may have changed while not attached.
updateSummary();
@@ -55,7 +54,7 @@
super.onDetached();
// Stop listening for state changes.
- mController.setListener(null);
+ mNightDisplayListener.setCallback(null);
}
@Override
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index 4896b53..6441d71 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -21,12 +21,12 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
+import android.hardware.display.NightDisplayListener;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import androidx.preference.Preference;
-import com.android.internal.app.ColorDisplayController;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -43,7 +43,7 @@
*/
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class NightDisplaySettings extends DashboardFragment
- implements ColorDisplayController.Callback {
+ implements NightDisplayListener.Callback {
private static final String TAG = "NightDisplaySettings";
@@ -51,7 +51,7 @@
private static final int DIALOG_END_TIME = 1;
private ColorDisplayManager mColorDisplayManager;
- private ColorDisplayController mController;
+ private NightDisplayListener mNightDisplayListener;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -59,7 +59,7 @@
final Context context = getContext();
mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
- mController = new ColorDisplayController(context);
+ mNightDisplayListener = new NightDisplayListener(context);
}
@Override
@@ -67,7 +67,7 @@
super.onStart();
// Listen for changes only while visible.
- mController.setListener(this);
+ mNightDisplayListener.setCallback(this);
}
@Override
@@ -75,7 +75,7 @@
super.onStop();
// Stop listening for state changes.
- mController.setListener(null);
+ mNightDisplayListener.setCallback(null);
}
@Override
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/NightDisplayConditionController.java b/src/com/android/settings/homepage/contextualcards/conditional/NightDisplayConditionController.java
index a673e46..347d4eb 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/NightDisplayConditionController.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/NightDisplayConditionController.java
@@ -19,7 +19,8 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
-import com.android.internal.app.ColorDisplayController;
+import android.hardware.display.ColorDisplayManager;
+import android.hardware.display.NightDisplayListener;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.display.NightDisplaySettings;
@@ -28,17 +29,20 @@
import java.util.Objects;
public class NightDisplayConditionController implements ConditionalCardController,
- ColorDisplayController.Callback {
+ NightDisplayListener.Callback {
+
static final int ID = Objects.hash("NightDisplayConditionController");
private final Context mAppContext;
private final ConditionManager mConditionManager;
- private final ColorDisplayController mController;
+ private final ColorDisplayManager mColorDisplayManager;
+ private final NightDisplayListener mNightDisplayListener;
public NightDisplayConditionController(Context appContext, ConditionManager manager) {
- mController = new ColorDisplayController(appContext);
mAppContext = appContext;
mConditionManager = manager;
+ mColorDisplayManager = appContext.getSystemService(ColorDisplayManager.class);
+ mNightDisplayListener = new NightDisplayListener(appContext);
}
@Override
@@ -48,7 +52,7 @@
@Override
public boolean isDisplayable() {
- return mController.isActivated();
+ return mColorDisplayManager.isNightDisplayActivated();
}
@Override
@@ -62,7 +66,7 @@
@Override
public void onActionClick() {
- mController.setActivated(false);
+ mColorDisplayManager.setNightDisplayActivated(false);
}
@Override
@@ -84,12 +88,12 @@
@Override
public void startMonitoringStateChange() {
- mController.setListener(this);
+ mNightDisplayListener.setCallback(this);
}
@Override
public void stopMonitoringStateChange() {
- mController.setListener(null);
+ mNightDisplayListener.setCallback(null);
}
@Override
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
index 9ebeda0..47822b6 100644
--- a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -118,7 +118,8 @@
@Override
public boolean isChecked() {
- return mTelephonyManager.isDataEnabled();
+ return mTelephonyManager.isDataEnabled()
+ && mSubId == SubscriptionManager.getDefaultDataSubscriptionId();
}
public void init(FragmentManager fragmentManager, int subId) {
@@ -129,7 +130,7 @@
@VisibleForTesting
boolean isDialogNeeded() {
- final boolean enableData = !mTelephonyManager.isDataEnabled();
+ final boolean enableData = !isChecked();
final boolean isMultiSim = (mTelephonyManager.getSimCount() > 1);
final int defaultSubId = mSubscriptionManager.getDefaultDataSubscriptionId();
final boolean needToDisableOthers = mSubscriptionManager
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
index 12559f4..2855554 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
@@ -35,15 +35,19 @@
import android.net.NetworkPolicyManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
+import android.telephony.SubscriptionManager;
import android.text.format.DateUtils;
import android.util.ArraySet;
import android.view.View;
+import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
+import com.android.settings.applications.AppInfoBase;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
import com.android.settings.widget.EntityHeaderController;
@@ -60,9 +64,11 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowSubscriptionManager;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
@@ -82,7 +88,6 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest();
}
@After
@@ -277,4 +282,26 @@
assertThat(uids.get(1)).isEqualTo(456);
assertThat(uids.get(2)).isEqualTo(789);
}
+
+ @Config(shadows = {ShadowDataUsageUtils.class, ShadowSubscriptionManager.class})
+ public void onCreate_noNetworkTemplateAndInvalidDataSubscription_shouldUseWifiTemplate() {
+ ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
+ ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
+ ShadowDataUsageUtils.HAS_SIM = false;
+ ShadowSubscriptionManager.setDefaultDataSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ mFragment = spy(new AppDataUsage());
+ doReturn(Robolectric.setupActivity(FragmentActivity.class)).when(mFragment).getActivity();
+ doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
+ ReflectionHelpers.setField(mFragment, "mDashboardFeatureProvider",
+ FakeFeatureFactory.setupForTest().dashboardFeatureProvider);
+ final Bundle args = new Bundle();
+ args.putInt(AppInfoBase.ARG_PACKAGE_UID, 123123);
+ mFragment.setArguments(args);
+
+ mFragment.onCreate(Bundle.EMPTY);
+
+ assertThat(mFragment.mTemplate.getMatchRule())
+ .isEqualTo(NetworkTemplate.MATCH_WIFI_WILDCARD);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
index e0bfce4..4c242c1 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
@@ -20,7 +20,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -31,10 +30,6 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-import androidx.preference.SwitchPreference;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,10 +37,18 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowSubscriptionManager;
+
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.SwitchPreference;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowSubscriptionManager.class)
public class MobileDataPreferenceControllerTest {
private static final int SUB_ID = 2;
+ private static final int SUB_ID_OTHER = 3;
@Mock
private FragmentManager mFragmentManager;
@@ -78,6 +81,7 @@
mPreference = new SwitchPreference(mContext);
mController = new MobileDataPreferenceController(mContext, "mobile_data");
+ ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID);
mController.init(mFragmentManager, SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
}
@@ -104,7 +108,8 @@
public void isDialogNeeded_enableNonDefaultSimInMultiSimMode_returnTrue() {
doReturn(false).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
- doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(anyInt());
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID_OTHER);
+ ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID_OTHER);
doReturn(2).when(mTelephonyManager).getSimCount();
assertThat(mController.isDialogNeeded()).isTrue();