1 /*
2  * Copyright (C) 2022 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 package com.android.se;
17 
18 import android.content.Context;
19 import android.content.pm.PackageManager;
20 import android.os.IBinder;
21 import android.os.ServiceManager;
22 
23 import androidx.test.InstrumentationRegistry;
24 import androidx.test.ext.junit.runners.AndroidJUnit4;
25 
26 import org.junit.After;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 @RunWith(AndroidJUnit4.class)
33 public final class SecureElementVendorStableInterfaceFlagTest {
34 
35     private static final String TAG =
36             SecureElementVendorStableInterfaceFlagTest.class.getSimpleName();
37     public static final String VSTABLE_SECURE_ELEMENT_SERVICE =
38             "android.se.omapi.ISecureElementService/default";
39     private Context mContext;
40 
41     @Before
setUp()42     public void setUp() {
43         mContext = InstrumentationRegistry.getTargetContext();
44         PackageManager pm = mContext.getPackageManager();
45     }
46 
47     @After
tearDown()48     public void tearDown() throws Exception {
49     }
50 
51     @Test
testIsVendorStableInterfaceEnabled()52     public void testIsVendorStableInterfaceEnabled() {
53         boolean secure_element_vintf_enabled =
54                 mContext.getResources().getBoolean(R.bool.secure_element_vintf_enabled);
55 
56         IBinder binder = ServiceManager.getService(VSTABLE_SECURE_ELEMENT_SERVICE);
57         if (secure_element_vintf_enabled) {
58             Assert.assertNotNull(binder);
59         } else {
60             Assert.assertNull(binder);
61         }
62 
63     }
64 }
65