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

Commit aa794b93 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9406096 from 23bef9ea to tm-qpr2-release

Change-Id: If5a98a92c60a5a6252ec6e04c41cf67413aa1222
parents e5966df1 23bef9ea
Loading
Loading
Loading
Loading
+71 −6
Original line number Diff line number Diff line
@@ -29,9 +29,13 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioDeviceCallback;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.BluetoothProfileConnectionInfo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.ParcelUuid;
import android.sysprop.BluetoothProperties;
import android.util.Log;
@@ -73,6 +77,7 @@ public class HearingAidService extends ProfileService {
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private BluetoothDevice mPreviousAudioDevice;
    private BluetoothDevice mActiveDevice;

    @VisibleForTesting
    HearingAidNativeInterface mHearingAidNativeInterface;
@@ -88,6 +93,12 @@ public class HearingAidService extends ProfileService {

    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mConnectionStateChangedReceiver;
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private final AudioManagerOnAudioDevicesAddedCallback mAudioManagerOnAudioDevicesAddedCallback =
            new AudioManagerOnAudioDevicesAddedCallback();
    private final AudioManagerOnAudioDevicesRemovedCallback
            mAudioManagerOnAudioDevicesRemovedCallback =
            new AudioManagerOnAudioDevicesRemovedCallback();

    private final ServiceFactory mFactory = new ServiceFactory();

@@ -206,6 +217,9 @@ public class HearingAidService extends ProfileService {
            }
        }

        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerOnAudioDevicesAddedCallback);
        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerOnAudioDevicesRemovedCallback);

        // Clear AdapterService, HearingAidNativeInterface
        mAudioManager = null;
        mHearingAidNativeInterface = null;
@@ -593,6 +607,12 @@ public class HearingAidService extends ProfileService {
                }
                return true;
            }

            /* No action needed since this is the same device as previousely activated */
            if (device.equals(mActiveDevice)) {
                return true;
            }

            if (getConnectionState(device) != BluetoothProfile.STATE_CONNECTED) {
                Log.e(TAG, "setActiveDevice(" + device + "): failed because device not connected");
                return false;
@@ -682,6 +702,46 @@ public class HearingAidService extends ProfileService {
        }
    }

    private void notifyActiveDeviceChanged() {
        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mActiveDevice);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent, BLUETOOTH_CONNECT);
    }

    /* Notifications of audio device disconnection events. */
    private class AudioManagerOnAudioDevicesRemovedCallback extends AudioDeviceCallback {
        @Override
        public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
            for (AudioDeviceInfo deviceInfo : removedDevices) {
                if (deviceInfo.getType() == AudioDeviceInfo.TYPE_HEARING_AID) {
                    notifyActiveDeviceChanged();
                    if (DBG) {
                        Log.d(TAG, " onAudioDevicesRemoved: device type: " + deviceInfo.getType());
                    }
                    mAudioManager.unregisterAudioDeviceCallback(this);
                }
            }
        }
    }

    /* Notifications of audio device connection events. */
    private class AudioManagerOnAudioDevicesAddedCallback extends AudioDeviceCallback {
        @Override
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            for (AudioDeviceInfo deviceInfo : addedDevices) {
                if (deviceInfo.getType() == AudioDeviceInfo.TYPE_HEARING_AID) {
                    notifyActiveDeviceChanged();
                    if (DBG) {
                        Log.d(TAG, " onAudioDevicesAdded: device type: " + deviceInfo.getType());
                    }
                    mAudioManager.unregisterAudioDeviceCallback(this);
                }
            }
        }
    }

    private HearingAidStateMachine getOrCreateStateMachine(BluetoothDevice device) {
        if (device == null) {
            Log.e(TAG, "getOrCreateStateMachine failed: device cannot be null");
@@ -717,21 +777,26 @@ public class HearingAidService extends ProfileService {
            Log.d(TAG, "reportActiveDevice(" + device + ")");
        }

        mActiveDevice = device;

        BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED,
                BluetoothProfile.HEARING_AID, mAdapterService.obfuscateAddress(device),
                mAdapterService.getMetricId(device));

        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempAllowlistBroadcastOptions());

        boolean stopAudio = device == null && !hasFallbackDevice;
        if (DBG) {
            Log.d(TAG, "Hearing Aid audio: " + mPreviousAudioDevice + " -> " + device
                    + ". Stop audio: " + stopAudio);
        }

        if (device != null) {
            mAudioManager.registerAudioDeviceCallback(mAudioManagerOnAudioDevicesAddedCallback,
                    mHandler);
        } else {
            mAudioManager.registerAudioDeviceCallback(mAudioManagerOnAudioDevicesRemovedCallback,
                    mHandler);
        }

        mAudioManager.handleBluetoothActiveDeviceChanged(device, mPreviousAudioDevice,
                BluetoothProfileConnectionInfo.createHearingAidInfo(!stopAudio));
        mPreviousAudioDevice = device;
+3 −0
Original line number Diff line number Diff line
@@ -902,6 +902,8 @@ public class HeadsetClientService extends ProfileService {

    public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        Log.i(TAG, "setAudioRouteAllowed: device=" + device + ", allowed=" + allowed + ", "
                + Utils.getUidPidString());
        HeadsetClientStateMachine sm = mStateMachineMap.get(device);
        if (sm != null) {
            sm.setAudioRouteAllowed(allowed);
@@ -918,6 +920,7 @@ public class HeadsetClientService extends ProfileService {
    }

    public boolean connectAudio(BluetoothDevice device) {
        Log.i(TAG, "connectAudio: device=" + device + ", " + Utils.getUidPidString());
        HeadsetClientStateMachine sm = getStateMachine(device);
        if (sm == null) {
            Log.e(TAG, "SM does not exist for device " + device);
+13 −10
Original line number Diff line number Diff line
@@ -200,11 +200,12 @@ public class HeadsetClientStateMachine extends StateMachine {
    }

    public void dump(StringBuilder sb) {
        if (mCurrentDevice == null) return;
        if (mCurrentDevice != null) {
            ProfileService.println(sb,
                    "==== StateMachine for " + mCurrentDevice + " ====");
            ProfileService.println(sb, "  mCurrentDevice: " + mCurrentDevice.getAddress() + "("
                    + Utils.getName(mCurrentDevice) + ") " + this.toString());
        }
        ProfileService.println(sb, "  mAudioState: " + mAudioState);
        ProfileService.println(sb, "  mAudioWbs: " + mAudioWbs);
        ProfileService.println(sb, "  mIndicatorNetworkState: " + mIndicatorNetworkState);
@@ -984,8 +985,8 @@ public class HeadsetClientStateMachine extends StateMachine {
                broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_DISCONNECTED,
                        BluetoothProfile.STATE_CONNECTED);
            } else if (mPrevState != null) { // null is the default state before Disconnected
                Log.e(TAG, "Connected: Illegal state transition from " + mPrevState.getName()
                        + " to Connecting, mCurrentDevice=" + mCurrentDevice);
                Log.e(TAG, "Disconnected: Illegal state transition from " + mPrevState.getName()
                        + " to Disconnected, mCurrentDevice=" + mCurrentDevice);
            }
            mCurrentDevice = null;
        }
@@ -1086,7 +1087,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                        BluetoothProfile.STATE_DISCONNECTED);
            } else {
                String prevStateName = mPrevState == null ? "null" : mPrevState.getName();
                Log.e(TAG, "Connected: Illegal state transition from " + prevStateName
                Log.e(TAG, "Connecting: Illegal state transition from " + prevStateName
                        + " to Connecting, mCurrentDevice=" + mCurrentDevice);
            }
        }
@@ -1241,7 +1242,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            } else if (mPrevState != mAudioOn) {
                String prevStateName = mPrevState == null ? "null" : mPrevState.getName();
                Log.e(TAG, "Connected: Illegal state transition from " + prevStateName
                        + " to Connecting, mCurrentDevice=" + mCurrentDevice);
                        + " to Connected, mCurrentDevice=" + mCurrentDevice);
            }
            mService.updateBatteryLevel();
        }
@@ -1666,8 +1667,10 @@ public class HeadsetClientStateMachine extends StateMachine {
                        Log.d(TAG, "mAudioRouteAllowed=" + mAudioRouteAllowed);
                    }
                    if (!mAudioRouteAllowed) {
                        Log.i(TAG, "Audio is not allowed! Disconnect SCO.");
                        sendMessage(HeadsetClientStateMachine.DISCONNECT_AUDIO);
                        break;
                        // Don't continue connecting!
                        return;
                    }

                    // Audio state is split in two parts, the audio focus is maintained by the
+5 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.map.BluetoothMapbMessageMime.MimePart;
import com.android.bluetooth.mapapi.BluetoothMapContract;
import com.android.bluetooth.mapapi.BluetoothMapContract.ConversationColumns;
import com.android.internal.annotations.VisibleForTesting;

import com.google.android.mms.pdu.CharacterSets;
import com.google.android.mms.pdu.PduHeaders;
@@ -145,7 +146,8 @@ public class BluetoothMapContent {

    private final Context mContext;
    private final ContentResolver mResolver;
    private final String mBaseUri;
    @VisibleForTesting
    final String mBaseUri;
    private final BluetoothMapAccountItem mAccount;
    /* The MasInstance reference is used to update persistent (over a connection) version counters*/
    private final BluetoothMapMasInstance mMasInstance;
@@ -252,7 +254,8 @@ public class BluetoothMapContent {
        MMS_SMS_THREAD_COL_RECIPIENT_IDS = projection.indexOf(Threads.RECIPIENT_IDS);
    }

    private class FilterInfo {
    @VisibleForTesting
    static class FilterInfo {
        public static final int TYPE_SMS = 0;
        public static final int TYPE_MMS = 1;
        public static final int TYPE_EMAIL = 2;
+2 −1
Original line number Diff line number Diff line
@@ -537,7 +537,8 @@ public class BluetoothMapContentObserver {
        this.mFolders = folderStructure;
    }

    private class ConvoContactInfo {
    @VisibleForTesting
    static class ConvoContactInfo {
        public int mConvoColConvoId = -1;
        public int mConvoColLastActivity = -1;
        public int mConvoColName = -1;
Loading