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

Commit 88ef2d84 authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "Call System.exit(0) in onDestroy"

am: c4890e78

Change-Id: I6c742028f19ca69badf29ef2268e064fec1fd085
parents 96fa877f c4890e78
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -464,6 +464,11 @@ public class AdapterService extends Service {
    public void onDestroy() {
        debugLog("onDestroy()");
        mProfileObserver.stop();
        if (!isMock()) {
            // TODO(b/27859763)
            Log.i(TAG, "Force exit to cleanup internal state in Bluetooth stack");
            System.exit(0);
        }
    }

    void BleOnProcessStart() {
@@ -2302,4 +2307,14 @@ public class AdapterService extends Service {
            }
        }
    }

    // Returns if this is a mock object. This is currently used in testing so that we may not call
    // System.exit() while finalizing the object. Otherwise GC of mock objects unfortunately ends up
    // calling finalize() which in turn calls System.exit() and the process crashes.
    //
    // Mock this in your testing framework to return true to avoid the mentioned behavior. In
    // production this has no effect.
    public boolean isMock() {
        return false;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -91,6 +91,9 @@ public class PhonePolicyTest extends AndroidTestCase {
        // Mock the looper
        when(mockAdapterService.getMainLooper()).thenReturn(mHandlerThread.getLooper());

        // Tell the AdapterService that it is a mock (see isMock documentation)
        when(mockAdapterService.isMock()).thenReturn(true);

        PhonePolicy phPol = new PhonePolicy(mockAdapterService, mockServiceFactory);

        // Get the broadcast receiver to inject events.
@@ -147,6 +150,9 @@ public class PhonePolicyTest extends AndroidTestCase {
        // Mock the looper
        when(mockAdapterService.getMainLooper()).thenReturn(mHandlerThread.getLooper());

        // Tell the AdapterService that it is a mock (see isMock documentation)
        when(mockAdapterService.isMock()).thenReturn(true);

        PhonePolicy phPol = new PhonePolicy(mockAdapterService, mockServiceFactory);

        // Get the broadcast receiver to inject events
@@ -195,6 +201,9 @@ public class PhonePolicyTest extends AndroidTestCase {
        // Mock the looper
        when(mockAdapterService.getMainLooper()).thenReturn(mHandlerThread.getLooper());

        // Tell the AdapterService that it is a mock (see isMock documentation)
        when(mockAdapterService.isMock()).thenReturn(true);

        PhonePolicy phPol = new PhonePolicy(mockAdapterService, mockServiceFactory);

        // Get the broadcast receiver to inject events
@@ -254,6 +263,9 @@ public class PhonePolicyTest extends AndroidTestCase {
        // Mock the looper
        when(mockAdapterService.getMainLooper()).thenReturn(mHandlerThread.getLooper());

        // Tell the AdapterService that it is a mock (see isMock documentation)
        when(mockAdapterService.isMock()).thenReturn(true);

        PhonePolicy phPol = new PhonePolicy(mockAdapterService, mockServiceFactory);

        // Get the broadcast receiver to inject events