Merge "Cast device missing from output switcher list" into rvc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 436c42a..e1eae68 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4964,7 +4964,7 @@
<!-- Title for accessibility shortcut preference for accessibility apps. [CHAR LIMIT=40] -->
<string name="accessibility_shortcut_title"><xliff:g id="service" example="Select to Speak">%1$s</xliff:g> shortcut</string>
<!-- Title for software shortcut in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
- <string name="accessibility_shortcut_edit_summary_software">Accessibility Button</string>
+ <string name="accessibility_shortcut_edit_summary_software">Accessibility button</string>
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation is enabled. [CHAR LIMIT=NONE] -->
<string name="accessibility_shortcut_edit_dialog_title_software_gesture">Swipe up with 2 fingers</string>
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation and touch exploration are enabled. [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 3d47ca8..becd4e7 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -192,7 +192,7 @@
}
// Observe changes from accessibility selection menu
- shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);
+ shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
mSettingsContentObserver = new SettingsContentObserver(mHandler, shortcutFeatureKeys) {
@Override
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index ce0b5fb..a0e3d81 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -342,7 +342,7 @@
static String convertKeyFromSettings(@UserShortcutType int shortcutType) {
switch (shortcutType) {
case UserShortcutType.SOFTWARE:
- return Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
+ return Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
case UserShortcutType.HARDWARE:
return Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
case UserShortcutType.TRIPLETAP:
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index 0e6d3be..d589f0f 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -120,7 +120,7 @@
final AccessibilityManager am = (AccessibilityManager) context.getSystemService(
Context.ACCESSIBILITY_SERVICE);
final String assignedId = Settings.Secure.getString(context.getContentResolver(),
- Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);
+ Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
if (!TextUtils.isEmpty(assignedId) && !MAGNIFICATION_COMPONENT_ID.equals(assignedId)) {
final ComponentName assignedComponentName = ComponentName.unflattenFromString(
assignedId);
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index 4742192..a063327 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -62,7 +62,7 @@
public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceController implements
LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback {
private static final String TAG = "AdvancedBtHeaderCtrl";
- private static final int LOW_BATTERY_LEVEL = 20;
+ private static final int LOW_BATTERY_LEVEL = 15;
@VisibleForTesting
LayoutPreference mLayoutPreference;
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 135abfa..648b38c 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -120,14 +120,14 @@
mContext.getSystemService(NetworkPolicyManager.class);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
- mHasMobileData = SubscriptionManager.isValidSubscriptionId(mSubId)
- && DataUsageUtils.hasMobileData(mContext);
+ mHasMobileData = DataUsageUtils.hasMobileData(mContext);
mDataUsageController = new DataUsageController(mContext);
mDataUsageController.setSubscriptionId(mSubId);
mDataInfoController = new DataUsageInfoController();
- if (mHasMobileData) {
+ final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
+ if (subInfo != null) {
mDataUsageTemplate = R.string.cell_data_template;
} else if (DataUsageUtils.hasWifiRadio(mContext)) {
mDataUsageTemplate = R.string.wifi_data_template;
@@ -180,18 +180,16 @@
@VisibleForTesting
SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
+ if (!mHasMobileData) {
+ return null;
+ }
return ProxySubscriptionManager.getInstance(mContext)
.getAccessibleSubscriptionInfo(subscriptionId);
}
- @VisibleForTesting
- boolean hasSim() {
- return DataUsageUtils.hasSim(mContext);
- }
-
@Override
public int getAvailabilityStatus(int subId) {
- return hasSim()
+ return (getSubscriptionInfo(subId) != null)
|| DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@@ -199,16 +197,15 @@
public void updateState(Preference preference) {
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
- final boolean isSimCardAdded = hasSim();
- if (!isSimCardAdded) {
+ final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
+ if (subInfo == null) {
mDefaultTemplate = NetworkTemplate.buildTemplateWifiWildcard();
}
final DataUsageController.DataUsageInfo info =
mDataUsageController.getDataUsageInfo(mDefaultTemplate);
- final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
- if (isSimCardAdded) {
+ if (subInfo != null) {
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(mDefaultTemplate));
summaryPreference.setWifiMode(/* isWifiMode */ false,
/* usagePeriod */ null, /* isSingleWifi */ false);
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index 8544a53..7f82359 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -50,6 +50,7 @@
import android.widget.EditText;
import android.widget.Toast;
+import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -79,9 +80,9 @@
private OnClickListener mDisconnectListener;
private OnClickListener mCancelConnectListener;
private OnClickListener mDeleteGroupListener;
- private WifiP2pPeer mSelectedWifiPeer;
+ @VisibleForTesting WifiP2pPeer mSelectedWifiPeer;
private WifiP2pPersistentGroup mSelectedGroup;
- private String mSelectedGroupName;
+ @VisibleForTesting String mSelectedGroupName;
private EditText mDeviceNameText;
private boolean mWifiP2pEnabled;
@@ -100,13 +101,13 @@
private static final int DIALOG_DELETE_GROUP = 4;
private static final String SAVE_DIALOG_PEER = "PEER_STATE";
- private static final String SAVE_DEVICE_NAME = "DEV_NAME";
- private static final String SAVE_SELECTED_GROUP = "GROUP_NAME";
+ @VisibleForTesting static final String SAVE_DEVICE_NAME = "DEV_NAME";
+ @VisibleForTesting static final String SAVE_SELECTED_GROUP = "GROUP_NAME";
private WifiP2pDevice mThisDevice;
private WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
- private String mSavedDeviceName;
+ @VisibleForTesting String mSavedDeviceName;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
index 655e7b6..b8936c4 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java
@@ -52,7 +52,7 @@
private static final ComponentName DUMMY_COMPONENT_NAME2 = new ComponentName(DUMMY_PACKAGE_NAME,
DUMMY_CLASS_NAME2);
private static final String SOFTWARE_SHORTCUT_KEY =
- Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
+ Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
private static final String HARDWARE_SHORTCUT_KEY =
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
index 6cf9ad6..10d8af7 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
@@ -40,7 +40,7 @@
private static final ComponentName DUMMY_COMPONENT_NAME = new ComponentName(DUMMY_PACKAGE_NAME,
DUMMY_CLASS_NAME);
private static final String SOFTWARE_SHORTCUT_KEY =
- Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
+ Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
private static final String HARDWARE_SHORTCUT_KEY =
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
private static final String TRIPLETAP_SHORTCUT_KEY =
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index d6f3e94..210f0fd7 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -19,7 +19,6 @@
import static android.net.ConnectivityManager.TYPE_WIFI;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
@@ -159,8 +158,6 @@
doReturn(CARRIER_NAME).when(mSubscriptionInfo).getCarrierName();
doReturn(mSubscriptionInfo).when(mController).getSubscriptionInfo(mDefaultSubscriptionId);
doReturn(mSubscriptionPlans).when(mController).getSubscriptionPlans(mDefaultSubscriptionId);
-
- doReturn(true).when(mController).hasSim();
}
@After
@@ -356,55 +353,15 @@
}
@Test
- public void testSummaryUpdate_noSim_shouldSetWifiMode() {
- mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
- mController.mDataUsageController = mDataUsageController;
- doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
- doReturn(false).when(mController).hasSim();
-
- final long now = System.currentTimeMillis();
- final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
- info.warningLevel = BillingCycleSettings.MIB_IN_BYTES;
- info.limitLevel = BillingCycleSettings.MIB_IN_BYTES;
-
- final Intent intent = new Intent();
-
- doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
- setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
-
- mController.updateState(mSummaryPreference);
-
- verify(mSummaryPreference).setWifiMode(true /* isWifiMode */, info.period /* usagePeriod */,
- false /* isSingleWifi */);
- verify(mSummaryPreference).setLimitInfo(null);
- verify(mSummaryPreference).setUsageNumbers(info.usageLevel, -1L, true);
- verify(mSummaryPreference).setChartEnabled(false);
- verify(mSummaryPreference).setUsageInfo(info.cycleEnd, -1L, null, 0, null);
- }
-
- @Test
public void testMobileData_preferenceAvailable() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void testMobileData_noSimNoWifi_preferenceDisabled() {
- final int subscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- mController.init(subscriptionId);
- mController.mDataUsageController = mDataUsageController;
- doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
- doReturn(false).when(mController).hasSim();
- when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
- assertThat(mController.getAvailabilityStatus())
- .isEqualTo(CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
public void testMobileData_noSimWifi_preferenceDisabled() {
final int subscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mController.init(subscriptionId);
mController.mDataUsageController = mDataUsageController;
- doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java
new file mode 100644
index 0000000..ba6a075
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2020 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.wifi.p2p;
+
+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.os.Bundle;
+
+import androidx.fragment.app.FragmentActivity;
+
+import com.android.settings.testutils.XmlTestUtils;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiP2pSettingsTest {
+
+ private Context mContext;
+ private FragmentActivity mActivity;
+ private WifiP2pSettings mFragment;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mActivity = Robolectric.setupActivity(FragmentActivity.class);
+ mFragment = spy(new WifiP2pSettings());
+ }
+
+ @Test
+ public void preferenceScreenKey_shouldContainsAllControllerKeys() {
+ final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(mContext,
+ mFragment.getPreferenceScreenResId());
+ final List<String> preferenceKeys = new ArrayList<>();
+
+ for (AbstractPreferenceController controller : mFragment.createPreferenceControllers(
+ mContext)) {
+ preferenceKeys.add(controller.getPreferenceKey());
+ }
+
+ assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys);
+ }
+
+ @Test
+ public void onActivityCreate_withNullBundle_canNotGetValue() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+
+ mFragment.onActivityCreated(null);
+
+ assertThat(mFragment.mSelectedWifiPeer).isNull();
+ }
+
+ @Test
+ public void onActivityCreate_withDeviceName_shouldGetDeviceName() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ final String fakeDeviceName = "fakename";
+ final Bundle bundle = new Bundle();
+ bundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
+
+ mFragment.onActivityCreated(bundle);
+
+ assertThat(mFragment.mSavedDeviceName).isEqualTo(fakeDeviceName);
+ }
+
+ @Test
+ public void onActivityCreate_withGroupName_shouldGetGroupName() {
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ final String fakeGroupName = "fakegroup";
+ final Bundle bundle = new Bundle();
+ bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
+
+ mFragment.onActivityCreated(bundle);
+
+ assertThat(mFragment.mSelectedGroupName).isEqualTo(fakeGroupName);
+ assertThat(mFragment.mSavedDeviceName).isNull();
+ }
+}