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

Commit 938cad30 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Protect against adding a null config for the BT health profile

Bug: 25340134
Test: Manual and UnitTest
Change-Id: I595a61050c88787d79db2527aa4387966680e166
parent c3cfde70
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -401,6 +401,12 @@ public class HealthService extends ProfileService {
            IBluetoothHealthCallback callback) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM,
                "Need BLUETOOTH permission");

        if (config == null) {
            Log.e(TAG, "Trying to use a null config for registration");
            return false;
        }

        if (mApps.get(config) != null) {
            if (DBG) Log.d(TAG, "Config has already been registered");
            return false;
+19 −0
Original line number Diff line number Diff line
package com.android.bluetooth.hdp;

import android.test.InstrumentationTestCase;

import junit.framework.Assert;

public class HealthServiceTest extends InstrumentationTestCase {

    public void testRegisterAppConfiguration() {
        HealthService testService = new HealthService();

        // Attach a context to the Health Service for permission checks
        testService.attach(getInstrumentation().getContext(), null, null, null, null, null);

        // Test registering a null config
        assertEquals(false, testService.registerAppConfiguration(null, null));
    }

}