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() {
}
}
}
+
+ // 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;
+ }
}
// 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.
// 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
// 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
// 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