OSDN Git Service

Make model & hardware UI full screen.
authorFan Zhang <zhfan@google.com>
Mon, 25 Feb 2019 21:36:38 +0000 (13:36 -0800)
committerFan Zhang <zhfan@google.com>
Tue, 26 Feb 2019 00:36:04 +0000 (16:36 -0800)
Bug: 112427717
Test: robotests
Change-Id: I9f1edb0ab377aff142b57d86f4fa218b755356b1

14 files changed:
res/layout/dialog_hardware_info.xml [deleted file]
res/xml/hardware_info.xml [new file with mode: 0644]
res/xml/my_device_info.xml
src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java [deleted file]
src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java [moved from src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java with 71% similarity]
src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java [new file with mode: 0644]
src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java [new file with mode: 0644]
src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java [new file with mode: 0644]
src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java [new file with mode: 0644]
src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java [deleted file]
tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java [new file with mode: 0644]
tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java [moved from tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java with 64% similarity]

diff --git a/res/layout/dialog_hardware_info.xml b/res/layout/dialog_hardware_info.xml
deleted file mode 100644 (file)
index 7ea4783..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  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.
-  -->
-
-<ScrollView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content">
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:padding="24dp">
-
-        <TextView
-            style="@style/device_info_dialog_label"
-            android:id="@+id/model_label"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:text="@string/model_info" />
-        <TextView
-            style="@style/device_info_dialog_value"
-            android:id="@+id/model_value"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
-
-        <TextView
-            style="@style/device_info_dialog_label"
-            android:id="@+id/serial_number_label"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:text="@string/status_serial_number" />
-        <TextView
-            style="@style/device_info_dialog_value"
-            android:id="@+id/serial_number_value"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
-
-        <TextView
-            style="@style/device_info_dialog_label"
-            android:id="@+id/hardware_rev_label"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:text="@string/hardware_revision" />
-        <TextView
-            style="@style/device_info_dialog_value"
-            android:id="@+id/hardware_rev_value"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
-
-    </LinearLayout>
-</ScrollView>
\ No newline at end of file
diff --git a/res/xml/hardware_info.xml b/res/xml/hardware_info.xml
new file mode 100644 (file)
index 0000000..2e35101
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  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.
+  -->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
+    android:key="hardware_info_screen"
+    android:title="@string/hardware_info"
+    settings:keywords="@string/keywords_model_and_hardware">
+
+    <!-- Model -->
+    <Preference
+        android:key="hardware_info_device_model"
+        android:title="@string/model_info"
+        android:summary="@string/summary_placeholder"
+        settings:allowDynamicSummaryInSlice="true"
+        settings:controller="com.android.settings.deviceinfo.hardwareinfo.DeviceModelPreferenceController"
+        settings:enableCopying="true"/>
+
+    <!-- SerialNumber -->
+    <Preference
+        android:key="hardware_info_device_serial"
+        android:title="@string/status_serial_number"
+        android:summary="@string/summary_placeholder"
+        settings:allowDynamicSummaryInSlice="true"
+        settings:controller="com.android.settings.deviceinfo.hardwareinfo.SerialNumberPreferenceController"
+        settings:enableCopying="true"/>
+
+    <!-- Hardware revision -->
+    <Preference
+        android:key="hardware_info_device_revision"
+        android:title="@string/hardware_revision"
+        android:summary="@string/summary_placeholder"
+        settings:allowDynamicSummaryInSlice="true"
+        settings:controller="com.android.settings.deviceinfo.hardwareinfo.HardwareRevisionPreferenceController"
+        settings:enableCopying="true"/>
+
+</PreferenceScreen>
\ No newline at end of file
index 918e8ec..83bf5c4 100644 (file)
         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"/>
 
     <!-- IMEI -->
     <Preference
diff --git a/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java b/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java
deleted file mode 100644 (file)
index 34a7143..0000000
+++ /dev/null
@@ -1,91 +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 android.app.Dialog;
-import android.app.settings.SettingsEnums;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.SystemProperties;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextView;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.appcompat.app.AlertDialog;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class HardwareInfoDialogFragment extends InstrumentedDialogFragment {
-
-    public static final String TAG = "HardwareInfo";
-
-    @Override
-    public int getMetricsCategory() {
-        return SettingsEnums.DIALOG_SETTINGS_HARDWARE_INFO;
-    }
-
-    public static HardwareInfoDialogFragment newInstance() {
-        final HardwareInfoDialogFragment fragment = new HardwareInfoDialogFragment();
-        return fragment;
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
-                .setTitle(R.string.hardware_info)
-                .setPositiveButton(android.R.string.ok, null);
-        final View content = LayoutInflater.from(builder.getContext())
-                .inflate(R.layout.dialog_hardware_info, null /* parent */);
-        // Model
-        setText(content, R.id.model_label, R.id.model_value,
-                DeviceModelPreferenceController.getDeviceModel());
-
-        // Serial number
-        setText(content, R.id.serial_number_label, R.id.serial_number_value, getSerialNumber());
-
-        // Hardware rev
-        setText(content, R.id.hardware_rev_label, R.id.hardware_rev_value,
-                SystemProperties.get("ro.boot.hardware.revision"));
-
-        return builder.setView(content).create();
-    }
-
-    @VisibleForTesting
-    void setText(View content, int labelViewId, int valueViewId, String value) {
-        if (content == null) {
-            return;
-        }
-        final View labelView = content.findViewById(labelViewId);
-        final TextView valueView = content.findViewById(valueViewId);
-        if (!TextUtils.isEmpty(value)) {
-            labelView.setVisibility(View.VISIBLE);
-            valueView.setVisibility(View.VISIBLE);
-            valueView.setText(value);
-        } else {
-            labelView.setVisibility(View.GONE);
-            valueView.setVisibility(View.GONE);
-        }
-    }
-
-    @VisibleForTesting
-    String getSerialNumber() {
-        return Build.getSerial();
-    }
-}
@@ -17,11 +17,8 @@ package com.android.settings.deviceinfo;
 
 import android.content.Context;
 import android.os.Build;
-import android.text.TextUtils;
 import android.util.Log;
 
-import androidx.fragment.app.Fragment;
-import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
@@ -31,21 +28,14 @@ import com.android.settingslib.DeviceInfoUtils;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.FutureTask;
 
-public class DeviceModelPreferenceController extends BasePreferenceController {
-
+public class HardwareInfoPreferenceController extends BasePreferenceController {
 
     private static final String TAG = "DeviceModelPrefCtrl";
 
-    private Fragment mHost;
-
-    public DeviceModelPreferenceController(Context context, String key) {
+    public HardwareInfoPreferenceController(Context context, String key) {
         super(context, key);
     }
 
-    public void setHost(Fragment fragment) {
-        mHost = fragment;
-    }
-
     @Override
     public void displayPreference(PreferenceScreen screen) {
         super.displayPreference(screen);
@@ -54,7 +44,7 @@ public class DeviceModelPreferenceController extends BasePreferenceController {
     @Override
     public int getAvailabilityStatus() {
         return mContext.getResources().getBoolean(R.bool.config_show_device_model)
-                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+                ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
     }
 
     @Override
@@ -62,21 +52,6 @@ public class DeviceModelPreferenceController extends BasePreferenceController {
         return mContext.getResources().getString(R.string.model_summary, getDeviceModel());
     }
 
-    @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
-            return false;
-        }
-        final HardwareInfoDialogFragment fragment = HardwareInfoDialogFragment.newInstance();
-        fragment.show(mHost.getFragmentManager(), HardwareInfoDialogFragment.TAG);
-        return true;
-    }
-
-    @Override
-    public boolean isSliceable() {
-        return true;
-    }
-
     public static String getDeviceModel() {
         FutureTask<String> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix());
 
index c20e857..e6afb7b 100644 (file)
@@ -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 (file)
index 0000000..42c7b01
--- /dev/null
@@ -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 (file)
index 0000000..40e73ef
--- /dev/null
@@ -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<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final ArrayList<SearchIndexableResource> 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 (file)
index 0000000..ec0cdb2
--- /dev/null
@@ -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 (file)
index 0000000..4485c53
--- /dev/null
@@ -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();
+    }
+}
index e278baa..48a9aa5 100644 (file)
@@ -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 (file)
index 29d9a7c..0000000
+++ /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 (file)
index 0000000..1204c44
--- /dev/null
@@ -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();
+    }
+}
@@ -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.
  * 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);