Tony Mantler | f43b986 | 2017-10-03 15:46:20 -0700 | [diff] [blame] | 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.settingslib.deviceinfo; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Build; |
Fan Zhang | 7293cf4 | 2017-11-07 14:45:47 -0800 | [diff] [blame] | 21 | import android.support.annotation.VisibleForTesting; |
Tony Mantler | f43b986 | 2017-10-03 15:46:20 -0700 | [diff] [blame] | 22 | import android.support.v7.preference.Preference; |
| 23 | import android.support.v7.preference.PreferenceScreen; |
| 24 | import android.text.TextUtils; |
| 25 | |
Tony Mantler | f43b986 | 2017-10-03 15:46:20 -0700 | [diff] [blame] | 26 | import com.android.settingslib.core.AbstractPreferenceController; |
| 27 | |
| 28 | /** |
| 29 | * Preference controller for displaying device serial number. Wraps {@link Build#getSerial()}. |
| 30 | */ |
| 31 | public class AbstractSerialNumberPreferenceController extends AbstractPreferenceController { |
Fan Zhang | 7293cf4 | 2017-11-07 14:45:47 -0800 | [diff] [blame] | 32 | |
| 33 | @VisibleForTesting |
| 34 | static final String KEY_SERIAL_NUMBER = "serial_number"; |
Tony Mantler | f43b986 | 2017-10-03 15:46:20 -0700 | [diff] [blame] | 35 | |
| 36 | private final String mSerialNumber; |
| 37 | |
| 38 | public AbstractSerialNumberPreferenceController(Context context) { |
| 39 | this(context, Build.getSerial()); |
| 40 | } |
| 41 | |
| 42 | @VisibleForTesting |
| 43 | AbstractSerialNumberPreferenceController(Context context, String serialNumber) { |
| 44 | super(context); |
| 45 | mSerialNumber = serialNumber; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public boolean isAvailable() { |
| 50 | return !TextUtils.isEmpty(mSerialNumber); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void displayPreference(PreferenceScreen screen) { |
| 55 | super.displayPreference(screen); |
| 56 | final Preference pref = screen.findPreference(KEY_SERIAL_NUMBER); |
| 57 | if (pref != null) { |
| 58 | pref.setSummary(mSerialNumber); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String getPreferenceKey() { |
| 64 | return KEY_SERIAL_NUMBER; |
| 65 | } |
| 66 | } |