This also includes some changes to the window manager permission checks. Almost all of these
are to make it most testable (through an exception on a permission failure), though there is
one permission check that needed to be added: updateOrientationFromAppTokens().
*/
static final int DIM_DURATION_MULTIPLIER = 6;
+ static final int INJECT_FAILED = 0;
+ static final int INJECT_SUCCEEDED = 1;
+ static final int INJECT_NO_PERMISSION = -1;
+
static final int UPDATE_FOCUS_NORMAL = 0;
static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
// Update Orientation after adding a window, only if the window needs to be
// displayed right away
if (win.isVisibleOrAdding()) {
- if (updateOrientationFromAppTokens(null, null) != null) {
+ if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
sendNewConfiguration();
}
}
public void addWindowToken(IBinder token, int type) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"addWindowToken()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void removeWindowToken(IBinder token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"removeWindowToken()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
final long origId = Binder.clearCallingIdentity();
int groupId, int requestedOrientation, boolean fullscreen) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"addAppToken()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void setAppGroupId(IBinder token, int groupId) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppStartingIcon()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public Configuration updateOrientationFromAppTokens(
Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
+ if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+ "updateOrientationFromAppTokens()")) {
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+ }
+
Configuration config;
long ident = Binder.clearCallingIdentity();
+ config = updateOrientationFromAppTokensUnchecked(currentConfig,
+ freezeThisOneIfNeeded);
+ Binder.restoreCallingIdentity(ident);
+ return config;
+ }
+
+ Configuration updateOrientationFromAppTokensUnchecked(
+ Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
+ Configuration config;
synchronized(mWindowMap) {
config = updateOrientationFromAppTokensLocked(currentConfig, freezeThisOneIfNeeded);
}
mLayoutNeeded = true;
performLayoutAndPlaceSurfacesLocked();
}
- Binder.restoreCallingIdentity(ident);
return config;
}
public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppOrientation()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void setFocusedApp(IBinder token, boolean moveFocusNow) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setFocusedApp()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void prepareAppTransition(int transit) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"prepareAppTransition()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void executeAppTransition() {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"executeAppTransition()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
IBinder transferFrom, boolean createIfNeeded) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppStartingIcon()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void setAppWillBeHidden(IBinder token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppWillBeHidden()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
AppWindowToken wtoken;
public void setAppVisibility(IBinder token, boolean visible) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppVisibility()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
AppWindowToken wtoken;
public void startAppFreezingScreen(IBinder token, int configChanges) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppFreezingScreen()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void stopAppFreezingScreen(IBinder token, boolean force) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"setAppFreezingScreen()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void removeAppToken(IBinder token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"removeAppToken()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
AppWindowToken wtoken = null;
public void moveAppToken(int index, IBinder token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"moveAppToken()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized(mWindowMap) {
public void moveAppTokensToTop(List<IBinder> tokens) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"moveAppTokensToTop()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
final long origId = Binder.clearCallingIdentity();
public void moveAppTokensToBottom(List<IBinder> tokens) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"moveAppTokensToBottom()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
final long origId = Binder.clearCallingIdentity();
public void setAnimationScale(int which, float scale) {
if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
"setAnimationScale()")) {
- return;
+ throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
}
if (scale < 0) scale = 0;
public void setAnimationScales(float[] scales) {
if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
"setAnimationScale()")) {
- return;
+ throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
}
if (scales != null) {
public int getSwitchState(int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getSwitchState()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getSwitchState(sw);
}
public int getSwitchStateForDevice(int devid, int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getSwitchStateForDevice()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getSwitchState(devid, sw);
}
public int getScancodeState(int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getScancodeState()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getScancodeState(sw);
}
public int getScancodeStateForDevice(int devid, int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getScancodeStateForDevice()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getScancodeState(devid, sw);
}
public int getKeycodeState(int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getKeycodeState()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getKeycodeState(sw);
}
public int getKeycodeStateForDevice(int devid, int sw) {
if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE,
"getKeycodeStateForDevice()")) {
- return -1;
+ throw new SecurityException("Requires READ_INPUT_STATE permission");
}
return KeyInputQueue.getKeycodeState(devid, sw);
}
boolean alwaysSendConfiguration, int animFlags) {
if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
"setRotation()")) {
- return;
+ throw new SecurityException("Requires SET_ORIENTATION permission");
}
setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags);
/**
* @return Returns true if event was dispatched, false if it was dropped for any reason
*/
- private boolean dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
+ private int dispatchPointer(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
if (DEBUG_INPUT || WindowManagerPolicy.WATCH_POINTER) Log.v(TAG,
"dispatchPointer " + ev);
mQueue.recycleEvent(qev);
}
ev.recycle();
- return false;
+ return INJECT_FAILED;
}
if (targetObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
if (qev != null) {
mQueue.recycleEvent(qev);
}
ev.recycle();
- return true;
+ return INJECT_SUCCEEDED;
}
WindowState target = (WindowState)targetObj;
mQueue.recycleEvent(qev);
}
ev.recycle();
- return false;
+ return INJECT_NO_PERMISSION;
}
}
mQueue.recycleEvent(qev);
}
ev.recycle();
- return false;
+ return INJECT_FAILED;
}
} //end if target
Log.v(TAG, "Delivering pointer " + qev + " to " + target);
}
target.mClient.dispatchPointer(ev, eventTime);
- return true;
+ return INJECT_SUCCEEDED;
} catch (android.os.RemoteException e) {
Log.i(TAG, "WINDOW DIED during motion dispatch: " + target);
mKeyWaiter.mMotionTarget = null;
// removed.
}
}
- return false;
+ return INJECT_FAILED;
}
/**
* @return Returns true if event was dispatched, false if it was dropped for any reason
*/
- private boolean dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
+ private int dispatchTrackball(QueuedEvent qev, MotionEvent ev, int pid, int uid) {
if (DEBUG_INPUT) Log.v(
TAG, "dispatchTrackball [" + ev.getAction() +"] <" + ev.getX() + ", " + ev.getY() + ">");
mQueue.recycleEvent(qev);
}
ev.recycle();
- return false;
+ return INJECT_FAILED;
}
if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
if (qev != null) {
mQueue.recycleEvent(qev);
}
ev.recycle();
- return true;
+ return INJECT_SUCCEEDED;
}
WindowState focus = (WindowState)focusObj;
mQueue.recycleEvent(qev);
}
ev.recycle();
- return false;
+ return INJECT_NO_PERMISSION;
}
}
try {
focus.mClient.dispatchTrackball(ev, eventTime);
- return true;
+ return INJECT_SUCCEEDED;
} catch (android.os.RemoteException e) {
Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
try {
}
}
- return false;
+ return INJECT_FAILED;
}
/**
* @return Returns true if event was dispatched, false if it was dropped for any reason
*/
- private boolean dispatchKey(KeyEvent event, int pid, int uid) {
+ private int dispatchKey(KeyEvent event, int pid, int uid) {
if (DEBUG_INPUT) Log.v(TAG, "Dispatch key: " + event);
Object focusObj = mKeyWaiter.waitForNextEventTarget(event, null,
null, false, false);
if (focusObj == null) {
Log.w(TAG, "No focus window, dropping: " + event);
- return false;
+ return INJECT_FAILED;
}
if (focusObj == mKeyWaiter.CONSUMED_EVENT_TOKEN) {
- return true;
+ return INJECT_SUCCEEDED;
}
WindowState focus = (WindowState)focusObj;
Log.w(TAG, "Permission denied: injecting key event from pid "
+ pid + " uid " + uid + " to window " + focus
+ " owned by uid " + focus.mSession.mUid);
- return false;
+ return INJECT_NO_PERMISSION;
}
}
+ " to " + focus);
}
focus.mClient.dispatchKey(event);
- return true;
+ return INJECT_SUCCEEDED;
} catch (android.os.RemoteException e) {
Log.i(TAG, "WINDOW DIED during key dispatch: " + focus);
try {
}
}
- return false;
+ return INJECT_FAILED;
}
public void pauseKeyDispatching(IBinder _token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"pauseKeyDispatching()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized (mWindowMap) {
public void resumeKeyDispatching(IBinder _token) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"resumeKeyDispatching()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized (mWindowMap) {
public void setEventDispatching(boolean enabled) {
if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
"resumeKeyDispatching()")) {
- return;
+ throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
}
synchronized (mWindowMap) {
KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM);
- boolean result = dispatchKey(newEvent, Binder.getCallingPid(), Binder.getCallingUid());
+ int result = dispatchKey(newEvent, Binder.getCallingPid(), Binder.getCallingUid());
if (sync) {
mKeyWaiter.waitForNextEventTarget(null, null, null, false, true);
}
- return result;
+ switch (result) {
+ case INJECT_NO_PERMISSION:
+ throw new SecurityException(
+ "Injecting to another application requires INJECT_EVENT permission");
+ case INJECT_SUCCEEDED:
+ return true;
+ }
+ return false;
}
/**
* @return Returns true if event was dispatched, false if it was dropped for any reason
*/
public boolean injectPointerEvent(MotionEvent ev, boolean sync) {
- boolean result = dispatchPointer(null, ev, Binder.getCallingPid(), Binder.getCallingUid());
+ int result = dispatchPointer(null, ev, Binder.getCallingPid(), Binder.getCallingUid());
if (sync) {
mKeyWaiter.waitForNextEventTarget(null, null, null, false, true);
}
- return result;
+ switch (result) {
+ case INJECT_NO_PERMISSION:
+ throw new SecurityException(
+ "Injecting to another application requires INJECT_EVENT permission");
+ case INJECT_SUCCEEDED:
+ return true;
+ }
+ return false;
}
/**
* @return Returns true if event was dispatched, false if it was dropped for any reason
*/
public boolean injectTrackballEvent(MotionEvent ev, boolean sync) {
- boolean result = dispatchTrackball(null, ev, Binder.getCallingPid(), Binder.getCallingUid());
+ int result = dispatchTrackball(null, ev, Binder.getCallingPid(), Binder.getCallingUid());
if (sync) {
mKeyWaiter.waitForNextEventTarget(null, null, null, false, true);
}
- return result;
+ switch (result) {
+ case INJECT_NO_PERMISSION:
+ throw new SecurityException(
+ "Injecting to another application requires INJECT_EVENT permission");
+ case INJECT_SUCCEEDED:
+ return true;
+ }
+ return false;
}
private WindowState getFocusedWindow() {
}
case COMPUTE_AND_SEND_NEW_CONFIGURATION: {
- if (updateOrientationFromAppTokens(null, null) != null) {
+ if (updateOrientationFromAppTokensUnchecked(null, null) != null) {
sendNewConfiguration();
}
break;
--- /dev/null
+package com.android.framework.permission.tests;
+
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
+import android.content.res.Configuration;
+import android.os.RemoteException;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO: Remove this. This is only a placeholder, need to implement this.
+ */
+public class ActivityManagerPermissionTests extends TestCase {
+ IActivityManager mAm;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mAm = ActivityManagerNative.getDefault();
+ }
+
+ @SmallTest
+ public void testREORDER_TASKS() {
+ try {
+ mAm.moveTaskToFront(-1);
+ fail("IActivityManager.moveTaskToFront did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mAm.moveTaskToBack(-1);
+ fail("IActivityManager.moveTaskToBack did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mAm.moveTaskBackwards(-1);
+ fail("IActivityManager.moveTaskToFront did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testCHANGE_CONFIGURATION() {
+ try {
+ mAm.updateConfiguration(new Configuration());
+ fail("IActivityManager.updateConfiguration did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSET_DEBUG_APP() {
+ try {
+ mAm.setDebugApp(null, false, false);
+ fail("IActivityManager.setDebugApp did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSET_PROCESS_LIMIT() {
+ try {
+ mAm.setProcessLimit(10);
+ fail("IActivityManager.setProcessLimit did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testALWAYS_FINISH() {
+ try {
+ mAm.setAlwaysFinish(false);
+ fail("IActivityManager.setAlwaysFinish did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSIGNAL_PERSISTENT_PROCESSES() {
+ try {
+ mAm.signalPersistentProcesses(-1);
+ fail("IActivityManager.signalPersistentProcesses did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testFORCE_BACK() {
+ try {
+ mAm.unhandledBack();
+ fail("IActivityManager.unhandledBack did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSET_ACTIVITY_WATCHER() {
+ try {
+ mAm.setActivityWatcher(null);
+ fail("IActivityManager.setActivityWatcher did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSHUTDOWN() {
+ try {
+ mAm.shutdown(0);
+ fail("IActivityManager.shutdown did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSTOP_APP_SWITCHES() {
+ try {
+ mAm.stopAppSwitches();
+ fail("IActivityManager.stopAppSwitches did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mAm.resumeAppSwitches();
+ fail("IActivityManager.resumeAppSwitches did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+}
--- /dev/null
+package com.android.framework.permission.tests;
+
+import com.android.internal.os.BinderInternal;
+
+import android.os.Binder;
+import android.os.IPermissionController;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.ServiceManagerNative;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO: Remove this. This is only a placeholder, need to implement this.
+ */
+public class ServiceManagerPermissionTests extends TestCase {
+ @SmallTest
+ public void testAddService() {
+ try {
+ // The security in the service manager is that you can't replace
+ // a service that is already published.
+ Binder binder = new Binder();
+ ServiceManager.addService("activity", binder);
+ fail("ServiceManager.addService did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ @SmallTest
+ public void testSetPermissionController() {
+ try {
+ IPermissionController pc = new IPermissionController.Stub() {
+ public boolean checkPermission(java.lang.String permission, int pid, int uid) {
+ return true;
+ }
+ };
+ ServiceManagerNative.asInterface(BinderInternal.getContextObject())
+ .setPermissionController(pc);
+ fail("IServiceManager.setPermissionController did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+}
--- /dev/null
+package com.android.framework.permission.tests;
+
+import android.content.res.Configuration;
+import android.os.Binder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.IWindowManager;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO: Remove this. This is only a placeholder, need to implement this.
+ */
+public class WindowManagerPermissionTests extends TestCase {
+ IWindowManager mWm;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mWm = IWindowManager.Stub.asInterface(
+ ServiceManager.getService("window"));
+ }
+
+ @SmallTest
+ public void testMANAGE_APP_TOKENS() {
+ try {
+ mWm.pauseKeyDispatching(null);
+ fail("IWindowManager.pauseKeyDispatching did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.resumeKeyDispatching(null);
+ fail("IWindowManager.resumeKeyDispatching did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setEventDispatching(true);
+ fail("IWindowManager.setEventDispatching did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.addWindowToken(null, 0);
+ fail("IWindowManager.addWindowToken did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.removeWindowToken(null);
+ fail("IWindowManager.removeWindowToken did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.addAppToken(0, null, 0, 0, false);
+ fail("IWindowManager.addAppToken did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAppGroupId(null, 0);
+ fail("IWindowManager.setAppGroupId did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.updateOrientationFromAppTokens(new Configuration(), null);
+ fail("IWindowManager.updateOrientationFromAppTokens did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAppOrientation(null, 0);
+ mWm.addWindowToken(null, 0);
+ fail("IWindowManager.setAppOrientation did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setFocusedApp(null, false);
+ fail("IWindowManager.setFocusedApp did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.prepareAppTransition(0);
+ fail("IWindowManager.prepareAppTransition did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.executeAppTransition();
+ fail("IWindowManager.executeAppTransition did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAppStartingWindow(null, "foo", 0, null, 0, 0, null, false);
+ fail("IWindowManager.setAppStartingWindow did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAppWillBeHidden(null);
+ fail("IWindowManager.setAppWillBeHidden did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAppVisibility(null, false);
+ fail("IWindowManager.setAppVisibility did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.startAppFreezingScreen(null, 0);
+ fail("IWindowManager.startAppFreezingScreen did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.stopAppFreezingScreen(null, false);
+ fail("IWindowManager.stopAppFreezingScreen did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.removeAppToken(null);
+ fail("IWindowManager.removeAppToken did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.moveAppToken(0, null);
+ fail("IWindowManager.moveAppToken did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.moveAppTokensToTop(null);
+ fail("IWindowManager.moveAppTokensToTop did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.moveAppTokensToBottom(null);
+ fail("IWindowManager.moveAppTokensToBottom did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testINJECT_EVENTS() {
+ try {
+ mWm.injectKeyEvent(new KeyEvent(0, 0), false);
+ fail("IWindowManager.injectKeyEvent did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.injectPointerEvent(MotionEvent.obtain(0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0), false);
+ fail("IWindowManager.injectPointerEvent did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.injectTrackballEvent(MotionEvent.obtain(0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0), false);
+ fail("IWindowManager.injectTrackballEvent did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testDISABLE_KEYGUARD() {
+ Binder token = new Binder();
+ try {
+ mWm.disableKeyguard(token, "foo");
+ fail("IWindowManager.disableKeyguard did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.reenableKeyguard(token);
+ fail("IWindowManager.reenableKeyguard did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.exitKeyguardSecurely(null);
+ fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSET_ANIMATION_SCALE() {
+ try {
+ mWm.setAnimationScale(0, 1);
+ fail("IWindowManager.setAnimationScale did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.setAnimationScales(new float[1]);
+ fail("IWindowManager.setAnimationScales did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testREAD_INPUT_STATE() {
+ try {
+ mWm.getSwitchState(0);
+ fail("IWindowManager.getSwitchState did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.getSwitchStateForDevice(0, 0);
+ fail("IWindowManager.getSwitchStateForDevice did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.getScancodeState(0);
+ fail("IWindowManager.getScancodeState did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.getScancodeStateForDevice(0, 0);
+ fail("IWindowManager.getScancodeStateForDevice did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.getKeycodeState(0);
+ fail("IWindowManager.getKeycodeState did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+
+ try {
+ mWm.getKeycodeStateForDevice(0, 0);
+ fail("IWindowManager.getKeycodeStateForDevice did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+
+ @SmallTest
+ public void testSET_ORIENTATION() {
+ try {
+ mWm.setRotation(0, true, 0);
+ mWm.getSwitchState(0);
+ fail("IWindowManager.setRotation did not throw SecurityException as"
+ + " expected");
+ } catch (SecurityException e) {
+ // expected
+ } catch (RemoteException e) {
+ fail("Unexpected remote exception");
+ }
+ }
+}