1 /* 2 * Copyright (C) 2018 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 android.debug; 18 19 import android.annotation.RequiresPermission; 20 import android.annotation.SystemApi; 21 import android.annotation.SystemService; 22 import android.content.Context; 23 import android.os.RemoteException; 24 25 /** 26 * This class allows the control of ADB-related functions. 27 * @hide 28 */ 29 @SystemApi 30 @SystemService(Context.ADB_SERVICE) 31 public class AdbManager { 32 private static final String TAG = "AdbManager"; 33 34 /** 35 * Action indicating the state change of wireless debugging. Can be either 36 * STATUS_CONNECTED 37 * STATUS_DISCONNECTED 38 * 39 * @hide 40 */ 41 public static final String WIRELESS_DEBUG_STATE_CHANGED_ACTION = 42 "com.android.server.adb.WIRELESS_DEBUG_STATUS"; 43 44 /** 45 * Contains the list of paired devices. 46 * 47 * @hide 48 */ 49 public static final String WIRELESS_DEBUG_PAIRED_DEVICES_ACTION = 50 "com.android.server.adb.WIRELESS_DEBUG_PAIRED_DEVICES"; 51 52 /** 53 * Action indicating the status of a pairing. Can be either 54 * WIRELESS_STATUS_FAIL 55 * WIRELESS_STATUS_SUCCESS 56 * WIRELESS_STATUS_CANCELLED 57 * WIRELESS_STATUS_PAIRING_CODE 58 * WIRELESS_STATUS_CONNECTED 59 * 60 * @hide 61 */ 62 public static final String WIRELESS_DEBUG_PAIRING_RESULT_ACTION = 63 "com.android.server.adb.WIRELESS_DEBUG_PAIRING_RESULT"; 64 65 /** 66 * Extra containing the PairDevice map of paired/pairing devices. 67 * 68 * @hide 69 */ 70 public static final String WIRELESS_DEVICES_EXTRA = "devices_map"; 71 72 /** 73 * The status of the pairing/unpairing. 74 * 75 * @hide 76 */ 77 public static final String WIRELESS_STATUS_EXTRA = "status"; 78 79 /** 80 * The PairDevice. 81 * 82 * @hide 83 */ 84 public static final String WIRELESS_PAIR_DEVICE_EXTRA = "pair_device"; 85 86 /** 87 * The six-digit pairing code. 88 * 89 * @hide 90 */ 91 public static final String WIRELESS_PAIRING_CODE_EXTRA = "pairing_code"; 92 93 /** 94 * The adb connection/pairing port that was opened. 95 * 96 * @hide 97 */ 98 public static final String WIRELESS_DEBUG_PORT_EXTRA = "adb_port"; 99 100 /** 101 * Status indicating the pairing/unpairing failed. 102 * 103 * @hide 104 */ 105 public static final int WIRELESS_STATUS_FAIL = 0; 106 107 /** 108 * Status indicating the pairing/unpairing succeeded. 109 * 110 * @hide 111 */ 112 public static final int WIRELESS_STATUS_SUCCESS = 1; 113 114 /** 115 * Status indicating the pairing/unpairing was cancelled. 116 * 117 * @hide 118 */ 119 public static final int WIRELESS_STATUS_CANCELLED = 2; 120 121 /** 122 * Status indicating the pairing code for pairing. 123 * 124 * @hide 125 */ 126 public static final int WIRELESS_STATUS_PAIRING_CODE = 3; 127 128 /** 129 * Status indicating wireless debugging is connected. 130 * 131 * @hide 132 */ 133 public static final int WIRELESS_STATUS_CONNECTED = 4; 134 135 /** 136 * Status indicating wireless debugging is disconnected. 137 * 138 * @hide 139 */ 140 public static final int WIRELESS_STATUS_DISCONNECTED = 5; 141 142 private final Context mContext; 143 private final IAdbManager mService; 144 145 /** 146 * {@hide} 147 */ AdbManager(Context context, IAdbManager service)148 public AdbManager(Context context, IAdbManager service) { 149 mContext = context; 150 mService = service; 151 } 152 153 /** 154 * @return true if the device supports secure ADB over Wi-Fi. 155 * @hide 156 */ 157 @SystemApi 158 @RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING) isAdbWifiSupported()159 public boolean isAdbWifiSupported() { 160 try { 161 return mService.isAdbWifiSupported(); 162 } catch (RemoteException e) { 163 throw e.rethrowFromSystemServer(); 164 } 165 } 166 167 /** 168 * @return true if the device supports secure ADB over Wi-Fi and device pairing by 169 * QR code. 170 * @hide 171 */ 172 @SystemApi 173 @RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING) isAdbWifiQrSupported()174 public boolean isAdbWifiQrSupported() { 175 try { 176 return mService.isAdbWifiQrSupported(); 177 } catch (RemoteException e) { 178 throw e.rethrowFromSystemServer(); 179 } 180 } 181 } 182