Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4055ce53 authored by Inseob Kim's avatar Inseob Kim
Browse files

Add an api for platform sepolicy version to vintf

PLATFORM_SEPOLICY_VERSION will be the latest version in system's
compatibility matrix. This change adds a function
getPlatformSepolicyVersion, which ultimately gets
PLATFORM_SEPOLICY_VERSION, just like getSepolicyVersion for vendor.

This will be used from the SELinux CTS.

Bug: 186596569
Test: atest CtsSecurityHostTestCases:android.security.cts.SELinuxNeverallowRulesTest
Change-Id: Ic7863ece9413b9a6a4a91ff42d3121935823fe8b
parent 9ef59ac9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1191,6 +1191,7 @@ package android.os {

  public class VintfObject {
    method public static String[] getHalNamesAndVersions();
    method @NonNull public static String getPlatformSepolicyVersion();
    method public static String getSepolicyVersion();
    method public static Long getTargetFrameworkCompatibilityMatrixVersion();
    method public static java.util.Map<java.lang.String,java.lang.String[]> getVndkSnapshots();
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.os;

import android.annotation.NonNull;
import android.annotation.TestApi;
import android.util.Slog;

@@ -111,6 +112,15 @@ public class VintfObject {
    @TestApi
    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
     * specified in framework manifest. For example,
+35 −6
Original line number Diff line number Diff line
@@ -37,11 +37,13 @@ static jmethodID gLongValueOf;

namespace android {

using vintf::CompatibilityMatrix;
using vintf::HalManifest;
using vintf::Level;
using vintf::SchemaType;
using vintf::to_string;
using vintf::toXml;
using vintf::Version;
using vintf::VintfObject;
using vintf::Vndk;

@@ -119,6 +121,28 @@ static jstring android_os_VintfObject_getSepolicyVersion(JNIEnv* env, jclass) {
    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) {
    std::shared_ptr<const HalManifest> manifest = VintfObject::GetFrameworkHalManifest();
    if (manifest == nullptr || manifest->type() != SchemaType::FRAMEWORK) {
@@ -147,10 +171,15 @@ static jobject android_os_VintfObject_getTargetFrameworkCompatibilityMatrixVersi
static const JNINativeMethod gVintfObjectMethods[] = {
        {"report", "()[Ljava/lang/String;", (void*)android_os_VintfObject_report},
        {"verifyWithoutAvb", "()I", (void*)android_os_VintfObject_verifyWithoutAvb},
    {"getHalNamesAndVersions", "()[Ljava/lang/String;", (void*)android_os_VintfObject_getHalNamesAndVersions},
    {"getSepolicyVersion", "()Ljava/lang/String;", (void*)android_os_VintfObject_getSepolicyVersion},
        {"getHalNamesAndVersions", "()[Ljava/lang/String;",
         (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},
    {"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";