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 static android.content.Context.CLIPBOARD_SERVICE; 20 21 import android.content.ClipData; 22 import android.content.ClipboardManager; 23 import android.content.Context; 24 import android.os.Build; 25 import android.provider.Settings; 26 import android.widget.Toast; 27 28 import androidx.preference.PreferenceScreen; 29 30 import com.android.settings.R; 31 import com.android.settings.core.BasePreferenceController; 32 33 /** 34 * Controller for the device name preference in the Wireless debugging 35 * fragment. 36 */ 37 public class AdbDeviceNamePreferenceController extends BasePreferenceController { 38 private static final String TAG = "AdbDeviceNamePrefCtrl"; 39 40 private String mDeviceName; 41 AdbDeviceNamePreferenceController(Context context, String key)42 public AdbDeviceNamePreferenceController(Context context, String key) { 43 super(context, key); 44 } 45 46 @Override displayPreference(PreferenceScreen screen)47 public void displayPreference(PreferenceScreen screen) { 48 super.displayPreference(screen); 49 50 // Keep device name in sync with Settings > About phone > Device name 51 mDeviceName = Settings.Global.getString(mContext.getContentResolver(), 52 Settings.Global.DEVICE_NAME); 53 if (mDeviceName == null) { 54 mDeviceName = Build.MODEL; 55 } 56 } 57 58 @Override getSummary()59 public CharSequence getSummary() { 60 return mDeviceName; 61 } 62 63 @Override getAvailabilityStatus()64 public int getAvailabilityStatus() { 65 return AVAILABLE; 66 } 67 68 @Override copy()69 public void copy() { 70 final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService( 71 CLIPBOARD_SERVICE); 72 clipboard.setPrimaryClip(ClipData.newPlainText("text", mDeviceName)); 73 74 final String toast = mContext.getString(R.string.copyable_slice_toast, 75 mDeviceName); 76 Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); 77 } 78 } 79