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.app.ActivityManagerNative;
20import android.app.IActivityManager;
21import android.content.res.Configuration;
22import android.os.RemoteException;
23import android.test.suitebuilder.annotation.SmallTest;
24
25import junit.framework.TestCase;
26
27/**
28 * TODO: Remove this. This is only a placeholder, need to implement this.
29 */
30public class ActivityManagerPermissionTests extends TestCase {
31    IActivityManager mAm;
32
33    @Override
34    protected void setUp() throws Exception {
35        super.setUp();
36        mAm = ActivityManagerNative.getDefault();
37    }
38
39    @SmallTest
40    public void testREORDER_TASKS() {
41        try {
42            mAm.moveTaskToFront(0, 0, null);
43            fail("IActivityManager.moveTaskToFront did not throw SecurityException as"
44                    + " expected");
45        } catch (SecurityException e) {
46            // expected
47        } catch (RemoteException e) {
48            fail("Unexpected remote exception");
49        }
50
51        try {
52            mAm.moveTaskBackwards(-1);
53            fail("IActivityManager.moveTaskToFront did not throw SecurityException as"
54                    + " expected");
55        } catch (SecurityException e) {
56            // expected
57        } catch (RemoteException e) {
58            fail("Unexpected remote exception");
59        }
60    }
61
62    @SmallTest
63    public void testCHANGE_CONFIGURATION() {
64        try {
65            mAm.updateConfiguration(new Configuration());
66            fail("IActivityManager.updateConfiguration 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
75    @SmallTest
76    public void testSET_DEBUG_APP() {
77        try {
78            mAm.setDebugApp(null, false, false);
79            fail("IActivityManager.setDebugApp did not throw SecurityException as"
80                    + " expected");
81        } catch (SecurityException e) {
82            // expected
83        } catch (RemoteException e) {
84            fail("Unexpected remote exception");
85        }
86    }
87
88    @SmallTest
89    public void testSET_PROCESS_LIMIT() {
90        try {
91            mAm.setProcessLimit(10);
92            fail("IActivityManager.setProcessLimit did not throw SecurityException as"
93                    + " expected");
94        } catch (SecurityException e) {
95            // expected
96        } catch (RemoteException e) {
97            fail("Unexpected remote exception");
98        }
99    }
100
101    @SmallTest
102    public void testALWAYS_FINISH() {
103        try {
104            mAm.setAlwaysFinish(false);
105            fail("IActivityManager.setAlwaysFinish did not throw SecurityException as"
106                    + " expected");
107        } catch (SecurityException e) {
108            // expected
109        } catch (RemoteException e) {
110            fail("Unexpected remote exception");
111        }
112    }
113
114    @SmallTest
115    public void testSIGNAL_PERSISTENT_PROCESSES() {
116        try {
117            mAm.signalPersistentProcesses(-1);
118            fail("IActivityManager.signalPersistentProcesses did not throw SecurityException as"
119                    + " expected");
120        } catch (SecurityException e) {
121            // expected
122        } catch (RemoteException e) {
123            fail("Unexpected remote exception");
124        }
125    }
126
127    @SmallTest
128    public void testFORCE_BACK() {
129        try {
130            mAm.unhandledBack();
131            fail("IActivityManager.unhandledBack did not throw SecurityException as"
132                    + " expected");
133        } catch (SecurityException e) {
134            // expected
135        } catch (RemoteException e) {
136            fail("Unexpected remote exception");
137        }
138    }
139
140    @SmallTest
141    public void testSET_ACTIVITY_WATCHER() {
142        try {
143            mAm.setActivityController(null, false);
144            fail("IActivityManager.setActivityController did not throw SecurityException as"
145                    + " expected");
146        } catch (SecurityException e) {
147            // expected
148        } catch (RemoteException e) {
149            fail("Unexpected remote exception");
150        }
151    }
152
153    @SmallTest
154    public void testSHUTDOWN() {
155        try {
156            mAm.shutdown(0);
157            fail("IActivityManager.shutdown did not throw SecurityException as"
158                    + " expected");
159        } catch (SecurityException e) {
160            // expected
161        } catch (RemoteException e) {
162            fail("Unexpected remote exception");
163        }
164    }
165
166    @SmallTest
167    public void testSTOP_APP_SWITCHES() {
168        try {
169            mAm.stopAppSwitches();
170            fail("IActivityManager.stopAppSwitches did not throw SecurityException as"
171                    + " expected");
172        } catch (SecurityException e) {
173            // expected
174        } catch (RemoteException e) {
175            fail("Unexpected remote exception");
176        }
177
178        try {
179            mAm.resumeAppSwitches();
180            fail("IActivityManager.resumeAppSwitches did not throw SecurityException as"
181                    + " expected");
182        } catch (SecurityException e) {
183            // expected
184        } catch (RemoteException e) {
185            fail("Unexpected remote exception");
186        }
187    }
188}
189