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

Commit 26257a09 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Allow for setting test type as a monkey." into jb-mr2-dev

parents 72ab9b80 8f6f1f43
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4195,6 +4195,7 @@ package android.app {
    method public final boolean performGlobalAction(int);
    method public void setOnAccessibilityEventListener(android.app.UiAutomation.OnAccessibilityEventListener);
    method public boolean setRotation(int);
    method public void setRunAsMonkey(boolean);
    method public final void setServiceInfo(android.accessibilityservice.AccessibilityServiceInfo);
    method public android.graphics.Bitmap takeScreenshot();
    method public void waitForIdle(long, long) throws java.util.concurrent.TimeoutException;
+20 −1
Original line number Diff line number Diff line
@@ -1413,6 +1413,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }
        
        case SET_USER_IS_MONKEY_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            final boolean monkey = (data.readInt() == 1);
            setUserIsMonkey(monkey);
            reply.writeNoException();
            return true;
        }

        case FINISH_HEAVY_WEIGHT_APP_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            finishHeavyWeightApp();
@@ -3634,6 +3642,17 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    public void setUserIsMonkey(boolean monkey) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeInt(monkey ? 1 : 0);
        mRemote.transact(SET_USER_IS_MONKEY_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    public void finishHeavyWeightApp() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+4 −1
Original line number Diff line number Diff line
@@ -286,6 +286,8 @@ public interface IActivityManager extends IInterface {
    
    public boolean isUserAMonkey() throws RemoteException;

    public void setUserIsMonkey(boolean monkey) throws RemoteException;

    public void finishHeavyWeightApp() throws RemoteException;

    public void setImmersive(IBinder token, boolean immersive) throws RemoteException;
@@ -635,4 +637,5 @@ public interface IActivityManager extends IInterface {
    int REPORT_TOP_ACTIVITY_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+162;
    int GET_LAUNCHED_FROM_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+163;
    int KILL_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+164;
    int SET_USER_IS_MONKEY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+165;
}
+4 −4
Original line number Diff line number Diff line
@@ -189,6 +189,10 @@ public class Instrumentation {
        if (mPerfMetrics != null) {
            results.putAll(mPerfMetrics);
        }
        if (mUiAutomation != null) {
            mUiAutomation.disconnect();
            mUiAutomation = null;
        }
        mThread.finishInstrumentation(resultCode, results);
    }
    
@@ -1695,10 +1699,6 @@ public class Instrumentation {
                startPerformanceSnapshot();
            }
            onStart();
            if (mUiAutomation != null) {
                mUiAutomation.disconnect();
                mUiAutomation = null;
            }
        }
    }

+19 −0
Original line number Diff line number Diff line
@@ -619,6 +619,25 @@ public final class UiAutomation {
        return screenShot;
    }

    /**
     * Sets whether this UiAutomation to run in a "monkey" mode. Applications can query whether
     * they are executed in a "monkey" mode, i.e. run by a test framework, and avoid doing
     * potentially undesirable actions such as calling 911 or posting on public forums etc.
     *
     * @param enable whether to run in a "monkey" mode or not. Default is not.
     * @see {@link ActivityManager#isUserAMonkey()}
     */
    public void setRunAsMonkey(boolean enable) {
        synchronized (mLock) {
            throwIfNotConnectedLocked();
        }
        try {
            ActivityManagerNative.getDefault().setUserIsMonkey(enable);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error while setting run as monkey!", re);
        }
    }

    private static float getDegreesForRotation(int value) {
        switch (value) {
            case Surface.ROTATION_90: {
Loading