From 9b70c293ad0a2bf343a93701a37a5f152c6a4214 Mon Sep 17 00:00:00 2001 From: Brandon Maxwell Date: Wed, 16 Dec 2015 11:00:18 -0800 Subject: Backporting InCallUI so to allow calls on nonOEM devices VideoProfile#videoStateToString, TelecomManager#getLine1Number, and TelecomManager#isVoiceMailNumber don't exist in the L sdk, so Compat classes were added which duplicated the needed logic. Bug=25776171 Change-Id: Ib546b8fbd802aa6f8f5c712e59b99716db4c6a7b --- InCallUI/src/com/android/incallui/Call.java | 3 +- .../com/android/incallui/CallCardPresenter.java | 7 +- .../src/com/android/incallui/CallerInfoUtils.java | 9 +- .../src/com/android/incallui/InCallPresenter.java | 17 ++- .../compat/telecom/VideoProfileCompat.java | 127 +++++++++++++++++++++ 5 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 InCallUI/src/com/android/incallui/compat/telecom/VideoProfileCompat.java (limited to 'InCallUI') diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index 9ee27221d..f47a4c39a 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -37,6 +37,7 @@ import com.android.contacts.common.compat.SdkVersionOverride; import com.android.contacts.common.testing.NeededForTesting; import com.android.dialer.util.IntentUtil; import com.android.incallui.compat.telecom.DetailsCompat; +import com.android.incallui.compat.telecom.VideoProfileCompat; import com.android.incallui.util.TelecomCallUtil; import java.util.ArrayList; @@ -958,7 +959,7 @@ public class Call { mChildCallIds, getParentId(), this.mTelecomCall.getConferenceableCalls(), - VideoProfile.videoStateToString(mTelecomCall.getDetails().getVideoState()), + VideoProfileCompat.videoStateToString(mTelecomCall.getDetails().getVideoState()), mSessionModificationState, getVideoSettings()); } diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 0183b41b9..fda337b7f 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -50,6 +50,7 @@ import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; import com.android.incallui.compat.telecom.DetailsCompat; +import com.android.dialer.compat.telecom.TelecomManagerCompat; import com.android.incalluibind.ObjectFactory; import java.lang.ref.WeakReference; @@ -481,8 +482,10 @@ public class CallCardPresenter extends Presenter } } - TelecomManager mgr = InCallPresenter.getInstance().getTelecomManager(); - String simNumber = mgr.getLine1Number(mPrimary.getAccountHandle()); + final String simNumber = TelecomManagerCompat.getLine1Number( + InCallPresenter.getInstance().getTelecomManager(), + InCallPresenter.getInstance().getTelephonyManager(), + mPrimary.getAccountHandle()); if (!showCallbackNumber && PhoneNumberUtils.compare(callbackNumber, simNumber)) { Log.d(this, "Numbers are the same (and callback number is not being forced to show);" + " not showing the callback number"); diff --git a/InCallUI/src/com/android/incallui/CallerInfoUtils.java b/InCallUI/src/com/android/incallui/CallerInfoUtils.java index 2cbf456b3..095f995ca 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoUtils.java +++ b/InCallUI/src/com/android/incallui/CallerInfoUtils.java @@ -11,6 +11,7 @@ import android.util.Log; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; +import com.android.dialer.compat.telecom.TelecomManagerCompat; import java.util.Arrays; @@ -87,10 +88,10 @@ public class CallerInfoUtils { } public static boolean isVoiceMailNumber(Context context, Call call) { - TelecomManager telecomManager = - (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); - return telecomManager.isVoiceMailNumber( - call.getTelecomCall().getDetails().getAccountHandle(), call.getNumber()); + return TelecomManagerCompat.isVoiceMailNumber( + (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE), + call.getTelecomCall().getDetails().getAccountHandle(), + call.getNumber()); } /** diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 637b4aa93..4bb86d004 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -16,11 +16,12 @@ package com.android.incallui; +import com.google.common.base.Preconditions; + import android.app.ActivityManager.TaskDescription; import android.app.FragmentManager; import android.content.Context; import android.content.Intent; -import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Point; @@ -36,12 +37,12 @@ import android.telecom.VideoProfile; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.view.Surface; import android.view.View; import android.view.Window; import android.view.WindowManager; import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.compat.CompatUtils; import com.android.contacts.common.compat.SdkVersionOverride; import com.android.contacts.common.interactions.TouchPointManager; import com.android.contacts.common.testing.NeededForTesting; @@ -56,15 +57,14 @@ import com.android.dialer.logging.Logger; import com.android.incallui.compat.telecom.DetailsCompat; import com.android.incallui.util.TelecomCallUtil; import com.android.incalluibind.ObjectFactory; -import com.google.common.base.Preconditions; import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicBoolean; /** * Takes updates from the CallList and notifies the InCallActivity (UI) @@ -1793,7 +1793,7 @@ public class InCallPresenter implements CallList.Listener, final PhoneAccount account = tm.getPhoneAccount(phoneAccountHandle); // For single-sim devices, there will be no selected highlight color, so the phone // account will default to NO_HIGHLIGHT_COLOR. - if (account != null) { + if (account != null && CompatUtils.isLollipopMr1Compatible()) { highlightColor = account.getHighlightColor(); } } @@ -1813,6 +1813,13 @@ public class InCallPresenter implements CallList.Listener, return mTelecomManager; } + /** + * @return An instance of TelephonyManager + */ + public TelephonyManager getTelephonyManager() { + return mTelephonyManager; + } + InCallActivity getActivity() { return mInCallActivity; } diff --git a/InCallUI/src/com/android/incallui/compat/telecom/VideoProfileCompat.java b/InCallUI/src/com/android/incallui/compat/telecom/VideoProfileCompat.java new file mode 100644 index 000000000..54d8eed65 --- /dev/null +++ b/InCallUI/src/com/android/incallui/compat/telecom/VideoProfileCompat.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015 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.compat.telecom; + +import android.telecom.VideoProfile; + +import com.android.contacts.common.compat.CompatUtils; + +/** + * Compatibility class for {@link android.telecom.VideoProfile} + */ +public class VideoProfileCompat { + + /** + * Generates a string representation of a video state. + * + * @param videoState The video state. + * @return String representation of the video state. + */ + public static String videoStateToString(int videoState) { + if (CompatUtils.isMarshmallowCompatible()) { + return VideoProfile.videoStateToString(videoState); + } + return videoStateToStringLollipop(videoState); + } + + /** + * Copied from {@link android.telecom.VideoProfile#videoStateToString} + */ + private static String videoStateToStringLollipop(int videoState) { + StringBuilder sb = new StringBuilder(); + sb.append("Audio"); + if (isAudioOnly(videoState)) { + sb.append(" Only"); + } else { + if (isTransmissionEnabled(videoState)) { + sb.append(" Tx"); + } + if (isReceptionEnabled(videoState)) { + sb.append(" Rx"); + } + if (isPaused(videoState)) { + sb.append(" Pause"); + } + } + return sb.toString(); + } + + /** + * Indicates whether the video state is audio only. + * + * @param videoState The video state. + * @return {@code true} if the video state is audio only, {@code false} otherwise. + */ + public static boolean isAudioOnly(int videoState) { + if (CompatUtils.isMarshmallowCompatible()) { + return VideoProfile.isAudioOnly(videoState); + } + return !hasState(videoState, VideoProfile.STATE_TX_ENABLED) + && !hasState(videoState, VideoProfile.STATE_RX_ENABLED); + } + + /** + * Indicates whether the video state has video transmission enabled. + * + * @param videoState The video state. + * @return {@code true} if video transmission is enabled, {@code false} otherwise. + */ + public static boolean isTransmissionEnabled(int videoState) { + if (CompatUtils.isMarshmallowCompatible()) { + return VideoProfile.isTransmissionEnabled(videoState); + } + return hasState(videoState, VideoProfile.STATE_TX_ENABLED); + } + + /** + * Indicates whether the video state has video reception enabled. + * + * @param videoState The video state. + * @return {@code true} if video reception is enabled, {@code false} otherwise. + */ + public static boolean isReceptionEnabled(int videoState) { + if (CompatUtils.isMarshmallowCompatible()) { + return VideoProfile.isReceptionEnabled(videoState); + } + return hasState(videoState, VideoProfile.STATE_RX_ENABLED); + } + + /** + * Indicates whether the video state is paused. + * + * @param videoState The video state. + * @return {@code true} if the video is paused, {@code false} otherwise. + */ + public static boolean isPaused(int videoState) { + if (CompatUtils.isMarshmallowCompatible()) { + return VideoProfile.isPaused(videoState); + } + return hasState(videoState, VideoProfile.STATE_PAUSED); + } + + /** + * Copied from {@link android.telecom.VideoProfile} + * + * Determines if a specified state is set in a videoState bit-mask. + * + * @param videoState The video state bit-mask. + * @param state The state to check. + * @return {@code true} if the state is set. + */ + private static boolean hasState(int videoState, int state) { + return (videoState & state) == state; + } +} -- cgit v1.2.3