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

Commit dd4156cb authored by Yifan Hong's avatar Yifan Hong Committed by android-build-merger
Browse files

Add compatibility matrices to VintfObject.report()

am: 4463d991

Change-Id: I26c78cca5e807ee291bdb097d11d5f4ac43bba29
parents 0b34d001 4463d991
Loading
Loading
Loading
Loading
+3 −19
Original line number Original line Diff line number Diff line
@@ -26,17 +26,12 @@ public class VintfObject {
    private static final String LOG_TAG = "VintfObject";
    private static final String LOG_TAG = "VintfObject";


    /**
    /**
     * Slurps all device information (both manifests)
     * Slurps all device information (both manifests and both matrices)
     * and report it.
     * and report them.
     * If any error in getting one of the manifests, it is not included in
     * If any error in getting one of the manifests, it is not included in
     * the list.
     * the list.
     */
     */
    public static String[] report() {
    public static native String[] report();
        ArrayList<String> ret = new ArrayList<>();
        put(ret, getDeviceManifest(), "device manifest");
        put(ret, getFrameworkManifest(), "framework manifest");
        return ret.toArray(new String[0]);
    }


    /**
    /**
     * Verify that the given metadata for an OTA package is compatible with
     * Verify that the given metadata for an OTA package is compatible with
@@ -50,15 +45,4 @@ public class VintfObject {
     */
     */
    public static native int verify(String[] packageInfo);
    public static native int verify(String[] packageInfo);


    // return null if any error, otherwise XML string.
    private static native String getDeviceManifest();
    private static native String getFrameworkManifest();

    private static void put(ArrayList<String> list, String content, String message) {
        if (content == null || content.length() == 0) {
            Log.e(LOG_TAG, "Cannot get;" + message + "; check native logs for details.");
            return;
        }
        list.add(content);
    }
}
}
+44 −20
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2012 The Android Open Source Project
 * Copyright (C) 2017 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@


#define LOG_TAG "VintfObject"
#define LOG_TAG "VintfObject"
//#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#include <android-base/logging.h>

#include <vector>
#include <string>


#include <JNIHelp.h>
#include <JNIHelp.h>
#include <vintf/VintfObject.h>
#include <vintf/VintfObject.h>
@@ -23,31 +27,48 @@


#include "core_jni_helpers.h"
#include "core_jni_helpers.h"


static jclass gString;

namespace android {
namespace android {


using vintf::HalManifest;
using vintf::RuntimeInfo;
using vintf::VintfObject;
using vintf::VintfObject;
using vintf::gHalManifestConverter;
using vintf::gHalManifestConverter;
using vintf::gCompatibilityMatrixConverter;
using vintf::XmlConverter;


static jstring android_os_VintfObject_getDeviceManifest(JNIEnv* env, jclass clazz)
static inline jobjectArray toJavaStringArray(JNIEnv* env, const std::vector<std::string>& v) {
{
    jobjectArray ret = env->NewObjectArray(v.size(), gString, NULL /* init element */);
    const HalManifest *manifest = VintfObject::GetDeviceHalManifest();
    for (size_t i = 0; i < v.size(); ++i) {
    if (manifest == nullptr) {
        env->SetObjectArrayElement(ret, i, env->NewStringUTF(v[i].c_str()));
        return nullptr;
    }
    }
    std::string xml = gHalManifestConverter(*manifest);
    return ret;
    return env->NewStringUTF(xml.c_str());
}
}


static jstring android_os_VintfObject_getFrameworkManifest(JNIEnv* env, jclass clazz)
template<typename T>
{
static void tryAddSchema(const T* object, const XmlConverter<T>& converter,
    const HalManifest *manifest = VintfObject::GetFrameworkHalManifest();
        const std::string& description,
    if (manifest == nullptr) {
        std::vector<std::string>* cStrings) {
        return nullptr;
    if (object == nullptr) {
        LOG(WARNING) << __FUNCTION__ << "Cannot get " << description;
    } else {
        cStrings->push_back(converter(*object));
    }
}
}
    std::string xml = gHalManifestConverter(*manifest);

    return env->NewStringUTF(xml.c_str());
static jobjectArray android_os_VintfObject_report(JNIEnv* env, jclass clazz)
{
    std::vector<std::string> cStrings;

    tryAddSchema(VintfObject::GetDeviceHalManifest(), gHalManifestConverter,
            "device manifest", &cStrings);
    tryAddSchema(VintfObject::GetFrameworkHalManifest(), gHalManifestConverter,
            "framework manifest", &cStrings);
    tryAddSchema(VintfObject::GetDeviceCompatibilityMatrix(), gCompatibilityMatrixConverter,
            "device compatibility matrix", &cStrings);
    tryAddSchema(VintfObject::GetFrameworkCompatibilityMatrix(), gCompatibilityMatrixConverter,
            "framework compatibility matrix", &cStrings);

    return toJavaStringArray(env, cStrings);
}
}


static jint android_os_VintfObject_verify(JNIEnv *env, jclass clazz, jobjectArray packageInfo) {
static jint android_os_VintfObject_verify(JNIEnv *env, jclass clazz, jobjectArray packageInfo) {
@@ -66,15 +87,18 @@ static jint android_os_VintfObject_verify(JNIEnv *env, jclass clazz, jobjectArra
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


static const JNINativeMethod gVintfObjectMethods[] = {
static const JNINativeMethod gVintfObjectMethods[] = {
    {"getDeviceManifest",    "()Ljava/lang/String;",   (void*)android_os_VintfObject_getDeviceManifest},
    {"report", "()[Ljava/lang/String;", (void*)android_os_VintfObject_report},
    {"getFrameworkManifest", "()Ljava/lang/String;",   (void*)android_os_VintfObject_getFrameworkManifest},
    {"verify", "([Ljava/lang/String;)I", (void*)android_os_VintfObject_verify},
    {"verify", "([Ljava/lang/String;)I", (void*)android_os_VintfObject_verify},
};
};



const char* const kVintfObjectPathName = "android/os/VintfObject";
const char* const kVintfObjectPathName = "android/os/VintfObject";


int register_android_os_VintfObject(JNIEnv* env)
int register_android_os_VintfObject(JNIEnv* env)
{
{

    gString = MakeGlobalRefOrDie(env, FindClassOrDie(env, "java/lang/String"));

    return RegisterMethodsOrDie(env, kVintfObjectPathName, gVintfObjectMethods,
    return RegisterMethodsOrDie(env, kVintfObjectPathName, gVintfObjectMethods,
            NELEM(gVintfObjectMethods));
            NELEM(gVintfObjectMethods));
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -26,5 +26,8 @@ public class VintfObjectTest extends TestCase {
        // From /system/manifest.xml
        // From /system/manifest.xml
        assertTrue(String.join("", xmls).contains(
        assertTrue(String.join("", xmls).contains(
                "<manifest version=\"1.0\" type=\"framework\">"));
                "<manifest version=\"1.0\" type=\"framework\">"));
        // From /system/compatibility-matrix.xml
        assertTrue(String.join("", xmls).contains(
                "<compatibility-matrix version=\"1.0\" type=\"framework\">"));
    }
    }
}
}