• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.deviceinfo;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.os.Build;
22 import android.os.Bundle;
23 import android.os.SystemProperties;
24 import android.support.annotation.VisibleForTesting;
25 import android.text.TextUtils;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.widget.TextView;
29 
30 import com.android.internal.logging.nano.MetricsProto;
31 import com.android.settings.R;
32 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
33 
34 public class HardwareInfoDialogFragment extends InstrumentedDialogFragment {
35 
36     public static final String TAG = "HardwareInfo";
37 
38     @Override
getMetricsCategory()39     public int getMetricsCategory() {
40         return MetricsProto.MetricsEvent.DIALOG_SETTINGS_HARDWARE_INFO;
41     }
42 
newInstance()43     public static HardwareInfoDialogFragment newInstance() {
44         final HardwareInfoDialogFragment fragment = new HardwareInfoDialogFragment();
45         return fragment;
46     }
47 
48     @Override
onCreateDialog(Bundle savedInstanceState)49     public Dialog onCreateDialog(Bundle savedInstanceState) {
50         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
51                 .setTitle(R.string.hardware_info)
52                 .setPositiveButton(android.R.string.ok, null);
53         final View content = LayoutInflater.from(builder.getContext())
54                 .inflate(R.layout.dialog_hardware_info, null /* parent */);
55         // Model
56         setText(content, R.id.model_label, R.id.model_value,
57                 DeviceModelPreferenceController.getDeviceModel());
58 
59         // Serial number
60         setText(content, R.id.serial_number_label, R.id.serial_number_value, getSerialNumber());
61 
62         // Hardware rev
63         setText(content, R.id.hardware_rev_label, R.id.hardware_rev_value,
64                 SystemProperties.get("ro.boot.hardware.revision"));
65 
66         return builder.setView(content).create();
67     }
68 
69     @VisibleForTesting
setText(View content, int labelViewId, int valueViewId, String value)70     void setText(View content, int labelViewId, int valueViewId, String value) {
71         if (content == null) {
72             return;
73         }
74         final View labelView = content.findViewById(labelViewId);
75         final TextView valueView = content.findViewById(valueViewId);
76         if (!TextUtils.isEmpty(value)) {
77             labelView.setVisibility(View.VISIBLE);
78             valueView.setVisibility(View.VISIBLE);
79             valueView.setText(value);
80         } else {
81             labelView.setVisibility(View.GONE);
82             valueView.setVisibility(View.GONE);
83         }
84     }
85 
86     @VisibleForTesting
getSerialNumber()87     String getSerialNumber() {
88         return Build.getSerial();
89     }
90 }
91