diff --git a/res/layout/dialog_hardware_info.xml b/res/layout/dialog_hardware_info.xml deleted file mode 100644 index 7ea47831556..00000000000 --- a/res/layout/dialog_hardware_info.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/xml/hardware_info.xml b/res/xml/hardware_info.xml new file mode 100644 index 00000000000..2e35101aca6 --- /dev/null +++ b/res/xml/hardware_info.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml index 918e8ec0cf3..83bf5c45d08 100644 --- a/res/xml/my_device_info.xml +++ b/res/xml/my_device_info.xml @@ -105,7 +105,8 @@ settings:keywords="@string/keywords_model_and_hardware" android:summary="@string/summary_placeholder" settings:allowDynamicSummaryInSlice="true" - settings:controller="com.android.settings.deviceinfo.DeviceModelPreferenceController"/> + android:fragment="com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFragment" + settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix()); diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java index c20e857a803..e6afb7b821c 100644 --- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java +++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java @@ -31,7 +31,6 @@ import com.android.settings.Utils; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.deviceinfo.BluetoothAddressPreferenceController; import com.android.settings.deviceinfo.BuildNumberPreferenceController; -import com.android.settings.deviceinfo.DeviceModelPreferenceController; import com.android.settings.deviceinfo.DeviceNamePreferenceController; import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController; import com.android.settings.deviceinfo.FeedbackPreferenceController; @@ -41,7 +40,6 @@ import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController; import com.android.settings.deviceinfo.SafetyInfoPreferenceController; import com.android.settings.deviceinfo.UptimePreferenceController; import com.android.settings.deviceinfo.WifiMacAddressPreferenceController; -import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController; import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController; import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; @@ -77,7 +75,6 @@ public class MyDeviceInfoFragment extends DashboardFragment @Override public void onAttach(Context context) { super.onAttach(context); - use(DeviceModelPreferenceController.class).setHost(this /* parent */); use(ImeiInfoPreferenceController.class).setHost(this /* parent */); use(DeviceNamePreferenceController.class).setHost(this /* parent */); mBuildNumberPreferenceController = use(BuildNumberPreferenceController.class); diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java new file mode 100644 index 00000000000..42c7b0104e7 --- /dev/null +++ b/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 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.hardwareinfo; + +import android.content.Context; + +import com.android.settings.deviceinfo.HardwareInfoPreferenceController; + +public class DeviceModelPreferenceController extends HardwareInfoPreferenceController { + + public DeviceModelPreferenceController(Context context, String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + final int availability = super.getAvailabilityStatus(); + if (availability == AVAILABLE_UNSEARCHABLE) { + return AVAILABLE; + } + return availability; + } + + @Override + public boolean isSliceable() { + return true; + } +} diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java new file mode 100644 index 00000000000..40e73efe882 --- /dev/null +++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 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.hardwareinfo; + +import android.app.settings.SettingsEnums; +import android.content.Context; +import android.provider.SearchIndexableResource; + +import com.android.settings.R; +import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; +import com.android.settingslib.search.SearchIndexable; + +import java.util.ArrayList; +import java.util.List; + + +@SearchIndexable +public class HardwareInfoFragment extends DashboardFragment { + + public static final String TAG = "HardwareInfo"; + + @Override + public int getMetricsCategory() { + return SettingsEnums.DIALOG_SETTINGS_HARDWARE_INFO; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.hardware_info; + } + + @Override + protected String getLogTag() { + return TAG; + } + + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex(Context context, + boolean enabled) { + final ArrayList result = new ArrayList<>(); + + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.hardware_info; + result.add(sir); + return result; + } + + @Override + protected boolean isPageSearchEnabled(Context context) { + return context.getResources().getBoolean(R.bool.config_show_device_model); + } + }; +} diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java new file mode 100644 index 00000000000..ec0cdb2a362 --- /dev/null +++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 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.hardwareinfo; + +import android.content.Context; +import android.os.SystemProperties; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +public class HardwareRevisionPreferenceController extends BasePreferenceController { + + public HardwareRevisionPreferenceController(Context context, String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public int getAvailabilityStatus() { + return mContext.getResources().getBoolean(R.bool.config_show_device_model) + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + } + + @Override + public boolean isSliceable() { + return true; + } + + @Override + public CharSequence getSummary() { + return SystemProperties.get("ro.boot.hardware.revision"); + } +} diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java new file mode 100644 index 00000000000..4485c53d7ae --- /dev/null +++ b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 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.hardwareinfo; + +import android.content.Context; +import android.os.Build; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +public class SerialNumberPreferenceController extends BasePreferenceController { + + public SerialNumberPreferenceController(Context context, String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public int getAvailabilityStatus() { + return mContext.getResources().getBoolean(R.bool.config_show_device_model) + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + } + + @Override + public boolean isSliceable() { + return true; + } + + @Override + public CharSequence getSummary() { + return Build.getSerial(); + } +} diff --git a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java index e278baae130..48a9aa54617 100644 --- a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java +++ b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java @@ -36,7 +36,7 @@ import androidx.slice.builders.SliceAction; import com.android.settings.R; import com.android.settings.SubSettings; import com.android.settings.Utils; -import com.android.settings.deviceinfo.DeviceModelPreferenceController; +import com.android.settings.deviceinfo.HardwareInfoPreferenceController; import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment; import com.android.settings.slices.CustomSliceRegistry; import com.android.settings.slices.CustomSliceable; @@ -107,7 +107,7 @@ public class DeviceInfoSlice implements CustomSliceable { } private CharSequence getDeviceModel() { - return DeviceModelPreferenceController.getDeviceModel(); + return HardwareInfoPreferenceController.getDeviceModel(); } @VisibleForTesting diff --git a/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java deleted file mode 100644 index 29d9a7c8aa2..00000000000 --- a/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java +++ /dev/null @@ -1,66 +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.deviceinfo; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -import android.os.SystemProperties; -import android.view.View; - -import androidx.fragment.app.FragmentActivity; - -import com.android.settings.R; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.Robolectric; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class HardwareInfoDialogFragmentTest { - - private FragmentActivity mActivity; - - @Before - public void setUp() { - mActivity = Robolectric.setupActivity(FragmentActivity.class); - } - - @Test - public void display_shouldShowHardwareRevision() { - final String TEST_HARDWARE_REV = "123"; - SystemProperties.set("ro.boot.hardware.revision", TEST_HARDWARE_REV); - - final HardwareInfoDialogFragment fragment = spy(HardwareInfoDialogFragment.newInstance()); - doReturn("").when(fragment).getSerialNumber(); - fragment.show(mActivity.getSupportFragmentManager(), HardwareInfoDialogFragment.TAG); - - verify(fragment).setText( - any(View.class), eq(R.id.model_label), eq(R.id.model_value), - anyString()); - - verify(fragment).setText( - any(View.class), eq(R.id.hardware_rev_label), eq(R.id.hardware_rev_value), - anyString()); - } -} diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java new file mode 100644 index 00000000000..1204c443e1d --- /dev/null +++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2019 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.hardwareinfo; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; + +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +public class DeviceModelPreferenceControllerTest { + + private Context mContext; + private DeviceModelPreferenceController mController; + + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mController = new DeviceModelPreferenceController(mContext, "test_key"); + } + + @Test + public void getAvailabilityStatus_configAllowed_available() { + assertThat(mController.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.AVAILABLE); + } + + @Test + @Config(qualifiers = "mcc999") + public void getAvailabilityStatus_configDisallowed_unavailable() { + assertThat(mController.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.UNSUPPORTED_ON_DEVICE); + } + + @Test + public void isAlwaysSliceable() { + assertThat(mController.isSliceable()).isTrue(); + } +} diff --git a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java similarity index 64% rename from tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java index 6418cf8bb6f..413c4921bbd 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2019 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. @@ -13,56 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.settings.deviceinfo; +package com.android.settings.deviceinfo.hardwareinfo; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import android.content.Context; import android.os.Build; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; import androidx.preference.Preference; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; +import com.android.settings.deviceinfo.HardwareInfoPreferenceController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) -public class DeviceModelPreferenceControllerTest { +public class HardwareInfoPreferenceControllerTest { private final String KEY = "device_model"; - @Mock - private Fragment mFragment; private Preference mPreference; private PreferenceScreen mPreferenceScreen; private Context mContext; - private DeviceModelPreferenceController mController; + private HardwareInfoPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; - mController = new DeviceModelPreferenceController(mContext, KEY); - mController.setHost(mFragment); + mController = new HardwareInfoPreferenceController(mContext, KEY); mPreference = new Preference(mContext); mPreference.setKey(KEY); final PreferenceManager preferenceManager = new PreferenceManager(mContext); @@ -73,7 +61,7 @@ public class DeviceModelPreferenceControllerTest { @Test public void isAvailable_returnTrueIfVisible() { assertThat(mController.getAvailabilityStatus()).isEqualTo( - BasePreferenceController.AVAILABLE); + BasePreferenceController.AVAILABLE_UNSEARCHABLE); } @Test @@ -90,22 +78,6 @@ public class DeviceModelPreferenceControllerTest { assertThat(containBuildModel(mPreference.getSummary())).isTrue(); } - @Test - public void clickPreference_shouldLaunchHardwareInfoDialog() { - FragmentManager fragmentManager = mock(FragmentManager.class); - when(mFragment.getFragmentManager()).thenReturn(fragmentManager); - when(fragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class)); - - assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue(); - verify(fragmentManager.beginTransaction()) - .add(any(HardwareInfoDialogFragment.class), eq(HardwareInfoDialogFragment.TAG)); - } - - @Test - public void isSliceable_shouldBeTrue() { - assertThat(mController.isSliceable()).isTrue(); - } - private boolean containBuildModel(CharSequence result) { final String oracle = mContext.getResources().getString(R.string.model_summary, Build.MODEL);