android10 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务

android10 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务,第1张

学习总纲: Android10 硬件抽象层(HAL)概要介绍和学习计划 编写环境:
   - android 版本 - android-10.0.0_r41
   - 架构 - aosp_x86_64-eng
   - 内核分支:android-goldfish-4.14-gchips
参考资源
 罗升阳:https://blog.csdn.net/luoshengyang/article/details/6568411
 其他: https://blog.csdn.net/qq1045553189/article/details/121145529
       https://blog.csdn.net/zhaojigao/article/details/106487673
修改如下:

修改…/frameworks/base目录下的Android.bp
然后执行 mmm ./frameworks/base/core/java/android/os/
注意:千万别执行mmm ./frameworks/base,这个命令会将base中的所有文件都编译一遍,会导致一些多余Apk,导致。。。


在/frameworks/base/services/ core /java/com/android/server目录下新建HelloService.java文件 (添加了一些日志)

package com.android.server;
import android.content.Context;
import android.os.IHelloService;
import android.util.Slog;
public class HelloService extends IHelloService.Stub {
    private static final String TAG = "HelloService";
    HelloService() {
        Slog.i(TAG, "init_native");
        init_native();
    }
    public void setVal(int val) {
        Slog.i(TAG, "setVal =" +val);
	setVal_native(val);
    }	

    public int getVal() {
        Slog.i(TAG, "getVal");
	return getVal_native();
    }
	
    private static native boolean init_native();
    private static native void setVal_native(int val);
    private static native int getVal_native();
};

修改/frameworks/base/services/java/com/android/server/SystemServer.java文件,如下:

import com.android.server.HelloService;

traceBeginAndSlog("StartHelloService");
try {
    ServiceManager.addService("hello", new HelloService());
} catch (Throwable e) {
    reportWtf("starting HelloService", e);
}
traceEnd();

--------------------------------------------------------------------------------------------------------

添加selinux权限

./system/sepolicy/public/property_contexts
./system/sepolicy/prebuilts/api/28.0/public/property_contexts
./system/sepolicy/prebuilts/api/29.0/public/property_contexts

上面三个文件添加下面内容:

ro.hardware.hello u:object_r:exported_default_prop:s0 exact int

修改service_contexts和service.te文件

./system/sepolicy/private/service_contexts
./system/sepolicy/public/service.te

./system/sepolicy/prebuilts/api/26.0/private/service_contexts
./system/sepolicy/prebuilts/api/26.0/public/service.te

./system/sepolicy/prebuilts/api/27.0/private/service_contexts
./system/sepolicy/prebuilts/api/27.0/public/service.te

./system/sepolicy/prebuilts/api/28.0/private/service_contexts
./system/sepolicy/prebuilts/api/28.0/public/service.te

./system/sepolicy/prebuilts/api/29.0/private/service_contexts
./system/sepolicy/prebuilts/api/29.0/public/service.te

所有的 service_contexts文件添加一行

hello                                     u:object_r:hello_service:s0

所有的 service.te文件添加一行

type hello_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;

mmm frameworks/base/services/core/java
make snod
make -j8

启动成功:

问题记录:

AndroidRuntime: java.lang.IllegalStateException: Signature|privileged permissions not in privapp-permissions whitelist: {com.android.systemui: android.permission.MANAGE_DEBUGGING, com.android.systemui: android.permission.CONTROL_VPN, com.android.systemui: android.permission.START_TASKS_FROM_RECENTS, com.android.systemui: android.permission.STATUS_BAR, com.android.systemui: android.permission.GET_APP_OPS_STATS, com.android.systemui: android.permission.CONTROL_KEYGUARD_SECURE_NOTIFICATIONS, com.android.systemui: android.permission.MOUNT_UNMOUNT_FILESYSTEMS, com.android.statsd.dogfood: android.permission.DUMP, com.android.systemui: android.permission.USE_RESERVED_DISK, com.android.systemui: android.permission.CONNECTIVITY_INTERNAL, com.android.systemui: android.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, com.android.systemui: android.permission.WRITE_MEDIA_STORAGE, com.android.systemui: android.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS, com.android.systemui: android.permission.READ_DREAM_STATE, com.android.systemui: android.permission.CHANGE_COMPONENT_ENABLED_STATE, com.android.systemui: android.permission.MODIFY_PHONE_STATE, com.android.systemui: android.permission.CHANGE_OVERLAY_PACKAGES, com.android.systemui: android.permission.MEDIA_CONTENT_CONTROL, com.android.systemui: android.permission.STOP_APP_SWITCHES, com.android.systemui: android.permission.TETHER_PRIVILEGED, com.android.systemui: android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS, com.android.hardware.usb.externalmanagementtest: android.permission.MANAGE_USB, com.android.systemui: android.permission.MASTER_CLEAR, com.android.systemui: android.permission.BLUETOOTH_PRIVILEGED, com.android.systemui: android.permission.RECEIVE_MEDIA_RESOURCE_USAGE, com.android.systemui: android.permission.BATTERY_STATS, com.android.systemui: android.permission.MANAGE_USB, com.android.systemui: android.permission.REAL_GET_TASKS, com.android.systemui: android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, com.android.statsd.loadtest: android.permission.DUMP, com.android.systemui: android.permission.WATCH_APPOPS, com.android.test.soundtrigger: android.permission.MANAGE_SOUND_TRIGGER, com.android.systemui: android.permission.WRITE_DREAM_STATE, com.android.systemui: android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, com.android.test.voiceenrollment: android.permission.MANAGE_VOICE_KEYPHRASES, com.android.test.soundtrigger: android.permission.CAPTURE_AUDIO_HOTWORD, com.android.systemui: android.permission.OVERRIDE_WIFI_CONFIG, com.android.systemui: android.permission.WRITE_SECURE_SETTINGS, com.android.systemui: android.permission.MANAGE_USERS, com.android.systemui: android.permission.READ_PRIVILEGED_PHONE_STATE, com.android.systemui: android.permission.READ_NETWORK_USAGE_HISTORY, com.android.systemui: android.permission.START_ACTIVITIES_FROM_BACKGROUND, com.android.systemui: android.permission.MODIFY_DAY_NIGHT_MODE, com.android.systemui: android.permission.DUMP, com.android.systemui: android.permission.UPDATE_APP_OPS_STATS, com.android.systemui: android.permission.INTERACT_ACROSS_USERS}

异常原因: 使用了 mmm ./frameworks/base 导致编译了多于的Apk.
解决方法:
方法1:
可参照本篇红色字体。
方法2:
将异常缺损权限添加到./frameworks/base/data/etc/privapp-permissions-platform.xml中

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/919395.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存