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 package com.android.settings.deviceinfo; 17 18 import android.app.Fragment; 19 import android.content.Context; 20 import android.os.Build; 21 import android.support.v7.preference.Preference; 22 import android.support.v7.preference.PreferenceScreen; 23 import android.text.TextUtils; 24 25 import com.android.settings.core.PreferenceController; 26 import com.android.settingslib.DeviceInfoUtils; 27 28 public class DeviceModelPreferenceController extends PreferenceController { 29 30 private static final String KEY_DEVICE_MODEL = "device_model"; 31 32 private final Fragment mHost; 33 DeviceModelPreferenceController(Context context, Fragment host)34 public DeviceModelPreferenceController(Context context, Fragment host) { 35 super(context); 36 mHost = host; 37 } 38 39 @Override isAvailable()40 public boolean isAvailable() { 41 return true; 42 } 43 44 @Override displayPreference(PreferenceScreen screen)45 public void displayPreference(PreferenceScreen screen) { 46 super.displayPreference(screen); 47 final Preference pref = screen.findPreference(KEY_DEVICE_MODEL); 48 if (pref != null) { 49 pref.setSummary(getDeviceModel()); 50 } 51 } 52 53 @Override getPreferenceKey()54 public String getPreferenceKey() { 55 return KEY_DEVICE_MODEL; 56 } 57 58 @Override handlePreferenceTreeClick(Preference preference)59 public boolean handlePreferenceTreeClick(Preference preference) { 60 if (!TextUtils.equals(preference.getKey(), KEY_DEVICE_MODEL)) { 61 return false; 62 } 63 final HardwareInfoDialogFragment fragment = HardwareInfoDialogFragment.newInstance(); 64 fragment.show(mHost.getFragmentManager(), HardwareInfoDialogFragment.TAG); 65 return true; 66 } 67 getDeviceModel()68 public static String getDeviceModel() { 69 return Build.MODEL + DeviceInfoUtils.getMsvSuffix(); 70 } 71 } 72