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

Commit 6fb1b2a9 authored by Sal Savage's avatar Sal Savage
Browse files

Use a non-null package name when creating a ComponentName

While we shouldn't be able to use a null value for a ComponentName
(according to the comments in the code at least), it seems our test is
able to make make one with a mock context that doesn't have a mocked
value returned for getPackage(). This has downstream effects if someone
ever calls equals() with our ComponentName, which does not null check
the package name.

This change adds a simple mocked value for getPackageName().

Tag: #refactor
Bug: 231246591
Test: atest HfpClientDeviceBlockTest
Merged-In: Icedf4c11efd242d925c0c8d993d9706882df54c2
Change-Id: Icedf4c11efd242d925c0c8d993d9706882df54c2
parent 85dd9ef1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class HfpClientDeviceBlockTest {
    private static final String TEST_DEVICE_ADDRESS = "00:11:22:33:44:55";
    private static final String TEST_NUMBER = "000-111-2222";
    private static final String KEY_SCO_STATE = "com.android.bluetooth.hfpclient.SCO_STATE";
    private static final String TEST_PACKAGE = "test";

    @Mock
    private HeadsetClientService mHeadsetClientService;
@@ -76,6 +77,7 @@ public class HfpClientDeviceBlockTest {
                        .hfp_client_connection_service_support_emergency_call)).thenReturn(true);
        when(mApplicationContext.getResources()).thenReturn(mResources);
        when(mConnServ.getApplicationContext()).thenReturn(mApplicationContext);
        when(mConnServ.getPackageName()).thenReturn(TEST_PACKAGE);

        when(mConnServ.getSystemService(Context.TELECOM_SERVICE)).thenReturn(mTelecomManager);
        when(mConnServ.getSystemServiceName(TelecomManager.class))