Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +15 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } } android/app/tests/src/com/android/bluetooth/btservice/PhonePolicyTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +15 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } }
android/app/tests/src/com/android/bluetooth/btservice/PhonePolicyTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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 Loading