1 /* 2 * Copyright (C) 2023 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.bedstead.adb 18 19 import android.util.Log 20 import com.android.bedstead.nene.utils.ShellCommandUtils 21 import com.android.bedstead.nene.TestApis 22 import com.android.bedstead.nene.annotations.Experimental 23 import com.android.bedstead.nene.exceptions.NeneException 24 25 /** Helper methods related to Adb. */ 26 object Adb { 27 28 private const val ADB_WIFI_ENABLED = "adb_wifi_enabled" 29 private const val LOG_TAG = "Adb" 30 31 /** 32 * True if the device can run commands as root. 33 */ isRootAvailablenull34 fun isRootAvailable(): Boolean = ShellCommandUtils.isRootAvailable() 35 36 /** 37 * True if Adb is enabled over wifi. 38 */ 39 // TODO(scottjonathan): This API would be more useful if it checked if we actually had an 40 // active adb connection over wifi rather than just if the setting is set. 41 @Experimental 42 fun isEnabledOverWifi(): Boolean { 43 return try { 44 TestApis.settings().global().getInt(ADB_WIFI_ENABLED) == 1 45 } catch (exception: NeneException) { 46 Log.w(LOG_TAG,"ADB_WIFI_ENABLED setting not found on the device", exception) 47 false 48 } 49 } 50 } 51 TestApisnull52fun TestApis.adb() = Adb 53