From dec7e7e30e0352f08a6735e31c276a2aec2f554c Mon Sep 17 00:00:00 2001 From: Santos Cordon Date: Mon, 29 Jul 2013 13:46:53 -0700 Subject: Adding a CallList class to manage Calls from CallHandlerService. Change-Id: Ic6a7c88721a881654fb8afa174291415539b586e --- .../com/android/incallui/CallHandlerService.java | 10 +++- InCallUI/src/com/android/incallui/CallList.java | 64 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 InCallUI/src/com/android/incallui/CallList.java (limited to 'InCallUI/src/com') diff --git a/InCallUI/src/com/android/incallui/CallHandlerService.java b/InCallUI/src/com/android/incallui/CallHandlerService.java index 31d278bce..127e57513 100644 --- a/InCallUI/src/com/android/incallui/CallHandlerService.java +++ b/InCallUI/src/com/android/incallui/CallHandlerService.java @@ -35,9 +35,13 @@ public class CallHandlerService extends Service { private static final String TAG = CallHandlerService.class.getSimpleName(); private static final boolean DBG = false; // TODO: Have a shared location for this. + private CallList mCallList; + @Override public void onCreate() { super.onCreate(); + + mCallList = new CallList(); } @Override @@ -59,6 +63,8 @@ public class CallHandlerService extends Service { @Override public void onIncomingCall(Call call) { + mCallList.onUpdate(call); + final Intent intent = new Intent(getApplication(), InCallActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); @@ -66,10 +72,12 @@ public class CallHandlerService extends Service { @Override public void onDisconnect(Call call) { + mCallList.onUpdate(call); } @Override - public void onUpdate(List call) { + public void onUpdate(List calls) { + mCallList.onUpdate(calls); } }; diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java new file mode 100644 index 000000000..5fe261946 --- /dev/null +++ b/InCallUI/src/com/android/incallui/CallList.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui; + +import com.google.android.collect.Maps; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import com.android.services.telephony.common.Call; + +import java.util.HashMap; +import java.util.List; + +/** + * Maintains the list of active calls received from CallHandlerService. + * TODO(klp): This class should be used by InCallUI to read about + * changes to calls. + */ +public class CallList { + + final HashMap callMap = Maps.newHashMap(); + + public void onUpdate(Call call) { + updateCallInMap(call); + } + + public void onUpdate(List callsToUpdate) { + Preconditions.checkNotNull(callsToUpdate); + for (Call call : callsToUpdate) { + updateCallInMap(call); + } + } + + private void updateCallInMap(Call call) { + Preconditions.checkNotNull(call); + + final Integer id = new Integer(call.getCallId()); + + if (isCallActive(call)) { + callMap.put(id, call); + } else if (callMap.containsKey(id)) { + callMap.remove(id); + } + } + + private boolean isCallActive(Call call) { + final int state = call.getState(); + return Call.State.IDLE != state && Call.State.INVALID != state; + } +} -- cgit v1.2.3