diff --git a/core/java/Android.bp b/core/java/Android.bp index 3a883d8ebfc17..427bbd82f561d 100644 --- a/core/java/Android.bp +++ b/core/java/Android.bp @@ -323,6 +323,23 @@ aidl_interface { }, } +aidl_interface { + name: "android.debug_aidl", + unstable: true, + srcs: [ + "android/debug/AdbTransportType.aidl", + "android/debug/FingerprintAndPairDevice.aidl", + "android/debug/IAdbCallback.aidl", + "android/debug/IAdbManager.aidl", + "android/debug/PairDevice.aidl", + ], + backend: { + cpp: { + enabled: true, + }, + }, +} + // Avoid including Parcelable classes as we don't want to have two copies of // Parcelable cross the libraries. This is used by telephony-common (frameworks/opt/telephony) // and TeleService app (packages/services/Telephony). diff --git a/core/java/android/debug/IAdbCallback.aidl b/core/java/android/debug/IAdbCallback.aidl new file mode 100644 index 0000000000000..9c8f1cfac5273 --- /dev/null +++ b/core/java/android/debug/IAdbCallback.aidl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.debug; + +import android.debug.AdbTransportType; + +/** + * Callback interface of {@link android.debug.IAdbCallbackManager}. + * + * @hide + */ +oneway interface IAdbCallback { + /** + * On debugging enabled, service providing IAdbManager calls this function. + */ + void onDebuggingChanged(boolean enabled, AdbTransportType type); +} diff --git a/core/java/android/debug/IAdbManager.aidl b/core/java/android/debug/IAdbManager.aidl index d858c549c609e..314c4058dd062 100644 --- a/core/java/android/debug/IAdbManager.aidl +++ b/core/java/android/debug/IAdbManager.aidl @@ -17,6 +17,7 @@ package android.debug; import android.debug.FingerprintAndPairDevice; +import android.debug.IAdbCallback; /** * Interface to communicate remotely with the {@code AdbService} in the system server. @@ -111,4 +112,14 @@ interface IAdbManager { * QR code. */ boolean isAdbWifiQrSupported(); + + /** + * Register callback for ADB debugging changed notification. + */ + void registerCallback(IAdbCallback callback); + + /** + * Unregister callback for ADB debugging changed notification. + */ + void unregisterCallback(IAdbCallback callback); } diff --git a/services/core/java/com/android/server/adb/AdbService.java b/services/core/java/com/android/server/adb/AdbService.java index 6002001f14169..7a4d2ce50cd3f 100644 --- a/services/core/java/com/android/server/adb/AdbService.java +++ b/services/core/java/com/android/server/adb/AdbService.java @@ -28,6 +28,7 @@ import android.debug.AdbManager; import android.debug.AdbManagerInternal; import android.debug.AdbTransportType; import android.debug.FingerprintAndPairDevice; +import android.debug.IAdbCallback; import android.debug.IAdbManager; import android.debug.IAdbTransport; import android.debug.PairDevice; @@ -36,6 +37,7 @@ import android.net.Uri; import android.os.Binder; import android.os.IBinder; import android.os.ParcelFileDescriptor; +import android.os.RemoteCallbackList; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; @@ -88,6 +90,7 @@ public class AdbService extends IAdbManager.Stub { private final AdbConnectionPortListener mPortListener = new AdbConnectionPortListener(); private AdbDebuggingManager.AdbConnectionPortPoller mConnectionPortPoller; + private final RemoteCallbackList mCallbacks = new RemoteCallbackList<>(); /** * Manages the service lifecycle for {@code AdbService} in {@code SystemServer}. */ @@ -411,6 +414,21 @@ public class AdbService extends IAdbManager.Stub { return mConnectionPort.get(); } + @Override + public void registerCallback(IAdbCallback callback) throws RemoteException { + if (DEBUG) { + Slog.d(TAG, "Registering callback " + callback); + } + mCallbacks.register(callback); + } + + @Override + public void unregisterCallback(IAdbCallback callback) throws RemoteException { + if (DEBUG) { + Slog.d(TAG, "Unregistering callback " + callback); + } + mCallbacks.unregister(callback); + } /** * This listener is only used when ro.adb.secure=0. Otherwise, AdbDebuggingManager will * do this. @@ -517,6 +535,23 @@ public class AdbService extends IAdbManager.Stub { if (mDebuggingManager != null) { mDebuggingManager.setAdbEnabled(enable, transportType); } + + if (DEBUG) { + Slog.d(TAG, "Broadcasting enable = " + enable + ", type = " + transportType); + } + mCallbacks.broadcast((callback) -> { + if (DEBUG) { + Slog.d(TAG, "Sending enable = " + enable + ", type = " + transportType + + " to " + callback); + } + try { + callback.onDebuggingChanged(enable, transportType); + } catch (RemoteException ex) { + if (DEBUG) { + Slog.d(TAG, "Unable to send onDebuggingChanged:", ex); + } + } + }); } @Override