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

Commit 85a0ff26 authored by Steven Moreland's avatar Steven Moreland
Browse files

BinderProxyTest: fix failures

PowerManager was changed to use caching, and so this
test could not use it to reliably make binder calls.

I've refactored the test to use an API in ActivityManager
instead, which could not be cached, and am following up
separately to add presubmit coverage.

Bug: 348072409
Test: atest android.os.BinderProxyTest
Change-Id: I4a68e0e797c2489704ece144461461ed48ef3bae
parent 9fe82166
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.fail;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -42,7 +43,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;


@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
@IgnoreUnderRavenwood(blockedBy = PowerManager.class)
@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
public class BinderProxyTest {
public class BinderProxyTest {
    private static class CountingListener implements Binder.ProxyTransactListener {
    private static class CountingListener implements Binder.ProxyTransactListener {
        int mStartedCount;
        int mStartedCount;
@@ -62,7 +63,7 @@ public class BinderProxyTest {
    public final RavenwoodRule mRavenwood = new RavenwoodRule();
    public final RavenwoodRule mRavenwood = new RavenwoodRule();


    private Context mContext;
    private Context mContext;
    private PowerManager mPowerManager;
    private ActivityManager mActivityManager;


    /**
    /**
     * Setup any common data for the upcoming tests.
     * Setup any common data for the upcoming tests.
@@ -70,7 +71,7 @@ public class BinderProxyTest {
    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    }
    }


    @Test
    @Test
@@ -80,7 +81,7 @@ public class BinderProxyTest {
        Binder.setProxyTransactListener(listener);
        Binder.setProxyTransactListener(listener);
        Binder.setProxyTransactListener(null);
        Binder.setProxyTransactListener(null);


        mPowerManager.isInteractive();
        mActivityManager.isUserRunning(7); // something which does a binder call


        assertEquals(0, listener.mStartedCount);
        assertEquals(0, listener.mStartedCount);
        assertEquals(0, listener.mEndedCount);
        assertEquals(0, listener.mEndedCount);
@@ -92,7 +93,7 @@ public class BinderProxyTest {
        CountingListener listener = new CountingListener();
        CountingListener listener = new CountingListener();
        Binder.setProxyTransactListener(listener);
        Binder.setProxyTransactListener(listener);


        mPowerManager.isInteractive();
        mActivityManager.isUserRunning(27); // something which does a binder call


        assertEquals(1, listener.mStartedCount);
        assertEquals(1, listener.mStartedCount);
        assertEquals(1, listener.mEndedCount);
        assertEquals(1, listener.mEndedCount);
@@ -112,7 +113,7 @@ public class BinderProxyTest {
        });
        });


        // Check it does not throw..
        // Check it does not throw..
        mPowerManager.isInteractive();
        mActivityManager.isUserRunning(47); // something which does a binder call
    }
    }


    private IBinder mRemoteBinder = null;
    private IBinder mRemoteBinder = null;