Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c978bf0e authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "AdbService sends callback on adb debugging enabled / disabled." am:...

Merge "AdbService sends callback on adb debugging enabled / disabled." am: 6efa908b am: 870e9c26

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1775965

Change-Id: I54a60b127532a7a8ea4f20c597789362ac2eb47f
parents a883c2c9 870e9c26
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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).
+31 −0
Original line number Diff line number Diff line
/*
 * 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);
}
+11 −0
Original line number Diff line number Diff line
@@ -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);
}
+35 −0
Original line number Diff line number Diff line
@@ -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<IAdbCallback> 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