ServiceManagerPermissionTests.java revision cfaef699e1dfb3a75d5b51f3b15816f13670fd51
1package com.android.framework.permission.tests; 2 3import com.android.internal.os.BinderInternal; 4 5import android.os.Binder; 6import android.os.IPermissionController; 7import android.os.RemoteException; 8import android.os.ServiceManager; 9import android.os.ServiceManagerNative; 10import android.test.suitebuilder.annotation.SmallTest; 11 12import junit.framework.TestCase; 13 14/** 15 * TODO: Remove this. This is only a placeholder, need to implement this. 16 */ 17public class ServiceManagerPermissionTests extends TestCase { 18 @SmallTest 19 public void testAddService() { 20 try { 21 // The security in the service manager is that you can't replace 22 // a service that is already published. 23 Binder binder = new Binder(); 24 ServiceManager.addService("activity", binder); 25 fail("ServiceManager.addService did not throw SecurityException as" 26 + " expected"); 27 } catch (SecurityException e) { 28 // expected 29 } 30 } 31 32 @SmallTest 33 public void testSetPermissionController() { 34 try { 35 IPermissionController pc = new IPermissionController.Stub() { 36 public boolean checkPermission(java.lang.String permission, int pid, int uid) { 37 return true; 38 } 39 }; 40 ServiceManagerNative.asInterface(BinderInternal.getContextObject()) 41 .setPermissionController(pc); 42 fail("IServiceManager.setPermissionController did not throw SecurityException as" 43 + " expected"); 44 } catch (SecurityException e) { 45 // expected 46 } catch (RemoteException e) { 47 fail("Unexpected remote exception"); 48 } 49 } 50} 51