Split vnd.fwk_detect modules into vendor project
Change-Id: I6377d09bf4fc6f299f80701563e97439cea31214
CRs-Fixed: 2933750
diff --git a/fwk-detect/Android.bp b/fwk-detect/Android.bp
new file mode 100755
index 0000000..db821be
--- /dev/null
+++ b/fwk-detect/Android.bp
@@ -0,0 +1,54 @@
+cc_library_shared {
+ name: "libqti_vndfwk_detect_vendor",
+ srcs: ["vndfwk-detect.c"],
+ shared_libs: ["libcutils"],
+ vendor: true,
+ export_include_dirs: ["."],
+
+ compile_multilib: "both",
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+}
+
+cc_test {
+ name: "vndfwk-test-vendor",
+ srcs: ["vndfwk-test.c"],
+ shared_libs: ["libqti_vndfwk_detect_vendor"],
+ vendor: true,
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+}
+
+cc_library_shared {
+ name: "libvndfwk_detect_jni.qti_vendor",
+ srcs: ["jni/com_qualcomm_qti_VndFwkDetect.cpp"],
+ shared_libs: [
+ "libqti_vndfwk_detect_vendor",
+ "libcutils",
+ "libutils",
+ "liblog",
+ ],
+ include_dirs: [
+ ".",
+ ],
+ header_libs: [
+ "jni_headers",
+ ],
+ vendor: true,
+ compile_multilib: "both",
+
+ cflags: [
+ "-Wno-unused-parameter",
+ ],
+}
+
+java_library_static {
+ name: "vndfwk.detect_vendor",
+ srcs: ["src/**/*.java"],
+ sdk_version: "current",
+}
diff --git a/fwk-detect/jni/com_qualcomm_qti_VndFwkDetect.cpp b/fwk-detect/jni/com_qualcomm_qti_VndFwkDetect.cpp
new file mode 100755
index 0000000..68bfcb3
--- /dev/null
+++ b/fwk-detect/jni/com_qualcomm_qti_VndFwkDetect.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define LOG_TAG "VndFwkDetectJNI"
+
+#include "vndfwk-detect.h"
+
+#include "jni.h"
+#include <dlfcn.h>
+#include <string.h>
+#include <android/log.h>
+#include <utils/Log.h>
+#include <utils/misc.h>
+
+#define VNDFWK_DETECT_LIB "libqti_vndfwk_detect.so"
+
+typedef struct dlHandler {
+ void *dlHandle;
+ int (*vndFwkDetect)(void);
+ int (*vndEnhancedInfo)(void);
+ const char *dlName;
+} dlHandler;
+
+static dlHandler mDlHandler = {
+ NULL, NULL, NULL, VNDFWK_DETECT_LIB};
+
+static void
+com_qualcomm_qti_VndFwkDetect_init()
+{
+ mDlHandler.dlHandle = dlopen(VNDFWK_DETECT_LIB, RTLD_NOW | RTLD_LOCAL);
+ if (mDlHandler.dlHandle == NULL) return;
+
+ *(void **)(&mDlHandler.vndFwkDetect) = dlsym(mDlHandler.dlHandle, "isRunningWithVendorEnhancedFramework");
+ if (mDlHandler.vndFwkDetect == NULL)
+ {
+ if (mDlHandler.dlHandle)
+ {
+ dlclose(mDlHandler.dlHandle);
+ mDlHandler.dlHandle = NULL;
+ }
+
+ return;
+ }
+
+ *(void **)(&mDlHandler.vndEnhancedInfo) = dlsym(mDlHandler.dlHandle, "getVendorEnhancedInfo");
+ if (mDlHandler.vndEnhancedInfo == NULL)
+ {
+ if (mDlHandler.dlHandle)
+ {
+ dlclose(mDlHandler.dlHandle);
+ mDlHandler.dlHandle = NULL;
+ }
+ }
+
+ return;
+}
+
+static int
+com_qualcomm_qti_VndFwkDetect_native_isRunningWithVendorEnhancedFramework(JNIEnv *env, jobject clazz)
+{
+ if(mDlHandler.vndFwkDetect != NULL)
+ return (*mDlHandler.vndFwkDetect)();
+
+ return 0;
+}
+
+
+static int
+com_qualcomm_qti_VndFwkDetect_native_getVendorEnhancedInfo(JNIEnv *env, jobject clazz)
+{
+ if(mDlHandler.vndEnhancedInfo != NULL)
+ return (*mDlHandler.vndEnhancedInfo)();
+
+ return 0;
+}
+static JNINativeMethod gMethods[] = {
+ {"native_isRunningWithVendorEnhancedFramework", "()I", (int*)com_qualcomm_qti_VndFwkDetect_native_isRunningWithVendorEnhancedFramework},
+ {"native_getVendorEnhancedInfo", "()I", (int*)com_qualcomm_qti_VndFwkDetect_native_getVendorEnhancedInfo}
+};
+
+/*
+ * JNI initialization
+ */
+jint JNI_OnLoad(JavaVM *jvm, void *reserved)
+{
+ JNIEnv *e;
+ jclass clazz = 0;
+ int status;
+
+ ALOGV("com.qualcomm.qti.VndFwkDetect: loading JNI\n");
+
+ // check JNI version
+ if (jvm->GetEnv((void**)&e, JNI_VERSION_1_6)) {
+ ALOGE("com.qualcomm.qti.VndFwkDetect: JNI version mismatch error");
+ return JNI_ERR;
+ }
+
+ clazz = e->FindClass("com/qualcomm/qti/VndFwkDetect");
+ if((jclass)0 == clazz) {
+ ALOGE("JNI_OnLoad: FindClass failed");
+ return JNI_ERR;
+ }
+
+ com_qualcomm_qti_VndFwkDetect_init();
+
+ if ((status = e->RegisterNatives(clazz, gMethods, NELEM(gMethods))) < 0) {
+ ALOGE("com.qualcomm.qti.VndFwkDetect: jni registration failure: %d", status);
+ return JNI_ERR;
+ }
+
+ return JNI_VERSION_1_6;
+}
diff --git a/fwk-detect/src/com/qualcomm/qti/VndFwkDetect.java b/fwk-detect/src/com/qualcomm/qti/VndFwkDetect.java
new file mode 100755
index 0000000..0a96a0a
--- /dev/null
+++ b/fwk-detect/src/com/qualcomm/qti/VndFwkDetect.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.qualcomm.qti;
+
+import android.util.Log;
+
+public class VndFwkDetect
+{
+ private static final String TAG = "VndFwkDetect";
+
+ static {
+ try {
+ System.loadLibrary("vndfwk_detect_jni.qti");
+ } catch (Exception ex) {
+ Log.d(TAG, "Cannot load libvndfwk_detect_jni.qti shared library!!!");
+ ex.printStackTrace();
+ }
+ }
+
+ public VndFwkDetect() {
+ }
+
+ public int isRunningWithVendorEnhancedFramework() {
+ return native_isRunningWithVendorEnhancedFramework();
+ }
+
+ public int getVendorEnhancedInfo() {
+ return native_getVendorEnhancedInfo();
+ }
+
+ private native int native_isRunningWithVendorEnhancedFramework();
+ private native int native_getVendorEnhancedInfo();
+}
diff --git a/fwk-detect/vndfwk-detect.c b/fwk-detect/vndfwk-detect.c
new file mode 100755
index 0000000..1ff1aa7
--- /dev/null
+++ b/fwk-detect/vndfwk-detect.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <cutils/properties.h>
+
+#include "vndfwk-detect.h"
+
+#define VALUEADD_AOSP_SUPPORT_PROPERTY "ro.vendor.qti.va_aosp.support"
+#define VALUEADD_ODM_SUPPORT_PROPERTY "ro.vendor.qti.va_odm.support"
+#define VND_ENHANCED_ODM_STATUS_BIT 0x01
+#define VND_ENHANCED_SYS_STATUS_BIT 0x02
+
+int isRunningWithVendorEnhancedFramework() {
+ bool va_aosp_support = false;
+ va_aosp_support = property_get_bool(VALUEADD_AOSP_SUPPORT_PROPERTY, false);
+
+ if (va_aosp_support)
+ return 1;
+
+ return 0;
+}
+
+/*
+ * int getVendorEnhancedInfo(void)
+ * return val(int32_t):
+ * bit0: for ODM status
+ * =>0: PureAOSP Building
+ * =>1: QC VA Building
+ *
+ * bit1: for System status
+ * =>0: PureAOSP Building
+ * =>1: QC VA Building
+ */
+int getVendorEnhancedInfo() {
+ int val = 0;
+ bool va_odm_support = false;
+ va_odm_support = property_get_bool(VALUEADD_ODM_SUPPORT_PROPERTY, false);
+
+ if (va_odm_support) {
+ val |= VND_ENHANCED_ODM_STATUS_BIT;
+ }
+
+ if (1 == isRunningWithVendorEnhancedFramework()) {
+ val |= VND_ENHANCED_SYS_STATUS_BIT;
+ }
+
+ return val;
+}
diff --git a/fwk-detect/vndfwk-detect.h b/fwk-detect/vndfwk-detect.h
new file mode 100755
index 0000000..6a26394
--- /dev/null
+++ b/fwk-detect/vndfwk-detect.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __VNDFWK_DETECT_H__
+#define __VNDFWK_DETECT_H__
+// return 1 on enhanced AOSP framework; 0 otherwise
+int isRunningWithVendorEnhancedFramework(void);
+int getVendorEnhancedInfo(void);
+
+#endif // __VNDFWK_DETECT_H__
diff --git a/fwk-detect/vndfwk-test.c b/fwk-detect/vndfwk-test.c
new file mode 100755
index 0000000..4f91f26
--- /dev/null
+++ b/fwk-detect/vndfwk-test.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "vndfwk-detect.h"
+
+int main()
+{
+ printf("The framework is %s AOSP\n",
+ (isRunningWithVendorEnhancedFramework() ?
+ "enhanced" : "unmodified"));
+ printf("The value of vendor enhanced info: %d\n",
+ getVendorEnhancedInfo());
+
+ return 0;
+}