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

Commit 43b5d980 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Android (Google) Code Review
Browse files

Merge "PBAP client Settings profile." into nyc-dev

parents 0ade7ff3 563c700f
Loading
Loading
Loading
Loading
+66 −6
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ public final class BluetoothPbapClient implements BluetoothProfile {
        "android.bluetooth.pbap.profile.action.CONNECTION_STATE_CHANGED";

    private IBluetoothPbapClient mService;
    private BluetoothDevice mDevice;
    private final Context mContext;
    private ServiceListener mServiceListener;
    private BluetoothAdapter mAdapter;
@@ -173,7 +172,6 @@ public final class BluetoothPbapClient implements BluetoothProfile {
        }
        if (mService != null && isEnabled() && isValidDevice(device)) {
            try {
                mDevice = device;
                return mService.connect(device);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
@@ -193,13 +191,13 @@ public final class BluetoothPbapClient implements BluetoothProfile {
     * @return false on error,
     *               true otherwise
     */
    public boolean disconnect() {
    public boolean disconnect(BluetoothDevice device) {
        if (DBG) {
            log("disconnect(" + mDevice + ")");
            log("disconnect(" + device + ")" + new Exception() );
        }
        if (mService != null && isEnabled() && isValidDevice(mDevice)) {
        if (mService != null && isEnabled() && isValidDevice(device)) {
            try {
                mService.disconnect(mDevice);
                mService.disconnect(device);
                return true;
            } catch (RemoteException e) {
              Log.e(TAG, Log.getStackTraceString(new Throwable()));
@@ -328,4 +326,66 @@ public final class BluetoothPbapClient implements BluetoothProfile {
       }
       return false;
    }

    /**
     * Set priority of the profile
     *
     * <p> The device should already be paired.
     *  Priority can be one of {@link #PRIORITY_ON} or
     * {@link #PRIORITY_OFF},
     *
     * @param device Paired bluetooth device
     * @param priority
     * @return true if priority is set, false on error
     */
    public boolean setPriority(BluetoothDevice device, int priority) {
        if (DBG) {
            log("setPriority(" + device + ", " + priority + ")");
        }
        if (mService != null && isEnabled() &&
            isValidDevice(device)) {
            if (priority != BluetoothProfile.PRIORITY_OFF &&
                priority != BluetoothProfile.PRIORITY_ON) {
              return false;
            }
            try {
                return mService.setPriority(device, priority);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return false;
            }
        }
        if (mService == null) {
            Log.w(TAG, "Proxy not attached to service");
        }
        return false;
    }

    /**
     * Get the priority of the profile.
     *
     * <p> The priority can be any of:
     * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
     * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
     *
     * @param device Bluetooth device
     * @return priority of the device
     */
    public int getPriority(BluetoothDevice device) {
        if (VDBG) {
            log("getPriority(" + device + ")");
        }
        if (mService != null && isEnabled() && isValidDevice(device)) {
            try {
                return mService.getPriority(device);
            } catch (RemoteException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                return PRIORITY_OFF;
            }
        }
        if (mService == null) {
            Log.w(TAG, "Proxy not attached to service");
        }
        return PRIORITY_OFF;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -29,4 +29,6 @@ interface IBluetoothPbapClient {
    List<BluetoothDevice> getConnectedDevices();
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states);
    int getConnectionState(in BluetoothDevice device);
    boolean setPriority(in BluetoothDevice device, int priority);
    int getPriority(in BluetoothDevice device);
}
+11 −0
Original line number Diff line number Diff line
@@ -7678,6 +7678,9 @@ public final class Settings {
        public static final String
                BLUETOOTH_MAP_PRIORITY_PREFIX = "bluetooth_map_priority_";
        /** {@hide} */
        public static final String
                BLUETOOTH_PBAP_CLIENT_PRIORITY_PREFIX = "bluetooth_pbap_client_priority_";
        /** {@hide} */
        public static final String
                BLUETOOTH_SAP_PRIORITY_PREFIX = "bluetooth_sap_priority_";

@@ -7833,6 +7836,14 @@ public final class Settings {
            return BLUETOOTH_MAP_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
        }

        /**
         * Get the key that retrieves a bluetooth pbap client priority.
         * @hide
         */
        public static final String getBluetoothPbapClientPriorityKey(String address) {
            return BLUETOOTH_PBAP_CLIENT_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
        }

        /**
         * Get the key that retrieves a bluetooth map priority.
         * @hide
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2016, 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.
*/
-->
<resources>
    <!-- Configuration for automotive -->
    <bool name="enable_pbap_pce_profile">false</bool>
</resources>
+32 −2
Original line number Diff line number Diff line
@@ -24,12 +24,14 @@ import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothInputDevice;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothPbapClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.content.Context;
import android.content.Intent;
import android.os.ParcelUuid;
import android.util.Log;
import com.android.settingslib.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -82,7 +84,9 @@ public final class LocalBluetoothProfileManager {
    private final HidProfile mHidProfile;
    private OppProfile mOppProfile;
    private final PanProfile mPanProfile;
    private PbapClientProfile mPbapClientProfile;
    private final PbapServerProfile mPbapProfile;
    private final boolean mUsePbapPce;

    /**
     * Mapping from profile name, e.g. "HEADSET" to profile object.
@@ -99,6 +103,7 @@ public final class LocalBluetoothProfileManager {
        mLocalAdapter = adapter;
        mDeviceManager = deviceManager;
        mEventManager = eventManager;
        mUsePbapPce = mContext.getResources().getBoolean(R.bool.enable_pbap_pce_profile);
        // pass this reference to adapter and event manager (circular dependency)
        mLocalAdapter.setProfileManager(this);
        mEventManager.setProfileManager(this);
@@ -205,9 +210,24 @@ public final class LocalBluetoothProfileManager {
        } else if (mOppProfile != null) {
            Log.w(TAG, "Warning: OPP profile was previously added but the UUID is now missing.");
        }

        //PBAP Client
        if (mUsePbapPce) {
            if (mPbapClientProfile == null) {
                if(DEBUG) Log.d(TAG, "Adding local PBAP Client profile");
                mPbapClientProfile = new PbapClientProfile(mContext, mLocalAdapter, mDeviceManager,
                        this);
                addProfile(mPbapClientProfile, PbapClientProfile.NAME,
                        BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
            }
        } else if (mPbapClientProfile != null) {
            Log.w(TAG,
                "Warning: PBAP Client profile was previously added but the UUID is now missing.");
        }

        mEventManager.registerProfileIntentReceiver();

        // There is no local SDP record for HID and Settings app doesn't control PBAP
        // There is no local SDP record for HID and Settings app doesn't control PBAP Server.
    }

    private final Collection<ServiceListener> mServiceListeners =
@@ -351,6 +371,10 @@ public final class LocalBluetoothProfileManager {
        }
    }

    public PbapClientProfile getPbapClientProfile() {
        return mPbapClientProfile;
    }

    public PbapServerProfile getPbapProfile(){
        return mPbapProfile;
    }
@@ -430,6 +454,12 @@ public final class LocalBluetoothProfileManager {
            removedProfiles.remove(mMapProfile);
            mMapProfile.setPreferred(device, true);
        }
    }

        if (mUsePbapPce) {
            profiles.add(mPbapClientProfile);
            removedProfiles.remove(mPbapClientProfile);
            profiles.remove(mPbapProfile);
            removedProfiles.add(mPbapProfile);
        }
    }
}
Loading