Merge "Allow for setting test type as a monkey." into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
26257a09a5
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -3633,7 +3641,18 @@ class ActivityManagerProxy implements IActivityManager
|
||||
reply.recycle();
|
||||
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();
|
||||
|
||||
@@ -285,7 +285,9 @@ public interface IActivityManager extends IInterface {
|
||||
int enterAnim, int exitAnim) throws RemoteException;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -936,6 +936,12 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
CompatModeDialog mCompatModeDialog;
|
||||
long mLastMemUsageReportTime = 0;
|
||||
|
||||
/**
|
||||
* Flag whether the current user is a "monkey", i.e. whether
|
||||
* the UI is driven by a UI automation tool.
|
||||
*/
|
||||
private boolean mUserIsMonkey;
|
||||
|
||||
final Handler mHandler = new Handler() {
|
||||
//public Handler() {
|
||||
// if (localLOGV) Slog.v(TAG, "Handler started!");
|
||||
@@ -7434,11 +7440,27 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUserAMonkey() {
|
||||
// For now the fact that there is a controller implies
|
||||
// we have a monkey.
|
||||
public void setUserIsMonkey(boolean userIsMonkey) {
|
||||
synchronized (this) {
|
||||
return mController != null;
|
||||
synchronized (mPidsSelfLocked) {
|
||||
final int callingPid = Binder.getCallingPid();
|
||||
ProcessRecord precessRecord = mPidsSelfLocked.get(callingPid);
|
||||
if (precessRecord == null) {
|
||||
throw new SecurityException("Unknown process: " + callingPid);
|
||||
}
|
||||
if (precessRecord.instrumentationUiAutomationConnection == null) {
|
||||
throw new SecurityException("Only an instrumentation process "
|
||||
+ "with a UiAutomation can call setUserIsMonkey");
|
||||
}
|
||||
}
|
||||
mUserIsMonkey = userIsMonkey;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUserAMonkey() {
|
||||
synchronized (this) {
|
||||
// If there is a controller also implies the user is a monkey.
|
||||
return (mUserIsMonkey || mController != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12435,6 +12457,9 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
} catch (RemoteException re) {
|
||||
/* ignore */
|
||||
}
|
||||
// Only a UiAutomation can set this flag and now that
|
||||
// it is finished we make sure it is reset to its default.
|
||||
mUserIsMonkey = false;
|
||||
}
|
||||
app.instrumentationWatcher = null;
|
||||
app.instrumentationUiAutomationConnection = null;
|
||||
|
||||
Reference in New Issue
Block a user