OSDN Git Service

Prevent overlay drawing on top of Bluetooth discovery request dialog
[android-x86/packages-apps-Settings.git] / src / com / android / settings / bluetooth / RemoteDeviceNameDialogFragment.java
1 /*
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
17 package com.android.settings.bluetooth;
18
19 import android.bluetooth.BluetoothDevice;
20 import android.content.Context;
21 import android.os.Bundle;
22
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;
28
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";
33
34     private CachedBluetoothDevice mDevice;
35
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);
41         return fragment;
42     }
43
44     @VisibleForTesting
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);
50     }
51
52     @Override
53     public void onAttach(Context context) {
54         super.onAttach(context);
55         mDevice = getDevice(context);
56     }
57
58     @Override
59     public int getMetricsCategory() {
60         return MetricsProto.MetricsEvent.DIALOG_BLUETOOTH_PAIRED_DEVICE_RENAME;
61     }
62
63     @Override
64     protected int getDialogTitle() {
65         return R.string.bluetooth_device_name;
66     }
67
68     @Override
69     protected String getDeviceName() {
70         if (mDevice != null) {
71             return mDevice.getName();
72         }
73         return null;
74     }
75
76     @Override
77     protected void setDeviceName(String deviceName) {
78         if (mDevice != null) {
79             mDevice.setName(deviceName);
80         }
81     }
82 }