diff options
author | Brandon Maxwell <maxwelb@google.com> | 2015-12-08 11:22:08 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2015-12-09 12:04:18 -0800 |
commit | 359fca383f0f506632859e9a7878cc36aed611c8 (patch) | |
tree | 090584a9209bcb8a35d90474981d41581f90af20 /InCallUI/src | |
parent | a7086bc66eca9bbae80fb40ec532b3253361ee53 (diff) |
Backporting uses of android.telecom.Call$Callback
Use the android.telecom.Call$Listener object since it's the same as the
android.telecom.Call$Callback and available in L. Use branching logic to
avoid calling system apis when sdk >= M
Bug: 25776171
Change-Id: I87b26df0415e5583456ee5a6be103fe14a53f9df
Diffstat (limited to 'InCallUI/src')
-rw-r--r-- | InCallUI/src/com/android/incallui/Call.java | 223 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 120 |
2 files changed, 246 insertions, 97 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index 9526e7d5e..f860c85d3 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -16,15 +16,10 @@ package com.android.incallui; -import com.android.contacts.common.CallUtil; -import com.android.contacts.common.testing.NeededForTesting; -import com.android.dialer.util.IntentUtil; -import com.android.incallui.Call.LogState; -import com.android.incallui.util.TelecomCallUtil; - import android.content.Context; import android.hardware.camera2.CameraCharacteristics; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Trace; import android.telecom.Connection; @@ -35,9 +30,14 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telecom.VideoProfile; -import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import com.android.contacts.common.CallUtil; +import com.android.contacts.common.compat.SdkVersionOverride; +import com.android.contacts.common.testing.NeededForTesting; +import com.android.dialer.util.IntentUtil; +import com.android.incallui.util.TelecomCallUtil; + import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -287,73 +287,157 @@ public class Call { private static final String ID_PREFIX = Call.class.getSimpleName() + "_"; private static int sIdCounter = 0; - private android.telecom.Call.Callback mTelecomCallCallback = - new android.telecom.Call.Callback() { - @Override - public void onStateChanged(android.telecom.Call call, int newState) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " newState=" - + newState); - update(); - } + private Object mTelecomCallCallback = newTelecomCallCallback(); - @Override - public void onParentChanged(android.telecom.Call call, - android.telecom.Call newParent) { - Log.d(this, "TelecomCallCallback onParentChanged call=" + call + " newParent=" - + newParent); - update(); - } + private Object newTelecomCallCallback() { + if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { + return newMarshmallowTelecomCallCallback(); + } + return newLollipopTelecomCallCallback(); + } - @Override - public void onChildrenChanged(android.telecom.Call call, - List<android.telecom.Call> children) { - update(); - } + private Object newMarshmallowTelecomCallCallback() { + Log.i(this, "Using an android.telecom.Call$Callback"); + return new android.telecom.Call.Callback() { + @Override + public void onStateChanged(android.telecom.Call call, int newState) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " newState=" + + newState); + update(); + } - @Override - public void onDetailsChanged(android.telecom.Call call, - android.telecom.Call.Details details) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " details=" - + details); - update(); - } + @Override + public void onParentChanged(android.telecom.Call call, + android.telecom.Call newParent) { + Log.d(this, "TelecomCallCallback onParentChanged call=" + call + " newParent=" + + newParent); + update(); + } - @Override - public void onCannedTextResponsesLoaded(android.telecom.Call call, - List<String> cannedTextResponses) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call - + " cannedTextResponses=" + cannedTextResponses); - update(); - } + @Override + public void onChildrenChanged(android.telecom.Call call, + List<android.telecom.Call> children) { + update(); + } - @Override - public void onPostDialWait(android.telecom.Call call, - String remainingPostDialSequence) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call - + " remainingPostDialSequence=" + remainingPostDialSequence); - update(); - } + @Override + public void onDetailsChanged(android.telecom.Call call, + android.telecom.Call.Details details) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " details=" + + details); + update(); + } - @Override - public void onVideoCallChanged(android.telecom.Call call, - VideoCall videoCall) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " videoCall=" - + videoCall); - update(); - } + @Override + public void onCannedTextResponsesLoaded(android.telecom.Call call, + List<String> cannedTextResponses) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + + " cannedTextResponses=" + cannedTextResponses); + update(); + } - @Override - public void onCallDestroyed(android.telecom.Call call) { - Log.d(this, "TelecomCallCallback onStateChanged call=" + call); - call.unregisterCallback(mTelecomCallCallback); - } + @Override + public void onPostDialWait(android.telecom.Call call, + String remainingPostDialSequence) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + + " remainingPostDialSequence=" + remainingPostDialSequence); + update(); + } - @Override - public void onConferenceableCallsChanged(android.telecom.Call call, - List<android.telecom.Call> conferenceableCalls) { - update(); - } - }; + @Override + public void onVideoCallChanged(android.telecom.Call call, + VideoCall videoCall) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " videoCall=" + + videoCall); + update(); + } + + @Override + public void onCallDestroyed(android.telecom.Call call) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call); + call.unregisterCallback(this); + } + + @Override + public void onConferenceableCallsChanged(android.telecom.Call call, + List<android.telecom.Call> conferenceableCalls) { + update(); + } + }; + } + + private Object newLollipopTelecomCallCallback() { + // This code only runs for Google Experience phones on the pre-M sdk since only the system + // dialer can invoke the InCallUI code. This allows us to safely use the + // android.telecom.Call.Listener interface + Log.i(this, "Using an android.telecom.Call$Listener"); + return new android.telecom.Call.Listener() { + @Override + public void onStateChanged(android.telecom.Call call, int newState) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " newState=" + + newState); + update(); + } + + @Override + public void onParentChanged(android.telecom.Call call, + android.telecom.Call newParent) { + Log.d(this, "TelecomCallCallback onParentChanged call=" + call + " newParent=" + + newParent); + update(); + } + + @Override + public void onChildrenChanged(android.telecom.Call call, + List<android.telecom.Call> children) { + update(); + } + + @Override + public void onDetailsChanged(android.telecom.Call call, + android.telecom.Call.Details details) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " details=" + + details); + update(); + } + + @Override + public void onCannedTextResponsesLoaded(android.telecom.Call call, + List<String> cannedTextResponses) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + + " cannedTextResponses=" + cannedTextResponses); + update(); + } + + @Override + public void onPostDialWait(android.telecom.Call call, + String remainingPostDialSequence) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + + " remainingPostDialSequence=" + remainingPostDialSequence); + update(); + } + + @Override + public void onVideoCallChanged(android.telecom.Call call, + VideoCall videoCall) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call + " videoCall=" + + videoCall); + update(); + } + + @Override + public void onCallDestroyed(android.telecom.Call call) { + Log.d(this, "TelecomCallCallback onStateChanged call=" + call); + call.unregisterCallback(this); + } + + @Override + public void onConferenceableCallsChanged(android.telecom.Call call, + List<android.telecom.Call> conferenceableCalls) { + update(); + } + }; + } private android.telecom.Call mTelecomCall; private boolean mIsEmergencyCall; @@ -402,7 +486,12 @@ public class Call { mId = ID_PREFIX + Integer.toString(sIdCounter++); updateFromTelecomCall(); - mTelecomCall.registerCallback(mTelecomCallCallback); + + if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { + mTelecomCall.registerCallback((android.telecom.Call.Callback) mTelecomCallCallback); + } else { + mTelecomCall.addListener((android.telecom.Call.Listener) mTelecomCallCallback); + } mTimeAddedMs = System.currentTimeMillis(); } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 7d6409c45..697beadf8 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Point; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.provider.CallLog; @@ -41,6 +42,7 @@ import android.view.Window; import android.view.WindowManager; import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.compat.SdkVersionOverride; import com.android.contacts.common.interactions.TouchPointManager; import com.android.contacts.common.testing.NeededForTesting; import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; @@ -133,39 +135,89 @@ public class InCallPresenter implements CallList.Listener, */ private boolean mIsFullScreen = false; - private final android.telecom.Call.Callback mCallCallback = - new android.telecom.Call.Callback() { - @Override - public void onPostDialWait(android.telecom.Call telecomCall, - String remainingPostDialSequence) { - final Call call = mCallList.getCallByTelecomCall(telecomCall); - if (call == null) { - Log.w(this, "Call not found in call list: " + telecomCall); - return; - } - onPostDialCharWait(call.getId(), remainingPostDialSequence); + private final Object mCallCallback = newTelecomCallCallback(); + + private Object newTelecomCallCallback() { + if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { + return newMarshmallowTelecomCallCallback(); } + return newLollipopTelecomCallCallback(); + } - @Override - public void onDetailsChanged(android.telecom.Call telecomCall, - android.telecom.Call.Details details) { - final Call call = mCallList.getCallByTelecomCall(telecomCall); - if (call == null) { - Log.w(this, "Call not found in call list: " + telecomCall); - return; + private Object newMarshmallowTelecomCallCallback() { + Log.i(this, "Using android.telecom.Call.Callback"); + return new android.telecom.Call.Callback() { + @Override + public void onPostDialWait(android.telecom.Call telecomCall, + String remainingPostDialSequence) { + final Call call = mCallList.getCallByTelecomCall(telecomCall); + if (call == null) { + Log.w(this, "Call not found in call list: " + telecomCall); + return; + } + onPostDialCharWait(call.getId(), remainingPostDialSequence); } - for (InCallDetailsListener listener : mDetailsListeners) { - listener.onDetailsChanged(call, details); + + @Override + public void onDetailsChanged(android.telecom.Call telecomCall, + android.telecom.Call.Details details) { + final Call call = mCallList.getCallByTelecomCall(telecomCall); + if (call == null) { + Log.w(this, "Call not found in call list: " + telecomCall); + return; + } + for (InCallDetailsListener listener : mDetailsListeners) { + listener.onDetailsChanged(call, details); + } } - } - @Override - public void onConferenceableCallsChanged(android.telecom.Call telecomCall, - List<android.telecom.Call> conferenceableCalls) { - Log.i(this, "onConferenceableCallsChanged: " + telecomCall); - onDetailsChanged(telecomCall, telecomCall.getDetails()); - } - }; + @Override + public void onConferenceableCallsChanged(android.telecom.Call telecomCall, + List<android.telecom.Call> conferenceableCalls) { + Log.i(this, "onConferenceableCallsChanged: " + telecomCall); + onDetailsChanged(telecomCall, telecomCall.getDetails()); + } + }; + } + + private Object newLollipopTelecomCallCallback() { + // This code only runs for Google Experience phones on the pre-M sdk since only the system + // dialer can invoke the InCallUI code. This allows us to safely use the + // android.telecom.Call.Listener interface + Log.i(this, "Using android.telecom.Call.Listener"); + return new android.telecom.Call.Listener() { + @Override + public void onPostDialWait(android.telecom.Call telecomCall, + String remainingPostDialSequence) { + final Call call = mCallList.getCallByTelecomCall(telecomCall); + if (call == null) { + Log.w(this, "Call not found in call list: " + telecomCall); + return; + } + onPostDialCharWait(call.getId(), remainingPostDialSequence); + } + + @Override + public void onDetailsChanged(android.telecom.Call telecomCall, + android.telecom.Call.Details details) { + final Call call = mCallList.getCallByTelecomCall(telecomCall); + if (call == null) { + Log.w(this, "Call not found in call list: " + telecomCall); + return; + } + for (InCallDetailsListener listener : mDetailsListeners) { + listener.onDetailsChanged(call, details); + } + } + + @Override + public void onConferenceableCallsChanged(android.telecom.Call telecomCall, + List<android.telecom.Call> conferenceableCalls) { + Log.i(this, "onConferenceableCallsChanged: " + telecomCall); + onDetailsChanged(telecomCall, telecomCall.getDetails()); + } + }; + } private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) { @@ -501,7 +553,11 @@ public class InCallPresenter implements CallList.Listener, // Since a call has been added we are no longer waiting for Telecom to send us a call. setBoundAndWaitingForOutgoingCall(false, null); - call.registerCallback(mCallCallback); + if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { + call.registerCallback((android.telecom.Call.Callback) mCallCallback); + } else { + call.addListener((android.telecom.Call.Listener) mCallCallback); + } } /** @@ -570,7 +626,11 @@ public class InCallPresenter implements CallList.Listener, public void onCallRemoved(android.telecom.Call call) { mCallList.onCallRemoved(call); - call.unregisterCallback(mCallCallback); + if (SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M) { + call.unregisterCallback((android.telecom.Call.Callback) mCallCallback); + } else { + call.removeListener((android.telecom.Call.Listener) mCallCallback); + } } public void onCanAddCallChanged(boolean canAddCall) { |