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

Commit 51b250cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prevent NPE when profile is null"

parents c13c7f53 28963cdd
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -1194,7 +1194,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     * @return {@code true} if {@code cachedBluetoothDevice} is a2dp device
     */
    public boolean isA2dpDevice() {
        return mProfileManager.getA2dpProfile().getConnectionStatus(mDevice) ==
        A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
        return a2dpProfile != null && a2dpProfile.getConnectionStatus(mDevice) ==
                BluetoothProfile.STATE_CONNECTED;
    }

@@ -1202,7 +1203,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     * @return {@code true} if {@code cachedBluetoothDevice} is HFP device
     */
    public boolean isHfpDevice() {
        return mProfileManager.getHeadsetProfile().getConnectionStatus(mDevice) ==
        HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
        return headsetProfile != null && headsetProfile.getConnectionStatus(mDevice) ==
                BluetoothProfile.STATE_CONNECTED;
    }

@@ -1210,7 +1212,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     * @return {@code true} if {@code cachedBluetoothDevice} is Hearing Aid device
     */
    public boolean isConnectedHearingAidDevice() {
        return mProfileManager.getHearingAidProfile().getConnectionStatus(mDevice) ==
        HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();
        return hearingAidProfile != null && hearingAidProfile.getConnectionStatus(mDevice) ==
                BluetoothProfile.STATE_CONNECTED;
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -590,4 +590,25 @@ public class CachedBluetoothDeviceTest {

        assertThat(mCachedDevice.isConnectedHearingAidDevice()).isFalse();
    }

    @Test
    public void isConnectedHfpDevice_profileIsNull_returnFalse() {
        when(mProfileManager.getHeadsetProfile()).thenReturn(null);

        assertThat(mCachedDevice.isHfpDevice()).isFalse();
    }

    @Test
    public void isConnectedA2dpDevice_profileIsNull_returnFalse() {
        when(mProfileManager.getA2dpProfile()).thenReturn(null);

        assertThat(mCachedDevice.isA2dpDevice()).isFalse();
    }

    @Test
    public void isConnectedHearingAidDevice_profileIsNull_returnFalse() {
        when(mProfileManager.getHearingAidProfile()).thenReturn(null);

        assertThat(mCachedDevice.isConnectedHearingAidDevice()).isFalse();
    }
}