RK3568 android 11 增加自定义API

这篇博客详细记录了如何在Android 11系统上针对RK3568处理器增加自定义API。通过一系列的代码修改,包括更新device.mk文件、frameworks中的API接口、Context类以及SystemServer等内容,实现了RockemdSmartApi服务,该服务提供了获取API版本号的功能。此外,还展示了如何在权限策略(sepolicy)中添加新服务的访问权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

commit 1516085b166501b98497f93c0aca3190a1692e95
Author: rockemd [email protected]
Date: Fri Oct 15 19:21:20 2021 +0800

add rockemdApi
make api-stubs-docs-update-current-api
make api-stubs-docs-non-updatable-update-current-api

diff --git a/device/rockchip/rk356x/device.mk b/device/rockchip/rk356x/device.mk
old mode 100644
new mode 100755
index 8b1fd0e…7a965b9
— a/device/rockchip/rk356x/device.mk
+++ b/device/rockchip/rk356x/device.mk
@@ -66,6 +66,7 @@ PRODUCT_COPY_FILES += vendor/rockchip/common/phone/etc/spn-conf.xml:system/etc/s
PRODUCT_PROPERTY_OVERRIDES +=
ro.product.ota.host = www.rockchip.com:2300
ro.vendor.sdkversion = $(CURRENT_SDK_VERSION) \

  • ro.product.apiversion = 1.0.0
    vendor.gralloc.disable_afbc = 0

PRODUCT_COPY_FILES +=
diff --git a/frameworks/base/api/current.txt b/frameworks/base/api/current.txt
old mode 100644
new mode 100755
index e909181…094de39
— a/frameworks/base/api/current.txt
+++ b/frameworks/base/api/current.txt
@@ -7613,6 +7613,21 @@ package android.app.blob {

}

+package android.app.rockemd {
+

  • public class RockemdSmartApi {
  • method @NonNull public String getApiVersion();
  • }

+}
+
package android.app.job {

public class JobInfo implements android.os.Parcelable {
@@ -10193,6 +10208,7 @@ package android.content {
field public static final String HARDWARE_PROPERTIES_SERVICE = “hardware_properties”;
field public static final String INPUT_METHOD_SERVICE = “input_method”;
field public static final String INPUT_SERVICE = “input”;

  • field public static final String ROCKEMD_SMARTAPI_SERVICE = “rockemdsmartapi”;
    field public static final String IPSEC_SERVICE = “ipsec”;
    field public static final String JOB_SCHEDULER_SERVICE = “jobscheduler”;
    field public static final String KEYGUARD_SERVICE = “keyguard”;
    diff --git a/frameworks/base/core/java/android/app/SystemServiceRegistry.java b/frameworks/base/core/java/android/app/SystemServiceRegistry.java
    old mode 100644
    new mode 100755
    index e599a5c…5868a2b
    — a/frameworks/base/core/java/android/app/SystemServiceRegistry.java
    +++ b/frameworks/base/core/java/android/app/SystemServiceRegistry.java
    @@ -43,6 +43,8 @@ import android.app.usage.IUsageStatsManager;
    import android.app.usage.NetworkStatsManager;
    import android.app.usage.StorageStatsManager;
    import android.app.usage.UsageStatsManager;
    +import android.app.rockemd.IRockemdSmartApi;
    +import android.app.rockemd.RockemdSmartApi;
    import android.appwidget.AppWidgetManager;
    import android.bluetooth.BluetoothManager;
    import android.companion.CompanionDeviceManager;
    @@ -786,6 +788,15 @@ public final class SystemServiceRegistry {
    return new UserManager(ctx, service);
    }});

  •    registerService(Context.ROCKEMD_SMARTAPI_SERVICE, RockemdSmartApi.class,
    
  •            new CachedServiceFetcher<RockemdSmartApi>() {
    
  •        @Override
    
  •        public RockemdSmartApi createService(ContextImpl ctx) {
    
  •            IBinder b = ServiceManager.getService(Context.ROCKEMD_SMARTAPI_SERVICE);
    
  •            IRockemdSmartApi service = IRockemdSmartApi.Stub.asInterface(b);
    
  •            return new RockemdSmartApi(ctx, service);
    
  •        }});
    
  •    registerService(Context.APP_OPS_SERVICE, AppOpsManager.class,
               new CachedServiceFetcher<AppOpsManager>() {
           @Override
    

diff --git a/frameworks/base/core/java/android/app/rockemd/IRockemdSmartApi.aidl b/frameworks/base/core/java/android/app/rockemd/IRockemdSmartApi.aidl
new file mode 100755
index 0000000…e0861de
— /dev/null
+++ b/frameworks/base/core/java/android/app/rockemd/IRockemdSmartApi.aidl
@@ -0,0 +1,14 @@
+package android.app.rockemd;
+
+/** {@hide} */
+interface IRockemdSmartApi
+{

  • String getApiVersion();
    +}
    \ No newline at end of file
    diff --git a/frameworks/base/core/java/android/app/rockemd/RockemdSmartApi.java b/frameworks/base/core/java/android/app/rockemd/RockemdSmartApi.java
    new file mode 100755
    index 0000000…79c2422
    — /dev/null
    +++ b/frameworks/base/core/java/android/app/rockemd/RockemdSmartApi.java
    @@ -0,0 +1,115 @@
    +package android.app.rockemd;

+import android.content.Context;
+import android.os.RemoteException;
+import android.util.Slog;
+
+import android.annotation.SystemService;
+import android.annotation.SystemApi;
+import android.annotation.NonNull;
+
+import java.util.Objects;
+
+@SystemService(Context.ROCKEMD_SMARTAPI_SERVICE)
+public class RockemdSmartApi {

  • private final Context mContext;
  • private final IRockemdSmartApi mService;
  • /** {@hide} */
  • public RockemdSmartApi(Context context, IRockemdSmartApi service) {
  •    mContext = Objects.requireNonNull(context);
    
  •    mService = Objects.requireNonNull(service);
    
  • }
  • @NonNull
  • public String getApiVersion() {
  •    if (mService != null) {
    
  •        try {
    
  •            return mService.getApiVersion();
    
  •        } catch (RemoteException e) {
    
  •            Slog.e("getApiVersion", "RemoteException " + e);
    
  •        }
    
  •    }
    
  •    return null;
    
  • }

+}
\ No newline at end of file
diff --git a/frameworks/base/core/java/android/content/Context.java b/frameworks/base/core/java/android/content/Context.java
old mode 100644
new mode 100755
index 8472144…c346ebc
— a/frameworks/base/core/java/android/content/Context.java
+++ b/frameworks/base/core/java/android/content/Context.java
@@ -3421,6 +3421,7 @@ public abstract class Context {
WIFI_RTT_RANGING_SERVICE,
NSD_SERVICE,
AUDIO_SERVICE,

  •        ROCKEMD_SMARTAPI_SERVICE,
           AUTH_SERVICE,
           FINGERPRINT_SERVICE,
           //@hide: FACE_SERVICE,
    

@@ -3944,6 +3945,12 @@ public abstract class Context {
public static final String VIBRATOR_SERVICE = “vibrator”;

 /**
  • * ROCKEMD_SMARTAPI_SERVICE
    
  • */
    
  • @SuppressLint(“ServiceName”)
  • public static final String ROCKEMD_SMARTAPI_SERVICE = “rockemdsmartapi”;
  • /**
    • Use with {@link #getSystemService(String)} to retrieve a {@link
    • android.app.StatusBarManager} for interacting with the status bar.

diff --git a/frameworks/base/non-updatable-api/current.txt b/frameworks/base/non-updatable-api/current.txt
old mode 100644
new mode 100755
index f0d6871…8e93bca
— a/frameworks/base/non-updatable-api/current.txt
+++ b/frameworks/base/non-updatable-api/current.txt
@@ -7613,6 +7613,21 @@ package android.app.blob {

}

+package android.app.rockemd {
+

  • public class RockemdSmartApi {
  • method @NonNull public String getApiVersion();
  • }

+}
+
package android.app.job {

public class JobInfo implements android.os.Parcelable {
@@ -10193,6 +10208,7 @@ package android.content {
field public static final String HARDWARE_PROPERTIES_SERVICE = “hardware_properties”;
field public static final String INPUT_METHOD_SERVICE = “input_method”;
field public static final String INPUT_SERVICE = “input”;

  • field public static final String ROCKEMD_SMARTAPI_SERVICE = “rockemdsmartapi”;
    field public static final String IPSEC_SERVICE = “ipsec”;
    field public static final String JOB_SCHEDULER_SERVICE = “jobscheduler”;
    field public static final String KEYGUARD_SERVICE = “keyguard”;
    diff --git a/frameworks/base/services/core/java/com/android/server/rockemd/RockemdSmartApiService.java b/frameworks/base/services/core/java/com/android/server/rockemd/RockemdSmartApiService.java
    new file mode 100755
    index 0000000…86c0c33
    — /dev/null
    +++ b/frameworks/base/services/core/java/com/android/server/rockemd/RockemdSmartApiService.java
    @@ -0,0 +1,167 @@
    +package com.android.server.rockemd;

+import android.app.rockemd.IRockemdSmartApi;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserHandle;
+import android.os.SystemProperties;
+import android.util.Slog;
+import java.util.List;
+import android.content.Intent;
+import android.app.ActivityManager;
+import android.provider.Settings;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class RockemdSmartApiService extends IRockemdSmartApi.Stub {

  • private Context mContext;
  • private static final String TAG = “RockemdSmartApiService”;
  • public static final boolean DEBUG = true;
  • public RockemdSmartApiService(Context context) {
  •    mContext = context;
    
  •    Slog.d(TAG, "================RockemdSmartApiService=======================");
    
  • }
  • /*
    • getApiVersion
  • */
  • public String getApiVersion() {
  •    if (DEBUG)
    
  •        Slog.d(TAG, "===================getApiVersion==================");
    
  •    String Version = SystemProperties.get("ro.product.apiversion");
    
  •    return Version;
    
  • }

+}
\ No newline at end of file
diff --git a/frameworks/base/services/java/com/android/server/SystemServer.java b/frameworks/base/services/java/com/android/server/SystemServer.java
index 72ebc90…c4fee60 100755
— a/frameworks/base/services/java/com/android/server/SystemServer.java
+++ b/frameworks/base/services/java/com/android/server/SystemServer.java
@@ -180,6 +180,7 @@ import com.android.server.webkit.WebViewUpdateService;
import com.android.server.wm.ActivityTaskManagerService;
import com.android.server.wm.WindowManagerGlobalLock;
import com.android.server.wm.WindowManagerService;
+import com.android.server.rockemd.RockemdSmartApiService;

import dalvik.system.VMRuntime;

@@ -1132,6 +1133,12 @@ public final class SystemServer {
mSystemServiceManager.startService(DropBoxManagerService.class);
t.traceEnd();

  •        /* pengbin */
    
  •        t.traceBegin("Startrockemdsmartapi");
    
  •        ServiceManager.addService(Context.ROCKEMD_SMARTAPI_SERVICE, new RockemdSmartApiService(context));
    
  •        t.traceEnd();
    
  •        /* pengbin */
    
  •        t.traceBegin("StartVibratorService");
           vibrator = new VibratorService(context);
           ServiceManager.addService("vibrator", vibrator);
    

diff --git a/system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil b/system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil
old mode 100644
new mode 100755
index 2ed4efa…ad8a456
— a/system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil
+++ b/system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil
@@ -17,11 +17,11 @@
(typeattributeset property_type (asan_reboot_prop_26_0 audio_prop_26_0 boottime_prop_26_0 bluetooth_prop_26_0 config_prop_26_0 cppreopt_prop_26_0 ctl_bootanim_prop_26_0 ctl_bugreport_prop_26_0 ctl_console_prop_26_0 ctl_default_prop_26_0 ctl_dumpstate_prop_26_0 ctl_fuse_prop_26_0 ctl_mdnsd_prop_26_0 ctl_rildaemon_prop_26_0 dalvik_prop_26_0 debuggerd_prop_26_0 debug_prop_26_0 default_prop_26_0 device_logging_prop_26_0 dhcp_prop_26_0 dumpstate_options_prop_26_0 dumpstate_prop_26_0 ffs_prop_26_0 fingerprint_prop_26_0 firstboot_prop_26_0 hwservicemanager_prop_26_0 logd_prop_26_0 logpersistd_logging_prop_26_0 log_prop_26_0 log_tag_prop_26_0 mmc_prop_26_0 net_dns_prop_26_0 net_radio_prop_26_0 nfc_prop_26_0 overlay_prop_26_0 pan_result_prop_26_0 persist_debug_prop_26_0 persistent_properties_ready_prop_26_0 powerctl_prop_26_0 radio_prop_26_0 restorecon_prop_26_0 safemode_prop_26_0 serialno_prop_26_0 shell_prop_26_0 system_prop_26_0 system_radio_prop_26_0 vold_prop_26_0 wifi_log_prop_26_0 wifi_prop_26_0))
(typeattributeset core_property_type (audio_prop_26_0 config_prop_26_0 cppreopt_prop_26_0 dalvik_prop_26_0 debuggerd_prop_26_0 debug_prop_26_0 default_prop_26_0 dhcp_prop_26_0 dumpstate_prop_26_0 ffs_prop_26_0 fingerprint_prop_26_0 logd_prop_26_0 net_radio_prop_26_0 nfc_prop_26_0 pan_result_prop_26_0 persist_debug_prop_26_0 powerctl_prop_26_0 radio_prop_26_0 restorecon_prop_26_0 shell_prop_26_0 system_prop_26_0 system_radio_prop_26_0 vold_prop_26_0))
(typeattributeset log_property_type (log_prop_26_0 log_tag_prop_26_0 wifi_log_prop_26_0))
-(typeattributeset system_server_service (accessibility_service_26_0 account_service_26_0 activity_service_26_0 alarm_service_26_0 appops_service_26_0 appwidget_service_26_0 assetatlas_service_26_0 audio_service_26_0 autofill_service_26_0 backup_service_26_0 batterystats_service_26_0 battery_service_26_0 bluetooth_manager_service_26_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

android framework

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值