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