Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b70c293 authored by Brandon Maxwell's avatar Brandon Maxwell
Browse files

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
parent 7a4d2c05
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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());
    }
+5 −2
Original line number Diff line number Diff line
@@ -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<CallCardPresenter.CallCardUi>
            }
        }

        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");
+5 −4
Original line number Diff line number Diff line
@@ -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());
    }

    /**
+12 −5
Original line number Diff line number Diff line
@@ -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;
    }
+127 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}