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, 0, false, false, 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, 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
227    @SmallTest
228    public void testDISABLE_KEYGUARD() {
229        Binder token = new Binder();
230        try {
231            mWm.disableKeyguard(token, "foo");
232            fail("IWindowManager.disableKeyguard 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.reenableKeyguard(token);
242            fail("IWindowManager.reenableKeyguard 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        try {
251            mWm.exitKeyguardSecurely(null);
252            fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as"
253                    + " expected");
254        } catch (SecurityException e) {
255            // expected
256        } catch (RemoteException e) {
257            fail("Unexpected remote exception");
258        }
259    }
260
261    @SmallTest
262    public void testSET_ANIMATION_SCALE() {
263        try {
264            mWm.setAnimationScale(0, 1);
265            fail("IWindowManager.setAnimationScale 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        try {
274            mWm.setAnimationScales(new float[1]);
275            fail("IWindowManager.setAnimationScales did not throw SecurityException as"
276                    + " expected");
277        } catch (SecurityException e) {
278            // expected
279        } catch (RemoteException e) {
280            fail("Unexpected remote exception");
281        }
282    }
283
284    @SmallTest
285    public void testSET_ORIENTATION() {
286        try {
287            mWm.updateRotation(true, false);
288            fail("IWindowManager.updateRotation 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.freezeRotation(-1);
298            fail("IWindowManager.freezeRotation 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        try {
307            mWm.thawRotation();
308            fail("IWindowManager.thawRotation did not throw SecurityException as"
309                    + " expected");
310        } catch (SecurityException e) {
311            // expected
312        } catch (RemoteException e) {
313            fail("Unexpected remote exception");
314        }
315    }
316}
317