1 /* 2 * Copyright (C) 2017 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.os; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.TestApi; 22 import android.app.ActivityThread; 23 24 import java.io.IOException; 25 import java.util.Map; 26 27 /** 28 * Java API for libvintf. 29 * 30 * @hide 31 */ 32 @TestApi 33 public class VintfObject { 34 35 private static final String LOG_TAG = "VintfObject"; 36 37 static { 38 System.loadLibrary("vintf_jni"); 39 } 40 41 /** 42 * Slurps all device information (both manifests and both matrices) 43 * and report them. 44 * If any error in getting one of the manifests, it is not included in 45 * the list. 46 * 47 * @hide 48 */ 49 @TestApi report()50 public static native String[] report(); 51 52 /** 53 * Verify Vintf compatibility on the device at boot time. Certain checks 54 * like kernel checks, AVB checks are disabled. 55 * 56 * @return = 0 if success (compatible) 57 * > 0 if incompatible 58 * < 0 if any error (mount partition fails, illformed XML, etc.) 59 * 60 * @hide 61 */ verifyBuildAtBoot()62 public static native int verifyBuildAtBoot(); 63 64 /** 65 * @return a list of HAL names and versions that is supported by this 66 * device as stated in device and framework manifests. For example, 67 * ["android.hidl.manager@1.0", "android.hardware.camera.device@1.0", 68 * "android.hardware.camera.device@3.2"]. There are no duplicates. 69 * 70 * For AIDL HALs, the version is a single number 71 * (e.g. "android.hardware.light@1"). Historically, this API strips the 72 * version number for AIDL HALs (e.g. "android.hardware.light"). Users 73 * of this API must be able to handle both for backwards compatibility. 74 * 75 * @hide 76 */ 77 @TestApi getHalNamesAndVersions()78 public static native String[] getHalNamesAndVersions(); 79 80 /** 81 * @return the BOARD_SEPOLICY_VERS build flag available in device manifest. 82 * 83 * @hide 84 */ 85 @TestApi getSepolicyVersion()86 public static native String getSepolicyVersion(); 87 88 /** 89 * @return the PLATFORM_SEPOLICY_VERSION build flag available in framework 90 * compatibility matrix. 91 * 92 * @hide 93 */ 94 @TestApi getPlatformSepolicyVersion()95 public static native @NonNull String getPlatformSepolicyVersion(); 96 97 /** 98 * @return a list of VNDK snapshots supported by the framework, as 99 * specified in framework manifest. For example, 100 * [("27", ["libjpeg.so", "libbase.so"]), 101 * ("28", ["libjpeg.so", "libbase.so"])] 102 * 103 * @hide 104 */ 105 @TestApi getVndkSnapshots()106 public static native Map<String, String[]> getVndkSnapshots(); 107 108 /** 109 * @return Target Framework Compatibility Matrix (FCM) version, a number 110 * specified in the device manifest indicating the FCM version that the 111 * device manifest implements. Null if device manifest doesn't specify this 112 * number (for legacy devices). 113 * 114 * @hide 115 */ 116 @TestApi getTargetFrameworkCompatibilityMatrixVersion()117 public static native Long getTargetFrameworkCompatibilityMatrixVersion(); 118 119 /** 120 * Executes a shell command using shell user identity, and return the standard output in string. 121 * 122 * @hide 123 */ runShellCommand(@onNull String command)124 private static @Nullable String runShellCommand(@NonNull String command) throws IOException { 125 var activityThread = ActivityThread.currentActivityThread(); 126 var instrumentation = activityThread.getInstrumentation(); 127 var automation = instrumentation.getUiAutomation(); 128 var pfd = automation.executeShellCommand(command); 129 try (var is = new ParcelFileDescriptor.AutoCloseInputStream(pfd)) { 130 return new String(is.readAllBytes()); 131 } 132 } 133 VintfObject()134 private VintfObject() {} 135 } 136