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.R; 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settingslib.DeviceInfoUtils; 28 import com.android.settingslib.core.AbstractPreferenceController; 29 30 public class DeviceModelPreferenceController extends AbstractPreferenceController implements 31 PreferenceControllerMixin { 32 33 private static final String KEY_DEVICE_MODEL = "device_model"; 34 35 private final Fragment mHost; 36 DeviceModelPreferenceController(Context context, Fragment host)37 public DeviceModelPreferenceController(Context context, Fragment host) { 38 super(context); 39 mHost = host; 40 } 41 42 @Override isAvailable()43 public boolean isAvailable() { 44 return mContext.getResources().getBoolean(R.bool.config_show_device_model); 45 } 46 47 @Override displayPreference(PreferenceScreen screen)48 public void displayPreference(PreferenceScreen screen) { 49 super.displayPreference(screen); 50 final Preference pref = screen.findPreference(KEY_DEVICE_MODEL); 51 if (pref != null) { 52 pref.setSummary(mContext.getResources().getString(R.string.model_summary, 53 getDeviceModel())); 54 } 55 } 56 57 @Override getPreferenceKey()58 public String getPreferenceKey() { 59 return KEY_DEVICE_MODEL; 60 } 61 62 @Override handlePreferenceTreeClick(Preference preference)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 } 71 getDeviceModel()72 public static String getDeviceModel() { 73 return Build.MODEL + DeviceInfoUtils.getMsvSuffix(); 74 } 75 } 76