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

Commit 7ffb8c9d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Replaced usage of net AIDL and bugfix"

parents b724b574 c1dcd413
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -26,14 +26,14 @@ import android.bluetooth.BluetoothPan.LocalPanRole;
import android.bluetooth.BluetoothPan.RemotePanRole;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothPan;
import android.bluetooth.IBluetoothPanCallback;
import android.content.AttributionSource;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.net.ITetheredInterfaceCallback;
import android.net.TetheringInterface;
import android.net.TetheringManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.UserManager;
@@ -46,7 +46,7 @@ import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.modules.utils.HandlerExecutor;
import com.android.modules.utils.SynchronousResultReceiver;

import java.util.ArrayList;
@@ -74,7 +74,7 @@ public class PanService extends ProfileService {
    private String mPanIfName;
    private boolean mIsTethering = false;
    private boolean mNativeAvailable;
    private List<ITetheredInterfaceCallback> mBluetoothTetheringCallbacks;
    private HashMap<String, IBluetoothPanCallback> mBluetoothTetheringCallbacks;

    private TetheringManager mTetheringManager;
    private DatabaseManager mDatabaseManager;
@@ -144,7 +144,7 @@ public class PanService extends ProfileService {
        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
                "DatabaseManager cannot be null when PanService starts");

        mBluetoothTetheringCallbacks = new ArrayList<>();
        mBluetoothTetheringCallbacks = new HashMap<>();
        mPanDevices = new HashMap<BluetoothDevice, BluetoothPanDevice>();
        try {
            mMaxPanDevices = getResources().getInteger(
@@ -159,7 +159,7 @@ public class PanService extends ProfileService {

        mTetheringManager = getSystemService(TetheringManager.class);
        mTetheringManager.registerTetheringEventCallback(
                new HandlerExecutor(BackgroundThread.getHandler()), mTetheringCallback);
                new HandlerExecutor(new Handler(Looper.getMainLooper())), mTetheringCallback);
        setPanService(this);
        mStarted = true;

@@ -356,7 +356,7 @@ public class PanService extends ProfileService {
        }

        @Override
        public void setBluetoothTethering(ITetheredInterfaceCallback callback,
        public void setBluetoothTethering(IBluetoothPanCallback callback, int id,
                boolean value, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
@@ -365,8 +365,7 @@ public class PanService extends ProfileService {
                    Log.d(TAG, "setBluetoothTethering: " + value
                            + ", pkgName: " + source.getPackageName()
                            + ", mTetherOn: " + service.mTetherOn);
                    service.setBluetoothTethering(callback, value, source.getPackageName(),
                            source.getAttributionTag());
                    service.setBluetoothTethering(callback, id, source.getUid(), value);
                }
                receiver.send(null);
            } catch (RuntimeException e) {
@@ -446,8 +445,8 @@ public class PanService extends ProfileService {
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
            android.Manifest.permission.TETHER_PRIVILEGED,
    })
    void setBluetoothTethering(ITetheredInterfaceCallback callback, boolean value,
            final String pkgName, final String callingAttributionTag) {
    void setBluetoothTethering(IBluetoothPanCallback callback, int id, int callerUid,
            boolean value) {
        if (DBG) {
            Log.d(TAG, "setBluetoothTethering: " + value + ", mTetherOn: " + mTetherOn);
        }
@@ -460,11 +459,23 @@ public class PanService extends ProfileService {
        if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING) && value) {
            throw new SecurityException("DISALLOW_CONFIG_TETHERING is enabled for this user.");
        }
        final String key = id + "/" + callerUid;
        if (callback != null) {
            boolean keyExists = mBluetoothTetheringCallbacks.containsKey(key);
            if (value) {
                mBluetoothTetheringCallbacks.add(callback);
                if (!keyExists) {
                    mBluetoothTetheringCallbacks.put(key, callback);
                } else {
                mBluetoothTetheringCallbacks.remove(callback);
                    Log.e(TAG, "setBluetoothTethering Error: Callback already registered.");
                    return;
                }
            } else {
                if (keyExists) {
                    mBluetoothTetheringCallbacks.remove(key);
                } else {
                    Log.e(TAG, "setBluetoothTethering Error: Callback not registered.");
                    return;
                }
            }
        } else if (mBluetoothTetheringCallbacks.isEmpty()) {
            Log.e(TAG, "setBluetoothTethering: " + value + ", Error: no callbacks registered.");
@@ -668,7 +679,7 @@ public class PanService extends ProfileService {
                if (!mIsTethering) {
                    mIsTethering = true;
                    try {
                        for (ITetheredInterfaceCallback cb : mBluetoothTetheringCallbacks) {
                        for (IBluetoothPanCallback cb : mBluetoothTetheringCallbacks.values()) {
                            cb.onAvailable(iface);
                        }
                    } catch (RemoteException e) {
@@ -681,7 +692,7 @@ public class PanService extends ProfileService {
                        + mPanDevices.size());
                if (mIsTethering && mPanDevices.size() == 0) {
                    try {
                        for (ITetheredInterfaceCallback cb : mBluetoothTetheringCallbacks) {
                        for (IBluetoothPanCallback cb : mBluetoothTetheringCallbacks.values()) {
                            cb.onUnavailable();
                        }
                    } catch (RemoteException e) {
+13 −11
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.net.ITetheredInterfaceCallback;
import android.net.TetheringManager.TetheredInterfaceCallback;
import android.net.TetheringManager.TetheredInterfaceRequest;
import android.os.Build;
@@ -198,12 +197,14 @@ public final class BluetoothPan implements BluetoothProfile {
     */
    public class BluetoothTetheredInterfaceRequest implements TetheredInterfaceRequest {
        private IBluetoothPan mService;
        private ITetheredInterfaceCallback mCb;
        private final IBluetoothPanCallback mPanCallback;
        private final int mId;

        private BluetoothTetheredInterfaceRequest(@NonNull IBluetoothPan service,
                @NonNull ITetheredInterfaceCallback cb) {
                @NonNull IBluetoothPanCallback panCallback, int id) {
            this.mService = service;
            this.mCb = cb;
            this.mPanCallback = panCallback;
            this.mId = id;
        }

        /**
@@ -216,19 +217,18 @@ public final class BluetoothPan implements BluetoothProfile {
        })
        @Override
        public void release() {
            if (mService == null || mCb == null) {
            if (mService == null) {
                throw new IllegalStateException(
                        "The tethered interface has already been released.");
            }
            try {
                final SynchronousResultReceiver recv = new SynchronousResultReceiver();
                mService.setBluetoothTethering(mCb, false, mAttributionSource, recv);
                mService.setBluetoothTethering(mPanCallback, mId, false, mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            } finally {
                mService = null;
                mCb = null;
            }
        }
    }
@@ -526,7 +526,7 @@ public final class BluetoothPan implements BluetoothProfile {
        } else if (isEnabled()) {
            try {
                final SynchronousResultReceiver recv = new SynchronousResultReceiver();
                service.setBluetoothTethering(null, value, mAttributionSource, recv);
                service.setBluetoothTethering(null, 0, value, mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
@@ -571,7 +571,7 @@ public final class BluetoothPan implements BluetoothProfile {
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
        } else if (isEnabled()) {
            final ITetheredInterfaceCallback cbInternal = new ITetheredInterfaceCallback.Stub() {
            final IBluetoothPanCallback panCallback = new IBluetoothPanCallback.Stub() {
                @Override
                public void onAvailable(String iface) {
                    executor.execute(() -> callback.onAvailable(iface));
@@ -584,9 +584,11 @@ public final class BluetoothPan implements BluetoothProfile {
            };
            try {
                final SynchronousResultReceiver recv = new SynchronousResultReceiver();
                service.setBluetoothTethering(cbInternal, true, mAttributionSource, recv);
                service.setBluetoothTethering(panCallback, callback.hashCode(), true,
                        mAttributionSource, recv);
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
                return new BluetoothTetheredInterfaceRequest(service, cbInternal);
                return new BluetoothTetheredInterfaceRequest(service, panCallback,
                        callback.hashCode());
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
+2 −1
Original line number Diff line number Diff line
@@ -28,12 +28,13 @@ filegroup {
        "android/bluetooth/IBluetoothVolumeControl.aidl",
        "android/bluetooth/IBluetoothHidHost.aidl",
        "android/bluetooth/IBluetoothLeAudio.aidl",
        "android/bluetooth/IBluetoothPan.aidl",
        "android/bluetooth/IBluetoothManager.aidl",
        "android/bluetooth/IBluetoothManagerCallback.aidl",
        "android/bluetooth/IBluetoothMap.aidl",
        "android/bluetooth/IBluetoothMapClient.aidl",
        "android/bluetooth/IBluetoothMcpServiceManager.aidl",
        "android/bluetooth/IBluetoothPan.aidl",
        "android/bluetooth/IBluetoothPanCallback.aidl",
        "android/bluetooth/IBluetoothPbap.aidl",
        "android/bluetooth/IBluetoothPbapClient.aidl",
        "android/bluetooth/IBluetoothSap.aidl",
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
package android.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.IBluetoothPanCallback;
import android.content.AttributionSource;
import android.net.ITetheredInterfaceCallback;

import com.android.modules.utils.SynchronousResultReceiver;

@@ -32,7 +32,7 @@ oneway interface IBluetoothPan {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    void isTetheringOn(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.TETHER_PRIVILEGED})")
    void setBluetoothTethering(ITetheredInterfaceCallback callback, boolean value, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    void setBluetoothTethering(IBluetoothPanCallback callback, int id, boolean value, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void connect(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright 2012 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.bluetooth;

/**
 * Callback for Bluetooth Pan Tethering
 *
 * {@hide}
 */
oneway interface IBluetoothPanCallback {
    void onAvailable(in String iface);
    void onUnavailable();
}
 No newline at end of file