2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.framework.permission.tests;
19 import android.content.res.Configuration;
20 import android.os.Binder;
21 import android.os.RemoteException;
22 import android.os.ServiceManager;
23 import android.test.suitebuilder.annotation.SmallTest;
24 import android.view.IWindowManager;
25 import junit.framework.TestCase;
27 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
30 * TODO: Remove this. This is only a placeholder, need to implement this.
32 public class WindowManagerPermissionTests extends TestCase {
36 protected void setUp() throws Exception {
38 mWm = IWindowManager.Stub.asInterface(
39 ServiceManager.getService("window"));
43 public void testMANAGE_APP_TOKENS() {
45 mWm.pauseKeyDispatching(null);
46 fail("IWindowManager.pauseKeyDispatching did not throw SecurityException as"
48 } catch (SecurityException e) {
50 } catch (RemoteException e) {
51 fail("Unexpected remote exception");
55 mWm.resumeKeyDispatching(null);
56 fail("IWindowManager.resumeKeyDispatching did not throw SecurityException as"
58 } catch (SecurityException e) {
60 } catch (RemoteException e) {
61 fail("Unexpected remote exception");
65 mWm.setEventDispatching(true);
66 fail("IWindowManager.setEventDispatching did not throw SecurityException as"
68 } catch (SecurityException e) {
70 } catch (RemoteException e) {
71 fail("Unexpected remote exception");
75 mWm.addWindowToken(null, 0);
76 fail("IWindowManager.addWindowToken did not throw SecurityException as"
78 } catch (SecurityException e) {
80 } catch (RemoteException e) {
81 fail("Unexpected remote exception");
85 mWm.removeWindowToken(null);
86 fail("IWindowManager.removeWindowToken did not throw SecurityException as"
88 } catch (SecurityException e) {
90 } catch (RemoteException e) {
91 fail("Unexpected remote exception");
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"
99 } catch (SecurityException e) {
101 } catch (RemoteException e) {
102 fail("Unexpected remote exception");
106 mWm.setAppTask(null, 0, INVALID_STACK_ID, null, null, 0, false);
107 fail("IWindowManager.setAppGroupId did not throw SecurityException as"
109 } catch (SecurityException e) {
111 } catch (RemoteException e) {
112 fail("Unexpected remote exception");
116 mWm.updateOrientationFromAppTokens(new Configuration(), null);
117 fail("IWindowManager.updateOrientationFromAppTokens did not throw SecurityException as"
119 } catch (SecurityException e) {
121 } catch (RemoteException e) {
122 fail("Unexpected remote exception");
126 mWm.setAppOrientation(null, 0);
127 mWm.addWindowToken(null, 0);
128 fail("IWindowManager.setAppOrientation did not throw SecurityException as"
130 } catch (SecurityException e) {
132 } catch (RemoteException e) {
133 fail("Unexpected remote exception");
137 mWm.setFocusedApp(null, false);
138 fail("IWindowManager.setFocusedApp did not throw SecurityException as"
140 } catch (SecurityException e) {
142 } catch (RemoteException e) {
143 fail("Unexpected remote exception");
147 mWm.prepareAppTransition(0, false);
148 fail("IWindowManager.prepareAppTransition did not throw SecurityException as"
150 } catch (SecurityException e) {
152 } catch (RemoteException e) {
153 fail("Unexpected remote exception");
157 mWm.executeAppTransition();
158 fail("IWindowManager.executeAppTransition did not throw SecurityException as"
160 } catch (SecurityException e) {
162 } catch (RemoteException e) {
163 fail("Unexpected remote exception");
167 mWm.setAppStartingWindow(null, "foo", 0, null, null, 0, 0, 0, 0, null, false);
168 fail("IWindowManager.setAppStartingWindow did not throw SecurityException as"
170 } catch (SecurityException e) {
172 } catch (RemoteException e) {
173 fail("Unexpected remote exception");
177 mWm.setAppVisibility(null, false);
178 fail("IWindowManager.setAppVisibility did not throw SecurityException as"
180 } catch (SecurityException e) {
182 } catch (RemoteException e) {
183 fail("Unexpected remote exception");
187 mWm.startAppFreezingScreen(null, 0);
188 fail("IWindowManager.startAppFreezingScreen did not throw SecurityException as"
190 } catch (SecurityException e) {
192 } catch (RemoteException e) {
193 fail("Unexpected remote exception");
197 mWm.stopAppFreezingScreen(null, false);
198 fail("IWindowManager.stopAppFreezingScreen did not throw SecurityException as"
200 } catch (SecurityException e) {
202 } catch (RemoteException e) {
203 fail("Unexpected remote exception");
207 mWm.removeAppToken(null);
208 fail("IWindowManager.removeAppToken did not throw SecurityException as"
210 } catch (SecurityException e) {
212 } catch (RemoteException e) {
213 fail("Unexpected remote exception");
218 public void testDISABLE_KEYGUARD() {
219 Binder token = new Binder();
221 mWm.disableKeyguard(token, "foo");
222 fail("IWindowManager.disableKeyguard did not throw SecurityException as"
224 } catch (SecurityException e) {
226 } catch (RemoteException e) {
227 fail("Unexpected remote exception");
231 mWm.reenableKeyguard(token);
232 fail("IWindowManager.reenableKeyguard did not throw SecurityException as"
234 } catch (SecurityException e) {
236 } catch (RemoteException e) {
237 fail("Unexpected remote exception");
241 mWm.exitKeyguardSecurely(null);
242 fail("IWindowManager.exitKeyguardSecurely did not throw SecurityException as"
244 } catch (SecurityException e) {
246 } catch (RemoteException e) {
247 fail("Unexpected remote exception");
252 public void testSET_ANIMATION_SCALE() {
254 mWm.setAnimationScale(0, 1);
255 fail("IWindowManager.setAnimationScale did not throw SecurityException as"
257 } catch (SecurityException e) {
259 } catch (RemoteException e) {
260 fail("Unexpected remote exception");
264 mWm.setAnimationScales(new float[1]);
265 fail("IWindowManager.setAnimationScales did not throw SecurityException as"
267 } catch (SecurityException e) {
269 } catch (RemoteException e) {
270 fail("Unexpected remote exception");
275 public void testSET_ORIENTATION() {
277 mWm.updateRotation(true, false);
278 fail("IWindowManager.updateRotation did not throw SecurityException as"
280 } catch (SecurityException e) {
282 } catch (RemoteException e) {
283 fail("Unexpected remote exception");
287 mWm.freezeRotation(-1);
288 fail("IWindowManager.freezeRotation did not throw SecurityException as"
290 } catch (SecurityException e) {
292 } catch (RemoteException e) {
293 fail("Unexpected remote exception");
298 fail("IWindowManager.thawRotation did not throw SecurityException as"
300 } catch (SecurityException e) {
302 } catch (RemoteException e) {
303 fail("Unexpected remote exception");