diff --git a/proguard.flags b/proguard.flags index b66a7862df2..d509dba9797 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 * extends com.android.settings.core.BasePreferenceController { +-keep class !com.google.android.settings.aware.*, * extends com.android.settings.core.BasePreferenceController { *; } diff --git a/protos/contextual_card_list.proto b/protos/contextual_card_list.proto index 5645c8740a5..37383ba4b98 100644 --- a/protos/contextual_card_list.proto +++ b/protos/contextual_card_list.proto @@ -18,7 +18,7 @@ message ContextualCard { SUGGESTION = 1; POSSIBLE = 2; IMPORTANT = 3; - EXCLUSIVE = 4; + EXCLUSIVE = 4 [deprecated = true]; DEFERRED_SETUP = 5; } diff --git a/res/layout/radio_info.xml b/res/layout/radio_info.xml index 100521e57d5..fc8cc263c2a 100644 --- a/res/layout/radio_info.xml +++ b/res/layout/radio_info.xml @@ -182,6 +182,14 @@ android:layout_height="wrap_content" android:text="@string/cbrs_data_switch_string" /> + + + Cbrs Data + + Enable DSDS + + + Restart Device? + + + You need to restart your device to change this setting. + + + Restart + + + Cancel + Mobile Radio Power @@ -9590,8 +9605,8 @@ %d apps can use unrestricted data - - More + + See more Really wipe user data and convert to file encryption? @@ -9775,11 +9790,6 @@ To check time, notifications, and other info, pick up your device. - - Wake lock screen gesture - - - Tap to check phone @@ -10553,7 +10563,7 @@ Privacy - Permissions, activity controls, data shown on screen + Permissions, web activity, personal data Remove diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml index 4b17bd95e15..b1250ec79db 100644 --- a/res/xml/gestures.xml +++ b/res/xml/gestures.xml @@ -33,12 +33,6 @@ android:fragment="com.android.settings.gestures.WakeScreenGestureSettings" settings:controller="com.android.settings.gestures.WakeScreenGesturePreferenceController" /> - - - - - - - - - - - \ No newline at end of file diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java index 251bfbc0ad2..db6bd9b8983 100644 --- a/src/com/android/settings/RadioInfo.java +++ b/src/com/android/settings/RadioInfo.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.app.QueuedWork; import android.content.ComponentName; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -40,6 +41,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Settings; +import android.provider.Telephony; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentityCdma; import android.telephony.CellIdentityGsm; @@ -81,11 +83,13 @@ import android.widget.Switch; import android.widget.TextView; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AlertDialog.Builder; import com.android.ims.ImsConfig; import com.android.ims.ImsException; import com.android.ims.ImsManager; import com.android.internal.telephony.Phone; +import com.android.internal.telephony.PhoneConfigurationManager; import com.android.internal.telephony.PhoneFactory; import java.io.IOException; @@ -93,6 +97,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; +// TODO(b/123598192) consider to move this activity to telephony package. public class RadioInfo extends Activity { private static final String TAG = "RadioInfo"; @@ -214,6 +219,7 @@ public class RadioInfo extends Activity { private Switch imsWfcProvisionedSwitch; private Switch eabProvisionedSwitch; private Switch cbrsDataSwitch; + private Switch dsdsSwitch; private Spinner preferredNetworkType; private Spinner cellInfoRefreshRateSpinner; @@ -454,6 +460,23 @@ public class RadioInfo extends Activity { cbrsDataSwitch = (Switch) findViewById(R.id.cbrs_data_switch); cbrsDataSwitch.setVisibility(isCbrsSupported() ? View.VISIBLE : View.GONE); + dsdsSwitch = findViewById(R.id.dsds_switch); + if (isDsdsSupported()) { + dsdsSwitch.setVisibility(View.VISIBLE); + dsdsSwitch.setOnClickListener(v -> { + if (mTelephonyManager.isRebootRequiredForModemConfigChange()) { + // Undo the click action until user clicks the confirm dialog. + dsdsSwitch.toggle(); + showDsdsChangeDialog(); + } else { + performDsdsSwitch(); + } + }); + dsdsSwitch.setChecked(isDsdsEnabled()); + } else { + dsdsSwitch.setVisibility(View.GONE); + } + radioPowerOnSwitch = (Switch) findViewById(R.id.radio_power); mDownlinkKbps = (TextView) findViewById(R.id.dl_kbps); @@ -1525,5 +1548,38 @@ public class RadioInfo extends Activity { } }; + private void showDsdsChangeDialog() { + final AlertDialog confirmDialog = new Builder(RadioInfo.this) + .setTitle(R.string.dsds_dialog_title) + .setMessage(R.string.dsds_dialog_message) + .setPositiveButton(R.string.dsds_dialog_confirm, mOnDsdsDialogConfirmedListener) + .setNegativeButton(R.string.dsds_dialog_cancel, mOnDsdsDialogConfirmedListener) + .create(); + confirmDialog.show(); + } + private static boolean isDsdsSupported() { + return PhoneConfigurationManager.getInstance().getStaticPhoneCapability() + .logicalModemList.size() >= 2 + && !TelephonyManager.getDefault().isMultisimCarrierRestricted(); + } + + private static boolean isDsdsEnabled() { + return TelephonyManager.getDefault().getPhoneCount() > 1; + } + + private void performDsdsSwitch() { + mTelephonyManager.switchMultiSimConfig(dsdsSwitch.isChecked() ? 2 : 1); + } + + DialogInterface.OnClickListener mOnDsdsDialogConfirmedListener = + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_POSITIVE) { + dsdsSwitch.toggle(); + performDsdsSwitch(); + } + } + }; } diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java index 7f14c0d8e2c..d1c2fd51de9 100644 --- a/src/com/android/settings/core/FeatureFlags.java +++ b/src/com/android/settings/core/FeatureFlags.java @@ -28,4 +28,5 @@ public class FeatureFlags { public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2"; public static final String WIFI_SHARING = "settings_wifi_sharing"; public static final String SLICE_INJECTION = "settings_slice_injection"; + public static final String MAINLINE_MODULE = "settings_mainline_module"; } diff --git a/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java index d6fcc38bf7f..0dc953d1599 100644 --- a/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java +++ b/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java @@ -19,9 +19,11 @@ package com.android.settings.deviceinfo.firmwareversion; import android.content.Context; import android.content.pm.PackageManager; import android.text.TextUtils; +import android.util.FeatureFlagUtils; import android.util.Log; import com.android.settings.R; +import com.android.settings.core.FeatureFlags; import androidx.annotation.VisibleForTesting; @@ -48,6 +50,11 @@ public class ModuleVersionDialogController { * Updates the mainline module version field of the dialog. */ public void initialize() { + if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) { + mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID); + mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID); + return; + } final String moduleProvider = mContext.getString( com.android.internal.R.string.config_defaultModuleMetadataProvider); if (!TextUtils.isEmpty(moduleProvider)) { diff --git a/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceController.java b/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceController.java deleted file mode 100644 index 2b61ec8d522..00000000000 --- a/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceController.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2018 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.gestures; - -import static android.provider.Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE; - -import android.annotation.UserIdInt; -import android.content.Context; -import android.os.UserHandle; -import android.provider.Settings; -import android.text.TextUtils; - -import com.android.internal.hardware.AmbientDisplayConfiguration; - -public class WakeLockScreenGesturePreferenceController extends GesturePreferenceController { - - private static final int ON = 1; - private static final int OFF = 0; - - private static final String PREF_KEY_VIDEO = "gesture_wake_lock_screen_video"; - private final String mWakeLockScreenPrefKey; - - private AmbientDisplayConfiguration mAmbientConfig; - @UserIdInt - private final int mUserId; - - public WakeLockScreenGesturePreferenceController(Context context, String key) { - super(context, key); - mUserId = UserHandle.myUserId(); - mWakeLockScreenPrefKey = key; - } - - public WakeLockScreenGesturePreferenceController - setConfig(AmbientDisplayConfiguration config) { - mAmbientConfig = config; - return this; - } - - @Override - public int getAvailabilityStatus() { - // No hardware support for this Gesture - if (!getAmbientConfig().wakeScreenGestureAvailable()) { - return UNSUPPORTED_ON_DEVICE; - } - - return AVAILABLE; - } - - @Override - public boolean isSliceable() { - return TextUtils.equals(getPreferenceKey(), "gesture_wake_lock_screen"); - } - - @Override - protected String getVideoPrefKey() { - return PREF_KEY_VIDEO; - } - - @Override - public boolean isChecked() { - return getAmbientConfig().wakeLockScreenGestureEnabled(mUserId); - } - - @Override - public String getPreferenceKey() { - return mWakeLockScreenPrefKey; - } - - @Override - public boolean setChecked(boolean isChecked) { - return Settings.Secure.putInt(mContext.getContentResolver(), DOZE_WAKE_LOCK_SCREEN_GESTURE, - isChecked ? ON : OFF); - } - - private AmbientDisplayConfiguration getAmbientConfig() { - if (mAmbientConfig == null) { - mAmbientConfig = new AmbientDisplayConfiguration(mContext); - } - - return mAmbientConfig; - } -} diff --git a/src/com/android/settings/gestures/WakeLockScreenGestureSettings.java b/src/com/android/settings/gestures/WakeLockScreenGestureSettings.java deleted file mode 100644 index 0fbdaa1a3a4..00000000000 --- a/src/com/android/settings/gestures/WakeLockScreenGestureSettings.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2018 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.gestures; - -import android.app.settings.SettingsEnums; -import android.content.Context; -import android.content.SharedPreferences; -import android.provider.SearchIndexableResource; - -import com.android.internal.hardware.AmbientDisplayConfiguration; -import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider; -import com.android.settings.overlay.FeatureFactory; -import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settingslib.search.SearchIndexable; - -import java.util.Arrays; -import java.util.List; - -@SearchIndexable -public class WakeLockScreenGestureSettings extends DashboardFragment { - - private static final String TAG = "WakeLockScreenGestureSettings"; - - public static final String PREF_KEY_SUGGESTION_COMPLETE = - "pref_wake_lock_screen_gesture_suggestion_complete"; - - @Override - public void onAttach(Context context) { - super.onAttach(context); - SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) - .getSuggestionFeatureProvider(context); - SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); - prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); - - use(WakeLockScreenGesturePreferenceController.class) - .setConfig(new AmbientDisplayConfiguration(context)); - } - - @Override - public int getMetricsCategory() { - return SettingsEnums.SETTINGS_GESTURE_WAKE_LOCK_SCREEN; - } - - @Override - protected String getLogTag() { - return TAG; - } - - @Override - protected int getPreferenceScreenResId() { - return R.xml.wake_lock_screen_gesture_settings; - } - - public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider() { - @Override - public List getXmlResourcesToIndex( - Context context, boolean enabled) { - final SearchIndexableResource sir = new SearchIndexableResource(context); - sir.xmlResId = R.xml.wake_lock_screen_gesture_settings; - return Arrays.asList(sir); - } - }; - -} diff --git a/src/com/android/settings/gestures/WakeScreenGesturePreferenceController.java b/src/com/android/settings/gestures/WakeScreenGesturePreferenceController.java index 2c7bed254dd..a43fad1e733 100644 --- a/src/com/android/settings/gestures/WakeScreenGesturePreferenceController.java +++ b/src/com/android/settings/gestures/WakeScreenGesturePreferenceController.java @@ -26,6 +26,8 @@ import android.text.TextUtils; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.hardware.AmbientDisplayConfiguration; +import com.android.settings.aware.AwareFeatureProvider; +import com.android.settings.overlay.FeatureFactory; public class WakeScreenGesturePreferenceController extends GesturePreferenceController { @@ -34,6 +36,7 @@ public class WakeScreenGesturePreferenceController extends GesturePreferenceCont private static final String PREF_KEY_VIDEO = "gesture_wake_screen_video"; + private final AwareFeatureProvider mFeatureProvider; private AmbientDisplayConfiguration mAmbientConfig; @UserIdInt private final int mUserId; @@ -41,16 +44,16 @@ public class WakeScreenGesturePreferenceController extends GesturePreferenceCont public WakeScreenGesturePreferenceController(Context context, String key) { super(context, key); mUserId = UserHandle.myUserId(); + mFeatureProvider = FeatureFactory.getFactory(context).getAwareFeatureProvider(); } @Override public int getAvailabilityStatus() { - // No hardware support for Wake Screen Gesture - if (!getAmbientConfig().wakeScreenGestureAvailable()) { + if (!getAmbientConfig().wakeScreenGestureAvailable() + || !mFeatureProvider.isSupported(mContext)) { return UNSUPPORTED_ON_DEVICE; } - - return AVAILABLE; + return mFeatureProvider.isEnabled(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } @Override diff --git a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java index ae111b20812..f1ce0af9da2 100644 --- a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java +++ b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java @@ -23,6 +23,7 @@ import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; +import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; @@ -62,7 +63,11 @@ public class VibrateWhenRingPreferenceController extends TogglePreferenceControl @Override @AvailabilityStatus public int getAvailabilityStatus() { - return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + // If ramping ringer is enabled then this setting will be injected + // with additional options. + return Utils.isVoiceCapable(mContext) && !isRampingRingerEnabled() + ? AVAILABLE + : UNSUPPORTED_ON_DEVICE; } @Override @@ -123,4 +128,19 @@ public class VibrateWhenRingPreferenceController extends TogglePreferenceControl } } } + + private boolean isRampingRingerEnabled() { + String enableRampingRinger = DeviceConfig.getProperty( + DeviceConfig.Telephony.NAMESPACE, + DeviceConfig.Telephony.RAMPING_RINGER_ENABLED); + if (enableRampingRinger == null) { + return false; + } + try { + return Boolean.valueOf(enableRampingRinger); + } catch (Exception e) { + return false; + } + } + } diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java index e5958aab550..b84ea99d072 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java @@ -25,6 +25,9 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.util.FeatureFlagUtils; + +import com.android.settings.core.FeatureFlags; import org.junit.Before; import org.junit.Test; @@ -52,6 +55,17 @@ public class ModuleVersionDialogControllerTest { when(mDialog.getContext()).thenReturn(mContext); when(mContext.getPackageManager()).thenReturn(mPackageManager); mController = new ModuleVersionDialogController(mDialog); + FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, true); + } + + @Test + public void initialize_featureDisabled_shouldRemoveSettingFromDialog() { + FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, false); + + mController.initialize(); + + verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID); + verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID); } @Test diff --git a/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceControllerTest.java deleted file mode 100644 index cd213511503..00000000000 --- a/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGesturePreferenceControllerTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2018 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.gestures; - -import static com.android.settings.core.BasePreferenceController.AVAILABLE; -import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.when; - -import android.content.Context; - -import com.android.internal.hardware.AmbientDisplayConfiguration; - -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; - -@RunWith(RobolectricTestRunner.class) -public class WakeLockScreenGesturePreferenceControllerTest { - - private static final String KEY_WAKE_LOCK_SCREEN = "gesture_wake_lock_screen"; - - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - @Mock - private AmbientDisplayConfiguration mAmbientDisplayConfiguration; - - private WakeLockScreenGesturePreferenceController mController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mController = new WakeLockScreenGesturePreferenceController(mContext, KEY_WAKE_LOCK_SCREEN); - mController.setConfig(mAmbientDisplayConfiguration); - } - - @Test - public void testIsChecked_configIsSet_shouldReturnTrue() { - // Set the setting to be enabled. - when(mAmbientDisplayConfiguration.wakeLockScreenGestureEnabled(anyInt())).thenReturn(true); - assertThat(mController.isChecked()).isTrue(); - } - - @Test - public void testIsChecked_configIsNotSet_shouldReturnFalse() { - // Set the setting to be disabled. - when(mAmbientDisplayConfiguration.wakeLockScreenGestureEnabled(anyInt())).thenReturn(false); - assertThat(mController.isChecked()).isFalse(); - } - - @Test - public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() { - when(mAmbientDisplayConfiguration.wakeScreenGestureAvailable()).thenReturn(false); - final int availabilityStatus = mController.getAvailabilityStatus(); - - assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE); - } - - @Test - public void getAvailabilityStatus_gestureSupported_AVAILABLE() { - when(mAmbientDisplayConfiguration.wakeScreenGestureAvailable()).thenReturn(true); - final int availabilityStatus = mController.getAvailabilityStatus(); - - assertThat(availabilityStatus).isEqualTo(AVAILABLE); - } - - @Test - public void isSliceableCorrectKey_returnsTrue() { - final WakeLockScreenGesturePreferenceController controller = - new WakeLockScreenGesturePreferenceController(mContext, KEY_WAKE_LOCK_SCREEN); - assertThat(controller.isSliceable()).isTrue(); - } - - @Test - public void isSliceableIncorrectKey_returnsFalse() { - final WakeLockScreenGesturePreferenceController controller = - new WakeLockScreenGesturePreferenceController(mContext, "bad_key"); - assertThat(controller.isSliceable()).isFalse(); - } -} diff --git a/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGestureSettingsTest.java deleted file mode 100644 index 686a0fff628..00000000000 --- a/tests/robotests/src/com/android/settings/gestures/WakeLockScreenGestureSettingsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2018 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.gestures; - -import static com.google.common.truth.Truth.assertThat; - -import android.provider.SearchIndexableResource; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -import java.util.List; - -@RunWith(RobolectricTestRunner.class) -public class WakeLockScreenGestureSettingsTest { - - private WakeLockScreenGestureSettings mSettings; - - @Before - public void setUp() { - mSettings = new WakeLockScreenGestureSettings(); - } - - @Test - public void testSearchIndexProvider_shouldIndexResource() { - final List indexRes = - WakeLockScreenGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( - RuntimeEnvironment.application, true /* enabled */); - - assertThat(indexRes).isNotNull(); - assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); - } -} diff --git a/tests/robotests/src/com/android/settings/gestures/WakeScreenGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/WakeScreenGesturePreferenceControllerTest.java index ebc0f27f7ca..61495390d39 100644 --- a/tests/robotests/src/com/android/settings/gestures/WakeScreenGesturePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/WakeScreenGesturePreferenceControllerTest.java @@ -21,12 +21,15 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import android.content.Context; import com.android.internal.hardware.AmbientDisplayConfiguration; +import com.android.settings.aware.AwareFeatureProvider; +import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; @@ -45,12 +48,15 @@ public class WakeScreenGesturePreferenceControllerTest { private Context mContext; @Mock private AmbientDisplayConfiguration mAmbientDisplayConfiguration; - private WakeScreenGesturePreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); + AwareFeatureProvider featureProvider = + FakeFeatureFactory.setupForTest().getAwareFeatureProvider(); + when(featureProvider.isSupported(any())).thenReturn(true); + when(featureProvider.isEnabled(any())).thenReturn(true); mController = new WakeScreenGesturePreferenceController(mContext, KEY_WAKE_SCREEN); mController.setConfig(mAmbientDisplayConfiguration); } diff --git a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java index 4f3dce6c22b..56d0828ca2c 100644 --- a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java +++ b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java @@ -32,6 +32,7 @@ import android.preference.SeekBarVolumizer; import com.android.settings.R; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.ShadowAudioHelper; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowUserManager; import org.junit.Test; @@ -47,7 +48,7 @@ import java.util.List; public class SoundSettingsTest { @Test - @Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class}) + @Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class, ShadowDeviceConfig.class}) public void getNonIndexableKeys_existInXmlLayout() { final Context context = spy(RuntimeEnvironment.application); AudioManager audioManager = mock(AudioManager.class); diff --git a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java index 7334b452267..3f53ce923cd 100644 --- a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; +import android.provider.DeviceConfig; import android.provider.Settings; import android.telephony.TelephonyManager; @@ -36,17 +37,21 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import androidx.preference.TwoStatePreference; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowContentResolver; @RunWith(RobolectricTestRunner.class) +@Config(shadows={ShadowDeviceConfig.class}) public class VibrateWhenRingPreferenceControllerTest { private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing"; @@ -74,20 +79,42 @@ public class VibrateWhenRingPreferenceControllerTest { } @Test - public void display_voiceCapable_shouldDisplay() { + public void display_shouldDisplay() { when(mTelephonyManager.isVoiceCapable()).thenReturn(true); - + DeviceConfig.setProperty("namespace", "key", "false", false); mController.displayPreference(mScreen); - assertThat(mPreference.isVisible()).isTrue(); } @Test - public void display_notVoiceCapable_shouldNotDisplay() { + public void display_shouldNotDisplay_notVoiceCapable() { when(mTelephonyManager.isVoiceCapable()).thenReturn(false); - + DeviceConfig.setProperty("namespace", "key", "false", false); mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isFalse(); + } + @Test + public void display_shouldNotDisplay_RampingRingerEnabled() { + when(mTelephonyManager.isVoiceCapable()).thenReturn(true); + DeviceConfig.setProperty("namespace", "key", "true", false); + mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isFalse(); + } + + @Test + public void display_shouldNotDisplay_VoiceEnabled_RampingRingerEnabled() { + when(mTelephonyManager.isVoiceCapable()).thenReturn(true); + DeviceConfig.setProperty("namespace", "key", "true", false); + mController.displayPreference(mScreen); + assertThat(mPreference.isVisible()).isFalse(); + } + + @Test + public void display_shouldNotDisplay_VoiceDisabled_RampingRingerEnabled() { + when(mTelephonyManager.isVoiceCapable()).thenReturn(false); + DeviceConfig.setProperty("namespace", "key", "true", false); + mController.displayPreference(mScreen); assertThat(mPreference.isVisible()).isFalse(); } @@ -112,14 +139,14 @@ public class VibrateWhenRingPreferenceControllerTest { @Test public void voiceCapable_availabled() { when(mTelephonyManager.isVoiceCapable()).thenReturn(true); - + DeviceConfig.setProperty("namespace", "key", "false", false); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void voiceCapable_notAvailabled() { when(mTelephonyManager.isVoiceCapable()).thenReturn(false); - + DeviceConfig.setProperty("namespace", "key", "false", false); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @@ -197,4 +224,5 @@ public class VibrateWhenRingPreferenceControllerTest { new VibrateWhenRingPreferenceController(mContext, "bad_key"); assertThat(controller.isSliceable()).isFalse(); } + } diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java new file mode 100644 index 00000000000..d46e7556793 --- /dev/null +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2018 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.testutils.shadow; + +import org.robolectric.annotation.Config; +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; + +@Implements(android.provider.DeviceConfig.class) +public class ShadowDeviceConfig { + + private static String configValue; + + @Implementation + protected static boolean setProperty( + String namespace, String name, String value, boolean makeDefault) { + configValue = value; + return true; + } + + @Implementation + protected static String getProperty(String ns, String key) { return configValue; } +} + +