Merge "Revert "Get rid of SearchIndexableResources entirely.""
diff --git a/res/values/config.xml b/res/values/config.xml
index 4ba73cc..097350b 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -41,9 +41,6 @@
<!-- Whether to show Connectivity Monitor switch in Developer Options -->
<bool name="config_show_connectivity_monitor">false</bool>
- <!-- Whether to show Camera HAL HDR+ switch in Developer Options -->
- <bool name="config_show_camera_hal_hdrplus">false</bool>
-
<!-- Whether to show Camera laser sensor switch in Developer Options -->
<bool name="config_show_camera_laser_sensor">false</bool>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d08d314..3b474ab 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8277,12 +8277,6 @@
<!-- Toast message letting the user know the how to apply connectivity monitor change -->
<string name="connectivity_monitor_toast">To apply connectivity monitor change, reboot device</string>
- <!-- Title for Camera HAL HDR+ switch [CHAR LIMIT=50] -->
- <string name="camera_hal_hdrplus_switch">Camera HAL HDR+</string>
-
- <!-- Toast message letting the user know how to enable Camera HAL HDR+ -->
- <string name="camera_hal_hdrplus_toast">To apply Camera HAL HDR+ change, reboot device</string>
-
<!-- Title for Camera laser sensor switch [CHAR LIMIT=NONE] -->
<string name="camera_laser_sensor_switch">Camera Laser Sensor</string>
diff --git a/res/xml/app_default_settings.xml b/res/xml/app_default_settings.xml
index 0204c64..4d5c9d7 100644
--- a/res/xml/app_default_settings.xml
+++ b/res/xml/app_default_settings.xml
@@ -33,7 +33,7 @@
<extra android:name="for_work" android:value="false" />
</com.android.settings.widget.AppPreference>
- <com.android.settings.widget.AppPreference
+ <com.android.settings.widget.GearPreference
android:key="default_home"
android:title="@string/home_app"
android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index c8c57a5..669f4fb 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -172,10 +172,6 @@
android:key="camera_laser_sensor_switch"
android:title="@string/camera_laser_sensor_switch" />
- <SwitchPreference
- android:key="camera_hal_hdrplus_switch"
- android:title="@string/camera_hal_hdrplus_switch" />
-
<Preference
android:key="feature_flags_dashboard"
android:title="@string/feature_flags_dashboard_title"
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index f265f98..a3d26af 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -150,8 +150,8 @@
}
// Prepare help url and enable menu if necessary
- final Bundle arguments = getArguments();
- final int helpResource;
+ Bundle arguments = getArguments();
+ int helpResource;
if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
helpResource = arguments.getInt(HELP_URI_RESOURCE_KEY);
} else {
@@ -160,14 +160,6 @@
if (helpResource != 0) {
mHelpUri = getResources().getString(helpResource);
}
-
- // Check if we should keep the preferences expanded.
- if (arguments != null) {
- mPreferenceKey = arguments.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
- if (!TextUtils.isEmpty(mPreferenceKey)) {
- getPreferenceScreen().setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- }
- }
}
@Override
@@ -232,7 +224,9 @@
public void onResume() {
super.onResume();
- if (mPreferenceKey != null) {
+ final Bundle args = getArguments();
+ if (args != null) {
+ mPreferenceKey = args.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
highlightPreferenceIfNeeded();
}
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
index bd8b5d1..a7d65d3 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
@@ -63,7 +63,7 @@
if (currentDefaultHome != null) {
return new DefaultAppInfo(mContext, mPackageManager, mUserId, currentDefaultHome);
}
- final ActivityInfo onlyAppInfo = getOnlyAppInfo();
+ final ActivityInfo onlyAppInfo = getOnlyAppInfo(homeActivities);
if (onlyAppInfo != null) {
return new DefaultAppInfo(mContext, mPackageManager, mUserId,
onlyAppInfo.getComponentName());
@@ -71,8 +71,7 @@
return null;
}
- private ActivityInfo getOnlyAppInfo() {
- final List<ResolveInfo> homeActivities = new ArrayList<>();
+ private ActivityInfo getOnlyAppInfo(List<ResolveInfo> homeActivities) {
final List<ActivityInfo> appLabels = new ArrayList<>();
mPackageManager.getHomeActivities(homeActivities);
@@ -88,6 +87,23 @@
: null;
}
+ @Override
+ protected Intent getSettingIntent(DefaultAppInfo info) {
+ final String packageName;
+ if (info.componentName != null) {
+ packageName = info.componentName.getPackageName();
+ } else if (info.packageItemInfo != null) {
+ packageName = info.packageItemInfo.packageName;
+ } else {
+ return null;
+ }
+
+ Intent intent = new Intent(Intent.ACTION_APPLICATION_PREFERENCES)
+ .setPackage(packageName)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ return mPackageManager.queryIntentActivities(intent, 0).size() == 1 ? intent : null;
+ }
+
public static boolean hasHomePreference(String pkg, Context context) {
ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
PackageManager pm = context.getPackageManager();
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsController.java b/src/com/android/settings/bluetooth/BluetoothDetailsController.java
index 265690b..63d7b5c 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsController.java
@@ -72,8 +72,8 @@
@Override
public final void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
init(screen);
+ super.displayPreference(screen);
}
/**
diff --git a/src/com/android/settings/datetime/ZonePicker.java b/src/com/android/settings/datetime/ZonePicker.java
index 00a77df..57f9b7d 100644
--- a/src/com/android/settings/datetime/ZonePicker.java
+++ b/src/com/android/settings/datetime/ZonePicker.java
@@ -22,6 +22,7 @@
import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -39,6 +40,7 @@
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
import com.android.settingslib.datetime.ZoneGetter;
+import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -261,15 +263,21 @@
mVisibilityLoggerMixin.onPause();
}
- private static class MyComparator implements Comparator<Map<?, ?>> {
+ @VisibleForTesting
+ static class MyComparator implements Comparator<Map<?, ?>> {
+ private final Collator mCollator;
private String mSortingKey;
+ private boolean mSortedByName;
public MyComparator(String sortingKey) {
+ mCollator = Collator.getInstance();
mSortingKey = sortingKey;
+ mSortedByName = ZoneGetter.KEY_DISPLAY_LABEL.equals(sortingKey);
}
public void setSortingKey(String sortingKey) {
mSortingKey = sortingKey;
+ mSortedByName = ZoneGetter.KEY_DISPLAY_LABEL.equals(sortingKey);
}
public int compare(Map<?, ?> map1, Map<?, ?> map2) {
@@ -286,7 +294,11 @@
return -1;
}
- return ((Comparable) value1).compareTo(value2);
+ if (mSortedByName) {
+ return mCollator.compare(value1, value2);
+ } else {
+ return ((Comparable) value1).compareTo(value2);
+ }
}
private boolean isComparable(Object value) {
diff --git a/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java b/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java
deleted file mode 100644
index a5390cc..0000000
--- a/src/com/android/settings/development/CameraHalHdrplusPreferenceController.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development;
-
-import android.content.Context;
-import android.os.SystemProperties;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.widget.Toast;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-/**
- * deprecated in favor of {@link CameraHalHdrPlusPreferenceControllerV2}
- */
-@Deprecated
-public class CameraHalHdrplusPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
-
- private static final String KEY_CAMERA_HAL_HDRPLUS_SWITCH = "camera_hal_hdrplus_switch";
- @VisibleForTesting
- static final String BUILD_TYPE = "ro.build.type";
- @VisibleForTesting
- static final String PROPERTY_CAMERA_HAL_HDRPLUS = "persist.camera.hdrplus.enable";
- @VisibleForTesting
- static final String ENABLED = "1";
- @VisibleForTesting
- static final String DISABLED = "0";
-
- private SwitchPreference mPreference;
-
- public CameraHalHdrplusPreferenceController(Context context) {
- super(context);
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- if (isAvailable()) {
- mPreference = (SwitchPreference) screen.findPreference(KEY_CAMERA_HAL_HDRPLUS_SWITCH);
- mPreference.setChecked(isHalHdrplusEnabled());
- }
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_CAMERA_HAL_HDRPLUS_SWITCH;
- }
-
- @Override
- public boolean isAvailable() {
- return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus);
- }
-
- @Override
- public void updateState(Preference preference) {
- updatePreference();
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (KEY_CAMERA_HAL_HDRPLUS_SWITCH.equals(preference.getKey())) {
- final SwitchPreference switchPreference = (SwitchPreference)preference;
- SystemProperties.set(PROPERTY_CAMERA_HAL_HDRPLUS,
- switchPreference.isChecked() ? ENABLED : DISABLED);
- Toast.makeText(mContext, R.string.camera_hal_hdrplus_toast,
- Toast.LENGTH_LONG).show();
- return true;
- }
- return false;
- }
-
- public void enablePreference(boolean enabled) {
- if (isAvailable()) {
- mPreference.setEnabled(enabled);
- }
- }
-
- public boolean updatePreference() {
- if (!isAvailable()) {
- return false;
- }
- final boolean enabled = isHalHdrplusEnabled();
- mPreference.setChecked(enabled);
- return enabled;
- }
-
- private boolean isHalHdrplusEnabled() {
- return SystemProperties.getBoolean(PROPERTY_CAMERA_HAL_HDRPLUS, true);
- }
-}
diff --git a/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2.java b/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2.java
deleted file mode 100644
index b8828fe..0000000
--- a/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development;
-
-import android.content.Context;
-import android.os.SystemProperties;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.widget.Toast;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-
-public class CameraHalHdrplusPreferenceControllerV2 extends
- DeveloperOptionsPreferenceController implements
- Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
-
- private static final String KEY_CAMERA_HAL_HDRPLUS_SWITCH = "camera_hal_hdrplus_switch";
- @VisibleForTesting
- static final String BUILD_TYPE = "ro.build.type";
- @VisibleForTesting
- static final String PROPERTY_CAMERA_HAL_HDRPLUS = "persist.camera.hdrplus.enable";
- @VisibleForTesting
- static final String ENABLED = "1";
- @VisibleForTesting
- static final String DISABLED = "0";
-
- private SwitchPreference mPreference;
-
- public CameraHalHdrplusPreferenceControllerV2(Context context) {
- super(context);
- }
-
- @Override
- public boolean isAvailable() {
- final String buildType = SystemProperties.get(BUILD_TYPE);
-
- return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus);
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_CAMERA_HAL_HDRPLUS_SWITCH;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
-
- mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean isEnabled = (Boolean) newValue;
- SystemProperties.set(PROPERTY_CAMERA_HAL_HDRPLUS, isEnabled ? ENABLED : DISABLED);
- Toast.makeText(mContext, R.string.camera_hal_hdrplus_toast, Toast.LENGTH_LONG).show();
- return true;
- }
-
- @Override
- public void updateState(Preference preference) {
- final boolean enabled = isHalHdrplusEnabled();
- mPreference.setChecked(enabled);
- }
-
- @Override
- protected void onDeveloperOptionsSwitchEnabled() {
- mPreference.setEnabled(true);
- }
-
- @Override
- protected void onDeveloperOptionsSwitchDisabled() {
- SystemProperties.set(PROPERTY_CAMERA_HAL_HDRPLUS, DISABLED);
- mPreference.setChecked(false);
- mPreference.setEnabled(false);
- }
-
- private boolean isHalHdrplusEnabled() {
- return SystemProperties.getBoolean(PROPERTY_CAMERA_HAL_HDRPLUS, true /* default */);
- }
-}
diff --git a/src/com/android/settings/development/ClearAdbKeysPreferenceController.java b/src/com/android/settings/development/ClearAdbKeysPreferenceController.java
index b512757..2248b89 100644
--- a/src/com/android/settings/development/ClearAdbKeysPreferenceController.java
+++ b/src/com/android/settings/development/ClearAdbKeysPreferenceController.java
@@ -28,7 +28,6 @@
import android.text.TextUtils;
import android.util.Log;
-import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
@@ -76,10 +75,6 @@
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (Utils.isMonkeyRunning()) {
- return false;
- }
-
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
ClearAdbKeysWarningDialog.show(mFragment);
return true;
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 558ebcf..37296cf 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -336,7 +336,6 @@
private BugReportPreferenceController mBugReportController;
private BugReportInPowerPreferenceController mBugReportInPowerController;
private ConnectivityMonitorPreferenceController mConnectivityMonitorController;
- private CameraHalHdrplusPreferenceController mCameraHalHdrplusController;
private CameraLaserSensorPreferenceController mCameraLaserSensorController;
private BroadcastReceiver mEnableAdbReceiver;
@@ -384,7 +383,6 @@
mLogpersistController = new LogpersistPreferenceController(getActivity(), getLifecycle());
mWebViewAppPrefController = new WebViewAppPreferenceController(getActivity());
mVerifyAppsOverUsbController = new VerifyAppsOverUsbPreferenceController(getActivity());
- mCameraHalHdrplusController = new CameraHalHdrplusPreferenceController(getActivity());
mCameraLaserSensorController = new CameraLaserSensorPreferenceController(getActivity());
setIfOnlyAvailableForAdmins(true);
@@ -421,7 +419,6 @@
mLogdSizeController.displayPreference(preferenceScreen);
mLogpersistController.displayPreference(preferenceScreen);
mWebViewAppPrefController.displayPreference(preferenceScreen);
- mCameraHalHdrplusController.displayPreference(preferenceScreen);
mEnableAdbController.displayPreference(preferenceScreen);
mCameraLaserSensorController.displayPreference(getPreferenceScreen());
@@ -646,7 +643,6 @@
mLogdSizeController.enablePreference(enabled);
mLogpersistController.enablePreference(enabled);
mWebViewAppPrefController.enablePreference(enabled);
- mCameraHalHdrplusController.enablePreference(enabled);
mCameraLaserSensorController.enablePreference(enabled);
updateAllOptions();
}
@@ -793,7 +789,6 @@
}
mHaveDebugSettings |= mBugReportInPowerController.updatePreference();
mHaveDebugSettings |= mConnectivityMonitorController.updatePreference();
- mHaveDebugSettings |= mCameraHalHdrplusController.updatePreference();
mHaveDebugSettings |= mCameraLaserSensorController.updatePreference();
updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
@@ -2260,10 +2255,6 @@
return true;
}
- if (mCameraHalHdrplusController.handlePreferenceTreeClick(preference)) {
- return true;
- }
-
if (mEnableAdbController.handlePreferenceTreeClick(preference)) {
return true;
}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 83f395f..50dfeff 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -135,6 +135,15 @@
}
@Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ if (Utils.isMonkeyRunning()) {
+ getActivity().finish();
+ return;
+ }
+ }
+
+ @Override
public void onActivityCreated(Bundle icicle) {
super.onActivityCreated(icicle);
// Apply page-level restrictions
@@ -377,7 +386,6 @@
controllers.add(new LogPersistPreferenceControllerV2(context, fragment, lifecycle));
controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
- controllers.add(new CameraHalHdrplusPreferenceControllerV2(context));
controllers.add(new WifiDisplayCertificationPreferenceController(context));
controllers.add(new WifiVerboseLoggingPreferenceController(context));
controllers.add(new WifiAggressiveHandoverPreferenceController(context));
diff --git a/src/com/android/settings/development/SelectUsbConfigPreferenceController.java b/src/com/android/settings/development/SelectUsbConfigPreferenceController.java
index 87b206c..59ac23f 100644
--- a/src/com/android/settings/development/SelectUsbConfigPreferenceController.java
+++ b/src/com/android/settings/development/SelectUsbConfigPreferenceController.java
@@ -29,7 +29,6 @@
import android.text.TextUtils;
import com.android.settings.R;
-import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -90,10 +89,6 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (Utils.isMonkeyRunning()) {
- return false;
- }
-
writeUsbConfigurationOption(newValue.toString());
updateUsbConfigurationValues();
return true;
@@ -143,4 +138,5 @@
setCurrentFunction(newValue, true);
}
}
+
}
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 33a1d95..c2909ac 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -15,7 +15,6 @@
-->
<resources>
- <bool name="config_show_camera_hal_hdrplus">false</bool>
<bool name="config_enableColorTemperature">false</bool>
<bool name="config_show_camera_laser_sensor">false</bool>
<bool name="config_show_connectivity_monitor">false</bool>
diff --git a/tests/robotests/res/values/config.xml b/tests/robotests/res/values/config.xml
index 0afbe29..9e2d911 100644
--- a/tests/robotests/res/values/config.xml
+++ b/tests/robotests/res/values/config.xml
@@ -19,6 +19,5 @@
<bool name="config_new_device_intro_suggestion_supported">true</bool>
<bool name="config_enableColorTemperature">true</bool>
<bool name="config_show_camera_laser_sensor">true</bool>
- <bool name="config_show_camera_hal_hdrplus">true</bool>
<bool name="config_show_connectivity_monitor">true</bool>
</resources>
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
index aa92ebb..dc4166d 100644
--- a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java
@@ -16,9 +16,9 @@
package com.android.settings;
+
import android.app.Activity;
import android.content.Context;
-import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceManager;
@@ -39,19 +39,19 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.SettingsShadowResources;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsPreferenceFragmentTest {
private static final int ITEM_COUNT = 5;
@Mock
+ private PreferenceManager mPreferenceManager;
+ @Mock
private Activity mActivity;
@Mock
private View mListContainer;
@@ -142,21 +142,6 @@
assertThat(mEmptyView.getVisibility()).isEqualTo(View.GONE);
}
- @Test
- @Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
- public void onCreate_hasExtraFragmentKey_shouldExpandPreferences() {
- doReturn(mContext.getTheme()).when(mActivity).getTheme();
- doReturn(mContext.getResources()).when(mFragment).getResources();
- doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
- final Bundle bundle = new Bundle();
- bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, "test_key");
- doReturn(bundle).when(mFragment).getArguments();
-
- mFragment.onCreate(null /* icicle */);
-
- verify(mPreferenceScreen).setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- }
-
public static class TestFragment extends SettingsPreferenceFragment {
@Override
@@ -165,4 +150,5 @@
}
}
+
}
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
index ca5c10b..8a8cc29 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
@@ -17,6 +17,9 @@
package com.android.settings.applications.defaultapps;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.anyList;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
@@ -26,6 +29,8 @@
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
import android.os.UserManager;
import android.support.v7.preference.Preference;
@@ -42,6 +47,9 @@
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
+import java.util.Arrays;
+
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DefaultHomePreferenceControllerTest {
@@ -112,4 +120,32 @@
assertThat(DefaultHomePreferenceController.isHomeDefault(pkgName, mPackageManager))
.isFalse();
}
+
+ @Test
+ public void testGetSettingIntent_homeHasNoSetting_shouldNotReturnSettingIntent() {
+ when(mPackageManager.getHomeActivities(anyList())).thenReturn(
+ new ComponentName("test.pkg", "class"));
+ assertThat(mController.getSettingIntent(mController.getDefaultAppInfo())).isNull();
+ }
+
+ @Test
+ public void testGetSettingIntent_homeHasOneSetting_shouldReturnSettingIntent() {
+ when(mPackageManager.getHomeActivities(anyList())).thenReturn(
+ new ComponentName("test.pkg", "class"));
+ when(mPackageManager.queryIntentActivities(any(), eq(0))).thenReturn(
+ Arrays.asList(mock(ResolveInfo.class)));
+
+ Intent intent = mController.getSettingIntent(mController.getDefaultAppInfo());
+ assertThat(intent).isNotNull();
+ assertThat(intent.getPackage()).isEqualTo("test.pkg");
+ }
+
+ @Test
+ public void testGetSettingIntent_homeHasMultipleSettings_shouldNotReturnSettingIntent() {
+ when(mPackageManager.getHomeActivities(anyList())).thenReturn(
+ new ComponentName("test.pkg", "class"));
+ when(mPackageManager.queryIntentActivities(any(), eq(0))).thenReturn(
+ Arrays.asList(mock(ResolveInfo.class), mock(ResolveInfo.class)));
+ assertThat(mController.getSettingIntent(mController.getDefaultAppInfo())).isNull();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerEventsTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerEventsTest.java
index 240ece1..62e4986 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerEventsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerEventsTest.java
@@ -36,7 +36,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows=SettingsShadowBluetoothDevice.class)
public class BluetoothDetailsControllerEventsTest extends BluetoothDetailsControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
index 3b8db04..a02a0c1 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsControllerTestBase.java
@@ -37,7 +37,7 @@
import org.robolectric.RuntimeEnvironment;
public class BluetoothDetailsControllerTestBase {
- protected Context mContext = RuntimeEnvironment.application;
+ protected Context mContext;
protected Lifecycle mLifecycle;
protected DeviceConfig mDeviceConfig;
protected BluetoothDevice mDevice;
@@ -58,6 +58,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
mPreferenceManager = new PreferenceManager(mContext);
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
mDeviceConfig = makeDefaultDeviceConfig();
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index 98a3580..2dc411c 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -45,7 +45,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows={SettingsShadowBluetoothDevice.class, ShadowEntityHeaderController.class,
SettingsShadowResources.class})
public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressControllerTest.java
index 24b28a1..4edcc74 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressControllerTest.java
@@ -17,8 +17,8 @@
import static com.google.common.truth.Truth.assertThat;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowBluetoothDevice;
import com.android.settingslib.widget.FooterPreference;
@@ -27,9 +27,10 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
- shadows=SettingsShadowBluetoothDevice.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
+ shadows = SettingsShadowBluetoothDevice.class)
public class BluetoothDetailsMacAddressControllerTest extends BluetoothDetailsControllerTestBase {
+
private BluetoothDetailsMacAddressController mController;
@Override
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
index 445e4e3..eca5df9 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
@@ -54,7 +54,7 @@
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows=SettingsShadowBluetoothDevice.class)
public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsControllerTestBase {
private BluetoothDetailsProfilesController mController;
diff --git a/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java b/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java
new file mode 100644
index 0000000..4c1794c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/ZonePickerComparatorTest.java
@@ -0,0 +1,123 @@
+package com.android.settings.datetime;
+
+import com.android.settings.datetime.ZonePicker;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.datetime.ZoneGetter;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ZonePickerComparatorTest {
+
+ // Strings in Chinese are sorted by alphabet order of their Pinyin.
+ // "伦敦" -> "lundun"; "纽约" -> "niuyue"; "悉尼" -> "xini"
+ // "开罗" -> "kailuo"; "雅典" -> "yadian"; "上海" -> "shanghai"
+ private static final String[] TEST_CHINESE_NAME =
+ new String[]{"伦敦", "纽约", "悉尼", "开罗", "雅典", "上海"};
+ private static final String[] ORDERED_CHINESE_NAME =
+ new String[]{"开罗", "伦敦", "纽约", "上海", "悉尼", "雅典"};
+
+ private static final String[] TEST_ENGLISH_NAME =
+ new String[]{"London", "New York", "Sydney", "Cairo", "Athens", "Shanghai"};
+ private static final String[] ORDERED_ENGLISH_NAME =
+ new String[]{"Athens", "Cairo", "London", "New York", "Shanghai", "Sydney"};
+
+ private static final Locale INIT_LOCALE = Locale.getDefault();
+
+ private Map<String, List> mTestDataMap;
+ private List<Map<String, Object>> mTestList;
+
+ @Before
+ public void setUp() {
+ mTestDataMap = new HashMap<>();
+ mTestDataMap.put("zh_CN", Arrays.asList(TEST_CHINESE_NAME));
+ mTestDataMap.put("en_US", Arrays.asList(TEST_ENGLISH_NAME));
+ }
+
+ @After
+ public void tearDown() {
+ Locale.setDefault(INIT_LOCALE);
+ }
+
+ @Test
+ public void testComparator_sortChineseString() {
+ String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
+ mTestList = getMockZonesList("zh_CN");
+ Locale.setDefault(new Locale("zh"));
+ final ZonePicker.MyComparator comparator = new ZonePicker.MyComparator(sortKey);
+ assertThat(comparator).isNotNull();
+ Collections.sort(mTestList, comparator);
+ for (int i = 0; i < mTestList.size(); i++) {
+ assertThat(mTestList.get(i).get(sortKey).toString())
+ .isEqualTo(ORDERED_CHINESE_NAME[i]);
+ }
+ }
+
+ @Test
+ public void testComparator_sortEnglishString() {
+ String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
+ mTestList = getMockZonesList("en_US");
+ Locale.setDefault(new Locale("en"));
+ final ZonePicker.MyComparator comparator = new ZonePicker.MyComparator(sortKey);
+ assertThat(comparator).isNotNull();
+ Collections.sort(mTestList, comparator);
+ for (int i = 0; i < mTestList.size(); i++) {
+ assertThat(mTestList.get(i).get(sortKey).toString())
+ .isEqualTo(ORDERED_ENGLISH_NAME[i]);
+ }
+ }
+
+ @Test
+ public void testComparator_sortInteger() {
+ String sortKey = ZoneGetter.KEY_OFFSET;
+ // TestList of any locale can be selected to test integer sorting.
+ mTestList = getMockZonesList("en_US");
+ final ZonePicker.MyComparator comparator = new ZonePicker.MyComparator(sortKey);
+ assertThat(comparator).isNotNull();
+ Collections.sort(mTestList, comparator);
+ for (int i = 0; i < mTestList.size(); i++) {
+ assertThat(mTestList.get(i).get(sortKey)).isEqualTo(i);
+ }
+ }
+
+ private List<Map<String, Object>> getMockZonesList(String locale) {
+ List<Map<String, Object>> zones = new ArrayList<>();
+ List<String> testData = mTestDataMap.get(locale);
+ TimeZone tz = TimeZone.getDefault();
+ int testSize = testData.size();
+ for (int i = 0; i < testSize; i++) {
+ zones.add(createMockDisplayEntry(tz, "GMT+08:00",
+ testData.get(i), testSize - i - 1));
+ }
+ return zones;
+ }
+
+ private Map<String, Object> createMockDisplayEntry(
+ TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ZoneGetter.KEY_ID, tz.getID());
+ map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
+ map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
+ map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
+ map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
+ map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
+ return map;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java
deleted file mode 100644
index 48833e4..0000000
--- a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development;
-
-import android.content.Context;
-import android.os.SystemProperties;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
-
-import org.junit.After;
-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.annotation.Config;
-import org.robolectric.RuntimeEnvironment;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/**
- * deprecated in favor of {@link CameraHalHdrPlusPreferenceControllerV2}
- */
-@Deprecated
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
- shadows = {SettingsShadowSystemProperties.class})
-public class CameraHalHdrplusPreferenceControllerTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Context mContext;
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private SwitchPreference mPreference;
-
- static final String USERDEBUG_BUILD = "userdebug";
-
- private CameraHalHdrplusPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mController = new CameraHalHdrplusPreferenceController(mContext);
- when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
- when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
- }
-
- @After
- public void tearDown() {
- SettingsShadowSystemProperties.clear();
- }
-
- @Test
- public void isAvailable_withConfigNoShow_shouldReturnFalse() {
- when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
- .thenReturn(false);
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void displayPreference_cameraHalHdrplusEnabled_shouldCheckedPreference() {
- when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
- .thenReturn(true);
-
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceController.ENABLED);
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
-
- mController.displayPreference(mScreen);
-
- verify(mPreference).setChecked(true);
- }
-
- @Test
- public void displayPreference_cameraHalHdrplusEnabled_shouldUncheckedPreference() {
- when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
- .thenReturn(true);
-
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceController.DISABLED);
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceController.BUILD_TYPE, USERDEBUG_BUILD);
-
- mController.displayPreference(mScreen);
-
- verify(mPreference).setChecked(false);
- }
-
- @Test
- public void handlePreferenceTreeClick_preferenceChecked_shouldEnableCameraHalHdrplus() {
- when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
- .thenReturn(true);
-
- when(mPreference.isChecked()).thenReturn(true);
-
- when(mContext.getResources().getString(R.string.camera_hal_hdrplus_toast)).thenReturn(
- RuntimeEnvironment.application.getString(R.string.camera_hal_hdrplus_toast));
-
- mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(CameraHalHdrplusPreferenceController.ENABLED.equals(
- SystemProperties.get(
- CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceController.DISABLED))).isTrue();
- }
-
- @Test
- public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraHalHdrplus() {
- when(mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus))
- .thenReturn(true);
-
- when(mPreference.isChecked()).thenReturn(false);
-
- when(mContext.getResources().getString(R.string.camera_hal_hdrplus_toast)).thenReturn(
- RuntimeEnvironment.application.getString(R.string.camera_hal_hdrplus_toast));
-
- mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(CameraHalHdrplusPreferenceController.DISABLED.equals(
- SystemProperties.get(
- CameraHalHdrplusPreferenceController.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceController.DISABLED))).isTrue();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2Test.java
deleted file mode 100644
index e0e137c..0000000
--- a/tests/robotests/src/com/android/settings/development/CameraHalHdrplusPreferenceControllerV2Test.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.development;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.os.SystemProperties;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.PreferenceScreen;
-
-import com.android.settings.TestConfig;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
- shadows = {SettingsShadowSystemProperties.class})
-public class CameraHalHdrplusPreferenceControllerV2Test {
-
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private SwitchPreference mPreference;
-
- private Context mContext;
- private CameraHalHdrplusPreferenceControllerV2 mController;
-
- static final String USERDEBUG_BUILD = "userdebug";
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mController = new CameraHalHdrplusPreferenceControllerV2(mContext);
- when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
- when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
- mController.displayPreference(mScreen);
- }
-
- @After
- public void tearDown() {
- SettingsShadowSystemProperties.clear();
- }
-
- @Test
- @Config(qualifiers = "mcc999")
- public void isAvailable_withConfigNoShowAndUserDebugBuild_shouldReturnFalse() {
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
-
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void updateState_cameraHalHdrplusEnabled_shouldCheckedPreference() {
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceControllerV2.ENABLED);
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setChecked(true);
- }
-
- @Test
- public void updateState_cameraHalHdrplusEnabled_shouldUncheckedPreference() {
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceControllerV2.DISABLED);
- SettingsShadowSystemProperties.set(
- CameraHalHdrplusPreferenceControllerV2.BUILD_TYPE, USERDEBUG_BUILD);
-
- mController.updateState(mPreference);
-
- verify(mPreference).setChecked(false);
- }
-
- @Test
- public void onPreferenceChange_preferenceChecked_shouldEnableCameraHalHdrplus() {
- mController.onPreferenceChange(mPreference, true /* new value */);
-
- assertThat(CameraHalHdrplusPreferenceControllerV2.ENABLED).isEqualTo(
- SystemProperties.get(
- CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceControllerV2.DISABLED));
- }
-
- @Test
- public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableCameraHalHdrplus() {
- mController.onPreferenceChange(mPreference, false /* new value */);
-
- assertThat(CameraHalHdrplusPreferenceControllerV2.DISABLED).isEqualTo(
- SystemProperties.get(
- CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceControllerV2.DISABLED));
- }
-
- @Test
- public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
- mController.onDeveloperOptionsSwitchEnabled();
-
- verify(mPreference).setEnabled(true);
- }
-
- @Test
- public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
- mController.onDeveloperOptionsSwitchDisabled();
-
- verify(mPreference).setEnabled(false);
- verify(mPreference).setChecked(false);
- assertThat(CameraHalHdrplusPreferenceControllerV2.DISABLED).isEqualTo(
- SystemProperties.get(
- CameraHalHdrplusPreferenceControllerV2.PROPERTY_CAMERA_HAL_HDRPLUS,
- CameraHalHdrplusPreferenceControllerV2.DISABLED));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/development/ClearAdbKeysPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ClearAdbKeysPreferenceControllerTest.java
index c4be569..4bcdb98 100644
--- a/tests/robotests/src/com/android/settings/development/ClearAdbKeysPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/ClearAdbKeysPreferenceControllerTest.java
@@ -38,7 +38,6 @@
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
-import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.After;
import org.junit.Before;
@@ -55,7 +54,7 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
- shadows = {SettingsShadowSystemProperties.class, ShadowUtils.class})
+ shadows = {SettingsShadowSystemProperties.class})
public class ClearAdbKeysPreferenceControllerTest {
@Mock
@@ -84,7 +83,6 @@
public void tearDown() {
ShadowClearAdbKeysWarningDialog.resetDialog();
SettingsShadowSystemProperties.clear();
- ShadowUtils.reset();
}
@Test
@@ -139,20 +137,6 @@
}
@Test
- public void handlePreferenceTreeClick_monkeyUser_shouldReturnFalse() {
- SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
- doReturn(true).when(mController).isAdminUser();
- ShadowUtils.setIsUserAMonkey(true);
- mController.displayPreference(mScreen);
- final String preferenceKey = mController.getPreferenceKey();
- when(mPreference.getKey()).thenReturn(preferenceKey);
-
- final boolean isHandled = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(isHandled).isFalse();
- }
-
- @Test
public void onDeveloperOptionsSwitchEnabled_isAdminUser_shouldEnablePreference() {
SystemProperties.set(RO_ADB_SECURE_PROPERTY_KEY, Boolean.toString(true));
doReturn(true).when(mController).isAdminUser();
diff --git a/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
index f95855d..8b96af0 100644
--- a/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/SelectUsbConfigPreferenceControllerTest.java
@@ -16,14 +16,11 @@
package com.android.settings.development;
-import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -36,10 +33,8 @@
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,9 +44,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH,
- sdk = TestConfig.SDK_VERSION,
- shadows = {ShadowUtils.class})
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SelectUsbConfigPreferenceControllerTest {
@Mock
@@ -92,11 +85,6 @@
}
- @After
- public void teardown() {
- ShadowUtils.reset();
- }
-
@Test
public void onPreferenceChange_setCharging_shouldEnableCharging() {
when(mUsbManager.isFunctionEnabled(mValues[0])).thenReturn(true);
@@ -116,18 +104,6 @@
}
@Test
- public void onPreferenceChange_monkeyUser_shouldReturnFalse() {
- when(mUsbManager.isFunctionEnabled(mValues[1])).thenReturn(true);
- ShadowUtils.setIsUserAMonkey(true);
- doNothing().when(mController).setCurrentFunction(anyString(), anyBoolean());
-
- final boolean isHandled = mController.onPreferenceChange(mPreference, mValues[1]);
-
- assertThat(isHandled).isFalse();
- verify(mController, never()).setCurrentFunction(any(), anyBoolean());
- }
-
- @Test
public void updateState_chargingEnabled_shouldSetPreferenceToCharging() {
when(mUsbManager.isFunctionEnabled(mValues[0])).thenReturn(true);