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

Commit 5cd20c3c authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

[LeAudio] Stop initialzing if stopped

There was missing return in LeAudioService#init()

nativInterface could be null when LeAudioService is stopped
right after it's started (e.g., turning on/off BT rapidly).

An additional test ensures the behaivor.
(i.e. it failed withour return)

Tag: #feature
Bug: 237321622
Test: atest BluetoothInstrumentationTests

Change-Id: I0cd0421975926895f2e2a508b848a97e3c327e6e
parent 1790bbc9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ public class LeAudioService extends ProfileService {
        LeAudioNativeInterface nativeInterface = mLeAudioNativeInterface;
        if (nativeInterface == null) {
            Log.w(TAG, "the service is stopped. ignore init()");
            return;
        }
        nativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());
    }
@@ -295,6 +296,7 @@ public class LeAudioService extends ProfileService {
            return true;
        }

        mHandler.removeCallbacks(this::init);
        setActiveDevice(null);

        if (mTmapGattServer == null) {
+15 −0
Original line number Diff line number Diff line
@@ -304,6 +304,21 @@ public class LeAudioServiceTest {
        });
    }

    /**
     * Test if stop during init is ok.
     */
    @Test
    public void testStopStartStopService() throws Exception {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            public void run() {
                assertThat(mService.stop()).isTrue();
                assertThat(mService.start()).isTrue();
                assertThat(mService.stop()).isTrue();
                assertThat(mService.start()).isTrue();
            }
        });
    }

    /**
     * Test get/set priority for BluetoothDevice
     */