1 /* 2 * Copyright (C) 2021, 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 android.aidl.tests; 18 19 import static org.hamcrest.core.Is.is; 20 import static org.hamcrest.core.IsNull.notNullValue; 21 import static org.hamcrest.core.IsNull.nullValue; 22 import static org.junit.Assert.assertNotNull; 23 import static org.junit.Assert.assertThat; 24 import static org.junit.Assert.assertTrue; 25 import static org.junit.Assert.fail; 26 import static org.junit.Assume.assumeTrue; 27 28 import android.os.Binder; 29 import android.os.IBinder; 30 import android.os.RemoteException; 31 import android.os.ServiceManager; 32 import java.util.ArrayList; 33 import java.util.List; 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.junit.runners.JUnit4; 38 39 @RunWith(JUnit4.class) 40 public class VintfTests { 41 private static final String kInstance = "android.does.not.exist.IFoo/default"; 42 43 @Test cantAddVintfService()44 public void cantAddVintfService() throws RemoteException { 45 Binder binder = new Binder(); 46 binder.markVintfStability(); // <- do not do this, for test only 47 48 boolean hasException = false; 49 try { 50 ServiceManager.addService(kInstance, binder); 51 } catch (IllegalArgumentException e) { 52 hasException = true; 53 } 54 55 assertTrue(hasException); 56 } 57 58 @Test canDowngradeVintfService()59 public void canDowngradeVintfService() throws RemoteException { 60 Binder binder = new Binder(); 61 binder.markVintfStability(); // <- do not do this, for test only 62 63 binder.forceDowngradeToSystemStability(); 64 65 ServiceManager.addService(kInstance, binder); 66 } 67 } 68