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

Commit ebacd74e authored by Jack He's avatar Jack He
Browse files

AdapterService: Do not call System.exit() on onUnbind

* Process termination should be handled by the OS
* System.exit() in onUnbind also prevents onDestroy() to be called
* Removed isMock() since its only use case is to check if System.exit()
  should be called

Bug: 35366908
Test: make, run java test, turning Bluetooth ON/OFF
Change-Id: Ieba927ce86d5dd27269f10188c74308fa76e66d9
parent 241ac1af
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -638,10 +638,6 @@ public class AdapterService extends Service {
        if (mCallbacks !=null) {
            mCallbacks.kill();
        }

        if (!isMock()) {
            System.exit(0);
        }
    }

    private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED =1;
@@ -2295,14 +2291,4 @@ 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;
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -91,9 +91,6 @@ 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.
@@ -150,8 +147,6 @@ 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
@@ -200,8 +195,6 @@ 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
@@ -261,8 +254,6 @@ 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
@@ -322,9 +313,6 @@ 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.