1 /*
2  * Copyright (C) 2020 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.development;
18 
19 import android.content.Context;
20 import android.os.Build;
21 import android.provider.Settings;
22 
23 import androidx.preference.PreferenceScreen;
24 
25 import com.android.settings.core.BasePreferenceController;
26 
27 /**
28  * Controller for the device name preference in the Wireless debugging
29  * fragment.
30  */
31 public class AdbDeviceNamePreferenceController extends BasePreferenceController {
32     private String mDeviceName;
33 
AdbDeviceNamePreferenceController(Context context, String key)34     public AdbDeviceNamePreferenceController(Context context, String key) {
35         super(context, key);
36     }
37 
38     @Override
displayPreference(PreferenceScreen screen)39     public void displayPreference(PreferenceScreen screen) {
40         super.displayPreference(screen);
41 
42         // Keep device name in sync with Settings > About phone > Device name
43         mDeviceName = Settings.Global.getString(mContext.getContentResolver(),
44                 Settings.Global.DEVICE_NAME);
45         if (mDeviceName == null) {
46             mDeviceName = Build.MODEL;
47         }
48     }
49 
50     @Override
getSummary()51     public CharSequence getSummary() {
52         return mDeviceName;
53     }
54 
55     @Override
getAvailabilityStatus()56     public int getAvailabilityStatus() {
57         return AVAILABLE;
58     }
59 }
60