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 com.android.internal.os.BinderInternal; 20 21import android.os.Binder; 22import android.os.IPermissionController; 23import android.os.RemoteException; 24import android.os.ServiceManager; 25import android.os.ServiceManagerNative; 26import android.test.suitebuilder.annotation.SmallTest; 27 28import junit.framework.TestCase; 29 30/** 31 * TODO: Remove this. This is only a placeholder, need to implement this. 32 */ 33public class ServiceManagerPermissionTests extends TestCase { 34 @SmallTest 35 public void testAddService() { 36 try { 37 // The security in the service manager is that you can't replace 38 // a service that is already published. 39 Binder binder = new Binder(); 40 ServiceManager.addService("activity", binder); 41 fail("ServiceManager.addService did not throw SecurityException as" 42 + " expected"); 43 } catch (SecurityException e) { 44 // expected 45 } 46 } 47 48 @SmallTest 49 public void testSetPermissionController() { 50 try { 51 IPermissionController pc = new IPermissionController.Stub() { 52 public boolean checkPermission(java.lang.String permission, int pid, int uid) { 53 return true; 54 } 55 }; 56 ServiceManagerNative.asInterface(BinderInternal.getContextObject()) 57 .setPermissionController(pc); 58 fail("IServiceManager.setPermissionController did not throw SecurityException as" 59 + " expected"); 60 } catch (SecurityException e) { 61 // expected 62 } catch (RemoteException e) { 63 fail("Unexpected remote exception"); 64 } 65 } 66} 67