1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.framework.permission.tests; 18 19import android.content.res.Configuration; 20import android.os.Binder; 21import android.os.RemoteException; 22import android.os.ServiceManager; 23import android.test.suitebuilder.annotation.SmallTest; 24import android.view.IWindowManager; 25import android.view.KeyEvent; 26import android.view.MotionEvent; 27 28import junit.framework.TestCase; 29 30/** 31 * TODO: Remove this. This is only a placeholder, need to implement this. 32 */ 33public class WindowManagerPermissionTests extends TestCase { 34 IWindowManager mWm; 35 36 @Override 37 protected void setUp() throws Exception { 38 super.setUp(); 39 mWm = IWindowManager.Stub.asInterface( 40 ServiceManager.getService("window")); 41 } 42 43 @SmallTest 44 public void testMANAGE_APP_TOKENS() { 45 try { 46 mWm.pauseKeyDispatching(null); 47 fail("IWindowManager.pauseKeyDispatching did not throw SecurityException as" 48 + " expected"); 49 } catch (SecurityException e) { 50 // expected 51 } catch (RemoteException e) { 52 fail("Unexpected remote exception"); 53 } 54 55 try { 56 mWm.resumeKeyDispatching(null); 57 fail("IWindowManager.resumeKeyDispatching did not throw SecurityException as" 58 + " expected"); 59 } catch (SecurityException e) { 60 // expected 61 } catch (RemoteException e) { 62 fail("Unexpected remote exception"); 63 } 64 65 try { 66 mWm.setEventDispatching(true); 67 fail("IWindowManager.setEventDispatching did not throw SecurityException as" 68 + " expected"); 69 } catch (SecurityException e) { 70 // expected 71 } catch (RemoteException e) { 72 fail("Unexpected remote exception"); 73 } 74 75 try { 76 mWm.addWindowToken(null, 0); 77 fail("IWindowManager.addWindowToken did not throw SecurityException as" 78 + " expected"); 79 } catch (SecurityException e) { 80 // expected 81 } catch (RemoteException e) { 82 fail("Unexpected remote exception"); 83 } 84 85 try { 86 mWm.removeWindowToken(null); 87 fail("IWindowManager.removeWindowToken did not throw SecurityException as" 88 + " expected"); 89 } catch (SecurityException e) { 90 // expected 91 } catch (RemoteException e) { 92 fail("Unexpected remote exception"); 93 } 94 95 try { 96 mWm.addAppToken(0, 0, null, 0, 0, false, false); 97 fail("IWindowManager.addAppToken did not throw SecurityException as" 98 + " expected"); 99 } catch (SecurityException e) { 100 // expected 101 } catch (RemoteException e) { 102 fail("Unexpected remote exception"); 103 } 104 105 try { 106 mWm.setAppGroupId(null, 0); 107 fail("IWindowManager.setAppGroupId did not throw SecurityException as" 108 + " expected"); 109 } catch (SecurityException e) { 110 // expected 111 } catch (RemoteException e) { 112 fail("Unexpected remote exception"); 113 } 114 115 try { 116 mWm.updateOrientationFromAppTokens(new Configuration(), null); 117 fail("IWindowManager.updateOrientationFromAppTokens did not throw SecurityException as" 118 + " expected"); 119 } catch (SecurityException e) { 120 // expected 121 } catch (RemoteException e) { 122 fail("Unexpected remote exception"); 123 } 124 125 try { 126 mWm.setAppOrientation(null, 0); 127 mWm.addWindowToken(null, 0); 128 fail("IWindowManager.setAppOrientation did not throw SecurityException as" 129 + " expected"); 130 } catch (SecurityException e) { 131 // expected 132 } catch (RemoteException e) { 133 fail("Unexpected remote exception"); 134 } 135 136 try { 137 mWm.setFocusedApp(null, false); 138 fail("IWindowManager.setFocusedApp did not throw SecurityException as" 139 + " expected"); 140 } catch (SecurityException e) { 141 // expected 142 } catch (RemoteException e) { 143 fail("Unexpected remote exception"); 144 } 145 146 try { 147 mWm.prepareAppTransition(0, false); 148 fail("IWindowManager.prepareAppTransition did not throw SecurityException as" 149 + " expected"); 150 } catch (SecurityException e) { 151 // expected 152 } catch (RemoteException e) { 153 fail("Unexpected remote exception"); 154 } 155 156 try { 157 mWm.executeAppTransition(); 158 fail("IWindowManager.executeAppTransition did not throw SecurityException as" 159 + " expected"); 160 } catch (SecurityException e) { 161 // expected 162 } catch (RemoteException e) { 163 fail("Unexpected remote exception"); 164 } 165 166 try { 167 mWm.setAppStartingWindow(null, "foo", 0, null, null, 0, 0, 0, null, false); 168 fail("IWindowManager.setAppStartingWindow did not throw SecurityException as" 169 + " expected"); 170 } catch (SecurityException e) { 171 // expected 172 } catch (RemoteException e) { 173 fail("Unexpected remote exception"); 174 } 175 176 try { 177 mWm.setAppWillBeHidden(null); 178 fail("IWindowManager.setAppWillBeHidden did not throw SecurityException as" 179 + " expected"); 180 } catch (SecurityException e) { 181 // expected 182 } catch (RemoteException e) { 183 fail("Unexpected remote exception"); 184 } 185 186 try { 187 mWm.setAppVisibility(null, false); 188 fail("IWindowManager.setAppVisibility did not throw SecurityException as" 189 + " expected"); 190 } catch (SecurityException e) { 191 // expected 192 } catch (RemoteException e) { 193 fail("Unexpected remote exception"); 194 } 195 196 try { 197 mWm.startAppFreezingScreen(null, 0); 198 fail("IWindowManager.startAppFreezingScreen did not throw SecurityException as" 199 + " expected"); 200 } catch (SecurityException e) { 201 // expected 202 } catch (RemoteException e) { 203 fail("Unexpected remote exception"); 204 } 205 206 try { 207 mWm.stopAppFreezingScreen(null, false); 208 fail("IWindowManager.stopAppFreezingScreen did not throw SecurityException as" 209 + " expected"); 210 } catch (SecurityException e) { 211 // expected 212 } catch (RemoteException e) { 213 fail("Unexpected remote exception"); 214 } 215 216 try { 217 mWm.removeAppToken(null); 218 fail("IWindowManager.removeAppToken did not throw SecurityException as" 219 + " expected"); 220 } catch (SecurityException e) { 221 // expected 222 } catch (RemoteException e) { 223 fail("Unexpected remote exception"); 224 } 225 226 try { 227 mWm.moveAppToken(0, null); 228 fail("IWindowManager.moveAppToken did not throw SecurityException as" 229 + " expected"); 230 } catch (SecurityException e) { 231 // expected 232 } catch (RemoteException e) { 233 fail("Unexpected remote exception"); 234 } 235 236 try { 237 mWm.moveAppTokensToTop(null); 238 fail("IWindowManager.moveAppTokensToTop did not throw SecurityException as" 239 + " expected"); 240 } catch (SecurityException e) { 241 // expected 242 } catch (RemoteException e) { 243 fail("Unexpected remote exception"); 244 } 245 246 try { 247 mWm.moveAppTokensToBottom(null); 248 fail("IWindowManager.moveAppTokensToBottom did not throw SecurityException as" 249 + " expected"); 250 } catch (SecurityException e) { 251 // expected 252 } catch (RemoteException e) { 253 fail("Unexpected remote exception"); 254 } 255 } 256 257 @SmallTest 258 public void testDISABLE_KEYGUARD() { 259 Binder token = new Binder(); 260 try { 261 mWm.disableKeyguard(token, "foo"); 262 fail("IWindowManager.disableKeyguard did not throw SecurityException as" 263 + " expected"); 264 } catch (SecurityException e) { 265 // expected 266 } catch (RemoteException e) { 267 fail("Unexpected remote exception"); 268 } 269 270 try { 271 mWm.reenableKeyguard(token); 272 fail("IWindowManager.reenableKeyguard did not throw SecurityException as" 273 + " expected"); 274 } catch (SecurityException e) { 275 // expected 276 } catch (RemoteException e) { 277 fail("Unexpected remote exception"); 278 } 279 280 try { 281 mWm.exitKeyguardSecurely(null); 282 fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as" 283 + " expected"); 284 } catch (SecurityException e) { 285 // expected 286 } catch (RemoteException e) { 287 fail("Unexpected remote exception"); 288 } 289 } 290 291 @SmallTest 292 public void testSET_ANIMATION_SCALE() { 293 try { 294 mWm.setAnimationScale(0, 1); 295 fail("IWindowManager.setAnimationScale did not throw SecurityException as" 296 + " expected"); 297 } catch (SecurityException e) { 298 // expected 299 } catch (RemoteException e) { 300 fail("Unexpected remote exception"); 301 } 302 303 try { 304 mWm.setAnimationScales(new float[1]); 305 fail("IWindowManager.setAnimationScales did not throw SecurityException as" 306 + " expected"); 307 } catch (SecurityException e) { 308 // expected 309 } catch (RemoteException e) { 310 fail("Unexpected remote exception"); 311 } 312 } 313 314 @SmallTest 315 public void testSET_ORIENTATION() { 316 try { 317 mWm.updateRotation(true, false); 318 fail("IWindowManager.updateRotation did not throw SecurityException as" 319 + " expected"); 320 } catch (SecurityException e) { 321 // expected 322 } catch (RemoteException e) { 323 fail("Unexpected remote exception"); 324 } 325 326 try { 327 mWm.freezeRotation(-1); 328 fail("IWindowManager.freezeRotation did not throw SecurityException as" 329 + " expected"); 330 } catch (SecurityException e) { 331 // expected 332 } catch (RemoteException e) { 333 fail("Unexpected remote exception"); 334 } 335 336 try { 337 mWm.thawRotation(); 338 fail("IWindowManager.thawRotation did not throw SecurityException as" 339 + " expected"); 340 } catch (SecurityException e) { 341 // expected 342 } catch (RemoteException e) { 343 fail("Unexpected remote exception"); 344 } 345 } 346} 347