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

Commit a33557d4 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Start/Finish ap-op when telephony uses mic/camera

Bug: 162547999
Test: Started phone call and looked at app-ops
Change-Id: I4b21b45342ddf0f26cf24e81cb69dd978c4b1d6a
parent 7b85cfb7
Loading
Loading
Loading
Loading
+13 −14
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.BroadcastReceiver;
@@ -928,6 +931,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;
@@ -967,6 +971,7 @@ public class InCallController extends CallsManagerListenerBase {
            EmergencyCallHelper emergencyCallHelper, CarModeTracker carModeTracker,
            ClockProxy clockProxy) {
        mContext = context;
        mAppOpsManager = context.getSystemService(AppOpsManager.class);
        mLock = lock;
        mCallsManager = callsManager;
        mSystemStateHelper = systemStateHelper;
@@ -1225,13 +1230,11 @@ public class InCallController extends CallsManagerListenerBase {
    public void onSetCamera(Call call, String cameraId) {
        Log.i(this, "onSetCamera callId=%s, cameraId=%s", call.getId(), cameraId);
        if (cameraId != null) {
            Log.i(this, "onSetCamera: %s is using the camera.",
                    mCurrentUserInterfacePackageName);
            // TODO: Call AppOpsManager#startOp(camera, mCurrentMicrophonePackage)
            mAppOpsManager.startOp(AppOpsManager.OP_PHONE_CALL_CAMERA, myUid(),
                    mContext.getOpPackageName(), false, null, null);
        } else {
            Log.i(this, "onSetCamera: %s is no longer using the camera.",
                    mCurrentUserInterfacePackageName);
            // TODO: Call AppOpsManager#endOp(camera, mCurrentMicrophonePackage)
            mAppOpsManager.finishOp(AppOpsManager.OP_PHONE_CALL_CAMERA, myUid(),
                    mContext.getOpPackageName(), null);
        }
    }

@@ -1952,7 +1955,6 @@ public class InCallController extends CallsManagerListenerBase {
        if (!Objects.equals(mCurrentUserInterfacePackageName, packageName)) {
            Log.i(this, "trackCallingUserInterfaceStarted: %s is now calling UX.", packageName);
            mCurrentUserInterfacePackageName = packageName;
            // TODO: Call AppOpsManager#startOp(microphone, mCurrentMicrophonePackage)
        }
        maybeTrackMicrophoneUse(isMuted());
    }
@@ -1966,7 +1968,6 @@ public class InCallController extends CallsManagerListenerBase {
        mCurrentUserInterfacePackageName = null;
        String packageName = info.getComponentName().getPackageName();
        Log.i(this, "trackCallingUserInterfaceStopped: %s is no longer calling UX", packageName);
        // TODO: Call AppOpsManager#endOp(microphone, mCurrentMicrophonePackage)
    }

    /**
@@ -1979,13 +1980,11 @@ public class InCallController extends CallsManagerListenerBase {
        mIsCallUsingMicrophone = isTrackingManagedCall() && !isMuted;
        if (wasTrackingManagedCall != mIsCallUsingMicrophone) {
            if (mIsCallUsingMicrophone) {
                Log.i(this, "maybeTrackMicrophoneUse: %s is using the microphone",
                        mCurrentUserInterfacePackageName);
                // TODO: Call AppOpsManager#startOp(microphone, mCurrentMicrophonePackage)
                mAppOpsManager.startOp(AppOpsManager.OP_PHONE_CALL_MICROPHONE, myUid(),
                        mContext.getOpPackageName(), false, null, null);
            } else {
                Log.i(this, "maybeTrackMicrophoneUse: %s stopped using the microphone",
                        mCurrentUserInterfacePackageName);
                // TODO: Call AppOpsManager#endOp(microphone, mCurrentMicrophonePackage)
                mAppOpsManager.finishOp(AppOpsManager.OP_PHONE_CALL_MICROPHONE, myUid(),
                        mContext.getOpPackageName(), null);
            }
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.Manifest;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.UiModeManager;
@@ -62,7 +63,6 @@ import android.os.Looper;
import android.os.UserHandle;
import android.telecom.CallAudioState;
import android.telecom.InCallService;
import android.telecom.Log;
import android.telecom.ParcelableCall;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -114,6 +114,7 @@ public class InCallControllerTests extends TelecomTestCase {
    @Mock PackageManager mMockPackageManager;
    @Mock Call mMockCall;
    @Mock Resources mMockResources;
    @Mock AppOpsManager mMockAppOpsManager;
    @Mock MockContext mMockContext;
    @Mock Timeouts.Adapter mTimeoutsAdapter;
    @Mock DefaultDialerCache mDefaultDialerCache;
@@ -159,6 +160,7 @@ public class InCallControllerTests extends TelecomTestCase {
        MockitoAnnotations.initMocks(this);
        when(mMockCall.getAnalytics()).thenReturn(new Analytics.CallInfo());
        doReturn(mMockResources).when(mMockContext).getResources();
        doReturn(mMockAppOpsManager).when(mMockContext).getSystemService(AppOpsManager.class);
        doReturn(SYS_PKG).when(mMockResources).getString(
                com.android.internal.R.string.config_defaultDialer);
        doReturn(SYS_CLASS).when(mMockResources).getString(R.string.incall_default_class);
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -348,6 +349,8 @@ public class TelecomSystemTest extends TelecomTestCase {
        doReturn(mSpyContext).when(mSpyContext).getApplicationContext();
        doNothing().when(mSpyContext).sendBroadcastAsUser(any(), any(), any());

        doReturn(mock(AppOpsManager.class)).when(mSpyContext).getSystemService(AppOpsManager.class);

        mHandlerThread = new HandlerThread("TelecomHandlerThread");
        mHandlerThread.start();