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

Commit fc9a25b7 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6780056 from 6235a794 to rvc-qpr1-release

Change-Id: I94372632e29f06b661378b0aded74687fb98f5c1
parents 048bcf42 6235a794
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.util.ArrayMap;

import com.android.internal.annotations.VisibleForTesting;

import java.util.Collection;
import java.util.Map;

/** Utility to map {@link Call} objects to unique IDs. IDs are generated when a call is added. */
@@ -132,6 +133,10 @@ public class CallIdMapper {
        return mCalls.getValue(callId);
    }

    Collection<Call> getCalls() {
        return mCalls.mPrimaryMap.values();
    }

    void clear() {
        mCalls.clear();
    }
+13 −0
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ public class CallsManager extends Call.ListenerBase
        void onConnectionTimeChanged(Call call);
        void onConferenceStateChanged(Call call, boolean isConference);
        void onCdmaConferenceSwap(Call call);
        void onSetCamera(Call call, String cameraId);
    }

    /** Interface used to define the action which is executed delay under some condition. */
@@ -1011,6 +1012,18 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    /**
     * Handles a change to the currently active camera for a call by notifying listeners.
     * @param call The call.
     * @param cameraId The ID of the camera in use, or {@code null} if no camera is in use.
     */
    @Override
    public void onSetCamera(Call call, String cameraId) {
        for (CallsManagerListener listener : mListeners) {
            listener.onSetCamera(call, cameraId);
        }
    }

    public Collection<Call> getCalls() {
        return Collections.unmodifiableCollection(mCalls);
    }
+4 −0
Original line number Diff line number Diff line
@@ -104,4 +104,8 @@ public class CallsManagerListenerBase implements CallsManager.CallsManagerListen
    @Override
    public void onCdmaConferenceSwap(Call call) {
    }

    @Override
    public void onSetCamera(Call call, String cameraId) {
    }
}
+112 −2
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.server.telecom;

import static android.os.Process.myUid;

import android.Manifest;
import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.ComponentName;
@@ -214,7 +217,7 @@ public class InCallController extends CallsManagerListenerBase {
                Log.startSession("ICSBC.oSD", Log.getPackageAbbreviation(name));
                synchronized (mLock) {
                    try {
                        Log.d(this, "onDisconnected: %s", name);
                        Log.d(this, "onServiceDisconnected: %s", name);
                        mIsBound = false;
                        onDisconnected();
                    } finally {
@@ -335,6 +338,8 @@ public class InCallController extends CallsManagerListenerBase {
                            mInCallServiceInfo.getDisconnectTime()
                                    - mInCallServiceInfo.getBindingStartTime(), mIsNullBinding);
                }

                InCallController.this.onDisconnected(mInCallServiceInfo);
            } else {
                Log.i(InCallController.this, "ICSBC#disconnect: already disconnected; %s",
                        mInCallServiceInfo);
@@ -867,6 +872,7 @@ public class InCallController extends CallsManagerListenerBase {
    private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getId);

    private final Context mContext;
    private final AppOpsManager mAppOpsManager;
    private final TelecomSystem.SyncRoot mLock;
    private final CallsManager mCallsManager;
    private final SystemStateHelper mSystemStateHelper;
@@ -884,12 +890,24 @@ public class InCallController extends CallsManagerListenerBase {

    private final CarModeTracker mCarModeTracker;

    /**
     * The package name of the app which is showing the calling UX.
     */
    private String mCurrentUserInterfacePackageName = null;

    /**
     * {@code true} if InCallController is tracking a managed, not external call which is using the
     * microphone, {@code false} otherwise.
     */
    private boolean mIsCallUsingMicrophone = false;

    public InCallController(Context context, TelecomSystem.SyncRoot lock, CallsManager callsManager,
            SystemStateHelper systemStateHelper,
            DefaultDialerCache defaultDialerCache, Timeouts.Adapter timeoutsAdapter,
            EmergencyCallHelper emergencyCallHelper, CarModeTracker carModeTracker,
            ClockProxy clockProxy) {
        mContext = context;
        mAppOpsManager = context.getSystemService(AppOpsManager.class);
        mLock = lock;
        mCallsManager = callsManager;
        mSystemStateHelper = systemStateHelper;
@@ -975,6 +993,7 @@ public class InCallController extends CallsManagerListenerBase {
        }
        call.removeListener(mCallListener);
        mCallIdMapper.removeCall(call);
        maybeTrackMicrophoneUse(isMuted());
    }

    @Override
@@ -1048,6 +1067,7 @@ public class InCallController extends CallsManagerListenerBase {
            }
            Log.i(this, "External call removed from components: %s", componentsUpdated);
        }
        maybeTrackMicrophoneUse(isMuted());
    }

    @Override
@@ -1069,6 +1089,7 @@ public class InCallController extends CallsManagerListenerBase {
        if (!mInCallServices.isEmpty()) {
            Log.i(this, "Calling onAudioStateChanged, audioState: %s -> %s", oldCallAudioState,
                    newCallAudioState);
            maybeTrackMicrophoneUse(newCallAudioState.isMuted());
            for (IInCallService inCallService : mInCallServices.values()) {
                try {
                    inCallService.onCallAudioStateChanged(newCallAudioState);
@@ -1133,6 +1154,23 @@ public class InCallController extends CallsManagerListenerBase {
        updateCall(call);
    }

    /**
     * Track changes to camera usage for a call.
     * @param call The call.
     * @param cameraId The id of the camera to use, or {@code null} if camera is off.
     */
    @Override
    public void onSetCamera(Call call, String cameraId) {
        Log.i(this, "onSetCamera callId=%s, cameraId=%s", call.getId(), cameraId);
        if (cameraId != null) {
            mAppOpsManager.startOp(AppOpsManager.OP_PHONE_CALL_CAMERA, myUid(),
                    mContext.getOpPackageName(), false, null, null);
        } else {
            mAppOpsManager.finishOp(AppOpsManager.OP_PHONE_CALL_CAMERA, myUid(),
                    mContext.getOpPackageName(), null);
        }
    }

    void bringToForeground(boolean showDialpad) {
        if (!mInCallServices.isEmpty()) {
            for (IInCallService inCallService : mInCallServices.values()) {
@@ -1509,6 +1547,11 @@ public class InCallController extends CallsManagerListenerBase {
    private boolean onConnected(InCallServiceInfo info, IBinder service) {
        Log.i(this, "onConnected to %s", info.getComponentName());

        if (info.getType() == IN_CALL_SERVICE_TYPE_CAR_MODE_UI
                || info.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI
                || info.getType() == IN_CALL_SERVICE_TYPE_DIALER_UI) {
            trackCallingUserInterfaceStarted(info);
        }
        IInCallService inCallService = IInCallService.Stub.asInterface(service);
        mInCallServices.put(info, inCallService);

@@ -1575,7 +1618,11 @@ public class InCallController extends CallsManagerListenerBase {
     */
    private void onDisconnected(InCallServiceInfo disconnectedInfo) {
        Log.i(this, "onDisconnected from %s", disconnectedInfo.getComponentName());

        if (disconnectedInfo.getType() == IN_CALL_SERVICE_TYPE_CAR_MODE_UI
                || disconnectedInfo.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI
                || disconnectedInfo.getType() == IN_CALL_SERVICE_TYPE_DIALER_UI) {
            trackCallingUserInterfaceStopped(disconnectedInfo);
        }
        mInCallServices.remove(disconnectedInfo);
    }

@@ -1641,6 +1688,7 @@ public class InCallController extends CallsManagerListenerBase {
            mCallIdMapper.addCall(call);
            call.addListener(mCallListener);
        }
        maybeTrackMicrophoneUse(isMuted());
    }

    /**
@@ -1815,6 +1863,68 @@ public class InCallController extends CallsManagerListenerBase {
        }
    }

    /**
     * Tracks start of microphone use on binding to the current calling UX.
     * @param info
     */
    private void trackCallingUserInterfaceStarted(InCallServiceInfo info) {
        String packageName = info.getComponentName().getPackageName();
        if (!Objects.equals(mCurrentUserInterfacePackageName, packageName)) {
            Log.i(this, "trackCallingUserInterfaceStarted: %s is now calling UX.", packageName);
            mCurrentUserInterfacePackageName = packageName;
        }
        maybeTrackMicrophoneUse(isMuted());
    }

    /**
     * Tracks stop of microphone use on unbind from the current calling UX.
     * @param info
     */
    private void trackCallingUserInterfaceStopped(InCallServiceInfo info) {
        maybeTrackMicrophoneUse(isMuted());
        mCurrentUserInterfacePackageName = null;
        String packageName = info.getComponentName().getPackageName();
        Log.i(this, "trackCallingUserInterfaceStopped: %s is no longer calling UX", packageName);
    }

    /**
     * As calls are added, removed and change between external and non-external status, track
     * whether the current active calling UX is using the microphone.  We assume if there is a
     * managed call present and the mic is not muted that the microphone is in use.
     */
    private void maybeTrackMicrophoneUse(boolean isMuted) {
        boolean wasTrackingManagedCall = mIsCallUsingMicrophone;
        mIsCallUsingMicrophone = isTrackingManagedCall() && !isMuted;
        if (wasTrackingManagedCall != mIsCallUsingMicrophone) {
            if (mIsCallUsingMicrophone) {
                mAppOpsManager.startOp(AppOpsManager.OP_PHONE_CALL_MICROPHONE, myUid(),
                        mContext.getOpPackageName(), false, null, null);
            } else {
                mAppOpsManager.finishOp(AppOpsManager.OP_PHONE_CALL_MICROPHONE, myUid(),
                        mContext.getOpPackageName(), null);
            }
        }
    }

    /**
     * @return {@code true} if InCallController is tracking a managed call (i.e. not self managed
     * and not external).
     */
    private boolean isTrackingManagedCall() {
        return mCallIdMapper.getCalls().stream().anyMatch(c -> !c.isExternalCall()
            && !c.isSelfManaged());
    }

    /**
     * @return {@code true} if the audio is currently muted, {@code false} otherwise.
     */
    private boolean isMuted() {
        if (mCallsManager.getAudioState() == null) {
            return false;
        }
        return mCallsManager.getAudioState().isMuted();
    }

    private void sendCrashedInCallServiceNotification(String packageName) {
        PackageManager packageManager = mContext.getPackageManager();
        CharSequence appName;
+7 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class VideoProviderProxy extends Connection.VideoProvider {
     */
    public interface Listener {
        void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
        void onSetCamera(Call call, String cameraId);
    }

    /**
@@ -346,6 +347,12 @@ public class VideoProviderProxy extends Connection.VideoProvider {
                    return;
                }
            }

            // Inform other Telecom components of the change in camera status.
            for (Listener listener : mListeners) {
                listener.onSetCamera(mCall, cameraId);
            }

            try {
                mConectionServiceVideoProvider.setCamera(cameraId, callingPackage,
                        targetSdkVersion);
Loading