Loading Android.mk +0 −2 Original line number Diff line number Diff line Loading @@ -4,8 +4,6 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_JAVA_LIBRARIES := telephony-common LOCAL_STATIC_JAVA_LIBRARIES := \ guava \ LOCAL_SRC_FILES := $(call all-java-files-under, src) Loading src/com/android/server/telecom/CallIdMapper.java +59 −5 Original line number Diff line number Diff line Loading @@ -16,11 +16,65 @@ package com.android.server.telecom; import com.google.common.collect.HashBiMap; import android.util.ArrayMap; import java.util.Map; /** Utility to map {@link Call} objects to unique IDs. IDs are generated when a call is added. */ class CallIdMapper { private final HashBiMap<String, Call> mCalls = HashBiMap.create(); /** * A very basic bidirectional map. */ static class BiMap<K, V> { private Map<K, V> mPrimaryMap = new ArrayMap<>(); private Map<V, K> mSecondaryMap = new ArrayMap<>(); public boolean put(K key, V value) { if (key == null || value == null || mPrimaryMap.containsKey(key) || mSecondaryMap.containsKey(value)) { return false; } mPrimaryMap.put(key, value); mSecondaryMap.put(value, key); return true; } public boolean remove(K key) { if (key == null) { return false; } if (mPrimaryMap.containsKey(key)) { V value = getValue(key); mPrimaryMap.remove(key); mSecondaryMap.remove(value); return true; } return false; } public boolean removeValue(V value) { if (value == null) { return false; } return remove(getKey(value)); } public V getValue(K key) { return mPrimaryMap.get(key); } public K getKey(V value) { return mSecondaryMap.get(value); } public void clear() { mPrimaryMap.clear(); mSecondaryMap.clear(); } } private final BiMap<String, Call> mCalls = new BiMap<>(); private final String mCallIdPrefix; private static int sIdCount; Loading Loading @@ -55,7 +109,7 @@ class CallIdMapper { return; } ThreadUtil.checkOnMainThread(); mCalls.inverse().remove(call); mCalls.removeValue(call); } void removeCall(String callId) { Loading @@ -68,7 +122,7 @@ class CallIdMapper { return null; } ThreadUtil.checkOnMainThread(); return mCalls.inverse().get(call); return mCalls.getKey(call); } Call getCall(Object objId) { Loading @@ -82,7 +136,7 @@ class CallIdMapper { return null; } return mCalls.get(callId); return mCalls.getValue(callId); } void clear() { Loading src/com/android/server/telecom/CallsManager.java +3 −5 Original line number Diff line number Diff line Loading @@ -40,9 +40,7 @@ import android.telephony.TelephonyManager; import com.android.internal.util.IndentingPrintWriter; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; Loading Loading @@ -314,8 +312,8 @@ public final class CallsManager extends Call.ListenerBase { return true; } ImmutableCollection<Call> getCalls() { return ImmutableList.copyOf(mCalls); Collection<Call> getCalls() { return Collections.unmodifiableCollection(mCalls); } Call getForegroundCall() { Loading src/com/android/server/telecom/DtmfLocalTonePlayer.java +14 −21 Original line number Diff line number Diff line Loading @@ -22,9 +22,6 @@ import android.media.ToneGenerator; import android.provider.Settings; // TODO: Needed for move to system service: import com.android.internal.R; import com.google.common.collect.ImmutableMap; import java.util.Map; /** * Plays DTMF tones locally for the caller to hear. In order to reduce (1) the amount of times we Loading @@ -33,22 +30,6 @@ import java.util.Map; * changes. */ class DtmfLocalTonePlayer extends CallsManagerListenerBase { private static final Map<Character, Integer> TONE_MAP = ImmutableMap.<Character, Integer>builder() .put('1', ToneGenerator.TONE_DTMF_1) .put('2', ToneGenerator.TONE_DTMF_2) .put('3', ToneGenerator.TONE_DTMF_3) .put('4', ToneGenerator.TONE_DTMF_4) .put('5', ToneGenerator.TONE_DTMF_5) .put('6', ToneGenerator.TONE_DTMF_6) .put('7', ToneGenerator.TONE_DTMF_7) .put('8', ToneGenerator.TONE_DTMF_8) .put('9', ToneGenerator.TONE_DTMF_9) .put('0', ToneGenerator.TONE_DTMF_0) .put('#', ToneGenerator.TONE_DTMF_P) .put('*', ToneGenerator.TONE_DTMF_S) .build(); /** Generator used to actually play the tone. */ private ToneGenerator mToneGenerator; Loading Loading @@ -85,8 +66,9 @@ class DtmfLocalTonePlayer extends CallsManagerListenerBase { Log.d(this, "playTone: mToneGenerator == null, %c.", c); } else { Log.d(this, "starting local tone: %c.", c); if (TONE_MAP.containsKey(c)) { mToneGenerator.startTone(TONE_MAP.get(c), -1 /* toneDuration */); int tone = getMappedTone(c); if (tone != ToneGenerator.TONE_UNKNOWN) { mToneGenerator.startTone(tone, -1 /* toneDuration */); } } } Loading Loading @@ -160,4 +142,15 @@ class DtmfLocalTonePlayer extends CallsManagerListenerBase { } } } private static final int getMappedTone(char digit) { if (digit >= '0' && digit <= '9') { return ToneGenerator.TONE_DTMF_0 + digit - '0'; } else if (digit == '#') { return ToneGenerator.TONE_DTMF_P; } else if (digit == '*') { return ToneGenerator.TONE_DTMF_S; } return ToneGenerator.TONE_UNKNOWN; } } src/com/android/server/telecom/InCallController.java +3 −3 Original line number Diff line number Diff line Loading @@ -40,13 +40,13 @@ import android.telecom.TelecomManager; import android.util.ArrayMap; // TODO: Needed for move to system service: import com.android.internal.R; import com.android.internal.telecom.IInCallService; import com.android.internal.util.IndentingPrintWriter; import com.google.common.collect.ImmutableCollection; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; Loading Loading @@ -355,7 +355,7 @@ public final class InCallController extends CallsManagerListenerBase { } // Upon successful connection, send the state of the world to the service. ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls(); Collection<Call> calls = CallsManager.getInstance().getCalls(); if (!calls.isEmpty()) { Log.i(this, "Adding %s calls to InCallService after onConnected: %s", calls.size(), componentName); Loading Loading
Android.mk +0 −2 Original line number Diff line number Diff line Loading @@ -4,8 +4,6 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_JAVA_LIBRARIES := telephony-common LOCAL_STATIC_JAVA_LIBRARIES := \ guava \ LOCAL_SRC_FILES := $(call all-java-files-under, src) Loading
src/com/android/server/telecom/CallIdMapper.java +59 −5 Original line number Diff line number Diff line Loading @@ -16,11 +16,65 @@ package com.android.server.telecom; import com.google.common.collect.HashBiMap; import android.util.ArrayMap; import java.util.Map; /** Utility to map {@link Call} objects to unique IDs. IDs are generated when a call is added. */ class CallIdMapper { private final HashBiMap<String, Call> mCalls = HashBiMap.create(); /** * A very basic bidirectional map. */ static class BiMap<K, V> { private Map<K, V> mPrimaryMap = new ArrayMap<>(); private Map<V, K> mSecondaryMap = new ArrayMap<>(); public boolean put(K key, V value) { if (key == null || value == null || mPrimaryMap.containsKey(key) || mSecondaryMap.containsKey(value)) { return false; } mPrimaryMap.put(key, value); mSecondaryMap.put(value, key); return true; } public boolean remove(K key) { if (key == null) { return false; } if (mPrimaryMap.containsKey(key)) { V value = getValue(key); mPrimaryMap.remove(key); mSecondaryMap.remove(value); return true; } return false; } public boolean removeValue(V value) { if (value == null) { return false; } return remove(getKey(value)); } public V getValue(K key) { return mPrimaryMap.get(key); } public K getKey(V value) { return mSecondaryMap.get(value); } public void clear() { mPrimaryMap.clear(); mSecondaryMap.clear(); } } private final BiMap<String, Call> mCalls = new BiMap<>(); private final String mCallIdPrefix; private static int sIdCount; Loading Loading @@ -55,7 +109,7 @@ class CallIdMapper { return; } ThreadUtil.checkOnMainThread(); mCalls.inverse().remove(call); mCalls.removeValue(call); } void removeCall(String callId) { Loading @@ -68,7 +122,7 @@ class CallIdMapper { return null; } ThreadUtil.checkOnMainThread(); return mCalls.inverse().get(call); return mCalls.getKey(call); } Call getCall(Object objId) { Loading @@ -82,7 +136,7 @@ class CallIdMapper { return null; } return mCalls.get(callId); return mCalls.getValue(callId); } void clear() { Loading
src/com/android/server/telecom/CallsManager.java +3 −5 Original line number Diff line number Diff line Loading @@ -40,9 +40,7 @@ import android.telephony.TelephonyManager; import com.android.internal.util.IndentingPrintWriter; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; Loading Loading @@ -314,8 +312,8 @@ public final class CallsManager extends Call.ListenerBase { return true; } ImmutableCollection<Call> getCalls() { return ImmutableList.copyOf(mCalls); Collection<Call> getCalls() { return Collections.unmodifiableCollection(mCalls); } Call getForegroundCall() { Loading
src/com/android/server/telecom/DtmfLocalTonePlayer.java +14 −21 Original line number Diff line number Diff line Loading @@ -22,9 +22,6 @@ import android.media.ToneGenerator; import android.provider.Settings; // TODO: Needed for move to system service: import com.android.internal.R; import com.google.common.collect.ImmutableMap; import java.util.Map; /** * Plays DTMF tones locally for the caller to hear. In order to reduce (1) the amount of times we Loading @@ -33,22 +30,6 @@ import java.util.Map; * changes. */ class DtmfLocalTonePlayer extends CallsManagerListenerBase { private static final Map<Character, Integer> TONE_MAP = ImmutableMap.<Character, Integer>builder() .put('1', ToneGenerator.TONE_DTMF_1) .put('2', ToneGenerator.TONE_DTMF_2) .put('3', ToneGenerator.TONE_DTMF_3) .put('4', ToneGenerator.TONE_DTMF_4) .put('5', ToneGenerator.TONE_DTMF_5) .put('6', ToneGenerator.TONE_DTMF_6) .put('7', ToneGenerator.TONE_DTMF_7) .put('8', ToneGenerator.TONE_DTMF_8) .put('9', ToneGenerator.TONE_DTMF_9) .put('0', ToneGenerator.TONE_DTMF_0) .put('#', ToneGenerator.TONE_DTMF_P) .put('*', ToneGenerator.TONE_DTMF_S) .build(); /** Generator used to actually play the tone. */ private ToneGenerator mToneGenerator; Loading Loading @@ -85,8 +66,9 @@ class DtmfLocalTonePlayer extends CallsManagerListenerBase { Log.d(this, "playTone: mToneGenerator == null, %c.", c); } else { Log.d(this, "starting local tone: %c.", c); if (TONE_MAP.containsKey(c)) { mToneGenerator.startTone(TONE_MAP.get(c), -1 /* toneDuration */); int tone = getMappedTone(c); if (tone != ToneGenerator.TONE_UNKNOWN) { mToneGenerator.startTone(tone, -1 /* toneDuration */); } } } Loading Loading @@ -160,4 +142,15 @@ class DtmfLocalTonePlayer extends CallsManagerListenerBase { } } } private static final int getMappedTone(char digit) { if (digit >= '0' && digit <= '9') { return ToneGenerator.TONE_DTMF_0 + digit - '0'; } else if (digit == '#') { return ToneGenerator.TONE_DTMF_P; } else if (digit == '*') { return ToneGenerator.TONE_DTMF_S; } return ToneGenerator.TONE_UNKNOWN; } }
src/com/android/server/telecom/InCallController.java +3 −3 Original line number Diff line number Diff line Loading @@ -40,13 +40,13 @@ import android.telecom.TelecomManager; import android.util.ArrayMap; // TODO: Needed for move to system service: import com.android.internal.R; import com.android.internal.telecom.IInCallService; import com.android.internal.util.IndentingPrintWriter; import com.google.common.collect.ImmutableCollection; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; Loading Loading @@ -355,7 +355,7 @@ public final class InCallController extends CallsManagerListenerBase { } // Upon successful connection, send the state of the world to the service. ImmutableCollection<Call> calls = CallsManager.getInstance().getCalls(); Collection<Call> calls = CallsManager.getInstance().getCalls(); if (!calls.isEmpty()) { Log.i(this, "Adding %s calls to InCallService after onConnected: %s", calls.size(), componentName); Loading