Merge changes from topic 'vintf_check_compat_native'
* changes: Update for removing mount arg to VintfObject::CheckCompatibility Add Java API for libvintf.
This commit is contained in:
64
core/java/android/os/VintfObject.java
Normal file
64
core/java/android/os/VintfObject.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/** @hide */
|
||||
public class VintfObject {
|
||||
|
||||
private static final String LOG_TAG = "VintfObject";
|
||||
|
||||
/**
|
||||
* Slurps all device information (both manifests)
|
||||
* and report it.
|
||||
* If any error in getting one of the manifests, it is not included in
|
||||
* the list.
|
||||
*/
|
||||
public static 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
|
||||
* this device.
|
||||
*
|
||||
* @param packageInfo a list of serialized form of HalMaanifest's /
|
||||
* CompatibilityMatri'ces (XML).
|
||||
* @return = 0 if success (compatible)
|
||||
* > 0 if incompatible
|
||||
* < 0 if any error (mount partition fails, illformed XML, etc.)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,7 @@ LOCAL_SRC_FILES:= \
|
||||
android_os_SystemProperties.cpp \
|
||||
android_os_Trace.cpp \
|
||||
android_os_UEventObserver.cpp \
|
||||
android_os_VintfObject.cpp \
|
||||
android_net_LocalSocketImpl.cpp \
|
||||
android_net_NetUtils.cpp \
|
||||
android_net_TrafficStats.cpp \
|
||||
|
||||
@@ -164,6 +164,7 @@ extern int register_android_os_HwRemoteBinder(JNIEnv *env);
|
||||
extern int register_android_os_MessageQueue(JNIEnv* env);
|
||||
extern int register_android_os_Parcel(JNIEnv* env);
|
||||
extern int register_android_os_SELinux(JNIEnv* env);
|
||||
extern int register_android_os_VintfObject(JNIEnv *env);
|
||||
extern int register_android_os_seccomp(JNIEnv* env);
|
||||
extern int register_android_os_SystemProperties(JNIEnv *env);
|
||||
extern int register_android_os_SystemClock(JNIEnv* env);
|
||||
@@ -1306,6 +1307,7 @@ static const RegJNIRec gRegJNI[] = {
|
||||
REG_JNI(register_android_os_HwBlob),
|
||||
REG_JNI(register_android_os_HwParcel),
|
||||
REG_JNI(register_android_os_HwRemoteBinder),
|
||||
REG_JNI(register_android_os_VintfObject),
|
||||
REG_JNI(register_android_nio_utils),
|
||||
REG_JNI(register_android_graphics_Canvas),
|
||||
REG_JNI(register_android_graphics_Graphics),
|
||||
|
||||
82
core/jni/android_os_VintfObject.cpp
Normal file
82
core/jni/android_os_VintfObject.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "VintfObject"
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include <JNIHelp.h>
|
||||
#include <vintf/VintfObject.h>
|
||||
#include <vintf/parse_xml.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
using vintf::HalManifest;
|
||||
using vintf::RuntimeInfo;
|
||||
using vintf::VintfObject;
|
||||
using vintf::gHalManifestConverter;
|
||||
|
||||
static jstring android_os_VintfObject_getDeviceManifest(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
const HalManifest *manifest = VintfObject::GetDeviceHalManifest();
|
||||
if (manifest == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string xml = gHalManifestConverter(*manifest);
|
||||
return env->NewStringUTF(xml.c_str());
|
||||
}
|
||||
|
||||
static jstring android_os_VintfObject_getFrameworkManifest(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
const HalManifest *manifest = VintfObject::GetFrameworkHalManifest();
|
||||
if (manifest == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string xml = gHalManifestConverter(*manifest);
|
||||
return env->NewStringUTF(xml.c_str());
|
||||
}
|
||||
|
||||
static jint android_os_VintfObject_verify(JNIEnv *env, jclass clazz, jobjectArray packageInfo) {
|
||||
size_t count = env->GetArrayLength(packageInfo);
|
||||
std::vector<std::string> cPackageInfo{count};
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
jstring element = (jstring)env->GetObjectArrayElement(packageInfo, i);
|
||||
const char *cString = env->GetStringUTFChars(element, NULL /* isCopy */);
|
||||
cPackageInfo[i] = cString;
|
||||
env->ReleaseStringUTFChars(element, cString);
|
||||
}
|
||||
int32_t status = VintfObject::CheckCompatibility(cPackageInfo);
|
||||
return status;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static const JNINativeMethod gVintfObjectMethods[] = {
|
||||
{"getDeviceManifest", "()Ljava/lang/String;", (void*)android_os_VintfObject_getDeviceManifest},
|
||||
{"getFrameworkManifest", "()Ljava/lang/String;", (void*)android_os_VintfObject_getFrameworkManifest},
|
||||
{"verify", "([Ljava/lang/String;)I", (void*)android_os_VintfObject_verify},
|
||||
};
|
||||
|
||||
const char* const kVintfObjectPathName = "android/os/VintfObject";
|
||||
|
||||
int register_android_os_VintfObject(JNIEnv* env)
|
||||
{
|
||||
return RegisterMethodsOrDie(env, kVintfObjectPathName, gVintfObjectMethods,
|
||||
NELEM(gVintfObjectMethods));
|
||||
}
|
||||
|
||||
};
|
||||
30
core/tests/coretests/src/android/os/VintfObjectTest.java
Normal file
30
core/tests/coretests/src/android/os/VintfObjectTest.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class VintfObjectTest extends TestCase {
|
||||
public void testReport() {
|
||||
String[] xmls = VintfObject.report();
|
||||
assertTrue(xmls.length > 0);
|
||||
// From /system/manifest.xml
|
||||
assertTrue(String.join("", xmls).contains(
|
||||
"<manifest version=\"1.0\" type=\"framework\">"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user