Mobile Development 17 min read

Integrating Hardcoder Server into Android System: Build, Deploy, and Test

This article provides a step‑by‑step guide on compiling, deploying, and testing the Hardcoder server on Android, covering pre‑integration checks, property configuration, socket communication, JNI performance APIs, protobuf integration, build scripts, init scripts, and SELinux policies.

Coolpad Technology Team
Coolpad Technology Team
Coolpad Technology Team
Integrating Hardcoder Server into Android System: Build, Deploy, and Test

Hardcoder is an Android framework that enables apps to communicate directly with the system, allowing real‑time scheduling of low‑level hardware resources such as CPU, GPU, and core clusters, which improves performance in heavy scenarios like app launch and video sending.

The framework consists of a Server component running on the device firmware and a Client component packaged as an AAR library inside the app. The client sends resource‑request messages to the server, which then adjusts hardware settings; the server can also push system status back to the app.

Pre‑integration testing – Clone the Hardcoder source from https://github.com/Tencent/Hardcoder.git , build it with Android Studio, and locate the test APK, server binary, and required libc++_shared.so . Verify device support by checking the system property persist.sys.hardcoder.name . Set the property manually with:

adb shell setprop persist.sys.hardcoder.name coolsocket

Install testapp-debug.apk and press the “initHardCoder” button. The initial log shows a failed socket connection because the server is not running.

Starting the server – Push the server binary to /system/bin and the shared library to /system/lib64 , then launch it with the socket name:

adb shell server coolsocket

After the server starts, clicking “initHardCoder” again yields logs indicating a successful socket connection and the callback initHardCoder callback, isConnectSuccess:true .

JNI performance API testing – The app calls StartPerformance , which maps to JNI functions such as requestCpuHighFreq . Example implementation:

int requestCpuHighFreq(int scene, int64_t action, int level, int timeoutms, int callertid, int64_t timestamp) {
    pdbg("ManufacturerCoder requestCpuHighFreq scene:%d action:%d level:%d timeoutms:%d callertid:%d timestamp:%d", scene, TOINT(action), level, timeoutms, callertid, TOINT(timestamp/1000000L));
    return RET_OK;
}

Running the test button produces logs confirming the request was sent and processed by the server.

Integrating Hardcoder into the Android source tree – Build the server as part of the platform by adding protobuf (v3.1.0) sources, static libraries libcJSON and libamc_proto , and a binary target coolhcserver in an Android.bp file. Example snippets:

cc_binary {
  name: "coolhcserver",
  defaults: ["hcdefaults", "libprotobuf-cpp-lite-defaults-3.1.0"],
  shared_libs: ["liblog", "libc++_shared"],
  static_libs: ["libcJSON", "libamc_proto"],
  srcs: ["src/main/cpp/server.cpp"],
  local_include_dirs: ["build/generated/source/proto/cpp", "protobuf-3.1.0/src"],
  init_rc: ["rc/init.coolhcserver.rc"],
}

Define the system property in PRODUCT_PROPERTY_OVERRIDES :

PRODUCT_PROPERTY_OVERRIDES += \
  persist.sys.hardcoder.name=coolsocket

Create an init rc file to start the service:

service coolhcd /system/bin/coolhcserver
  class main
  user root
  socket coolsocket stream 660 root system

Update SELinux policies to allow execution and socket communication:

file_contexts
  /system/bin/coolhcserver     u:object_r:coolhcserver_exec:s0

coolhcserver.te
  type coolhcserver, domain, coredomain, mlstrustedsubject;
  type coolhcserver_exec, exec_type, file_type, system_file_type;
  init_daemon_domain(coolhcserver);

file_contexts
  /dev/socket/coolsocket      u:object_r:coolhcd_socket:s0

file.te
  type coolhcd_socket, file_type, coredomain_socket;

After adding the rc file to init.rc and rebuilding the system image, the server starts automatically on boot and establishes socket communication with the client.

In summary, the guide demonstrates how to compile Hardcoder, perform a manual pre‑integration test, embed the server into the Android build system, configure properties, init scripts, and SELinux, and finally verify that the JNI performance APIs work through end‑to‑end testing.

Performance OptimizationAndroidServerJNIsystem integrationHardcoder
Coolpad Technology Team
Written by

Coolpad Technology Team

Committed to advancing technology and supporting innovators. The Coolpad Technology Team regularly shares forward‑looking insights, product updates, and tech news. Tech experts are welcome to join; everyone is invited to follow us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.