Merge "Fix issue #27385109: control activity behavior without triggering..." into nyc-dev
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index eedb82b..df0e5fc 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -1216,6 +1216,7 @@
class MyActivityController extends IActivityController.Stub {
final String mGdbPort;
+ final boolean mMonkey;
static final int STATE_NORMAL = 0;
static final int STATE_CRASHED = 1;
@@ -1242,8 +1243,9 @@
Thread mGdbThread;
boolean mGotGdbPrint;
- MyActivityController(String gdbPort) {
+ MyActivityController(String gdbPort, boolean monkey) {
mGdbPort = gdbPort;
+ mMonkey = monkey;
}
@Override
@@ -1443,7 +1445,7 @@
try {
printMessageForState();
- mAm.setActivityController(this);
+ mAm.setActivityController(this, mMonkey);
mState = STATE_NORMAL;
InputStreamReader converter = new InputStreamReader(System.in);
@@ -1498,7 +1500,7 @@
} catch (IOException e) {
e.printStackTrace();
} finally {
- mAm.setActivityController(null);
+ mAm.setActivityController(null, mMonkey);
}
}
}
@@ -1506,16 +1508,19 @@
private void runMonitor() throws Exception {
String opt;
String gdbPort = null;
+ boolean monkey = false;
while ((opt=nextOption()) != null) {
if (opt.equals("--gdb")) {
gdbPort = nextArgRequired();
+ } else if (opt.equals("-m")) {
+ monkey = true;
} else {
System.err.println("Error: Unknown option: " + opt);
return;
}
}
- MyActivityController controller = new MyActivityController(gdbPort);
+ MyActivityController controller = new MyActivityController(gdbPort, monkey);
controller.run();
}
diff --git a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java
index 1fa9bac..ddeb8e7 100644
--- a/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java
+++ b/cmds/uiautomator/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java
@@ -50,9 +50,9 @@
}
try {
if (isSet) {
- am.setActivityController(new DummyActivityController());
+ am.setActivityController(new DummyActivityController(), true);
} else {
- am.setActivityController(null);
+ am.setActivityController(null, true);
}
} catch (RemoteException e) {
throw new RuntimeException(e);
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index a1f82de..b264e8e 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -1527,7 +1527,8 @@
data.enforceInterface(IActivityManager.descriptor);
IActivityController watcher = IActivityController.Stub.asInterface(
data.readStrongBinder());
- setActivityController(watcher);
+ boolean imAMonkey = data.readInt() != 0;
+ setActivityController(watcher, imAMonkey);
reply.writeNoException();
return true;
}
@@ -4860,12 +4861,14 @@
data.recycle();
reply.recycle();
}
- public void setActivityController(IActivityController watcher) throws RemoteException
+ public void setActivityController(IActivityController watcher, boolean imAMonkey)
+ throws RemoteException
{
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(watcher != null ? watcher.asBinder() : null);
+ data.writeInt(imAMonkey ? 1 : 0);
mRemote.transact(SET_ACTIVITY_CONTROLLER_TRANSACTION, data, reply, 0);
reply.readException();
data.recycle();
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 2cb6151..4bfd049 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -305,7 +305,7 @@
String packageName, boolean waitForDebugger, boolean persistent)
throws RemoteException;
public void setAlwaysFinish(boolean enabled) throws RemoteException;
- public void setActivityController(IActivityController watcher)
+ public void setActivityController(IActivityController watcher, boolean imAMonkey)
throws RemoteException;
public void setLenientBackgroundCheck(boolean enabled) throws RemoteException;
public int getMemoryTrimLevel() throws RemoteException;
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 71a0f49..cf7b537 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1297,6 +1297,7 @@
boolean mSupportsPictureInPicture;
Rect mDefaultPinnedStackBounds;
IActivityController mController = null;
+ boolean mControllerIsAMonkey = false;
String mProfileApp = null;
ProcessRecord mProfileProc = null;
String mProfileFile;
@@ -11423,11 +11424,12 @@
}
@Override
- public void setActivityController(IActivityController controller) {
+ public void setActivityController(IActivityController controller, boolean imAMonkey) {
enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
"setActivityController()");
synchronized (this) {
mController = controller;
+ mControllerIsAMonkey = imAMonkey;
Watchdog.getInstance().setActivityController(controller);
}
}
@@ -11454,7 +11456,7 @@
public boolean isUserAMonkey() {
synchronized (this) {
// If there is a controller also implies the user is a monkey.
- return (mUserIsMonkey || mController != null);
+ return (mUserIsMonkey || (mController != null && mControllerIsAMonkey));
}
}
@@ -14123,10 +14125,13 @@
}
}
if (dumpPackage == null) {
- if (mAlwaysFinishActivities || mLenientBackgroundCheck || mController != null) {
+ if (mAlwaysFinishActivities || mLenientBackgroundCheck) {
pw.println(" mAlwaysFinishActivities=" + mAlwaysFinishActivities
- + " mLenientBackgroundCheck=" + mLenientBackgroundCheck
- + " mController=" + mController);
+ + " mLenientBackgroundCheck=" + mLenientBackgroundCheck);
+ }
+ if (mController != null) {
+ pw.println(" mController=" + mController
+ + " mControllerIsAMonkey=" + mControllerIsAMonkey);
}
if (dumpAll) {
pw.println(" Total persistent processes: " + numPers);
diff --git a/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java
index 3791d02..d7f4a38 100644
--- a/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java
+++ b/tests/permission/src/com/android/framework/permission/tests/ActivityManagerPermissionTests.java
@@ -140,7 +140,7 @@
@SmallTest
public void testSET_ACTIVITY_WATCHER() {
try {
- mAm.setActivityController(null);
+ mAm.setActivityController(null, false);
fail("IActivityManager.setActivityController did not throw SecurityException as"
+ " expected");
} catch (SecurityException e) {