• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.debug.IAdbManager;
22 import android.os.RemoteException;
23 import android.os.ServiceManager;
24 import android.text.TextUtils;
25 import android.util.Log;
26 
27 import androidx.fragment.app.Fragment;
28 import androidx.preference.Preference;
29 
30 import com.android.settings.core.BasePreferenceController;
31 import com.android.settings.core.SubSettingLauncher;
32 
33 /**
34  * Controller for the "Pair device with QR code" preference in the Wireless debugging
35  * fragment.
36  */
37 public class AdbQrCodePreferenceController extends BasePreferenceController {
38     private static final String TAG = "AdbQrCodePrefCtrl";
39 
40     private IAdbManager mAdbManager;
41     private Fragment mParentFragment;
42 
AdbQrCodePreferenceController(Context context, String key)43     public AdbQrCodePreferenceController(Context context, String key) {
44         super(context, key);
45 
46         mAdbManager = IAdbManager.Stub.asInterface(ServiceManager.getService(
47                 Context.ADB_SERVICE));
48     }
49 
setParentFragment(Fragment parent)50     public void setParentFragment(Fragment parent) {
51         mParentFragment = parent;
52     }
53 
54     @Override
getAvailabilityStatus()55     public int getAvailabilityStatus() {
56         try {
57             return mAdbManager.isAdbWifiQrSupported() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
58         } catch (RemoteException e) {
59             Log.e(TAG, "Unable to check if adb wifi QR code scanning is supported.", e);
60         }
61 
62         return UNSUPPORTED_ON_DEVICE;
63     }
64 
65     @Override
handlePreferenceTreeClick(Preference preference)66     public boolean handlePreferenceTreeClick(Preference preference) {
67         if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
68             return false;
69         }
70 
71         new SubSettingLauncher(preference.getContext())
72                 .setDestination(AdbQrcodeScannerFragment.class.getName())
73                 .setSourceMetricsCategory(SettingsEnums.SETTINGS_ADB_WIRELESS)
74                 .setResultListener(mParentFragment,
75                     WirelessDebuggingFragment.PAIRING_DEVICE_REQUEST)
76                 .launch();
77         return true;
78     }
79 }
80