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:
Fan Zhang
2017-02-22 18:16:46 -08:00
parent 182e6ce2c7
commit c62e2f033d
6 changed files with 180 additions and 117 deletions

View File

@@ -18,28 +18,24 @@ package com.android.settings;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.settingslib.DeviceInfoUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.DeviceInfoUtils;
import org.junit.Before;
import org.junit.runner.RunWith;
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.any;
import static com.google.common.truth.Truth.assertWithMessage;
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;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -66,58 +62,47 @@ public class DeviceInfoSettingsTest extends AndroidTestCase {
doReturn(mScreen).when(mSettings).getPreferenceScreen();
}
@Test
public void getPrefXml_shoudlReturnDeviceInfoXml() {
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.device_info_settings);
}
@Test
public void testGetFormattedKernelVersion() throws Exception {
if ("Unavailable".equals(DeviceInfoUtils.getFormattedKernelVersion())) {
fail("formatKernelVersion can't cope with this device's /proc/version");
}
assertWithMessage("formatKernelVersion can't cope with this device's /proc/version")
.that(DeviceInfoUtils.getFormattedKernelVersion())
.isNotEqualTo("Unavailable");
}
@Test
public void testFormatKernelVersion() throws Exception {
assertEquals("Unavailable", DeviceInfoUtils.formatKernelVersion(""));
assertEquals("2.6.38.8-gg784\n" +
assertThat(DeviceInfoUtils.formatKernelVersion("")).isEqualTo("Unavailable");
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" +
"Fri Feb 24 03:31:23 PST 2012",
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"));
assertEquals("3.0.31-g6fb96c9\n" +
"Fri Feb 24 03:31:23 PST 2012");
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version 3.0.31-g6fb96c9 " +
"(android-build@vpbs1.mtv.corp.google.com) " +
"(gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 " +
"SMP PREEMPT Thu Jun 28 11:02:39 PDT 2012"))
.isEqualTo("3.0.31-g6fb96c9\n" +
"android-build@vpbs1.mtv.corp.google.com #1\n" +
"Thu Jun 28 11:02:39 PDT 2012",
DeviceInfoUtils.formatKernelVersion("Linux version 3.0.31-g6fb96c9 " +
"(android-build@vpbs1.mtv.corp.google.com) " +
"(gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 " +
"SMP PREEMPT Thu Jun 28 11:02:39 PDT 2012"));
assertEquals("2.6.38.8-a-b-jellybean+\n" +
"Thu Jun 28 11:02:39 PDT 2012");
assertThat(DeviceInfoUtils.formatKernelVersion("Linux version " +
"2.6.38.8-a-b-jellybean+ (x@y) " +
"(gcc version 4.4.3 (GCC) ) #1 PREEMPT Tue Aug 28 22:10:46 CDT 2012"))
.isEqualTo("2.6.38.8-a-b-jellybean+\n" +
"x@y #1\n" +
"Tue Aug 28 22:10:46 CDT 2012",
DeviceInfoUtils.formatKernelVersion("Linux version " +
"2.6.38.8-a-b-jellybean+ (x@y) " +
"(gcc version 4.4.3 (GCC) ) #1 PREEMPT Tue Aug 28 22:10:46 CDT 2012"));
assertEquals("3.18.31-g3ce5faa-dirty\n" +
"Tue Aug 28 22:10:46 CDT 2012");
assertThat(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"))
.isEqualTo("3.18.31-g3ce5faa-dirty\n" +
"x@y #5\n" +
"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));
"Fri Oct 28 14:38:13 PDT 2016");
}
}