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

Commit 234cf79b authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Enable BoundServiceSessionTests on Ravenwood

This newer class has limited dependencies, so this is a good starting
point to add a Ravenwood supported test module for
ProcessStateController.

Removing dependencies on extended-mockito and moving out of
mockingservicestests to simplify Ravenwood build config.

Flag: EXEMPT tests only

Test: atest FrameworksServicesTests:BoundServiceSessionTests
Test: atest FrameworksServicesTestsRavenwood_ProcessStateController

Bug: 424329084
Change-Id: Ia6a630a10ce1d4dda54aa320c2721e5b93733010
parent c4a91c99
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -673,6 +673,8 @@ com.android.server.ServiceThread
com.android.server.SystemService
com.android.server.SystemServiceManager

com.android.server.am.BoundServiceSession
com.android.server.am.ConnectionRecord
com.android.server.utils.TimingsTraceAndSlog

com.google.android.collect.Lists
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.am;
import android.app.IBinderSession;
import android.os.IBinder;
import android.os.Trace;
import android.ravenwood.annotation.RavenwoodKeepWholeClass;
import android.util.ArrayMap;
import android.util.IndentingPrintWriter;
import android.util.Slog;
@@ -35,6 +36,7 @@ import java.util.function.BiConsumer;
 * is used to facilitate important binder calls to a bound remote service hosted by a process that
 * is eligible to get frozen by {@link ProcessStateController}.
 */
@RavenwoodKeepWholeClass
public class BoundServiceSession implements IBinderSession {
    private static final String TAG = BoundServiceSession.class.getSimpleName();
    private static final int MAGIC_ID = 0xFBD_5E55;
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.os.SystemClock;
import android.ravenwood.annotation.RavenwoodKeepWholeClass;
import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -38,6 +39,7 @@ import java.io.PrintWriter;
/**
 * Description of a single binding to a service.
 */
@RavenwoodKeepWholeClass
final class ConnectionRecord implements OomAdjusterImpl.Connection{
    BoundServiceSession mBoundServiceSession;  // The associated bound service session if created.
    final AppBindRecord binding;    // The application/service binding.
+12 −0
Original line number Diff line number Diff line
@@ -205,6 +205,18 @@ android_ravenwood_test {
    ],
}

android_ravenwood_test {
    name: "FrameworksServicesTestsRavenwood_ProcessStateController",
    defaults: ["FrameworksServicesTestsRavenwood-defaults"],
    team: "trendy_team_framework_bpm",
    static_libs: [
        "services.core.ravenwood",
    ],
    srcs: [
        "src/com/android/server/am/BoundServiceSessionTests.java",
    ],
}

java_library {
    name: "servicestests-core-utils",
    srcs: [
+10 −8
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.am;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
@@ -25,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import android.platform.test.annotations.Presubmit;
@@ -38,17 +37,20 @@ import java.util.function.BiConsumer;
 * Test class for {@link BoundServiceSession}.
 *
 * Build/Install/Run:
 *  atest FrameworksMockingServicesTests:BoundServiceSessionTests
 *  atest FrameworksServicesTests:BoundServiceSessionTests
 * Or
 *  atest FrameworksServicesTestsRavenwood_ProcessStateController
 */
@Presubmit
public class BoundServiceSessionTests {
    private static final String TEST_DEBUG_NAME = "test_bound_service_session";

    private final ConnectionRecord mMockConnectionRecord = mock(ConnectionRecord.class);
    private final ConnectionRecord mEmptyConnectionRecord = new ConnectionRecord(null, null, null,
            0, 0, null, 0, null, null, null);
    private final BiConsumer<ConnectionRecord, Boolean> mMockConsumer = mock(BiConsumer.class);

    private BoundServiceSession getNewBoundServiceSessionForTest() {
        return new BoundServiceSession(mMockConsumer, new WeakReference<>(mMockConnectionRecord),
        return new BoundServiceSession(mMockConsumer, new WeakReference<>(mEmptyConnectionRecord),
                TEST_DEBUG_NAME);
    }

@@ -137,7 +139,7 @@ public class BoundServiceSessionTests {

        session.binderTransactionStarting("test");
        assertEquals(1, session.mTotal);
        verify(mMockConsumer).accept(mMockConnectionRecord, true);
        verify(mMockConsumer).accept(mEmptyConnectionRecord, true);

        session.binderTransactionStarting("test");
        session.binderTransactionStarting("test");
@@ -166,7 +168,7 @@ public class BoundServiceSessionTests {

        session.binderTransactionCompleted(token);
        assertEquals(0, session.mTotal);
        verify(mMockConsumer).accept(mMockConnectionRecord, false);
        verify(mMockConsumer).accept(mEmptyConnectionRecord, false);
    }

    @Test
@@ -182,7 +184,7 @@ public class BoundServiceSessionTests {

        session.binderTransactionCompleted(-1);
        assertEquals(0, session.mTotal);
        verify(mMockConsumer).accept(mMockConnectionRecord, false);
        verify(mMockConsumer).accept(mEmptyConnectionRecord, false);
    }

    @Test