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

Commit abf4b0dc authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

MapClient: Handle remote exception at cleanup

Catch and log any remote exceptions during cleanup.

Tag: #stability
Bug: 182826108
Test: atest BluetoothInstrumentationTests
Change-Id: Ic419726e3314477731de7c6a9e4e6f84aa4b711e
parent c86071ab
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -389,10 +389,13 @@ class MapClientContent {
     */
    void cleanUp() {
        clearMessages();
        try {
            mSubscriptionManager.removeSubscriptionInfoRecord(mDevice.getAddress(),
                    SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
        } catch (Exception e) {
            Log.w(TAG, "cleanUp failed: " + e.toString());
        }
    }


    /**
     * clearMessages
+13 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.mapclient;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -324,6 +325,18 @@ public class MapClientContentTest {
        mMapClientContent.storeMessage(mTestMessage2, mTestMessage2Handle, mTestMessage1Timestamp);
    }

    /**
     * Test to validate that an exception in the Subscription manager won't crash Bluetooth during
     * disconnect.
     */
    @Test
    public void testCleanUpRemoteException() {
        mMapClientContent = new MapClientContent(mMockContext, mCallbacks, mTestDevice);
        doThrow(java.lang.NullPointerException.class).when(mMockSubscriptionManager)
                .removeSubscriptionInfoRecord(any(), anyInt());
        mMapClientContent.cleanUp();
    }

    void createTestMessages() {
        mOriginator = new VCardEntry();
        VCardProperty property = new VCardProperty();