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

Commit 3ca0266c authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "specify what foregroundServiceTypes a client should be granted in VCM" into main

parents 961c49f4 91fdd182
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package com.android.server.telecom.voip;

import static android.app.ForegroundServiceDelegationOptions.DELEGATION_SERVICE_PHONE_CALL;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL;

import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ForegroundServiceDelegationOptions;
@@ -199,8 +205,11 @@ public class VoipCallMonitor extends CallsManagerListenerBase {
            ForegroundServiceDelegationOptions options = new ForegroundServiceDelegationOptions(pid,
                    uid, handle.getComponentName().getPackageName(), null /* clientAppThread */,
                    false /* isSticky */, String.valueOf(handle.hashCode()),
                    0 /* foregroundServiceType */,
                    ForegroundServiceDelegationOptions.DELEGATION_SERVICE_PHONE_CALL);
                    FOREGROUND_SERVICE_TYPE_PHONE_CALL |
                    FOREGROUND_SERVICE_TYPE_MICROPHONE |
                    FOREGROUND_SERVICE_TYPE_CAMERA |
                    FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE /* foregroundServiceTypes */,
                    DELEGATION_SERVICE_PHONE_CALL /* delegationService */);
            ServiceConnection fgsConnection = new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
+31 −0
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package com.android.server.telecom.tests;

import static android.app.ForegroundServiceDelegationOptions.DELEGATION_SERVICE_PHONE_CALL;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
import static android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -86,6 +92,31 @@ public class VoipCallMonitorTest extends TelecomTestCase {
                .thenReturn(true);
    }

    /**
     * This test ensures VoipCallMonitor is passing the correct foregroundServiceTypes when starting
     * foreground service delegation on behalf of a client.
     */
    @SmallTest
    @Test
    public void testVerifyForegroundServiceTypesBeingPassedToActivityManager() {
        Call call = createTestCall("testCall", mHandle1User1);
        ArgumentCaptor<ForegroundServiceDelegationOptions> optionsCaptor =
                ArgumentCaptor.forClass(ForegroundServiceDelegationOptions.class);

        mMonitor.onCallAdded(call);

        verify(mActivityManagerInternal, timeout(TIMEOUT)).startForegroundServiceDelegate(
                 optionsCaptor.capture(), any(ServiceConnection.class));

        assertEquals( FOREGROUND_SERVICE_TYPE_PHONE_CALL |
                FOREGROUND_SERVICE_TYPE_MICROPHONE |
                FOREGROUND_SERVICE_TYPE_CAMERA |
                FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE,
                optionsCaptor.getValue().mForegroundServiceTypes);

        mMonitor.onCallRemoved(call);
    }

    @SmallTest
    @Test
    public void testStartMonitorForOneCall() {