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(-1); 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.moveTaskToBack(-1); 53 fail("IActivityManager.moveTaskToBack 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 try { 62 mAm.moveTaskBackwards(-1); 63 fail("IActivityManager.moveTaskToFront did not throw SecurityException as" 64 + " expected"); 65 } catch (SecurityException e) { 66 // expected 67 } catch (RemoteException e) { 68 fail("Unexpected remote exception"); 69 } 70 } 71 72 @SmallTest 73 public void testCHANGE_CONFIGURATION() { 74 try { 75 mAm.updateConfiguration(new Configuration()); 76 fail("IActivityManager.updateConfiguration 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 85 @SmallTest 86 public void testSET_DEBUG_APP() { 87 try { 88 mAm.setDebugApp(null, false, false); 89 fail("IActivityManager.setDebugApp did not throw SecurityException as" 90 + " expected"); 91 } catch (SecurityException e) { 92 // expected 93 } catch (RemoteException e) { 94 fail("Unexpected remote exception"); 95 } 96 } 97 98 @SmallTest 99 public void testSET_PROCESS_LIMIT() { 100 try { 101 mAm.setProcessLimit(10); 102 fail("IActivityManager.setProcessLimit did not throw SecurityException as" 103 + " expected"); 104 } catch (SecurityException e) { 105 // expected 106 } catch (RemoteException e) { 107 fail("Unexpected remote exception"); 108 } 109 } 110 111 @SmallTest 112 public void testALWAYS_FINISH() { 113 try { 114 mAm.setAlwaysFinish(false); 115 fail("IActivityManager.setAlwaysFinish did not throw SecurityException as" 116 + " expected"); 117 } catch (SecurityException e) { 118 // expected 119 } catch (RemoteException e) { 120 fail("Unexpected remote exception"); 121 } 122 } 123 124 @SmallTest 125 public void testSIGNAL_PERSISTENT_PROCESSES() { 126 try { 127 mAm.signalPersistentProcesses(-1); 128 fail("IActivityManager.signalPersistentProcesses 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 137 @SmallTest 138 public void testFORCE_BACK() { 139 try { 140 mAm.unhandledBack(); 141 fail("IActivityManager.unhandledBack did not throw SecurityException as" 142 + " expected"); 143 } catch (SecurityException e) { 144 // expected 145 } catch (RemoteException e) { 146 fail("Unexpected remote exception"); 147 } 148 } 149 150 @SmallTest 151 public void testSET_ACTIVITY_WATCHER() { 152 try { 153 mAm.setActivityController(null); 154 fail("IActivityManager.setActivityController did not throw SecurityException as" 155 + " expected"); 156 } catch (SecurityException e) { 157 // expected 158 } catch (RemoteException e) { 159 fail("Unexpected remote exception"); 160 } 161 } 162 163 @SmallTest 164 public void testSHUTDOWN() { 165 try { 166 mAm.shutdown(0); 167 fail("IActivityManager.shutdown did not throw SecurityException as" 168 + " expected"); 169 } catch (SecurityException e) { 170 // expected 171 } catch (RemoteException e) { 172 fail("Unexpected remote exception"); 173 } 174 } 175 176 @SmallTest 177 public void testSTOP_APP_SWITCHES() { 178 try { 179 mAm.stopAppSwitches(); 180 fail("IActivityManager.stopAppSwitches 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 try { 189 mAm.resumeAppSwitches(); 190 fail("IActivityManager.resumeAppSwitches did not throw SecurityException as" 191 + " expected"); 192 } catch (SecurityException e) { 193 // expected 194 } catch (RemoteException e) { 195 fail("Unexpected remote exception"); 196 } 197 } 198} 199