Fix exception when setting audio mode
Bug: 16024792
Change-Id: I6efa23642ac38e9d2a2811abe2586cde76f4f1ee
diff --git a/src/com/android/telecomm/TelecommServiceImpl.java b/src/com/android/telecomm/TelecommServiceImpl.java
index 24d6cc4..d0b8676 100644
--- a/src/com/android/telecomm/TelecommServiceImpl.java
+++ b/src/com/android/telecomm/TelecommServiceImpl.java
@@ -322,21 +322,23 @@
*/
private Object sendRequest(int command) {
if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
- throw new RuntimeException("This method will deadlock if called from the main thread.");
- }
+ MainThreadRequest request = new MainThreadRequest();
+ mMainThreadHandler.handleMessage(mMainThreadHandler.obtainMessage(command, request));
+ return request.result;
+ } else {
+ MainThreadRequest request = sendRequestAsync(command, 0);
- MainThreadRequest request = sendRequestAsync(command, 0);
-
- // Wait for the request to complete
- synchronized (request) {
- while (request.result == null) {
- try {
- request.wait();
- } catch (InterruptedException e) {
- // Do nothing, go back and wait until the request is complete
+ // Wait for the request to complete
+ synchronized (request) {
+ while (request.result == null) {
+ try {
+ request.wait();
+ } catch (InterruptedException e) {
+ // Do nothing, go back and wait until the request is complete
+ }
}
}
+ return request.result;
}
- return request.result;
}
}