require to switch to the speaker mode when the call is in the dock mode

LA.UM.7.6.2/LINUX/android/frameworks/base/telecomm/java/android/telecom/InCallService.java 
index f3af514..6cbed0c 100644
@@ -44,4 +44,7 @@ import java.io.BufferedReader;
 import java.io.FileReader;
 
+import android.content.BroadcastReceiver;
+import android.content.Context;
+
 /**
  * This service is implemented by any app that wishes to provide the user-interface for managing
@@ -107,4 +110,7 @@ public abstract class InCallService extends Service {
     private static final int MSG_ON_HANDOVER_FAILED = 12;
     private static final int MSG_ON_HANDOVER_COMPLETE = 13;

+    //private static AudioState mPrevAudioState;
+    private final BroadcastReceiver mReceiver = new InCallServiceBroadcastReceiver();
 
     private static final String CRADLE_CHARGING_NODE = "/sys/class/switchs/dock/state";
@@ -135,4 +141,37 @@ public abstract class InCallService extends Service {
     }
 
+    /**
+     * Receiver for misc intent broadcasts the Phone app cares about.
+     */
+    private class InCallServiceBroadcastReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+
+            if (action.equals(Intent.ACTION_DOCK_EVENT)) {
+                if(!getCalls().isEmpty()) {
+                    int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
+                            Intent.EXTRA_DOCK_STATE_UNDOCKED);
+                    android.util.Log.d("heyimin","phone is inCall :: dockState =  " + dockState);
+                    switch (dockState) {
+                        case Intent.EXTRA_DOCK_STATE_DESK:
+                        case Intent.EXTRA_DOCK_STATE_CAR:
+                        case Intent.EXTRA_DOCK_STATE_LE_DESK:
+                        case Intent.EXTRA_DOCK_STATE_HE_DESK:
+                            setAudioRoute(CallAudioState.ROUTE_SPEAKER);
+                            android.util.Log.d("heyimin","state change to dock :: setAudioRoute to ROUTE_SPEAKER");
+                            break;
+                        case Intent.EXTRA_DOCK_STATE_UNDOCKED:
+                        default:
+                            setAudioRoute(CallAudioState.ROUTE_WIRED_OR_EARPIECE);
+                            android.util.Log.d("heyimin","state change to undock :: setAudioRoute to ROUTE_WIRED_OR_EARPIECE");
+                    }
+                } else {
+                    android.util.Log.d("heyimin","phone is not InCall, do nothing...");
+                }
+            }
+        }
+    } // end class InCallServiceBroadcastReceiver
+
     /** Default Handler used to consolidate binder method calls onto a single thread. */
     private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@@ -150,7 +189,7 @@ public abstract class InCallService extends Service {
                     mPhone.addListener(mPhoneListener);
                     onPhoneCreated(mPhone);
-
                     if (getCradleStatus()) {
                         setAudioRoute(CallAudioState.ROUTE_SPEAKER);
+                        android.util.Log.d("heyimin","set in call :: CradleStatus = true, setAudioRoute to ROUTE_SPEAKER");
                     }
                     break;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值