blob: a57ac5b74aea199885c0804a6f0b10a96dd4494d [file] [log] [blame]
Santos Cordon89647a62013-07-16 13:38:09 -07001/*
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
17package com.android.phone;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.content.ServiceConnection;
Chiao Cheng11a4b652013-09-02 01:08:19 -070023import android.content.pm.PackageManager;
24import android.content.pm.ResolveInfo;
Santos Cordon89647a62013-07-16 13:38:09 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Message;
28import android.os.RemoteException;
29import android.os.SystemProperties;
30import android.util.Log;
31
Santos Cordon9b7bac72013-08-06 08:04:52 -070032import com.android.phone.AudioRouter.AudioModeListener;
33import com.android.services.telephony.common.AudioMode;
Santos Cordonf4046882013-07-25 18:49:27 -070034import com.android.services.telephony.common.Call;
Santos Cordon345350e2013-07-19 17:16:14 -070035import com.android.services.telephony.common.ICallHandlerService;
Chiao Cheng6c6b2722013-08-22 18:35:54 -070036import com.google.common.collect.Lists;
Santos Cordon89647a62013-07-16 13:38:09 -070037
Santos Cordona3d05142013-07-29 11:25:17 -070038import java.util.List;
39
Santos Cordon89647a62013-07-16 13:38:09 -070040/**
Santos Cordon345350e2013-07-19 17:16:14 -070041 * This class is responsible for passing through call state changes to the CallHandlerService.
Santos Cordon89647a62013-07-16 13:38:09 -070042 */
Chiao Cheng6c6b2722013-08-22 18:35:54 -070043public class CallHandlerServiceProxy extends Handler
44 implements CallModeler.Listener, AudioModeListener {
Santos Cordon89647a62013-07-16 13:38:09 -070045
Santos Cordon345350e2013-07-19 17:16:14 -070046 private static final String TAG = CallHandlerServiceProxy.class.getSimpleName();
Chiao Cheng3e6486e2013-09-03 19:27:46 -070047 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 0) && (SystemProperties.getInt(
Chiao Cheng6c6b2722013-08-22 18:35:54 -070048 "ro.debuggable", 0) == 1);
Chiao Chenge41661c2013-07-23 13:28:26 -070049
Chiao Cheng6c6b2722013-08-22 18:35:54 -070050 public static final int RETRY_DELAY_MILLIS = 2000;
51 private static final int BIND_RETRY_MSG = 1;
52 private static final int MAX_RETRY_COUNT = 5;
Santos Cordon89647a62013-07-16 13:38:09 -070053
Santos Cordon593ab382013-08-06 21:58:23 -070054 private AudioRouter mAudioRouter;
Santos Cordoncba1b442013-07-18 12:43:58 -070055 private CallCommandService mCallCommandService;
Santos Cordon593ab382013-08-06 21:58:23 -070056 private CallModeler mCallModeler;
57 private Context mContext;
Chiao Chengd38eebc2013-08-28 14:38:14 -070058
Chiao Cheng6c6b2722013-08-22 18:35:54 -070059 private ICallHandlerService mCallHandlerServiceGuarded; // Guarded by mServiceAndQueueLock
Chiao Chengd38eebc2013-08-28 14:38:14 -070060 // Single queue to guarantee ordering
61 private List<QueueParams> mQueue; // Guarded by mServiceAndQueueLock
62
Chiao Cheng6c6b2722013-08-22 18:35:54 -070063 private final Object mServiceAndQueueLock = new Object();
64 private int mBindRetryCount = 0;
65
66 @Override
67 public void handleMessage(Message msg) {
68 super.handleMessage(msg);
69
70 switch (msg.what) {
71 case BIND_RETRY_MSG:
72 setupServiceConnection();
73 break;
74 }
75 }
Santos Cordon89647a62013-07-16 13:38:09 -070076
Santos Cordon63a84242013-07-23 13:32:52 -070077 public CallHandlerServiceProxy(Context context, CallModeler callModeler,
Santos Cordon593ab382013-08-06 21:58:23 -070078 CallCommandService callCommandService, AudioRouter audioRouter) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -070079 if (DBG) {
80 Log.d(TAG, "init CallHandlerServiceProxy");
81 }
Santos Cordon89647a62013-07-16 13:38:09 -070082 mContext = context;
Santos Cordoncba1b442013-07-18 12:43:58 -070083 mCallCommandService = callCommandService;
Santos Cordon63a84242013-07-23 13:32:52 -070084 mCallModeler = callModeler;
Santos Cordon593ab382013-08-06 21:58:23 -070085 mAudioRouter = audioRouter;
Santos Cordon89647a62013-07-16 13:38:09 -070086
Santos Cordon593ab382013-08-06 21:58:23 -070087 mAudioRouter.addAudioModeListener(this);
Christine Chendaf7bf62013-08-05 19:12:31 -070088 mCallModeler.addListener(this);
Santos Cordon63a84242013-07-23 13:32:52 -070089 }
Santos Cordon89647a62013-07-16 13:38:09 -070090
Santos Cordon63a84242013-07-23 13:32:52 -070091 @Override
Santos Cordon995c8162013-07-29 09:22:22 -070092 public void onDisconnect(Call call) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -070093 synchronized (mServiceAndQueueLock) {
94 if (mCallHandlerServiceGuarded == null) {
95 if (DBG) {
96 Log.d(TAG, "CallHandlerService not connected. Enqueue disconnect");
Chiao Cheng6c6b2722013-08-22 18:35:54 -070097 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -070098 enqueueDisconnect(call);
99 setupServiceConnection();
100 return;
Santos Cordon63a84242013-07-23 13:32:52 -0700101 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700102 }
103 processDisconnect(call);
104 }
105
106 private void processDisconnect(Call call) {
107 try {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700108 if (DBG) {
109 Log.d(TAG, "onDisconnect: " + call);
110 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700111 synchronized (mServiceAndQueueLock) {
112 if (mCallHandlerServiceGuarded != null) {
113 mCallHandlerServiceGuarded.onDisconnect(call);
114 }
115 }
116 if (!mCallModeler.hasLiveCall()) {
117 unbind();
118 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700119 } catch (Exception e) {
120 Log.e(TAG, "Remote exception handling onDisconnect ", e);
Santos Cordon89647a62013-07-16 13:38:09 -0700121 }
122 }
123
Santos Cordona3d05142013-07-29 11:25:17 -0700124 @Override
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700125 public void onIncoming(Call call) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700126 synchronized (mServiceAndQueueLock) {
127 if (mCallHandlerServiceGuarded == null) {
128 if (DBG) {
129 Log.d(TAG, "CallHandlerService not connected. Enqueue incoming.");
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700130 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700131 enqueueIncoming(call);
132 setupServiceConnection();
133 return;
Christine Chenee09a492013-08-06 16:02:29 -0700134 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700135 }
136 processIncoming(call);
137 }
138
139 private void processIncoming(Call call) {
140 if (DBG) {
141 Log.d(TAG, "onIncoming: " + call);
142 }
143 try {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700144 // TODO(klp): check RespondViaSmsManager.allowRespondViaSmsForCall()
145 // must refactor call method to accept proper call object.
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700146 synchronized (mServiceAndQueueLock) {
147 if (mCallHandlerServiceGuarded != null) {
148 mCallHandlerServiceGuarded.onIncoming(call,
149 RejectWithTextMessageManager.loadCannedResponses());
150 }
151 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700152 } catch (Exception e) {
153 Log.e(TAG, "Remote exception handling onUpdate", e);
Christine Chenee09a492013-08-06 16:02:29 -0700154 }
155 }
156
157 @Override
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700158 public void onUpdate(List<Call> calls) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700159 synchronized (mServiceAndQueueLock) {
160 if (mCallHandlerServiceGuarded == null) {
161 if (DBG) {
162 Log.d(TAG, "CallHandlerService not connected. Enqueue update.");
163 }
164 enqueueUpdate(calls);
165 setupServiceConnection();
166 return;
167 }
168 }
169 processUpdate(calls);
170 }
171
172 private void processUpdate(List<Call> calls) {
173 if (DBG) {
174 Log.d(TAG, "onUpdate: " + calls.toString());
175 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700176 try {
177 synchronized (mServiceAndQueueLock) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700178 if (mCallHandlerServiceGuarded != null) {
179 mCallHandlerServiceGuarded.onUpdate(calls);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700180 }
Santos Cordona3d05142013-07-29 11:25:17 -0700181 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700182 if (!mCallModeler.hasLiveCall()) {
183 // TODO: unbinding happens in both onUpdate and onDisconnect because the ordering
184 // is not deterministic. Unbinding in both ensures that the service is unbound.
185 // But it also makes this in-efficient because we are unbinding twice, which leads
186 // to the CallHandlerService performing onCreate() and onDestroy() twice for each
187 // disconnect.
188 unbind();
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700189 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700190 } catch (Exception e) {
191 Log.e(TAG, "Remote exception handling onUpdate", e);
Santos Cordona3d05142013-07-29 11:25:17 -0700192 }
193 }
194
Santos Cordon9b7bac72013-08-06 08:04:52 -0700195 @Override
Santos Cordoncd95f622013-08-29 03:38:52 -0700196 public void onAudioModeChange(int newMode, boolean muted) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700197 try {
198 synchronized (mServiceAndQueueLock) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700199 if (mCallHandlerServiceGuarded == null) {
200 if (DBG) {
201 Log.d(TAG, "CallHandlerService not conneccted. Skipping "
202 + "onAudioModeChange().");
203 }
204 return;
205 }
Santos Cordon9b7bac72013-08-06 08:04:52 -0700206 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700207
208 // Just do a simple log for now.
209 Log.i(TAG, "Updating with new audio mode: " + AudioMode.toString(newMode) +
Santos Cordoncd95f622013-08-29 03:38:52 -0700210 " with mute " + muted);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700211
212 if (DBG) {
213 Log.d(TAG, "onSupportAudioModeChange");
214 }
215
Santos Cordoncd95f622013-08-29 03:38:52 -0700216 mCallHandlerServiceGuarded.onAudioModeChange(newMode, muted);
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700217 } catch (Exception e) {
218 Log.e(TAG, "Remote exception handling onAudioModeChange", e);
Santos Cordon9b7bac72013-08-06 08:04:52 -0700219 }
220 }
221
Santos Cordon593ab382013-08-06 21:58:23 -0700222 @Override
223 public void onSupportedAudioModeChange(int modeMask) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700224 try {
225 synchronized (mServiceAndQueueLock) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700226 if (mCallHandlerServiceGuarded == null) {
227 if (DBG) {
228 Log.d(TAG, "CallHandlerService not conneccted. Skipping"
229 + "onSupportedAudioModeChange().");
230 }
231 return;
232 }
233 }
Santos Cordon593ab382013-08-06 21:58:23 -0700234
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700235 if (DBG) {
236 Log.d(TAG, "onSupportAudioModeChange: " + AudioMode.toString(modeMask));
237 }
238
239 mCallHandlerServiceGuarded.onSupportedAudioModeChange(modeMask);
240 } catch (Exception e) {
241 Log.e(TAG, "Remote exception handling onAudioModeChange", e);
242 }
243
244 }
245
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700246 private ServiceConnection mConnection = null;
247
248 private class InCallServiceConnection implements ServiceConnection {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700249 @Override public void onServiceConnected (ComponentName className, IBinder service){
250 if (DBG) {
251 Log.d(TAG, "Service Connected");
252 }
253 onCallHandlerServiceConnected(ICallHandlerService.Stub.asInterface(service));
Chiao Cheng11a4b652013-09-02 01:08:19 -0700254 mBindRetryCount = 0;
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700255 }
256
257 @Override public void onServiceDisconnected (ComponentName className){
258 Log.i(TAG, "Disconnected from UI service.");
259 synchronized (mServiceAndQueueLock) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700260 // Technically, unbindService is un-necessary since the framework will schedule and
261 // restart the crashed service. But there is a exponential backoff for the restart.
262 // Unbind explicitly and setup again to avoid the backoff since it's important to
263 // always have an in call ui.
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700264 unbind();
265
266 // TODO(klp): hang up all calls.
Santos Cordon593ab382013-08-06 21:58:23 -0700267 }
268 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700269 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700270
Santos Cordon406c0342013-08-28 00:07:47 -0700271 public void bringToForeground() {
272 // only support this call if the service is already connected.
Santos Cordon19d814b2013-08-28 14:58:17 -0700273 synchronized (mServiceAndQueueLock) {
274 if (mCallHandlerServiceGuarded != null && mCallModeler.hasLiveCall()) {
275 try {
276 if (DBG) Log.d(TAG, "bringToForeground");
277 mCallHandlerServiceGuarded.bringToForeground();
278 } catch (RemoteException e) {
279 Log.e(TAG, "Exception handling bringToForeground", e);
280 }
Santos Cordon406c0342013-08-28 00:07:47 -0700281 }
282 }
283 }
284
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700285 private static Intent getInCallServiceIntent(Context context) {
286 final Intent serviceIntent = new Intent(ICallHandlerService.class.getName());
287 final ComponentName component = new ComponentName(context.getResources().getString(
288 R.string.incall_ui_default_package), context.getResources().getString(
289 R.string.incall_ui_default_class));
290 serviceIntent.setComponent(component);
291 return serviceIntent;
292 }
293
Santos Cordon89647a62013-07-16 13:38:09 -0700294 /**
Santos Cordon345350e2013-07-19 17:16:14 -0700295 * Sets up the connection with ICallHandlerService
Santos Cordon89647a62013-07-16 13:38:09 -0700296 */
297 private void setupServiceConnection() {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700298 if (!PhoneGlobals.sVoiceCapable) {
299 return;
300 }
Chiao Cheng11a4b652013-09-02 01:08:19 -0700301
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700302 final Intent serviceIntent = getInCallServiceIntent(mContext);
Chiao Cheng11a4b652013-09-02 01:08:19 -0700303 if (DBG) {
304 Log.d(TAG, "binding to service " + serviceIntent);
305 }
306
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700307 synchronized (mServiceAndQueueLock) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700308 if (mConnection == null) {
309 mConnection = new InCallServiceConnection();
310
311 final PackageManager packageManger = mContext.getPackageManager();
312 final List<ResolveInfo> services = packageManger.queryIntentServices(serviceIntent,
313 0);
314 if (services.size() == 0) {
315 // Service not found, retry again after some delay
316 // This can happen if the service is being installed by the package manager.
317 // Between deletes and installs, bindService could get a silent service not
318 // found error.
319 mBindRetryCount++;
320 if (mBindRetryCount < MAX_RETRY_COUNT) {
321 Log.w(TAG, "InCallUI service not found. " + serviceIntent
322 + ". This happens if the service is being installed and should be"
323 + " transient. Retrying" + RETRY_DELAY_MILLIS + " ms.");
324 sendMessageDelayed(Message.obtain(this, BIND_RETRY_MSG),
325 RETRY_DELAY_MILLIS);
326 } else {
327 Log.e(TAG, "Tried to bind to in-call UI " + MAX_RETRY_COUNT + " times."
328 + " Giving up.");
329 }
330 return;
331 }
332
333 if (DBG) {
334 Log.d(TAG, "binding to service " + serviceIntent);
335 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700336 if (!mContext.bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE)) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700337 // This happens when the in-call package is in the middle of being
338 // installed.
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700339 // Delay the retry.
340 mBindRetryCount++;
341 if (mBindRetryCount < MAX_RETRY_COUNT) {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700342 Log.e(TAG, "bindService failed on " + serviceIntent + ". Retrying in "
343 + RETRY_DELAY_MILLIS + " ms.");
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700344 sendMessageDelayed(Message.obtain(this, BIND_RETRY_MSG),
345 RETRY_DELAY_MILLIS);
346 } else {
347 Log.wtf(TAG, "Tried to bind to in-call UI " + MAX_RETRY_COUNT + " times."
348 + " Giving up.");
349 }
350 }
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700351
352 } else {
353 Log.d(TAG, "Service connection to in call service already started.");
Santos Cordonaf763a12013-08-19 20:04:58 -0700354 }
355 }
356 }
357
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700358 private void unbind() {
359 synchronized (mServiceAndQueueLock) {
360 if (mCallHandlerServiceGuarded != null) {
361 Log.d(TAG, "Unbinding service.");
362 mCallHandlerServiceGuarded = null;
363 mContext.unbindService(mConnection);
364 }
365 mConnection = null;
366 }
367 }
368
Santos Cordonaf763a12013-08-19 20:04:58 -0700369 /**
Santos Cordoncba1b442013-07-18 12:43:58 -0700370 * Called when the in-call UI service is connected. Send command interface to in-call.
371 */
Santos Cordon63a84242013-07-23 13:32:52 -0700372 private void onCallHandlerServiceConnected(ICallHandlerService callHandlerService) {
Chiao Chengd38eebc2013-08-28 14:38:14 -0700373
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700374 synchronized (mServiceAndQueueLock) {
375 mCallHandlerServiceGuarded = callHandlerService;
376
Santos Cordonad078192013-08-28 15:14:54 -0700377 // Before we send any updates, we need to set up the initial service calls.
378 makeInitialServiceCalls();
379
Chiao Chengd38eebc2013-08-28 14:38:14 -0700380 processQueue();
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700381 }
Santos Cordonad078192013-08-28 15:14:54 -0700382 }
Santos Cordoncba1b442013-07-18 12:43:58 -0700383
Santos Cordonad078192013-08-28 15:14:54 -0700384 /**
385 * Makes initial service calls to set up callcommandservice and audio modes.
386 */
387 private void makeInitialServiceCalls() {
Santos Cordoncba1b442013-07-18 12:43:58 -0700388 try {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700389 mCallHandlerServiceGuarded.setCallCommandService(mCallCommandService);
Santos Cordonad078192013-08-28 15:14:54 -0700390
391 onSupportedAudioModeChange(mAudioRouter.getSupportedAudioModes());
Santos Cordon8fd0ec72013-08-29 16:44:43 -0700392 onAudioModeChange(mAudioRouter.getAudioMode(), mAudioRouter.getMute());
Santos Cordoncba1b442013-07-18 12:43:58 -0700393 } catch (RemoteException e) {
Santos Cordon63a84242013-07-23 13:32:52 -0700394 Log.e(TAG, "Remote exception calling CallHandlerService::setCallCommandService", e);
Santos Cordon89647a62013-07-16 13:38:09 -0700395 }
396 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700397
Chiao Chengd38eebc2013-08-28 14:38:14 -0700398 private List<QueueParams> getQueue() {
399 if (mQueue == null) {
400 mQueue = Lists.newArrayList();
401 }
402 return mQueue;
403 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700404
405 private void enqueueDisconnect(Call call) {
Chiao Chengd38eebc2013-08-28 14:38:14 -0700406 getQueue().add(new QueueParams(QueueParams.METHOD_DISCONNECT, new Call(call)));
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700407 }
408
409 private void enqueueIncoming(Call call) {
Chiao Chengd38eebc2013-08-28 14:38:14 -0700410 getQueue().add(new QueueParams(QueueParams.METHOD_INCOMING, new Call(call)));
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700411 }
412
413 private void enqueueUpdate(List<Call> calls) {
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700414 final List<Call> copy = Lists.newArrayList();
415 for (Call call : calls) {
416 copy.add(new Call(call));
417 }
Chiao Chengc340ba92013-08-30 13:04:46 -0700418 getQueue().add(new QueueParams(QueueParams.METHOD_UPDATE, copy));
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700419 }
420
Chiao Chengd38eebc2013-08-28 14:38:14 -0700421 private void processQueue() {
Chiao Cheng3e6486e2013-09-03 19:27:46 -0700422 synchronized (mServiceAndQueueLock) {
423 if (mQueue != null) {
424 for (QueueParams params : mQueue) {
425 switch (params.mMethod) {
426 case QueueParams.METHOD_INCOMING:
427 processIncoming((Call) params.mArg);
428 break;
429 case QueueParams.METHOD_UPDATE:
430 processUpdate((List<Call>) params.mArg);
431 break;
432 case QueueParams.METHOD_DISCONNECT:
433 processDisconnect((Call) params.mArg);
434 break;
435 default:
436 throw new IllegalArgumentException("Method type " + params.mMethod +
437 " not recognized.");
438 }
439 }
440 mQueue.clear();
441 mQueue = null;
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700442 }
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700443 }
444 }
445
Chiao Chengd38eebc2013-08-28 14:38:14 -0700446 /**
447 * Holds method parameters.
448 */
449 private static class QueueParams {
450 private static final int METHOD_INCOMING = 1;
451 private static final int METHOD_UPDATE = 2;
452 private static final int METHOD_DISCONNECT = 3;
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700453
Chiao Chengd38eebc2013-08-28 14:38:14 -0700454 private final int mMethod;
455 private final Object mArg;
456
457 private QueueParams(int method, Object arg) {
458 mMethod = method;
459 this.mArg = arg;
Chiao Cheng6c6b2722013-08-22 18:35:54 -0700460 }
461 }
Santos Cordon89647a62013-07-16 13:38:09 -0700462}