blob: 90f14ef4c32cdeb5244457bfdc147ed7dc980606 [file] [log] [blame]
Tony Mantlerf43b9862017-10-03 15:46:20 -07001/*
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
17package com.android.settingslib.deviceinfo;
18
19import android.content.Context;
20import android.os.Build;
Fan Zhang7293cf42017-11-07 14:45:47 -080021import android.support.annotation.VisibleForTesting;
Tony Mantlerf43b9862017-10-03 15:46:20 -070022import android.support.v7.preference.Preference;
23import android.support.v7.preference.PreferenceScreen;
24import android.text.TextUtils;
25
Tony Mantlerf43b9862017-10-03 15:46:20 -070026import com.android.settingslib.core.AbstractPreferenceController;
27
28/**
29 * Preference controller for displaying device serial number. Wraps {@link Build#getSerial()}.
30 */
31public class AbstractSerialNumberPreferenceController extends AbstractPreferenceController {
Fan Zhang7293cf42017-11-07 14:45:47 -080032
33 @VisibleForTesting
34 static final String KEY_SERIAL_NUMBER = "serial_number";
Tony Mantlerf43b9862017-10-03 15:46:20 -070035
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}