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

Commit 0b4a3a66 authored by Sunny Kapdi's avatar Sunny Kapdi Committed by Bruno Martins
Browse files

Bluetooth: Broadcast UI: Changes to existing files

CRs-fixed: 2856233
Change-Id: I04ecf35e9f6d8e778b3e8f90e8f1ab0cd34eeb9b
parent c0870bcb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -234,6 +234,8 @@
    <string name="bluetooth_profile_headset">Phone calls</string>
    <!-- Bluetooth settings.  The user-visible string that is used whenever referring to the OPP profile. -->
    <string name="bluetooth_profile_opp">File transfer</string>
    <!-- Bluetooth settings.  The user-visible string that is used whenever referring to the Broadcast profile. -->
    <string name="bluetooth_profile_broadcast">Broadcast</string>
    <!-- Bluetooth settings. The user-visible string that is used whenever referring to the HID profile. -->
    <string name="bluetooth_profile_hid">Input device</string>
    <!-- Bluetooth settings. The user-visible string that is used whenever referring to the PAN profile (accessing Internet through remote device). [CHAR LIMIT=40] -->
+21 −0
Original line number Diff line number Diff line
@@ -177,4 +177,25 @@ public interface BluetoothCallback {
    default void onGroupDiscoveryStatusChanged (int groupId, int status, int reason) {
    }

    /**
     * Called when Broadcast state is changed. It listens to
     * {@link android.bluetooth.BluetoothBroadcast#ACTION_BROADCAST_STATE_CHANGED}
     *
     * @param state        the Bluetooth device connection state, the possible values are:
     *                     {@link android.bluetooth.BluetoothBroadcast#STATE_DISABLED},
     *                     {@link android.bluetooth.BluetoothBroadcast#STATE_ENABLING},
     *                     {@link android.bluetooth.BluetoothBroadcast#STATE_ENABLED},
     *                     {@link android.bluetooth.BluetoothBroadcast#STATE_DISABLING},
     *                     {@link android.bluetooth.BluetoothBroadcast#STATE_STREAMING}
     */
    default void onBroadcastStateChanged(int state) {
    }

    /**
     * Called when Broadcast key is changed. It listens to
     * {@link android.bluetooth.BluetoothBroadcast#ACTION_BROADCAST_ENCRYPTION_KEY_GENERATED}
     *
     */
    default void onBroadcastKeyGenerated() {
    }
}
+34 −0
Original line number Diff line number Diff line
@@ -152,6 +152,12 @@ public class BluetoothEventManager {
                    (Handler)sourceInfoHandler);
        }

        // Broadcast broadcasts
        addHandler("android.bluetooth.broadcast.profile.action.BROADCAST_STATE_CHANGED",
                new BroadcastStateChangedHandler());
        addHandler("android.bluetooth.broadcast.profile.action.BROADCAST_ENCRYPTION_KEY_GENERATED",
                new BroadcastKeyGeneratedHandler());

        registerAdapterIntentReceiver();
    }

@@ -247,6 +253,18 @@ public class BluetoothEventManager {
        }
    }

    private void dispatchBroadcastStateChanged(int state) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onBroadcastStateChanged(state);
        }
    }

    private void dispatchBroadcastKeyGenerated() {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onBroadcastKeyGenerated();
        }
    }

    @VisibleForTesting
    void dispatchActiveDeviceChanged(CachedBluetoothDevice activeDevice,
            int bluetoothProfile) {
@@ -373,6 +391,22 @@ public class BluetoothEventManager {
        }
    }

    private class BroadcastStateChangedHandler implements Handler {
        //@Override
        public void onReceive(Context context, Intent intent, BluetoothDevice device) {
            int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                    BluetoothAdapter.ERROR);
            dispatchBroadcastStateChanged(state);
        }
    }

    private class BroadcastKeyGeneratedHandler implements Handler {
        //@Override
        public void onReceive(Context context, Intent intent, BluetoothDevice device) {
            dispatchBroadcastKeyGenerated();
        }
    }

    private class NameChangedHandler implements Handler {
        public void onReceive(Context context, Intent intent,
                BluetoothDevice device) {
+25 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -107,6 +109,7 @@ public class LocalBluetoothProfileManager {
    private PbapServerProfile mPbapProfile;
    private HearingAidProfile mHearingAidProfile;
    private SapProfile mSapProfile;
    private Object mBroadcastProfileObject;

    private static final String BC_CONNECTION_STATE_CHANGED =
            "android.bluetooth.bc.profile.action.CONNECTION_STATE_CHANGED";
@@ -246,6 +249,24 @@ public class LocalBluetoothProfileManager {
            mSapProfile = new SapProfile(mContext, mDeviceManager, this);
            addProfile(mSapProfile, SapProfile.NAME, BluetoothSap.ACTION_CONNECTION_STATE_CHANGED);
        }
        if (mBroadcastProfileObject == null && supportedList.contains(BluetoothProfile.BROADCAST)) {
            if (DEBUG) {
                Log.d(TAG, "Adding local Broadcast profile");
            }
            try {
              //mBroadcastProfileObject = new BroadcastProfile(mContext);
              Class<?> classBroadcastProfile =
                  Class.forName("com.android.settingslib.bluetooth.BroadcastProfile");
              Constructor ctor;
              ctor = classBroadcastProfile.getDeclaredConstructor(new Class[] {Context.class});
              mBroadcastProfileObject = ctor.newInstance(mContext);
              mProfileNameMap.put("Broadcast",
                  (LocalBluetoothProfile) mBroadcastProfileObject);
            } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
                  | InstantiationException | InvocationTargetException e) {
              e.printStackTrace();
            }
        }
        if (mGroupClientProfile == null && supportedList.contains(BluetoothProfile.GROUP_CLIENT)) {
            if (DEBUG) Log.d(TAG, "Adding local GROUP CLIENT profile");
            mGroupClientProfile = new DeviceGroupClientProfile(mContext, mDeviceManager, this);
@@ -477,6 +498,10 @@ public class LocalBluetoothProfileManager {
        return mSapProfile;
    }

    public Object getBroadcastProfile() {
        return mBroadcastProfileObject;
    }

    public LocalBluetoothProfile getBCProfile() {
        Log.d(TAG, "getBCProfile returning: " + mBCProfile);
        return mBCProfile;