summaryrefslogtreecommitdiff
path: root/InCallUI/src/com
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2013-07-29 13:46:53 -0700
committerSantos Cordon <santoscordon@google.com>2013-07-29 14:24:30 -0700
commitdec7e7e30e0352f08a6735e31c276a2aec2f554c (patch)
treedd1685a84b19686de53fe58244113d51891c6448 /InCallUI/src/com
parent184e8a44c70d9b93256232f339974280b97e9f7b (diff)
Adding a CallList class to manage Calls from CallHandlerService.
Change-Id: Ic6a7c88721a881654fb8afa174291415539b586e
Diffstat (limited to 'InCallUI/src/com')
-rw-r--r--InCallUI/src/com/android/incallui/CallHandlerService.java10
-rw-r--r--InCallUI/src/com/android/incallui/CallList.java64
2 files changed, 73 insertions, 1 deletions
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> call) {
+ public void onUpdate(List<Call> 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<Integer, Call> callMap = Maps.newHashMap();
+
+ public void onUpdate(Call call) {
+ updateCallInMap(call);
+ }
+
+ public void onUpdate(List<Call> 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;
+ }
+}