Home | History | Annotate | Download | only in deviceinfo
      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.Bundle;
     22 import android.os.SystemProperties;
     23 import android.support.annotation.VisibleForTesting;
     24 import android.text.TextUtils;
     25 import android.view.LayoutInflater;
     26 import android.view.View;
     27 import android.widget.TextView;
     28 
     29 import com.android.internal.logging.nano.MetricsProto;
     30 import com.android.settings.R;
     31 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
     32 
     33 public class HardwareInfoDialogFragment extends InstrumentedDialogFragment {
     34 
     35     public static final String TAG = "HardwareInfo";
     36 
     37     @Override
     38     public int getMetricsCategory() {
     39         return MetricsProto.MetricsEvent.DIALOG_SETTINGS_HARDWARE_INFO;
     40     }
     41 
     42     public static HardwareInfoDialogFragment newInstance() {
     43         final HardwareInfoDialogFragment fragment = new HardwareInfoDialogFragment();
     44         return fragment;
     45     }
     46 
     47     @Override
     48     public Dialog onCreateDialog(Bundle savedInstanceState) {
     49         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
     50                 .setTitle(R.string.hardware_info)
     51                 .setPositiveButton(android.R.string.ok, null);
     52         final View content = LayoutInflater.from(builder.getContext())
     53                 .inflate(R.layout.dialog_hardware_info, null /* parent */);
     54         // Model
     55         setText(content, R.id.model_label, R.id.model_value,
     56                 DeviceModelPreferenceController.getDeviceModel());
     57         // Hardware rev
     58         setText(content, R.id.hardware_rev_label, R.id.hardware_rev_value,
     59                 SystemProperties.get("ro.boot.hardware.revision"));
     60 
     61         return builder.setView(content).create();
     62     }
     63 
     64     @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
     65     void setText(View content, int labelViewId, int valueViewId, String value) {
     66         if (content == null) {
     67             return;
     68         }
     69         final View labelView = content.findViewById(labelViewId);
     70         final TextView valueView = content.findViewById(valueViewId);
     71         if (!TextUtils.isEmpty(value)) {
     72             labelView.setVisibility(View.VISIBLE);
     73             valueView.setVisibility(View.VISIBLE);
     74             valueView.setText(value);
     75         } else {
     76             labelView.setVisibility(View.GONE);
     77             valueView.setVisibility(View.GONE);
     78         }
     79     }
     80 }
     81