Home | History | Annotate | Download | only in deviceinfo
      1 /*
      2  * Copyright (C) 2016 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;
     18 
     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.internal.annotations.VisibleForTesting;
     26 import com.android.settings.core.PreferenceController;
     27 
     28 public class SerialNumberPreferenceController extends PreferenceController {
     29 
     30     private static final String KEY_SERIAL_NUMBER = "serial_number";
     31 
     32     private final String mSerialNumber;
     33 
     34     public SerialNumberPreferenceController(Context context) {
     35         this(context, Build.getSerial());
     36     }
     37 
     38     @VisibleForTesting
     39     SerialNumberPreferenceController(Context context, String serialNumber) {
     40         super(context);
     41         mSerialNumber = serialNumber;
     42     }
     43 
     44     @Override
     45     public boolean isAvailable() {
     46         return !TextUtils.isEmpty(mSerialNumber);
     47     }
     48 
     49     @Override
     50     public void displayPreference(PreferenceScreen screen) {
     51         super.displayPreference(screen);
     52         final Preference pref = screen.findPreference(KEY_SERIAL_NUMBER);
     53         if (pref != null) {
     54             pref.setSummary(mSerialNumber);
     55         }
     56     }
     57 
     58     @Override
     59     public String getPreferenceKey() {
     60         return KEY_SERIAL_NUMBER;
     61     }
     62 }
     63