Merge "Update codelab system app to use native code" into main am: 481b4c64f4
Original change: https://android-review.googlesource.com/c/platform/development/+/2712093 Change-Id: I8acae6bd21cb0ee1d504eacaa672df4e20dbfa14 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -8,13 +8,16 @@ android_app {
|
||||
srcs: [
|
||||
"src/**/*.java"
|
||||
],
|
||||
platform_apis: true,
|
||||
certificate: "platform",
|
||||
sdk_version: "current",
|
||||
static_libs: [
|
||||
"ContentLibs",
|
||||
"dagger2",
|
||||
"jsr330",
|
||||
],
|
||||
jni_libs: [
|
||||
"libexample_cpp_lib",
|
||||
],
|
||||
optimize: {
|
||||
enabled: true,
|
||||
proguard_compatibility: false,
|
||||
@@ -35,7 +38,7 @@ aconfig_declarations {
|
||||
|
||||
|
||||
java_aconfig_library {
|
||||
name: "aconfig_demo_flags_lib",
|
||||
name: "aconfig_demo_flags_java_lib",
|
||||
aconfig_declarations: "aconfig_demo_flags",
|
||||
}
|
||||
|
||||
@@ -53,7 +56,34 @@ java_library {
|
||||
],
|
||||
sdk_version: "current",
|
||||
static_libs: [
|
||||
"aconfig_demo_flags_lib",
|
||||
"aconfig_demo_flags_java_lib",
|
||||
],
|
||||
libs: ["jsr330"],
|
||||
}
|
||||
|
||||
cc_aconfig_library {
|
||||
name: "aconfig_demo_flags_c_lib",
|
||||
aconfig_declarations: "aconfig_demo_flags",
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "libexample_cpp_lib",
|
||||
srcs: ["src/example_cpp_lib.cc"],
|
||||
double_loadable: true,
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-unused-function",
|
||||
"-Wno-unused-parameter",
|
||||
],
|
||||
header_libs: [
|
||||
"jni_headers",
|
||||
],
|
||||
shared_libs: [
|
||||
"server_configurable_flags",
|
||||
],
|
||||
static_libs: [
|
||||
"aconfig_demo_flags_c_lib",
|
||||
],
|
||||
export_include_dirs: ["src/include"],
|
||||
}
|
||||
|
||||
@@ -28,6 +28,13 @@ flag {
|
||||
bug: "287644619"
|
||||
}
|
||||
|
||||
flag {
|
||||
name: "fifth_flag"
|
||||
namespace: "configuration"
|
||||
description: "The fifth flag, added right after the first three flags."
|
||||
bug: "287644619"
|
||||
}
|
||||
|
||||
flag {
|
||||
name: "third_flag"
|
||||
namespace: "configuration"
|
||||
|
||||
@@ -43,13 +43,16 @@ public class AconfigDemoActivity extends Activity {
|
||||
|
||||
setContentView(R.layout.main);
|
||||
TextView simpleTextView = (TextView) findViewById(R.id.simpleTextView);
|
||||
simpleTextView.setText("Show Flags: \n\n");
|
||||
simpleTextView.setText("Show Java Flags: \n\n");
|
||||
|
||||
StaticContent cp = new StaticContent();
|
||||
simpleTextView.append(cp.getContent());
|
||||
|
||||
simpleTextView.append(injectedContent.getContent());
|
||||
|
||||
simpleTextView.append("Show C/C++ Flags: \n\n");
|
||||
simpleTextView.append(printCFlag());
|
||||
|
||||
if (Flags.awesomeFlag1()) {
|
||||
Log.v("AconfigDemoActivity", Flags.FLAG_AWESOME_FLAG_1 + " is on!");
|
||||
}
|
||||
@@ -58,5 +61,10 @@ public class AconfigDemoActivity extends Activity {
|
||||
Log.v("AconfigDemoActivity", Flags.FLAG_AWESOME_FLAG_2 + " is on!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public native String printCFlag();
|
||||
|
||||
static {
|
||||
System.loadLibrary("example_cpp_lib");
|
||||
}
|
||||
}
|
||||
|
||||
34
samples/AconfigDemo/src/example_cpp_lib.cc
Normal file
34
samples/AconfigDemo/src/example_cpp_lib.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "example_cpp_lib.h"
|
||||
#include <string>
|
||||
#include <com_example_android_aconfig_demo_flags.h>
|
||||
|
||||
namespace demo_flags = com::example::android::aconfig::demo::flags;
|
||||
|
||||
// use static methods interface
|
||||
static std::string get_flag_via_static_interface() {
|
||||
return std::string("flag value : ") +
|
||||
(demo_flags::append_static_content() ? "true" : "false");
|
||||
}
|
||||
|
||||
// use flag provider for injection interface
|
||||
static std::string get_flag_via_injection_interface(
|
||||
demo_flags::flag_provider_interface* provider) {
|
||||
return std::string("flag value : ") +
|
||||
((provider->append_injected_content()) ? "true" : "false");
|
||||
}
|
||||
|
||||
jstring Java_com_example_android_aconfig_demo_AconfigDemoActivity_printCFlag(
|
||||
JNIEnv* env,
|
||||
jobject thiz) {
|
||||
auto result = std::string("flag name : append_static_content\n");
|
||||
result += "use pattern : static method\n";
|
||||
result += get_flag_via_static_interface();
|
||||
|
||||
result += "\n\n";
|
||||
|
||||
result += "flag name : append_injected_content\n";
|
||||
result += "use pattern : injection\n";
|
||||
result += get_flag_via_injection_interface(demo_flags::provider_.get());
|
||||
|
||||
return env->NewStringUTF(result.c_str());
|
||||
}
|
||||
7
samples/AconfigDemo/src/include/example_cpp_lib.h
Normal file
7
samples/AconfigDemo/src/include/example_cpp_lib.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
extern "C" jstring Java_com_example_android_aconfig_demo_AconfigDemoActivity_printCFlag(
|
||||
JNIEnv* env,
|
||||
jobject thiz);
|
||||
Reference in New Issue
Block a user