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

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

Merge "gtbs: Add AttributionSource to the API" am: d945a2f8 am: cd15d2b6

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1945475

Change-Id: I2d8ce1e1bb2f66475c2bcba64f064030403e2097
parents 6deb66b2 cd15d2b6
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.bluetooth.BluetoothLeCallControl;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.IBluetoothLeCallControl;
import android.bluetooth.IBluetoothLeCallControlCallback;
import android.content.AttributionSource;
import android.content.Context;
import android.os.ParcelUuid;
import android.os.RemoteException;
@@ -142,8 +143,10 @@ public class TbsService extends ProfileService {
    static class TbsServerBinder extends IBluetoothLeCallControl.Stub implements IProfileServiceBinder {
        private TbsService mService;

        private TbsService getService() {
            if (!Utils.checkCallerIsSystemOrActiveUser(TAG)) {
        private TbsService getService(AttributionSource source) {
            if (!Utils.checkCallerIsSystemOrActiveUser(TAG)
                || !Utils.checkServiceAvailable(mService, TAG)
                || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                Log.w(TAG, "TbsService call not allowed for non-active user");
                return null;
            }
@@ -171,8 +174,9 @@ public class TbsService extends ProfileService {

        @Override
        public void registerBearer(String token, IBluetoothLeCallControlCallback callback, String uci,
                List<String> uriSchemes, int capabilities, String providerName, int technology) {
            TbsService service = getService();
                List<String> uriSchemes, int capabilities, String providerName, int technology,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.registerBearer(token, callback, uci, uriSchemes, capabilities, providerName,
                        technology);
@@ -182,8 +186,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void unregisterBearer(String token) {
            TbsService service = getService();
        public void unregisterBearer(String token,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.unregisterBearer(token);
            } else {
@@ -192,8 +197,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void requestResult(int ccid, int requestId, int result) {
            TbsService service = getService();
        public void requestResult(int ccid, int requestId, int result,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.requestResult(ccid, requestId, result);
            } else {
@@ -202,8 +208,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void callAdded(int ccid, BluetoothLeCall call) {
            TbsService service = getService();
        public void callAdded(int ccid, BluetoothLeCall call,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.callAdded(ccid, call);
            } else {
@@ -212,8 +219,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void callRemoved(int ccid, ParcelUuid callId, int reason) {
            TbsService service = getService();
        public void callRemoved(int ccid, ParcelUuid callId, int reason,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.callRemoved(ccid, callId.getUuid(), reason);
            } else {
@@ -222,8 +230,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void callStateChanged(int ccid, ParcelUuid callId, int state) {
            TbsService service = getService();
        public void callStateChanged(int ccid, ParcelUuid callId, int state,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.callStateChanged(ccid, callId.getUuid(), state);
            } else {
@@ -232,8 +241,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void currentCallsList(int ccid, List<BluetoothLeCall> calls) {
            TbsService service = getService();
        public void currentCallsList(int ccid, List<BluetoothLeCall> calls,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.currentCallsList(ccid, calls);
            } else {
@@ -242,8 +252,9 @@ public class TbsService extends ProfileService {
        }

        @Override
        public void networkStateChanged(int ccid, String providerName, int technology) {
            TbsService service = getService();
        public void networkStateChanged(int ccid, String providerName, int technology,
                AttributionSource source) {
            TbsService service = getService(source);
            if (service != null) {
                service.networkStateChanged(ccid, providerName, technology);
            } else {
+83 −74
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.content.ComponentName;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Binder;
import android.os.Handler;
@@ -390,6 +391,7 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
    private ServiceListener mServiceListener;
    private volatile IBluetoothLeCallControl mService;
    private BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
    private int mCcid = 0;
    private String mToken;
    private Callback mCallback = null;
@@ -414,6 +416,7 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
    /* package */ BluetoothLeCallControl(Context context, ServiceListener listener) {
        mContext = context;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mAttributionSource = mAdapter.getAttributionSource();
        mServiceListener = listener;

        IBluetoothManager mgr = mAdapter.getBluetoothManager();
@@ -568,7 +571,11 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        mToken = uci;

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return false;
        }

        if (mCallback != null) {
            Log.e(TAG, "Bearer can be opened only once");
            return false;
@@ -578,9 +585,10 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        try {
            CallbackWrapper callbackWrapper = new CallbackWrapper(executor, callback);
            service.registerBearer(mToken, callbackWrapper, uci, uriSchemes, capabilities,
                                        provider, technology);
                                    provider, technology, mAttributionSource);

        } catch (RemoteException e) {
                Log.e(TAG, "", e);
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            mCallback = null;
            return false;
        }
@@ -593,13 +601,6 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        return true;
    }

        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
        }

        return false;
    }

    /**
     * Unregister Telephone Bearer Service and destroy all the associated data.
     *
@@ -614,20 +615,20 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
            return;
        }

        final IBluetoothLeCallControl service = getService();
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        int ccid = mCcid;
        mCcid = 0;
        mCallback = null;

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
        try {
                service.unregisterBearer(mToken);
            service.unregisterBearer(mToken, mAttributionSource);
        } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
        }
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }
    }

@@ -664,15 +665,15 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        }

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
            try {
                service.callAdded(mCcid, call);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
        }
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        try {
            service.callAdded(mCcid, call, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }
    }

@@ -699,16 +700,16 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        }

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
            try {
                service.callRemoved(mCcid, new ParcelUuid(callId), reason);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
        }
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }
        try {
            service.callRemoved(mCcid, new ParcelUuid(callId), reason, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }

    }

    /**
@@ -735,15 +736,16 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        }

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
            try {
                service.callStateChanged(mCcid, new ParcelUuid(callId), state);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
        }
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        try {
            service.callStateChanged(mCcid, new ParcelUuid(callId), state,
                mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }
    }

@@ -760,13 +762,17 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
     public void currentCallsList(@NonNull List<BluetoothLeCall> calls) {
        final IBluetoothLeCallControl service = getService();
        if (service != null) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        try {
                service.currentCallsList(mCcid, calls);
            service.currentCallsList(mCcid, calls, mAttributionSource);
        } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }

    }

    /**
@@ -796,15 +802,15 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        }

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
            try {
                service.networkStateChanged(mCcid, provider, technology);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
        }
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        try {
            service.networkStateChanged(mCcid, provider, technology, mAttributionSource);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }
    }

@@ -837,12 +843,15 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
        }

        final IBluetoothLeCallControl service = getService();
        if (service != null) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            return;
        }

        try {
                service.requestResult(mCcid, requestId, result);
            service.requestResult(mCcid, requestId, result, mAttributionSource);
        } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        }
    }

@@ -862,7 +871,7 @@ public final class BluetoothLeCallControl implements BluetoothProfile {
            if (DBG) {
                Log.d(TAG, "Proxy object connected");
            }
            mService = IBluetoothLeCallControl.Stub.asInterface(Binder.allowBlocking(service));
            mService = IBluetoothLeCallControl.Stub.asInterface(service);
            mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_TBS_SERVICE_CONNECTED));
        }

+10 −9
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
 */

package android.bluetooth;

import android.content.AttributionSource;
import android.bluetooth.BluetoothLeCall;
import android.bluetooth.IBluetoothLeCallControlCallback;

@@ -27,19 +27,20 @@ import android.os.ParcelUuid;
 */
oneway interface IBluetoothLeCallControl {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void registerBearer(in String token, in IBluetoothLeCallControlCallback callback, in String uci, in List<String> uriSchemes, in int capabilities, in String provider, in int technology);
    void registerBearer(in String token, in IBluetoothLeCallControlCallback callback, in String uci, in List<String> uriSchemes,
        in int capabilities, in String provider, in int technology, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void unregisterBearer(in String token);
    void unregisterBearer(in String token, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void requestResult(in int ccid, in int requestId, in int result);
    void requestResult(in int ccid, in int requestId, in int result, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void callAdded(in int ccid, in BluetoothLeCall call);
    void callAdded(in int ccid, in BluetoothLeCall call, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void callRemoved(in int ccid, in ParcelUuid callId, in int reason);
    void callRemoved(in int ccid, in ParcelUuid callId, in int reason, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void callStateChanged(in int ccid, in ParcelUuid callId, in int state);
    void callStateChanged(in int ccid, in ParcelUuid callId, in int state, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void currentCallsList(in int ccid, in List<BluetoothLeCall> calls);
    void currentCallsList(in int ccid, in List<BluetoothLeCall> calls, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    void networkStateChanged(in int ccid, in String provider, in int technology);
    void networkStateChanged(in int ccid, in String provider, in int technology, in AttributionSource attributionSource);
}