• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.car.settings.system;
18 
19 import android.bluetooth.BluetoothAdapter;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.Context;
22 import android.content.pm.PackageManager;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 
27 import com.android.car.settings.common.FragmentController;
28 import com.android.car.settings.common.PreferenceController;
29 
30 /** Updates the vehicle bluetooth mac address summary. */
31 public class BluetoothMacAddressPreferenceController extends
32         PreferenceController<Preference> {
33 
34     private BluetoothAdapter mBluetoothAdapter;
35 
BluetoothMacAddressPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)36     public BluetoothMacAddressPreferenceController(Context context, String preferenceKey,
37             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
38         this(context, preferenceKey, fragmentController, uxRestrictions,
39                 BluetoothAdapter.getDefaultAdapter());
40     }
41 
42     @VisibleForTesting
BluetoothMacAddressPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, BluetoothAdapter bluetoothAdapter)43     BluetoothMacAddressPreferenceController(Context context, String preferenceKey,
44             FragmentController fragmentController, CarUxRestrictions uxRestrictions,
45             BluetoothAdapter bluetoothAdapter) {
46         super(context, preferenceKey, fragmentController, uxRestrictions);
47         mBluetoothAdapter = bluetoothAdapter;
48     }
49 
50     @Override
getPreferenceType()51     protected Class<Preference> getPreferenceType() {
52         return Preference.class;
53     }
54 
55     @Override
getAvailabilityStatus()56     protected int getAvailabilityStatus() {
57         if (!getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
58             return UNSUPPORTED_ON_DEVICE;
59         }
60         return AVAILABLE_FOR_VIEWING;
61     }
62 
63     @Override
updateState(Preference preference)64     protected void updateState(Preference preference) {
65         preference.setSummary(mBluetoothAdapter.getAddress());
66     }
67 }
68