From a623e9923070d1057fad52507aaab9d74c623c4e Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 27 Jul 2021 13:35:36 -0700 Subject: [PATCH] IAdbManager.getPairDevices returns FingerprintAndPairDevice[]. Map is not supported in C++ backend. To compile IAdbManager in C++, Map is translated into a list of key, value tuples. Test: pass Bug: 194829333 Change-Id: I92e3ad29e8a2bfbab3756d2ef5a2db76ba3cc3d9 --- .../debug/FingerprintAndPairDevice.aidl | 28 +++++++++++++++++++ core/java/android/debug/IAdbManager.aidl | 7 +++-- .../com/android/server/adb/AdbService.java | 18 +++++++++--- 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 core/java/android/debug/FingerprintAndPairDevice.aidl diff --git a/core/java/android/debug/FingerprintAndPairDevice.aidl b/core/java/android/debug/FingerprintAndPairDevice.aidl new file mode 100644 index 0000000000000..b439e14282e7c --- /dev/null +++ b/core/java/android/debug/FingerprintAndPairDevice.aidl @@ -0,0 +1,28 @@ +/* + * 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.PairDevice; + +/** + * @see {@link android.debug.IAdbManager#getPairedDevices()} + * @hide + */ +parcelable FingerprintAndPairDevice { + String keyFingerprint; + PairDevice device; +} \ No newline at end of file diff --git a/core/java/android/debug/IAdbManager.aidl b/core/java/android/debug/IAdbManager.aidl index aea7633d91dcf..d858c549c609e 100644 --- a/core/java/android/debug/IAdbManager.aidl +++ b/core/java/android/debug/IAdbManager.aidl @@ -16,6 +16,8 @@ package android.debug; +import android.debug.FingerprintAndPairDevice; + /** * Interface to communicate remotely with the {@code AdbService} in the system server. * @@ -58,9 +60,10 @@ interface IAdbManager { void denyWirelessDebugging(); /** - * Returns a Map with the key fingerprint mapped to the device information. + * Returns an array of NamedPairDevice with the key fingerprint mapped to the device + * information. */ - Map getPairedDevices(); + FingerprintAndPairDevice[] getPairedDevices(); /** * Unpair the device identified by the key fingerprint it uses. diff --git a/services/core/java/com/android/server/adb/AdbService.java b/services/core/java/com/android/server/adb/AdbService.java index 29bb5428dd84b..6002001f14169 100644 --- a/services/core/java/com/android/server/adb/AdbService.java +++ b/services/core/java/com/android/server/adb/AdbService.java @@ -27,6 +27,7 @@ import android.database.ContentObserver; import android.debug.AdbManager; import android.debug.AdbManagerInternal; import android.debug.AdbTransportType; +import android.debug.FingerprintAndPairDevice; import android.debug.IAdbManager; import android.debug.IAdbTransport; import android.debug.PairDevice; @@ -348,12 +349,21 @@ public class AdbService extends IAdbManager.Stub { } @Override - public Map getPairedDevices() { + public FingerprintAndPairDevice[] getPairedDevices() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_DEBUGGING, null); - if (mDebuggingManager != null) { - return mDebuggingManager.getPairedDevices(); + if (mDebuggingManager == null) { + return null; } - return null; + Map map = mDebuggingManager.getPairedDevices(); + FingerprintAndPairDevice[] ret = new FingerprintAndPairDevice[map.size()]; + int i = 0; + for (Map.Entry entry : map.entrySet()) { + ret[i] = new FingerprintAndPairDevice(); + ret[i].keyFingerprint = entry.getKey(); + ret[i].device = entry.getValue(); + i++; + } + return ret; } @Override