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

Commit c9477608 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Remove unnecessary local service after test

Bug: 171762932
Test: atest FrameworksServicesTests:com.android.server.am
Change-Id: Idf5d954d89594f7b7a45650ab9173ae16e437dc9
parent 4b94029f
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import com.android.server.appop.AppOpsService;
import com.android.server.wm.ActivityTaskManagerService;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -128,11 +129,14 @@ public class ActivityManagerServiceTest {
        sPackageManagerInternal = mock(PackageManagerInternal.class);
        doReturn(new ComponentName("", "")).when(sPackageManagerInternal)
                .getSystemUiServiceComponent();
        // Remove stale instance of PackageManagerInternal if there is any
        LocalServices.removeServiceForTest(PackageManagerInternal.class);
        LocalServices.addService(PackageManagerInternal.class, sPackageManagerInternal);
    }

    @AfterClass
    public static void tearDownOnce() {
        LocalServices.removeServiceForTest(PackageManagerInternal.class);
    }

    @Rule public ServiceThreadRule mServiceThreadRule = new ServiceThreadRule();

    private Context mContext = getInstrumentation().getTargetContext();
+7 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.pm.PackageManagerInternal;
import com.android.server.LocalServices;
import com.android.server.wm.ActivityTaskManagerService;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -63,8 +64,6 @@ public class OomAdjusterTests {
        sPackageManagerInternal = mock(PackageManagerInternal.class);
        doReturn(new ComponentName("", "")).when(sPackageManagerInternal)
                .getSystemUiServiceComponent();
        // Remove stale instance of PackageManagerInternal if there is any
        LocalServices.removeServiceForTest(PackageManagerInternal.class);
        LocalServices.addService(PackageManagerInternal.class, sPackageManagerInternal);

        // We need to run with dexmaker share class loader to make use of
@@ -78,13 +77,18 @@ public class OomAdjusterTests {
            sService.mConstants = new ActivityManagerConstants(sContext, sService,
                    sContext.getMainThreadHandler());
            sService.mOomAdjuster = new OomAdjuster(sService, sService.mProcessList, null);
            LocalServices.removeServiceForTest(UsageStatsManagerInternal.class);
            LocalServices.addService(UsageStatsManagerInternal.class,
                    mock(UsageStatsManagerInternal.class));
            sService.mUsageStatsService = LocalServices.getService(UsageStatsManagerInternal.class);
        });
    }

    @AfterClass
    public static void tearDownOnce() {
        LocalServices.removeServiceForTest(PackageManagerInternal.class);
        LocalServices.removeServiceForTest(UsageStatsManagerInternal.class);
    }

    @Before
    public void setUpProcess() {
        // Need to run with dexmaker share class loader to mock package private class.