编写类似adb shell WM 类似的命令程序

1. 在/frameworks/base/cmds/目录下新建test目录,将wm下的Android.mk,wm和src目录拷贝到test目录
2. 修改wm文件名称为Test,内容修改为:
# Script to start "wm" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/test.jar
exec app_process $base/bin com.android.commands.wm.Test "$@"
3. 修改Android.mk文件内容为:
# Copyright 2013 The Android Open Source Project
#
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := test
include $(BUILD_JAVA_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := Test
LOCAL_SRC_FILES := Test
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
4. 修改frameworks/base/cmds/test/src/com/android/commands/wm目录下的WM.java为Test.java,内容修改为:
public static void main(String[] args) {
        // (new Wm()).run(args);
        Log.i("zhichao","hello world");
    }
5. 进入frameworks/base/cmds/test目录,执行mm命令,前提是已经加载了环境变量
6. 将/out/../system/framework下的test.jar push到开发板/system/framework
7. 将/out/../system/bin下的Test push到开发板的/system/bin目录
8. 开启一个终端输入 adb logcat -s "zhichao",监听tag为zhichao的log信息,开启另外一个终端adb shell进入板子后
   输入Test命令,会在第一个终端显示 hello world的log信息,表示命令已经添加成功

这些步骤仅仅作为一个流程,具体的功能实现都需要依照具体的需求和环境去实现

你可能感兴趣的:(Android)