Home | History | Annotate | Download | only in tests
      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 
     17 package com.android.framework.permission.tests;
     18 
     19 import com.android.internal.os.BinderInternal;
     20 
     21 import android.app.AppOpsManager;
     22 import android.os.Binder;
     23 import android.os.IPermissionController;
     24 import android.os.RemoteException;
     25 import android.os.ServiceManager;
     26 import android.os.ServiceManagerNative;
     27 import android.test.suitebuilder.annotation.SmallTest;
     28 
     29 import junit.framework.TestCase;
     30 
     31 /**
     32  * TODO: Remove this. This is only a placeholder, need to implement this.
     33  */
     34 public class ServiceManagerPermissionTests extends TestCase {
     35     @SmallTest
     36     public void testAddService() {
     37         try {
     38             // The security in the service manager is that you can't replace
     39             // a service that is already published.
     40             Binder binder = new Binder();
     41             ServiceManager.addService("activity", binder);
     42             fail("ServiceManager.addService did not throw SecurityException as"
     43                     + " expected");
     44         } catch (SecurityException e) {
     45             // expected
     46         }
     47     }
     48 
     49     @SmallTest
     50     public void testSetPermissionController() {
     51         try {
     52             IPermissionController pc = new IPermissionController.Stub() {
     53                 @Override
     54                 public boolean checkPermission(java.lang.String permission, int pid, int uid) {
     55                     return true;
     56                 }
     57 
     58                 @Override
     59                 public int noteOp(String op, int uid, String packageName) {
     60                     return AppOpsManager.MODE_ALLOWED;
     61                 }
     62 
     63                 @Override
     64                 public String[] getPackagesForUid(int uid) {
     65                     return new String[0];
     66                 }
     67 
     68                 @Override
     69                 public boolean isRuntimePermission(String permission) {
     70                     return false;
     71                 }
     72 
     73                 @Override
     74                 public int getPackageUid(String packageName, int flags) {
     75                     return -1;
     76                 }
     77             };
     78             ServiceManagerNative.asInterface(BinderInternal.getContextObject())
     79                     .setPermissionController(pc);
     80             fail("IServiceManager.setPermissionController did not throw SecurityException as"
     81                     + " expected");
     82         } catch (SecurityException e) {
     83             // expected
     84         } catch (RemoteException e) {
     85             fail("Unexpected remote exception");
     86         }
     87     }
     88 }
     89