2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.internal.telephony;
19 import android.os.AsyncResult;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.util.Log;
24 import com.android.internal.telephony.CommandException;
30 public abstract class CallTracker extends Handler {
32 private static final boolean DBG_POLL = false;
36 static final int POLL_DELAY_MSEC = 250;
38 protected int pendingOperations;
39 protected boolean needsPoll;
40 protected Message lastRelevantPoll;
42 public CommandsInterface cm;
47 protected static final int EVENT_POLL_CALLS_RESULT = 1;
48 protected static final int EVENT_CALL_STATE_CHANGE = 2;
49 protected static final int EVENT_REPOLL_AFTER_DELAY = 3;
50 protected static final int EVENT_OPERATION_COMPLETE = 4;
51 protected static final int EVENT_GET_LAST_CALL_FAIL_CAUSE = 5;
53 protected static final int EVENT_SWITCH_RESULT = 8;
54 protected static final int EVENT_RADIO_AVAILABLE = 9;
55 protected static final int EVENT_RADIO_NOT_AVAILABLE = 10;
56 protected static final int EVENT_CONFERENCE_RESULT = 11;
57 protected static final int EVENT_SEPARATE_RESULT = 12;
58 protected static final int EVENT_ECT_RESULT = 13;
59 protected static final int EVENT_EXIT_ECM_RESPONSE_CDMA = 14;
60 protected static final int EVENT_CALL_WAITING_INFO_CDMA = 15;
61 protected static final int EVENT_THREE_WAY_DIAL_L2_RESULT_CDMA = 16;
63 protected void pollCallsWhenSafe() {
66 if (checkNoOperationsPending()) {
67 lastRelevantPoll = obtainMessage(EVENT_POLL_CALLS_RESULT);
68 cm.getCurrentCalls(lastRelevantPoll);
73 pollCallsAfterDelay() {
74 Message msg = obtainMessage();
76 msg.what = EVENT_REPOLL_AFTER_DELAY;
77 sendMessageDelayed(msg, POLL_DELAY_MSEC);
81 isCommandExceptionRadioNotAvailable(Throwable e) {
82 return e != null && e instanceof CommandException
83 && ((CommandException)e).getCommandError()
84 == CommandException.Error.RADIO_NOT_AVAILABLE;
87 protected abstract void handlePollCalls(AsyncResult ar);
89 protected void handleRadioAvailable() {
94 * Obtain a complete message that indicates that this operation
95 * does not require polling of getCurrentCalls(). However, if other
96 * operations that do need getCurrentCalls() are pending or are
97 * scheduled while this operation is pending, the invocation
98 * of getCurrentCalls() will be postponed until this
99 * operation is also complete.
102 obtainNoPollCompleteMessage(int what) {
104 lastRelevantPoll = null;
105 return obtainMessage(what);
109 * @return true if we're idle or there's a call to getCurrentCalls() pending
113 checkNoOperationsPending() {
114 if (DBG_POLL) log("checkNoOperationsPending: pendingOperations=" +
116 return pendingOperations == 0;
120 //***** Overridden from Handler
121 public abstract void handleMessage (Message msg);
123 protected abstract void log(String msg);