Convert DeviceInfoSettings into a dashboard fragment.
This is needed to use logging from DashboardFragemnt. This page is now a mixture of PrefernceController and non-controller preferences. Also permanently removed system update preference from xml to simplify migration Todo: convert the rest of preference into controller. Bug: 34774945 Test: make RunSettingsRoboTests Change-Id: Ie5130ea7377db2ccf2236cdf48e5cc26d1347d7a
This commit is contained in:
@@ -19,13 +19,6 @@
|
|||||||
android:title="@string/about_settings">
|
android:title="@string/about_settings">
|
||||||
|
|
||||||
<!-- System update settings - launches activity -->
|
<!-- System update settings - launches activity -->
|
||||||
<Preference android:key="system_update_settings"
|
|
||||||
android:title="@string/system_update_settings_list_item_title"
|
|
||||||
android:summary="@string/system_update_settings_list_item_summary">
|
|
||||||
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS" />
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
|
|
||||||
<Preference android:key="additional_system_update_settings"
|
<Preference android:key="additional_system_update_settings"
|
||||||
android:title="@string/additional_system_update_settings_list_item_title">
|
android:title="@string/additional_system_update_settings_list_item_title">
|
||||||
<intent android:action="android.intent.action.MAIN"
|
<intent android:action="android.intent.action.MAIN"
|
||||||
@@ -48,7 +41,7 @@
|
|||||||
|
|
||||||
<!-- Legal Information -->
|
<!-- Legal Information -->
|
||||||
<Preference
|
<Preference
|
||||||
android:key="container"
|
android:key="legal_container"
|
||||||
android:title="@string/legal_information"
|
android:title="@string/legal_information"
|
||||||
android:fragment="com.android.settings.LegalSettings" />
|
android:fragment="com.android.settings.LegalSettings" />
|
||||||
|
|
||||||
|
@@ -28,18 +28,19 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
|
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
|
||||||
import com.android.settings.deviceinfo.BuildNumberPreferenceController;
|
import com.android.settings.deviceinfo.BuildNumberPreferenceController;
|
||||||
|
import com.android.settings.deviceinfo.ManualPreferenceController;
|
||||||
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
|
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settingslib.DeviceInfoUtils;
|
import com.android.settingslib.DeviceInfoUtils;
|
||||||
@@ -51,13 +52,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
public class DeviceInfoSettings extends SettingsPreferenceFragment implements Indexable {
|
public class DeviceInfoSettings extends DashboardFragment implements Indexable {
|
||||||
|
|
||||||
private static final String LOG_TAG = "DeviceInfoSettings";
|
private static final String LOG_TAG = "DeviceInfoSettings";
|
||||||
|
|
||||||
private static final String KEY_MANUAL = "manual";
|
|
||||||
private static final String KEY_REGULATORY_INFO = "regulatory_info";
|
private static final String KEY_REGULATORY_INFO = "regulatory_info";
|
||||||
private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
|
|
||||||
private static final String PROPERTY_URL_SAFETYLEGAL = "ro.url.safetylegal";
|
private static final String PROPERTY_URL_SAFETYLEGAL = "ro.url.safetylegal";
|
||||||
private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
|
private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
|
||||||
private static final String KEY_KERNEL_VERSION = "kernel_version";
|
private static final String KEY_KERNEL_VERSION = "kernel_version";
|
||||||
@@ -73,8 +72,6 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
|
|
||||||
|
|
||||||
long[] mHits = new long[3];
|
long[] mHits = new long[3];
|
||||||
private SystemUpdatePreferenceController mSystemUpdatePreferenceController;
|
|
||||||
private AdditionalSystemUpdatePreferenceController mAdditionalSystemUpdatePreferenceController;
|
|
||||||
private BuildNumberPreferenceController mBuildNumberPreferenceController;
|
private BuildNumberPreferenceController mBuildNumberPreferenceController;
|
||||||
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
@@ -92,6 +89,12 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
return R.string.help_uri_about;
|
return R.string.help_uri_about;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (mBuildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
|
if (mBuildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
|
||||||
@@ -103,14 +106,6 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
final Activity activity = getActivity();
|
|
||||||
mUm = UserManager.get(activity);
|
|
||||||
mAdditionalSystemUpdatePreferenceController =
|
|
||||||
new AdditionalSystemUpdatePreferenceController(activity);
|
|
||||||
mBuildNumberPreferenceController =
|
|
||||||
new BuildNumberPreferenceController(activity, activity, this /* fragment */);
|
|
||||||
getLifecycle().addObserver(mBuildNumberPreferenceController);
|
|
||||||
addPreferencesFromResource(R.xml.device_info_settings);
|
|
||||||
|
|
||||||
setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
|
setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
|
||||||
findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
|
findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
|
||||||
@@ -125,7 +120,6 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
setValueSummary(KEY_BASEBAND_VERSION, "gsm.version.baseband");
|
setValueSummary(KEY_BASEBAND_VERSION, "gsm.version.baseband");
|
||||||
setStringSummary(KEY_DEVICE_MODEL, Build.MODEL + DeviceInfoUtils.getMsvSuffix());
|
setStringSummary(KEY_DEVICE_MODEL, Build.MODEL + DeviceInfoUtils.getMsvSuffix());
|
||||||
setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID);
|
setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID);
|
||||||
mBuildNumberPreferenceController.displayPreference(getPreferenceScreen());
|
|
||||||
findPreference(KEY_KERNEL_VERSION).setSummary(DeviceInfoUtils.getFormattedKernelVersion());
|
findPreference(KEY_KERNEL_VERSION).setSummary(DeviceInfoUtils.getFormattedKernelVersion());
|
||||||
|
|
||||||
if (!SELinux.isSELinuxEnabled()) {
|
if (!SELinux.isSELinuxEnabled()) {
|
||||||
@@ -158,16 +152,6 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
getPreferenceScreen().removePreference(findPreference(KEY_DEVICE_FEEDBACK));
|
getPreferenceScreen().removePreference(findPreference(KEY_DEVICE_FEEDBACK));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Settings is a generic app and should not contain any device-specific
|
|
||||||
* info.
|
|
||||||
*/
|
|
||||||
displaySystemUpdates(activity);
|
|
||||||
mAdditionalSystemUpdatePreferenceController.displayPreference(getPreferenceScreen());
|
|
||||||
|
|
||||||
// Remove manual entry if none present.
|
|
||||||
removePreferenceIfBoolFalse(KEY_MANUAL, R.bool.config_show_manual);
|
|
||||||
|
|
||||||
// Remove regulatory labels if no activity present to handle intent.
|
// Remove regulatory labels if no activity present to handle intent.
|
||||||
removePreferenceIfActivityMissing(
|
removePreferenceIfActivityMissing(
|
||||||
KEY_REGULATORY_INFO, Settings.ACTION_SHOW_REGULATORY_INFO);
|
KEY_REGULATORY_INFO, Settings.ACTION_SHOW_REGULATORY_INFO);
|
||||||
@@ -222,25 +206,33 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
} else if (preference.getKey().equals(KEY_DEVICE_FEEDBACK)) {
|
} else if (preference.getKey().equals(KEY_DEVICE_FEEDBACK)) {
|
||||||
sendFeedback();
|
sendFeedback();
|
||||||
}
|
}
|
||||||
if (mSystemUpdatePreferenceController != null) {
|
|
||||||
mSystemUpdatePreferenceController.handlePreferenceTreeClick(preference);
|
|
||||||
}
|
|
||||||
return super.onPreferenceTreeClick(preference);
|
return super.onPreferenceTreeClick(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@Override
|
||||||
void displaySystemUpdates(Context context) {
|
protected String getLogTag() {
|
||||||
if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).isEnabled()) {
|
return LOG_TAG;
|
||||||
mSystemUpdatePreferenceController
|
}
|
||||||
= new SystemUpdatePreferenceController(context, UserManager.get(context));
|
|
||||||
mSystemUpdatePreferenceController.displayPreference(getPreferenceScreen());
|
@Override
|
||||||
} else {
|
protected int getPreferenceScreenResId() {
|
||||||
getPreferenceScreen().removePreference(findPreference(KEY_SYSTEM_UPDATE_SETTINGS));
|
return R.xml.device_info_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||||
|
final List<PreferenceController> controllers = new ArrayList<>();
|
||||||
|
mBuildNumberPreferenceController =
|
||||||
|
new BuildNumberPreferenceController(context, getActivity(), this /* fragment */);
|
||||||
|
getLifecycle().addObserver(mBuildNumberPreferenceController);
|
||||||
|
controllers.add(mBuildNumberPreferenceController);
|
||||||
|
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
|
||||||
|
controllers.add(new ManualPreferenceController(context));
|
||||||
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePreferenceIfPropertyMissing(PreferenceGroup preferenceGroup,
|
private void removePreferenceIfPropertyMissing(PreferenceGroup preferenceGroup,
|
||||||
String preference, String property ) {
|
String preference, String property) {
|
||||||
if (SystemProperties.get(property).equals("")) {
|
if (SystemProperties.get(property).equals("")) {
|
||||||
// Property is missing so remove preference from group
|
// Property is missing so remove preference from group
|
||||||
try {
|
try {
|
||||||
@@ -262,15 +254,6 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePreferenceIfBoolFalse(String preference, int resId) {
|
|
||||||
if (!getResources().getBoolean(resId)) {
|
|
||||||
Preference pref = findPreference(preference);
|
|
||||||
if (pref != null) {
|
|
||||||
getPreferenceScreen().removePreference(pref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setStringSummary(String preference, String value) {
|
private void setStringSummary(String preference, String value) {
|
||||||
try {
|
try {
|
||||||
findPreference(preference).setSummary(value);
|
findPreference(preference).setSummary(value);
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.deviceinfo;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
|
||||||
|
public class ManualPreferenceController extends PreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_MANUAL = "manual";
|
||||||
|
|
||||||
|
public ManualPreferenceController(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mContext.getResources().getBoolean(R.bool.config_show_manual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_MANUAL;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,28 +18,24 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
|
|
||||||
import com.android.settingslib.DeviceInfoUtils;
|
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settingslib.DeviceInfoUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -66,58 +62,47 @@ public class DeviceInfoSettingsTest extends AndroidTestCase {
|
|||||||
doReturn(mScreen).when(mSettings).getPreferenceScreen();
|
doReturn(mScreen).when(mSettings).getPreferenceScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPrefXml_shoudlReturnDeviceInfoXml() {
|
||||||
|
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.device_info_settings);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFormattedKernelVersion() throws Exception {
|
public void testGetFormattedKernelVersion() throws Exception {
|
||||||
if ("Unavailable".equals(DeviceInfoUtils.getFormattedKernelVersion())) {
|
assertWithMessage("formatKernelVersion can't cope with this device's /proc/version")
|
||||||
fail("formatKernelVersion can't cope with this device's /proc/version");
|
.that(DeviceInfoUtils.getFormattedKernelVersion())
|
||||||
}
|
.isNotEqualTo("Unavailable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatKernelVersion() throws Exception {
|
public void testFormatKernelVersion() throws Exception {
|
||||||
assertEquals("Unavailable", DeviceInfoUtils.formatKernelVersion(""));
|
assertThat(DeviceInfoUtils.formatKernelVersion("")).isEqualTo("Unavailable");
|
||||||
assertEquals("2.6.38.8-gg784\n" +
|
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version 2.6.38.8-gg784 " +
|
||||||
|
"(root@hpao4.eem.corp.google.com) " +
|
||||||
|
"(gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #2 SMP " +
|
||||||
|
"Fri Feb 24 03:31:23 PST 2012"))
|
||||||
|
.isEqualTo("2.6.38.8-gg784\n" +
|
||||||
"root@hpao4.eem.corp.google.com #2\n" +
|
"root@hpao4.eem.corp.google.com #2\n" +
|
||||||
"Fri Feb 24 03:31:23 PST 2012",
|
"Fri Feb 24 03:31:23 PST 2012");
|
||||||
DeviceInfoUtils.formatKernelVersion("Linux version 2.6.38.8-gg784 " +
|
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version 3.0.31-g6fb96c9 " +
|
||||||
"(root@hpao4.eem.corp.google.com) " +
|
"(android-build@vpbs1.mtv.corp.google.com) " +
|
||||||
"(gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #2 SMP " +
|
"(gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 " +
|
||||||
"Fri Feb 24 03:31:23 PST 2012"));
|
"SMP PREEMPT Thu Jun 28 11:02:39 PDT 2012"))
|
||||||
assertEquals("3.0.31-g6fb96c9\n" +
|
.isEqualTo("3.0.31-g6fb96c9\n" +
|
||||||
"android-build@vpbs1.mtv.corp.google.com #1\n" +
|
"android-build@vpbs1.mtv.corp.google.com #1\n" +
|
||||||
"Thu Jun 28 11:02:39 PDT 2012",
|
"Thu Jun 28 11:02:39 PDT 2012");
|
||||||
DeviceInfoUtils.formatKernelVersion("Linux version 3.0.31-g6fb96c9 " +
|
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version " +
|
||||||
"(android-build@vpbs1.mtv.corp.google.com) " +
|
"2.6.38.8-a-b-jellybean+ (x@y) " +
|
||||||
"(gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 " +
|
"(gcc version 4.4.3 (GCC) ) #1 PREEMPT Tue Aug 28 22:10:46 CDT 2012"))
|
||||||
"SMP PREEMPT Thu Jun 28 11:02:39 PDT 2012"));
|
.isEqualTo("2.6.38.8-a-b-jellybean+\n" +
|
||||||
assertEquals("2.6.38.8-a-b-jellybean+\n" +
|
|
||||||
"x@y #1\n" +
|
"x@y #1\n" +
|
||||||
"Tue Aug 28 22:10:46 CDT 2012",
|
"Tue Aug 28 22:10:46 CDT 2012");
|
||||||
DeviceInfoUtils.formatKernelVersion("Linux version " +
|
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version " +
|
||||||
"2.6.38.8-a-b-jellybean+ (x@y) " +
|
"3.18.31-g3ce5faa-dirty (x@y) (Android clang " +
|
||||||
"(gcc version 4.4.3 (GCC) ) #1 PREEMPT Tue Aug 28 22:10:46 CDT 2012"));
|
"version 3.8.275480 (based on LLVM 3.8.275480)) " +
|
||||||
assertEquals("3.18.31-g3ce5faa-dirty\n" +
|
"#5 SMP PREEMPT Fri Oct 28 14:38:13 PDT 2016"))
|
||||||
|
.isEqualTo("3.18.31-g3ce5faa-dirty\n" +
|
||||||
"x@y #5\n" +
|
"x@y #5\n" +
|
||||||
"Fri Oct 28 14:38:13 PDT 2016",
|
"Fri Oct 28 14:38:13 PDT 2016");
|
||||||
DeviceInfoUtils.formatKernelVersion("Linux version " +
|
|
||||||
"3.18.31-g3ce5faa-dirty (x@y) (Android clang " +
|
|
||||||
"version 3.8.275480 (based on LLVM 3.8.275480)) " +
|
|
||||||
"#5 SMP PREEMPT Fri Oct 28 14:38:13 PDT 2016"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testShowSystemUpdatesWhenIADisabled() throws Exception {
|
|
||||||
when(mFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
|
||||||
mSettings.displaySystemUpdates(mContext);
|
|
||||||
|
|
||||||
verify(mScreen).removePreference(any(Preference.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHideSystemUpdatesWhenIAEnabled() throws Exception {
|
|
||||||
when(mFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(false);
|
|
||||||
mSettings.displaySystemUpdates(mContext);
|
|
||||||
|
|
||||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -131,8 +131,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
|
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
|
||||||
final Preference preference = new Preference(
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
|
||||||
final Tile tile = new Tile();
|
final Tile tile = new Tile();
|
||||||
tile.metaData = new Bundle();
|
tile.metaData = new Bundle();
|
||||||
tile.userHandle = new ArrayList<>();
|
tile.userHandle = new ArrayList<>();
|
||||||
@@ -141,7 +140,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
tile.intent = new Intent();
|
tile.intent = new Intent();
|
||||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||||
|
|
||||||
when(mActivity.getSystemService(Context.USER_SERVICE))
|
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
|
||||||
.thenReturn(mUserManager);
|
.thenReturn(mUserManager);
|
||||||
|
|
||||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||||
@@ -153,8 +152,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
|
public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
|
||||||
final Preference preference = new Preference(
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
|
||||||
final Tile tile = new Tile();
|
final Tile tile = new Tile();
|
||||||
tile.metaData = new Bundle();
|
tile.metaData = new Bundle();
|
||||||
tile.userHandle = new ArrayList<>();
|
tile.userHandle = new ArrayList<>();
|
||||||
@@ -205,8 +203,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
||||||
final Preference preference = new Preference(
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
|
||||||
final Tile tile = new Tile();
|
final Tile tile = new Tile();
|
||||||
tile.intent = new Intent();
|
tile.intent = new Intent();
|
||||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||||
@@ -219,8 +216,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
|
public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
|
||||||
final Preference preference = new Preference(
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
|
||||||
final Tile tile = new Tile();
|
final Tile tile = new Tile();
|
||||||
tile.key = "key";
|
tile.key = "key";
|
||||||
tile.intent = new Intent();
|
tile.intent = new Intent();
|
||||||
@@ -234,8 +230,7 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void bindPreference_withBaseOrder_shouldOffsetPriority() {
|
public void bindPreference_withBaseOrder_shouldOffsetPriority() {
|
||||||
final int baseOrder = 100;
|
final int baseOrder = 100;
|
||||||
final Preference preference = new Preference(
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
ShadowApplication.getInstance().getApplicationContext());
|
|
||||||
final Tile tile = new Tile();
|
final Tile tile = new Tile();
|
||||||
tile.metaData = new Bundle();
|
tile.metaData = new Bundle();
|
||||||
tile.priority = 10;
|
tile.priority = 10;
|
||||||
|
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.deviceinfo;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
|
||||||
|
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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class ManualPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
private ManualPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mController = new ManualPreferenceController(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_configTurnedOff_shouldReturnFalse() {
|
||||||
|
when(mContext.getResources().getBoolean(anyInt()))
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_configTurnedOn_shouldReturnTrue() {
|
||||||
|
when(mContext.getResources().getBoolean(anyInt()))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user