栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

7. Android10内置app测试自定义service

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

7. Android10内置app测试自定义service

本文是在上文6. Android10向系统注册service访问硬件抽象层(HAL)模块的基础上进行的,虚拟机环境就是上文结束时的环境。

创建app

首先在windows下使用Android studio创建Hello项目

修改MainActivity.java

package com.test.hello;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.IHelloService;
import android.os.ServiceManager;

public class MainActivity extends AppCompatActivity {
    final String  TAG = "hello!";
    Button btn_write = null;
    Button btn_read = null;
    TextView text_result = null;
    EditText text_input = null;
    private IHelloService helloService = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_write = (Button) findViewById(R.id.btn_w);
        btn_read = (Button) findViewById(R.id.btn_r);
        text_result = (TextView) findViewById(R.id.text_result);
        text_input = (EditText) findViewById(R.id.text_input);
        helloService = IHelloService.Stub.asInterface(
                ServiceManager.getService("hello"));

        btn_write.setonClickListener(new View.onClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    helloService.wirteString(text_input.getText().toString());
                } catch (RemoteException e) {
                    Log.e(TAG, "Remote Exception while writing value to device.");
                }
            }
        });
        btn_read.setonClickListener(new View.onClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    text_result.setText(helloService.readString());
                } catch (RemoteException e) {
                    Log.e(TAG, "Remote Exception while writing value to device.");
                }
            }
        });
    }
}

 修改activity_main.xml



    
        
            
            

将AndroidStudioProjectsHelloappsrcmain目录下的所有文件和文件夹打包,并移动到虚拟机中aosp10/packages/apps目录下新建的Hello文件夹去

 在aosp10/packages/apps/Hello目录下新建Android.mk文件

Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := Hello

LOCAL_DEX_PREOPT := false
LOCAL_JACK_ENABLED := disabled
LOCAL_PRIVATE_PLATFORM_APIS := true

include $(BUILD_PACKAGE)
 编译Hello.apk
cd ~/documents/aosp10
export TARGET_PREBUILT_KERNEL=/home/test/documents/msm/arch/arm64/boot/Image.lz4-dtb
source build/envsetup.sh
lunch
aosp_walleye-userdebug
cd packages/apps/Hello/
mm

删掉这两个文件(packages/apps/Hello/res/values/themes.xml、packages/apps/Hello/res/values-night/themes.xml),重新编译 

mm

报错

 修改AndroidManifest.xml,删掉

        android:theme="@style/Theme.Hello"

修改前

修改后

 重新编译 

mm

编译完整镜像并重新刷机

编译,继续使用刚刚的terminal,先重新打包system.img

cd ../../..
make snod

 重新编译

time make -j16

报错

  解决

make api-stubs-docs-update-current-api
time make -j16

报错

解决

make system-api-stubs-docs-update-current-api
time make -j16

 刷机

sudo su
source build/envsetup.sh
lunch
aosp_walleye-userdebug
adb shell reboot bootloader
cd out/target/product/walleye/
fastboot flashall -w

 

测试

本文涉及到的知识主要和Android架构中的应用程序层、应用程序框架层相关

参考

Android应用程序访问linux驱动第四步:实现android应用程序_阳光玻璃杯-CSDN博客

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451094.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号