WindowManagerPermissionTests.java revision 2f0b17573d4324832f7a20402a3d2b5920bc4866
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, null, 0, 0, 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 testINJECT_EVENTS() {
259        try {
260            mWm.injectKeyEvent(new KeyEvent(0, 0), false);
261            fail("IWindowManager.injectKeyEvent did not throw SecurityException as"
262                    + " expected");
263        } catch (SecurityException e) {
264            // expected
265        } catch (RemoteException e) {
266            fail("Unexpected remote exception");
267        }
268
269        try {
270            mWm.injectPointerEvent(MotionEvent.obtain(0, 0, 0, 0, 0, 0, 0, 0, 0,
271                    0, 0, 0), false);
272            fail("IWindowManager.injectPointerEvent 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.injectTrackballEvent(MotionEvent.obtain(0, 0, 0, 0, 0, 0, 0, 0, 0,
282                    0, 0, 0), false);
283            fail("IWindowManager.injectTrackballEvent did not throw SecurityException as"
284                    + " expected");
285        } catch (SecurityException e) {
286            // expected
287        } catch (RemoteException e) {
288            fail("Unexpected remote exception");
289        }
290    }
291
292    @SmallTest
293    public void testDISABLE_KEYGUARD() {
294        Binder token = new Binder();
295        try {
296            mWm.disableKeyguard(token, "foo");
297            fail("IWindowManager.disableKeyguard did not throw SecurityException as"
298                    + " expected");
299        } catch (SecurityException e) {
300            // expected
301        } catch (RemoteException e) {
302            fail("Unexpected remote exception");
303        }
304
305        try {
306            mWm.reenableKeyguard(token);
307            fail("IWindowManager.reenableKeyguard did not throw SecurityException as"
308                    + " expected");
309        } catch (SecurityException e) {
310            // expected
311        } catch (RemoteException e) {
312            fail("Unexpected remote exception");
313        }
314
315        try {
316            mWm.exitKeyguardSecurely(null);
317            fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as"
318                    + " expected");
319        } catch (SecurityException e) {
320            // expected
321        } catch (RemoteException e) {
322            fail("Unexpected remote exception");
323        }
324    }
325
326    @SmallTest
327    public void testSET_ANIMATION_SCALE() {
328        try {
329            mWm.setAnimationScale(0, 1);
330            fail("IWindowManager.setAnimationScale did not throw SecurityException as"
331                    + " expected");
332        } catch (SecurityException e) {
333            // expected
334        } catch (RemoteException e) {
335            fail("Unexpected remote exception");
336        }
337
338        try {
339            mWm.setAnimationScales(new float[1]);
340            fail("IWindowManager.setAnimationScales did not throw SecurityException as"
341                    + " expected");
342        } catch (SecurityException e) {
343            // expected
344        } catch (RemoteException e) {
345            fail("Unexpected remote exception");
346        }
347    }
348
349    @SmallTest
350    public void testREAD_INPUT_STATE() {
351        try {
352            mWm.getSwitchState(0);
353            fail("IWindowManager.getSwitchState did not throw SecurityException as"
354                    + " expected");
355        } catch (SecurityException e) {
356            // expected
357        } catch (RemoteException e) {
358            fail("Unexpected remote exception");
359        }
360
361        try {
362            mWm.getSwitchStateForDevice(0, 0);
363            fail("IWindowManager.getSwitchStateForDevice did not throw SecurityException as"
364                    + " expected");
365        } catch (SecurityException e) {
366            // expected
367        } catch (RemoteException e) {
368            fail("Unexpected remote exception");
369        }
370
371        try {
372            mWm.getScancodeState(0);
373            fail("IWindowManager.getScancodeState did not throw SecurityException as"
374                    + " expected");
375        } catch (SecurityException e) {
376            // expected
377        } catch (RemoteException e) {
378            fail("Unexpected remote exception");
379        }
380
381        try {
382            mWm.getScancodeStateForDevice(0, 0);
383            fail("IWindowManager.getScancodeStateForDevice did not throw SecurityException as"
384                    + " expected");
385        } catch (SecurityException e) {
386            // expected
387        } catch (RemoteException e) {
388            fail("Unexpected remote exception");
389        }
390
391        try {
392            mWm.getKeycodeState(0);
393            fail("IWindowManager.getKeycodeState did not throw SecurityException as"
394                    + " expected");
395        } catch (SecurityException e) {
396            // expected
397        } catch (RemoteException e) {
398            fail("Unexpected remote exception");
399        }
400
401        try {
402            mWm.getKeycodeStateForDevice(0, 0);
403            fail("IWindowManager.getKeycodeStateForDevice did not throw SecurityException as"
404                    + " expected");
405        } catch (SecurityException e) {
406            // expected
407        } catch (RemoteException e) {
408            fail("Unexpected remote exception");
409        }
410    }
411
412    @SmallTest
413    public void testSET_ORIENTATION() {
414        try {
415            mWm.setRotation(0, true, 0);
416            mWm.getSwitchState(0);
417            fail("IWindowManager.setRotation did not throw SecurityException as"
418                    + " expected");
419        } catch (SecurityException e) {
420            // expected
421        } catch (RemoteException e) {
422            fail("Unexpected remote exception");
423        }
424    }
425}
426