blob: 831c630337e5294278c49ab4d2a1a53d604ff4ab [file] [log] [blame]
Fan Zhangefb8d622017-02-23 17:50:27 -08001/*
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 */
16package com.android.settings.deviceinfo;
17
Fan Zhangdc5a06e2017-03-07 14:52:51 -080018import android.app.Fragment;
Fan Zhangefb8d622017-02-23 17:50:27 -080019import android.content.Context;
20import android.os.Build;
21import android.support.v7.preference.Preference;
22import android.support.v7.preference.PreferenceScreen;
Fan Zhangdc5a06e2017-03-07 14:52:51 -080023import android.text.TextUtils;
Fan Zhangefb8d622017-02-23 17:50:27 -080024
jeffreyhuangf6d360e2017-10-19 16:44:59 -070025import com.android.settings.R;
Tony Mantler1d583e12017-06-13 13:09:25 -070026import com.android.settings.core.PreferenceControllerMixin;
Fan Zhangefb8d622017-02-23 17:50:27 -080027import com.android.settingslib.DeviceInfoUtils;
Tony Mantler1d583e12017-06-13 13:09:25 -070028import com.android.settingslib.core.AbstractPreferenceController;
Fan Zhangefb8d622017-02-23 17:50:27 -080029
Tony Mantler1d583e12017-06-13 13:09:25 -070030public class DeviceModelPreferenceController extends AbstractPreferenceController implements
31 PreferenceControllerMixin {
Fan Zhangefb8d622017-02-23 17:50:27 -080032
33 private static final String KEY_DEVICE_MODEL = "device_model";
34
Fan Zhangdc5a06e2017-03-07 14:52:51 -080035 private final Fragment mHost;
36
37 public DeviceModelPreferenceController(Context context, Fragment host) {
Fan Zhangefb8d622017-02-23 17:50:27 -080038 super(context);
Fan Zhangdc5a06e2017-03-07 14:52:51 -080039 mHost = host;
Fan Zhangefb8d622017-02-23 17:50:27 -080040 }
41
42 @Override
43 public boolean isAvailable() {
Ben Lin7190f852018-01-30 16:17:45 -080044 return mContext.getResources().getBoolean(R.bool.config_show_device_model);
Fan Zhangefb8d622017-02-23 17:50:27 -080045 }
46
47 @Override
48 public void displayPreference(PreferenceScreen screen) {
49 super.displayPreference(screen);
50 final Preference pref = screen.findPreference(KEY_DEVICE_MODEL);
51 if (pref != null) {
jeffreyhuang7ef47a92017-11-29 16:41:48 -080052 pref.setSummary(mContext.getResources().getString(R.string.model_summary,
53 getDeviceModel()));
Fan Zhangefb8d622017-02-23 17:50:27 -080054 }
55 }
56
57 @Override
58 public String getPreferenceKey() {
59 return KEY_DEVICE_MODEL;
60 }
Fan Zhangdc5a06e2017-03-07 14:52:51 -080061
62 @Override
63 public boolean handlePreferenceTreeClick(Preference preference) {
64 if (!TextUtils.equals(preference.getKey(), KEY_DEVICE_MODEL)) {
65 return false;
66 }
67 final HardwareInfoDialogFragment fragment = HardwareInfoDialogFragment.newInstance();
68 fragment.show(mHost.getFragmentManager(), HardwareInfoDialogFragment.TAG);
69 return true;
70 }
Fan Zhangd53859d2017-03-23 16:42:13 -070071
72 public static String getDeviceModel() {
73 return Build.MODEL + DeviceInfoUtils.getMsvSuffix();
74 }
Fan Zhangefb8d622017-02-23 17:50:27 -080075}