Merge "Add an api for platform sepolicy version to vintf"

This commit is contained in:
Inseob Kim
2021-05-04 15:11:20 +00:00
committed by Gerrit Code Review
3 changed files with 46 additions and 6 deletions

View File

@@ -1191,6 +1191,7 @@ package android.os {
public class VintfObject { public class VintfObject {
method public static String[] getHalNamesAndVersions(); method public static String[] getHalNamesAndVersions();
method @NonNull public static String getPlatformSepolicyVersion();
method public static String getSepolicyVersion(); method public static String getSepolicyVersion();
method public static Long getTargetFrameworkCompatibilityMatrixVersion(); method public static Long getTargetFrameworkCompatibilityMatrixVersion();
method public static java.util.Map<java.lang.String,java.lang.String[]> getVndkSnapshots(); method public static java.util.Map<java.lang.String,java.lang.String[]> getVndkSnapshots();

View File

@@ -16,6 +16,7 @@
package android.os; package android.os;
import android.annotation.NonNull;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.util.Slog; import android.util.Slog;
@@ -111,6 +112,15 @@ public class VintfObject {
@TestApi @TestApi
public static native String getSepolicyVersion(); public static native String getSepolicyVersion();
/**
* @return the PLATFORM_SEPOLICY_VERSION build flag available in framework
* compatibility matrix.
*
* @hide
*/
@TestApi
public static native @NonNull String getPlatformSepolicyVersion();
/** /**
* @return a list of VNDK snapshots supported by the framework, as * @return a list of VNDK snapshots supported by the framework, as
* specified in framework manifest. For example, * specified in framework manifest. For example,

View File

@@ -37,11 +37,13 @@ static jmethodID gLongValueOf;
namespace android { namespace android {
using vintf::CompatibilityMatrix;
using vintf::HalManifest; using vintf::HalManifest;
using vintf::Level; using vintf::Level;
using vintf::SchemaType; using vintf::SchemaType;
using vintf::to_string; using vintf::to_string;
using vintf::toXml; using vintf::toXml;
using vintf::Version;
using vintf::VintfObject; using vintf::VintfObject;
using vintf::Vndk; using vintf::Vndk;
@@ -119,6 +121,28 @@ static jstring android_os_VintfObject_getSepolicyVersion(JNIEnv* env, jclass) {
return env->NewStringUTF(cString.c_str()); return env->NewStringUTF(cString.c_str());
} }
static jstring android_os_VintfObject_getPlatformSepolicyVersion(JNIEnv* env, jclass) {
std::shared_ptr<const CompatibilityMatrix> matrix =
VintfObject::GetFrameworkCompatibilityMatrix();
if (matrix == nullptr || matrix->type() != SchemaType::FRAMEWORK) {
jniThrowRuntimeException(env, "Cannot get framework compatibility matrix");
return nullptr;
}
auto versions = matrix->getSepolicyVersions();
if (versions.empty()) {
jniThrowRuntimeException(env,
"sepolicy_version in framework compatibility matrix is empty");
return nullptr;
}
Version latest;
for (const auto& range : versions) {
latest = std::max(latest, range.maxVer());
}
return env->NewStringUTF(to_string(latest).c_str());
}
static jobject android_os_VintfObject_getVndkSnapshots(JNIEnv* env, jclass) { static jobject android_os_VintfObject_getVndkSnapshots(JNIEnv* env, jclass) {
std::shared_ptr<const HalManifest> manifest = VintfObject::GetFrameworkHalManifest(); std::shared_ptr<const HalManifest> manifest = VintfObject::GetFrameworkHalManifest();
if (manifest == nullptr || manifest->type() != SchemaType::FRAMEWORK) { if (manifest == nullptr || manifest->type() != SchemaType::FRAMEWORK) {
@@ -147,10 +171,15 @@ static jobject android_os_VintfObject_getTargetFrameworkCompatibilityMatrixVersi
static const JNINativeMethod gVintfObjectMethods[] = { static const JNINativeMethod gVintfObjectMethods[] = {
{"report", "()[Ljava/lang/String;", (void*)android_os_VintfObject_report}, {"report", "()[Ljava/lang/String;", (void*)android_os_VintfObject_report},
{"verifyWithoutAvb", "()I", (void*)android_os_VintfObject_verifyWithoutAvb}, {"verifyWithoutAvb", "()I", (void*)android_os_VintfObject_verifyWithoutAvb},
{"getHalNamesAndVersions", "()[Ljava/lang/String;", (void*)android_os_VintfObject_getHalNamesAndVersions}, {"getHalNamesAndVersions", "()[Ljava/lang/String;",
{"getSepolicyVersion", "()Ljava/lang/String;", (void*)android_os_VintfObject_getSepolicyVersion}, (void*)android_os_VintfObject_getHalNamesAndVersions},
{"getSepolicyVersion", "()Ljava/lang/String;",
(void*)android_os_VintfObject_getSepolicyVersion},
{"getPlatformSepolicyVersion", "()Ljava/lang/String;",
(void*)android_os_VintfObject_getPlatformSepolicyVersion},
{"getVndkSnapshots", "()Ljava/util/Map;", (void*)android_os_VintfObject_getVndkSnapshots}, {"getVndkSnapshots", "()Ljava/util/Map;", (void*)android_os_VintfObject_getVndkSnapshots},
{"getTargetFrameworkCompatibilityMatrixVersion", "()Ljava/lang/Long;", (void*)android_os_VintfObject_getTargetFrameworkCompatibilityMatrixVersion}, {"getTargetFrameworkCompatibilityMatrixVersion", "()Ljava/lang/Long;",
(void*)android_os_VintfObject_getTargetFrameworkCompatibilityMatrixVersion},
}; };
const char* const kVintfObjectPathName = "android/os/VintfObject"; const char* const kVintfObjectPathName = "android/os/VintfObject";