2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.bluetooth;
19 import android.bluetooth.BluetoothDevice;
20 import android.content.Context;
21 import android.os.Bundle;
23 import com.android.internal.annotations.VisibleForTesting;
24 import com.android.internal.logging.nano.MetricsProto;
25 import com.android.settings.R;
26 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
27 import com.android.settingslib.bluetooth.LocalBluetoothManager;
29 /** Provides a dialog for changing the display name of a remote bluetooth device. */
30 public class RemoteDeviceNameDialogFragment extends BluetoothNameDialogFragment {
31 public static final String TAG = "RemoteDeviceName";
32 private static final String KEY_CACHED_DEVICE_ADDRESS = "cached_device";
34 private CachedBluetoothDevice mDevice;
36 public static RemoteDeviceNameDialogFragment newInstance(CachedBluetoothDevice device) {
37 Bundle args = new Bundle(1);
38 args.putString(KEY_CACHED_DEVICE_ADDRESS, device.getDevice().getAddress());
39 RemoteDeviceNameDialogFragment fragment = new RemoteDeviceNameDialogFragment();
40 fragment.setArguments(args);
45 CachedBluetoothDevice getDevice(Context context) {
46 String deviceAddress = getArguments().getString(KEY_CACHED_DEVICE_ADDRESS);
47 LocalBluetoothManager manager = Utils.getLocalBtManager(context);
48 BluetoothDevice device = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
49 return manager.getCachedDeviceManager().findDevice(device);
53 public void onAttach(Context context) {
54 super.onAttach(context);
55 mDevice = getDevice(context);
59 public int getMetricsCategory() {
60 return MetricsProto.MetricsEvent.DIALOG_BLUETOOTH_PAIRED_DEVICE_RENAME;
64 protected int getDialogTitle() {
65 return R.string.bluetooth_device_name;
69 protected String getDeviceName() {
70 if (mDevice != null) {
71 return mDevice.getName();
77 protected void setDeviceName(String deviceName) {
78 if (mDevice != null) {
79 mDevice.setName(deviceName);