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 junit.framework.TestCase; 26 27import static android.app.ActivityManager.StackId.INVALID_STACK_ID; 28 29/** 30 * TODO: Remove this. This is only a placeholder, need to implement this. 31 */ 32public class WindowManagerPermissionTests extends TestCase { 33 IWindowManager mWm; 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 mWm = IWindowManager.Stub.asInterface( 39 ServiceManager.getService("window")); 40 } 41 42 @SmallTest 43 public void testMANAGE_APP_TOKENS() { 44 try { 45 mWm.pauseKeyDispatching(null); 46 fail("IWindowManager.pauseKeyDispatching did not throw SecurityException as" 47 + " expected"); 48 } catch (SecurityException e) { 49 // expected 50 } catch (RemoteException e) { 51 fail("Unexpected remote exception"); 52 } 53 54 try { 55 mWm.resumeKeyDispatching(null); 56 fail("IWindowManager.resumeKeyDispatching did not throw SecurityException as" 57 + " expected"); 58 } catch (SecurityException e) { 59 // expected 60 } catch (RemoteException e) { 61 fail("Unexpected remote exception"); 62 } 63 64 try { 65 mWm.setEventDispatching(true); 66 fail("IWindowManager.setEventDispatching did not throw SecurityException as" 67 + " expected"); 68 } catch (SecurityException e) { 69 // expected 70 } catch (RemoteException e) { 71 fail("Unexpected remote exception"); 72 } 73 74 try { 75 mWm.addWindowToken(null, 0); 76 fail("IWindowManager.addWindowToken did not throw SecurityException as" 77 + " expected"); 78 } catch (SecurityException e) { 79 // expected 80 } catch (RemoteException e) { 81 fail("Unexpected remote exception"); 82 } 83 84 try { 85 mWm.removeWindowToken(null); 86 fail("IWindowManager.removeWindowToken did not throw SecurityException as" 87 + " expected"); 88 } catch (SecurityException e) { 89 // expected 90 } catch (RemoteException e) { 91 fail("Unexpected remote exception"); 92 } 93 94 try { 95 mWm.addAppToken(0, null, 0, 0, 0, false, false, 0, 0, false, false, null, 96 Configuration.EMPTY, 0, false, false, 0); 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.setAppTask(null, 0, INVALID_STACK_ID, null, null, 0, false); 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, 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.setAppVisibility(null, false); 178 fail("IWindowManager.setAppVisibility 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.startAppFreezingScreen(null, 0); 188 fail("IWindowManager.startAppFreezingScreen 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.stopAppFreezingScreen(null, false); 198 fail("IWindowManager.stopAppFreezingScreen 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.removeAppToken(null); 208 fail("IWindowManager.removeAppToken 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 217 @SmallTest 218 public void testDISABLE_KEYGUARD() { 219 Binder token = new Binder(); 220 try { 221 mWm.disableKeyguard(token, "foo"); 222 fail("IWindowManager.disableKeyguard did not throw SecurityException as" 223 + " expected"); 224 } catch (SecurityException e) { 225 // expected 226 } catch (RemoteException e) { 227 fail("Unexpected remote exception"); 228 } 229 230 try { 231 mWm.reenableKeyguard(token); 232 fail("IWindowManager.reenableKeyguard did not throw SecurityException as" 233 + " expected"); 234 } catch (SecurityException e) { 235 // expected 236 } catch (RemoteException e) { 237 fail("Unexpected remote exception"); 238 } 239 240 try { 241 mWm.exitKeyguardSecurely(null); 242 fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as" 243 + " expected"); 244 } catch (SecurityException e) { 245 // expected 246 } catch (RemoteException e) { 247 fail("Unexpected remote exception"); 248 } 249 } 250 251 @SmallTest 252 public void testSET_ANIMATION_SCALE() { 253 try { 254 mWm.setAnimationScale(0, 1); 255 fail("IWindowManager.setAnimationScale did not throw SecurityException as" 256 + " expected"); 257 } catch (SecurityException e) { 258 // expected 259 } catch (RemoteException e) { 260 fail("Unexpected remote exception"); 261 } 262 263 try { 264 mWm.setAnimationScales(new float[1]); 265 fail("IWindowManager.setAnimationScales did not throw SecurityException as" 266 + " expected"); 267 } catch (SecurityException e) { 268 // expected 269 } catch (RemoteException e) { 270 fail("Unexpected remote exception"); 271 } 272 } 273 274 @SmallTest 275 public void testSET_ORIENTATION() { 276 try { 277 mWm.updateRotation(true, false); 278 fail("IWindowManager.updateRotation did not throw SecurityException as" 279 + " expected"); 280 } catch (SecurityException e) { 281 // expected 282 } catch (RemoteException e) { 283 fail("Unexpected remote exception"); 284 } 285 286 try { 287 mWm.freezeRotation(-1); 288 fail("IWindowManager.freezeRotation did not throw SecurityException as" 289 + " expected"); 290 } catch (SecurityException e) { 291 // expected 292 } catch (RemoteException e) { 293 fail("Unexpected remote exception"); 294 } 295 296 try { 297 mWm.thawRotation(); 298 fail("IWindowManager.thawRotation did not throw SecurityException as" 299 + " expected"); 300 } catch (SecurityException e) { 301 // expected 302 } catch (RemoteException e) { 303 fail("Unexpected remote exception"); 304 } 305 } 306} 307