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

Commit e780806f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "BtHelper/SoundDoseHelper: fix misc error-prone warnings" into main

parents e200be5c 5f9392e7
Loading
Loading
Loading
Loading
+15 −22
Original line number Diff line number Diff line
@@ -142,7 +142,6 @@ public class BtHelper {
    private static final int SCO_MODE_MAX = 2;

    private static final int BT_HEARING_AID_GAIN_MIN = -128;
    private static final int BT_LE_AUDIO_MIN_VOL = 0;
    private static final int BT_LE_AUDIO_MAX_VOL = 255;

    // BtDevice constants currently rolling out under flag protection. Use own
@@ -211,8 +210,7 @@ public class BtHelper {
    //----------------------------------------------------------------------
    // Interface for AudioDeviceBroker

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized void onSystemReady() {
        mScoConnectionState = android.media.AudioManager.SCO_AUDIO_STATE_ERROR;
        resetBluetoothSco();
@@ -373,8 +371,7 @@ public class BtHelper {
        return codecAndChanged;
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized void onReceiveBtEvent(Intent intent) {
        final String action = intent.getAction();

@@ -396,11 +393,11 @@ public class BtHelper {
    }

    /**
     * Exclusively called from AudioDeviceBroker when handling MSG_L_RECEIVED_BT_EVENT
     * Exclusively called from AudioDeviceBroker (with mSetModeLock held)
     * when handling MSG_L_RECEIVED_BT_EVENT in {@link #onReceiveBtEvent(Intent)}
     * as part of the serialization of the communication route selection
     */
    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    @GuardedBy("BtHelper.this")
    private void onScoAudioStateChanged(int state) {
        boolean broadcast = false;
        int scoAudioState = AudioManager.SCO_AUDIO_STATE_ERROR;
@@ -493,16 +490,14 @@ public class BtHelper {
              || mScoAudioState == SCO_STATE_ACTIVATE_REQ;
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized boolean startBluetoothSco(int scoAudioMode,
                @NonNull String eventSource) {
        AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(eventSource));
        return requestScoState(BluetoothHeadset.STATE_AUDIO_CONNECTED, scoAudioMode);
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized boolean stopBluetoothSco(@NonNull String eventSource) {
        AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(eventSource));
        return requestScoState(BluetoothHeadset.STATE_AUDIO_DISCONNECTED, SCO_MODE_VIRTUAL_CALL);
@@ -574,8 +569,7 @@ public class BtHelper {
        mScoConnectionState = state;
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized void resetBluetoothSco() {
        mScoAudioState = SCO_STATE_INACTIVE;
        broadcastScoConnectionState(AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
@@ -584,8 +578,7 @@ public class BtHelper {
        mDeviceBroker.setBluetoothScoOn(false, "resetBluetoothSco");
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized void onBtProfileDisconnected(int profile) {
        AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                "BT profile " + BluetoothProfile.getProfileName(profile)
@@ -649,8 +642,7 @@ public class BtHelper {

    MyLeAudioCallback mLeAudioCallback = null;

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package*/ synchronized void onBtProfileConnected(int profile, BluetoothProfile proxy) {
        AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                "BT profile " + BluetoothProfile.getProfileName(profile) + " connected to proxy "
@@ -787,8 +779,7 @@ public class BtHelper {
        }
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    private void onHeadsetProfileConnected(@NonNull BluetoothHeadset headset) {
        // Discard timeout message
        mDeviceBroker.handleCancelFailureToConnectToBtHeadsetService();
@@ -931,8 +922,7 @@ public class BtHelper {
        return btDevice == null ? "(null)" : btDevice.getAnonymizedAddress();
    }

    // @GuardedBy("mDeviceBroker.mSetModeLock")
    @GuardedBy("AudioDeviceBroker.this.mDeviceStateLock")
    // Called locked by ADeviceBroker.mSetModeLock -> AudioDeviceBroker.mDeviceStateLock
    /*package */ synchronized void onSetBtScoActiveDevice(BluetoothDevice btDevice) {
        Log.i(TAG, "onSetBtScoActiveDevice: " + getAnonymizedAddress(mBluetoothHeadsetDevice)
                + " -> " + getAnonymizedAddress(btDevice));
@@ -1133,6 +1123,9 @@ public class BtHelper {

    //-----------------------------------------------------
    // Utilities

    // suppress warning due to generic Intent passed as param
    @SuppressWarnings("AndroidFrameworkRequiresPermission")
    private void sendStickyBroadcastToAll(Intent intent) {
        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        final long ident = Binder.clearCallingIdentity();
+16 −12
Original line number Diff line number Diff line
@@ -643,9 +643,9 @@ public class SoundDoseHelper {
            if (index > safeIndex) {
                streamState.setIndex(safeIndex, deviceType, caller,
                        true /*hasModifyAudioSettings*/);
                mAudioHandler.sendMessageAtTime(
                mAudioHandler.sendMessage(
                        mAudioHandler.obtainMessage(MSG_SET_DEVICE_VOLUME, deviceType,
                                /*arg2=*/0, streamState), /*delay=*/0);
                                /*arg2=*/0, streamState));
            }
        }
    }
@@ -686,8 +686,11 @@ public class SoundDoseHelper {
    /*package*/ void disableSafeMediaVolume(String callingPackage) {
        synchronized (mSafeMediaVolumeStateLock) {
            final long identity = Binder.clearCallingIdentity();
            try {
                setSafeMediaVolumeEnabled(false, callingPackage);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }

            if (mPendingVolumeCommand != null) {
                mAudioService.onSetStreamVolume(mPendingVolumeCommand.mStreamType,
@@ -701,6 +704,7 @@ public class SoundDoseHelper {
        }
    }

    @SuppressWarnings("AndroidFrameworkRequiresPermission")
    /*package*/ void scheduleMusicActiveCheck() {
        synchronized (mSafeMediaVolumeStateLock) {
            cancelMusicActiveCheck();
@@ -1035,10 +1039,9 @@ public class SoundDoseHelper {
            mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
        }

        mAudioHandler.sendMessageAtTime(
        mAudioHandler.sendMessage(
                mAudioHandler.obtainMessage(MSG_PERSIST_SAFE_VOLUME_STATE,
                        persistedState, /*arg2=*/0,
                        /*obj=*/null), /*delay=*/0);
                        persistedState, /*arg2=*/0, /*obj=*/null));
    }

    private void updateCsdEnabled(String caller) {
@@ -1199,8 +1202,8 @@ public class SoundDoseHelper {

        sanitizeDoseRecords_l();

        mAudioHandler.sendMessageAtTime(mAudioHandler.obtainMessage(MSG_PERSIST_CSD_VALUES,
                /* arg1= */0, /* arg2= */0, /* obj= */null), /* delay= */0);
        mAudioHandler.sendMessage(mAudioHandler.obtainMessage(MSG_PERSIST_CSD_VALUES,
                /* arg1= */0, /* arg2= */0, /* obj= */null));

        mLogger.enqueue(SoundDoseEvent.getDoseUpdateEvent(currentCsd, totalDuration));
    }
@@ -1316,6 +1319,7 @@ public class SoundDoseHelper {
    }

    /** Called when handling MSG_LOWER_VOLUME_TO_RS1 */
    @SuppressWarnings("AndroidFrameworkRequiresPermission")
    private void onLowerVolumeToRs1() {
        final ArrayList<AudioDeviceAttributes> devices = mAudioService.getDevicesForAttributesInt(
                new AudioAttributes.Builder().setUsage(
@@ -1360,9 +1364,9 @@ public class SoundDoseHelper {

        @Override
        public String toString() {
            return new StringBuilder().append("{streamType=").append(mStreamType).append(",index=")
                    .append(mIndex).append(",flags=").append(mFlags).append(",device=")
                    .append(mDevice).append('}').toString();
            return "{streamType=" + mStreamType
                    + ",index=" + mIndex + ",flags=" + mFlags
                    + ",device=" + mDevice + "}";
        }
    }
}