1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.phone; 18 19 import android.os.AsyncResult; 20 import android.os.Handler; 21 import android.os.Message; 22 import android.os.SystemProperties; 23 import android.util.Log; 24 25 import com.android.internal.telephony.CallManager; 26 27 import java.util.ArrayList; 28 import java.util.LinkedList; 29 import java.util.List; 30 31 32 /** 33 * Dedicated Call state monitoring class. This class communicates directly with 34 * the call manager to listen for call state events and notifies registered 35 * handlers. 36 * It works as an inverse multiplexor for all classes wanted Call State updates 37 * so that there exists only one channel to the telephony layer. 38 * 39 * TODO: Add manual phone state checks (getState(), etc.). 40 */ 41 class CallStateMonitor extends Handler { 42 private static final String LOG_TAG = CallStateMonitor.class.getSimpleName(); 43 private static final boolean DBG = 44 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); 45 46 // Events from the Phone object: 47 public static final int PHONE_STATE_CHANGED = 1; 48 public static final int PHONE_NEW_RINGING_CONNECTION = 2; 49 public static final int PHONE_DISCONNECT = 3; 50 public static final int PHONE_UNKNOWN_CONNECTION_APPEARED = 4; 51 public static final int PHONE_STATE_DISPLAYINFO = 6; 52 public static final int PHONE_STATE_SIGNALINFO = 7; 53 public static final int PHONE_CDMA_CALL_WAITING = 8; 54 public static final int PHONE_ENHANCED_VP_ON = 9; 55 public static final int PHONE_ENHANCED_VP_OFF = 10; 56 public static final int PHONE_RINGBACK_TONE = 11; 57 public static final int PHONE_RESEND_MUTE = 12; 58 public static final int PHONE_ON_DIAL_CHARS = 13; 59 60 // Other events from call manager 61 public static final int EVENT_OTA_PROVISION_CHANGE = 20; 62 63 private CallManager callManager; 64 private ArrayList<Handler> registeredHandlers; 65 66 // Events generated internally: CallStateMonitor(CallManager callManager)67 public CallStateMonitor(CallManager callManager) { 68 this.callManager = callManager; 69 registeredHandlers = new ArrayList<Handler>(); 70 71 registerForNotifications(); 72 } 73 74 /** 75 * Register for call state notifications with the CallManager. 76 */ registerForNotifications()77 private void registerForNotifications() { 78 // 79 // TODO: The lines commented out here can be removed as their associated functionality in 80 // other files is removed. 81 // 82 //callManager.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null); 83 //callManager.registerForPreciseCallStateChanged(this, PHONE_STATE_CHANGED, null); 84 //callManager.registerForDisconnect(this, PHONE_DISCONNECT, null); 85 //callManager.registerForUnknownConnection(this, PHONE_UNKNOWN_CONNECTION_APPEARED, null); 86 callManager.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null); 87 //callManager.registerForCallWaiting(this, PHONE_CDMA_CALL_WAITING, null); 88 callManager.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null); 89 callManager.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null); 90 callManager.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null); 91 callManager.registerForInCallVoicePrivacyOff(this, PHONE_ENHANCED_VP_OFF, null); 92 //callManager.registerForRingbackTone(this, PHONE_RINGBACK_TONE, null); 93 //callManager.registerForResendIncallMute(this, PHONE_RESEND_MUTE, null); 94 //callManager.registerForPostDialCharacter(this, PHONE_ON_DIAL_CHARS, null); 95 } 96 addListener(Handler handler)97 public void addListener(Handler handler) { 98 if (handler != null && !registeredHandlers.contains(handler)) { 99 if (DBG) { 100 Log.d(LOG_TAG, "Adding Handler: " + handler); 101 } 102 103 registeredHandlers.add(handler); 104 } 105 } 106 107 @Override handleMessage(Message msg)108 public void handleMessage(Message msg) { 109 if (DBG) { 110 Log.d(LOG_TAG, "handleMessage(" + msg.what + ")"); 111 } 112 113 for (Handler handler : registeredHandlers) { 114 handler.handleMessage(msg); 115 } 116 } 117 118 /** 119 * When radio technology changes, we need to to reregister for all the events which are 120 * all tied to the old radio. 121 */ updateAfterRadioTechnologyChange()122 public void updateAfterRadioTechnologyChange() { 123 if (DBG) Log.d(LOG_TAG, "updateCallNotifierRegistrationsAfterRadioTechnologyChange..."); 124 125 // Unregister all events from the old obsolete phone 126 //callManager.unregisterForNewRingingConnection(this); 127 //callManager.unregisterForPreciseCallStateChanged(this); 128 //callManager.unregisterForDisconnect(this); 129 //callManager.unregisterForUnknownConnection(this); 130 //callManager.unregisterForCallWaiting(this); 131 callManager.unregisterForDisplayInfo(this); 132 callManager.unregisterForSignalInfo(this); 133 callManager.unregisterForCdmaOtaStatusChange(this); 134 //callManager.unregisterForRingbackTone(this); 135 //callManager.unregisterForResendIncallMute(this); 136 callManager.unregisterForInCallVoicePrivacyOn(this); 137 callManager.unregisterForInCallVoicePrivacyOff(this); 138 //callManager.unregisterForPostDialCharacter(this); 139 140 registerForNotifications(); 141 } 142 143 } 144