本文转载自:http://blog.csdn.net/u012719256/article/details/52094982
1.重要的property属性
#define ANDROID_RB_PROPERTY "sys.powerctl" // 控制启动状态
property_set(ANDROID_RB_PROPERTY, "shutdown,");
property_set(ANDROID_RB_PROPERTY, "reboot,bootloader"); property_set(ANDROID_RB_PROPERTY, "reboot,"); property_set(ANDROID_RB_PROPERTY, "reboot,edl");
- 1
- 2
- 3
- 4
- 5
- 6
2.propety属性的管理
init.c
if (is_charger)
{
action_for_each_trigger("charger", action_add_queue_tail);
}
else
{
if (is_ffbm) { action_for_each_trigger("ffbm", action_add_queue_tail); } else { // 正常开机模式进入最后的 late-init 阶段 action_for_each_trigger("late-init", action_add_queue_tail); } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
init.rc
on late-init
trigger load_all_props_action // 在late-init阶段加载所有的属性
---------- on load_all_props_action load_all_props
- 1
- 2
- 3
- 4
- 5
- 6
- 7
keywords.h property_service.c
KEYWORD(load_all_props, COMMAND, 0, do_load_all_props) //keywords.h
-> do_load_all_props // builtins.c
->load_all_props // property_service.c // 依次从下面几个路径中加载所有的属性 "system/build.prop" (常用) "system/default.prop"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
build/tools/buildinfo.sh
☆ 生成 system/build.prop 文件,需要添加prop只需要在这个编译脚本中添加即可!!!
in system/build.prop
# begin build properties
3 # autogenerated by buildinfo.sh 4 ro.build.id=LMY47V 5 ro.build.display.id=LMY47V.WW_Phone.12.0.0.020-20160719_userdebug 6 ro.build.display.wtid=LMY47V.WW_Ph
- 1
- 2
- 3
- 4
- 5
- 6
- 7
3.属性值的获取设置
1. 在system.prop里面添加需要使用的系统属性,添加完后需要编译生成system.img
2. 在native层,使用property_set(...)和property_get(...)来存取系统属性
3. 在Java层, 使用SystemProperties.set(...)和SystemProperties.get(...)来存取系统属性 4. 在adb shell命令行,使用getprop和setprop来存取系统属性
- 1
- 2
- 3
- 4
- 5
- 6
- 7
3.charger
# init.rc
on charger
class_start charger
----------
# init.qcom.rc
service charger /charger
class charger
----------
#system/core/healthd/Android.mk
LOCAL_MODULE := healthd
...
# Symlink /charger to /sbin/healthd
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
4.屏幕截图 & 屏幕录制
adb shell screencap /sdcard/test.png
adb shell screenrecord sdcard/sss.mp4
- 1
- 2
5.关闭selinux
setenforce 0
- 1
6.adb devices 串号
(1)init.rc
write /sys/class/android_usb/android0/iSerial ${ro.serialno}
- 1
- 2
- 3
(2)cat /pro/cmdline
adb root;adb shell cat /proc/cmdline
androidboot.serialno=YOGABOOK12
- 1
(3)init.cpp
process_kernel_cmdline
->import_kernel_cmdline(false, import_kernel_nv);
->import_kernel_nv
----------
char *value = strchr(name, '=');
(!strncmp(name, "androidboot.", 12) && name_len > 12) {
char *boot_prop_name = name + 12; char prop[PROP_NAME_MAX]; snprintf(prop, sizeof(prop), "ro.boot.%s", boot_prop_name); property_set(prop, value); } ---------- static void export_kernel_boot_props() { struct { const char *src_prop; const char *dst_prop; const char *default_value; } prop_map[] = { ... { "ro.boot.serialno", "ro.serialno", "", }, ... };
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
7.system/bin/input 命令
demo
input keyevent keycodeNum //4 表示KEYCODE_BACK
- 1
常用的几种事件:
//键值对应 android/keycodes.h
26 --> KEYCODE_POWER // 电源
82 --> "KEYCODE_MENU" //菜单 3 --> "KEYCODE_HOME" //返回home 4 --> "KEYCODE_BACK" //返回上一级菜单 19 --> "KEYCODE_DPAD_UP" //向上 20 --> "KEYCODE_DPAD_DOWN" //向下 21 --> "KEYCODE_DPAD_LEFT" //向左 22 --> "KEYCODE_DPAD_RIGHT" //向右 24 --> "KEYCODE_VOLUME_UP" //音量加 25 --> "KEYCODE_VOLUME_DOWN" //音量减 66 --> "KEYCODE_ENTER" //确定键
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
8. 重新挂载某个分区
mount -o remount,rw system system
- 1
9.命令行查看分辨率
frameworks/base/cmds/wm/
窗口分辨率
wm size
10.android init阶段 bootanimation之前的一张启动画面
// 在init.c中通过 “console_init” 这个action触发
queue_builtin_action(console_init_action, "console_init");
- 1
- 2
- 3
11.aplog
1.位置
/data/logs/aplog.n
data/local/log/aplog
- 1
- 2
2.crash信息
//logs\crashlog0_72612f74d4e263a53665\crashfile 中表明了crash原因
EVENT=CRASH
ID=61c96fdba2162a052323
SN=4cca94f595db403f749622792dfe73a6167ded48
DATE=2016-10-08/08:09:56
UPTIME=0000:00:19 BUILD=YB-Q501L_USR_S000014_1610010228_WW12_ROW,Lenovo/yogi_12_row_lte/YOGABOOK12:6.0.1/MMB29M/1610010228:user/release-keys,3.14.55-x86_64,queen@fyy-SMBIOSfyy,unknown,YOGI.T2000AH.V015,,,, BOARD=Lenovo YB-Q501L IMEI= TYPE=SWWDT_UNHANDLED // crash 类型 看门狗 DATA_READY=1 OPERATOR=UNKNOWN DATA0=SWWDT_RESET // _END ---------- EVENT=CRASH ID=72612f74d4e263a53665 SN=7f406c2f2e2675c73a5a85d52a237d80f747c2ea DATE=2016-10-07/21:23:08 UPTIME=0000:00:22 BUILD=YB-Q501L_USR_S000014_1610010228_WW12_ROW,Lenovo/yogi_12_row_lte/YOGABOOK12:6.0.1/MMB29M/1610010228:user/release-keys,3.14.55-x86_64,queen@fyy-SMBIOSfyy,unknown,YOGI.T2000AH.V015,,,, BOARD=Lenovo YB-Q501L IMEI= TYPE=IPANIC // // crash 类型 kernel panic DATA_READY=1 OPERATOR=UNKNOWN _END
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
3. ” BUG: “
搜索“ BUG: ”会有栈回溯或者null point信息
- 1
2.kernel启动信息/重启信息
beginning of kernel
10-07 21:22:46.780 0 0 I KERNEL : [ 0.000000] Initializing cgroup subsys cpuset
10-07 21:22:46.780 0 0 I KERNEL : [ 0.000000] Initializing cgroup subsys cpu
10-07 21:22:46.780 0 0 I KERNEL : [ 0.000000] Initializing cgroup subsys cpuacct
10-07 21:22:46.780 0 0 I KERNEL : [ 0.000000] Linux version 3.14.55-x86_64 (queen@fyy-SMBIOSfyy) (gcc version 4.9.2 (GCC) ) #1 SMP PREEMPT Sat Oct 1 03:04:35 CST 2016
10-07 21:22:46.780 0 0 I KERNEL : [ 0.000000] Command line: androidboot.bootloader=yogi_t2000ah_v015_kernelflinger-02_1f androidboot.diskbus=10.0 androidboot.verifiedbootstate=green androidboot.bootreason=kernel_panic androidboot.mode=0 :
12. 指定工程的 .config
KERNEL_DEFCONFIG
device/intel/cherrytrail/cht_ffd/AndroidBoard.mk
13. Android.mk中添加打印
$(warning "print info")
- 1
14.U盘插入拔出打印
1.mountservice 完整流程
MountService: Volume public:8,1 broadcasting checking to UserHandle{0} // 插入后检测挂载
MountService: Volume public:8,1 broadcasting mounted to UserHandle{0} MountService: Volume public:8,1 broadcasting ejecting to UserHandle{0} // 点击弹出umount MountService: Volume public:8,1 broadcasting unmounted to UserHandle{0} MountService: Volume public:8,1 broadcasting removed to UserHandle{0} // 拔出U盘
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
2.kernelU盘插入拔出kernel打印
usb 2-1: new SuperSpeed USB device number 2 using xhci_hcd // 插上 30375936 512-byte logical blocks: (15.5 GB/14.4 GiB) // 读取大小 USB disconnect, device number // 拔出
- 1
- 2
- 3
- 4
15.U盘插入拔出mount/umount代码流程
1.监听subsystem为block 的uevent事件
NetlinkHandler::onEvent
VolumeManager::handleBlockEvent
case add:
Disk::create // disk.cpp disk::readMetadata(); disk::readPartitions(); notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags)); case chager: disk::readMetadata(); disk::readPartitions(); case remove: Disk::destroy() destroyAllVolumes(); notifyEvent(ResponseCode::DiskDestroyed);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
2.发送广播
Disk::notifyEvent
VolumeManager::Instance()->getBroadcaster()->sendBroadcast
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
3.mountService接收来着vold的广播
MountService.onEvent
MountService.onEventLocked
case VoldResponseCode.VOLUME_STATE_CHANGED: //每一次状态的改变都会调用这个分支
onVolumeStateChangedLocked(vol, oldState, newState); // 状态改变做相应操作
mHandler.obtainMessage(H_VOLUME_BROADCAST, userVol).sendToTarget(); // mountService发广播给mountService
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
3.mountService接收来着mountService的广播
MountServiceHandler.handleMessage //接收广播
case H_VOLUME_MOUNT: // 挂载
mConnector.execute("volume", "mount", vol.id, vol.mountFlags,vol.mountUserId); case H_VOLUME_BROADCAST: // 发送广播给用户告知状态 Slog.d(TAG, "Volume " + userVol.getId() + " broadcasting " + envState + " to "+ userVol.getOwner()); mContext.sendBroadcastAsUser(intent, userVol.getOwner());
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
16.查看android分区及dd命令烧写分区
#ls /dev/block/by-name/
android_boot
android_bootloader
android_bootloader2
android_cache
android_config
android_data
android_factory
android_metadata
android_misc
android_persistent
android_recovery
android_system
----------
push boot.img到及机子的任意目录,在此目录执行 ,dd if=boot.img of=/dev/block/by-name/android_boot,重启之后,boot.img烧写成功.其他分区也类似.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
17.android 各层次获取时间的方法
1. 在Java层,long now = SystemClock.uptimeMillis();
2. 在native层,nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
3. 在驱动层,s64 time = ktime_to_us(ktime_get());
- 1
- 2
- 3
- 4
- 5
18.android 分区大小设置
vendor/qcom/non-hlos/MSM8953.LA.2.0/common/config/partition.xml
- 1
19.android framwork打印调用栈
// c++ 代码
#include
...
CallStack stack;
stack.update();
stack.dump();
----------
// java 代码
Log.d(TAG,Log.getStackTraceString(new Throwable()));
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
20.快速编译打包bootimage和system
make kernel:只重新编译kernel部分镜像,但是不会打包更新boot.img
make bootimage-nodeps:不会编译kernel以及ramdisk,只会将out目录中现有的kernel和ramdisk.img重新打包一次生成boot.img
make ramdisk:只重新编译ramdisk镜像,生成ramdisk.img,但是不会打包更新boot.img
make ramdisk-nodeps:不会编译ramdisk,只会将out目录中现有的文件重新打包一次。out/target/product/hq6737t_66_1ha_m0/root,比如更改了init..rc之类的文件,只需要修改out/…/root/中对应的文件,然后重新用此命令打包一次,就会生成一个包含更改过init..rc的ramdisk.img
make snod:打包system
21.modern
./mk johnson-eng update-none-hlos.bin vendor/qcom/non-hlos/MSM8953.LA.2.0/common/build/bin/asic/NON-HLOS.bin
- 1
- 2
- 3
22.Qcom 开机后继续打印串口log
主要是修改 persist.console.silent.config 属性,
persist.console.silent.config = 1是不打印, persist.console.silent.config = 0继续打印。 修改的文件, 将手机中的build.prop导出, 直接修改,再push进去; 修改 device/qcom/msmXXX/system.prop,编译systemimage。
- 1
- 2
- 3
- 4
- 5
- 6
23.关闭selinux
when build, open the CONFIG_SECURITY_SELINUX_DEVELOP, add then append the " androidboot.selinux=permissive" in commandline. or in device/qcom/msmxxxx/system.prop, add ro.boot.selinux=disable
- 1
- 2
- 3
- 4
24.sbl检测电池是否在位
Non-HOLS/BOOT.BF.3.3/boot_images/core/systemdrivers/pmic/app/chg/src/pm_app_smbchg.c 里有个检测电池在不在的函数,Check Battery presence
- 1
25.charge log mask
qpnp-smbcharger.c:
+ #define DEBUG
- static int smbchg_debug_mask;
+ static int smbchg_debug_mask = 0xFF;
- 1
- 2
- 3
- 4
26.各模块JNI层代码
26.1 surfaceflinger
android_view_Surface.cpp
static const JNINativeMethod gSurfaceMethods[] = {
demo
SurfaceTest.cpp
- 1
- 2
- 3
- 4
- 5
- 6
27.input keyevent 命令
对应的键值 frameworks/native/include/android/keycodes.h
$adb shell input keyevent 26 // power
$adb shell input keyevent 4 //模拟返回键(BACK) $adb shell input keyevent 82 //模拟菜单键(MENU) $adb shell input keyevent 3 //模拟主页键(HOME)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
28.inpudispatch中添加tp报点
--- a/frameworks/native/services/inputflinger/InputDispatcher.cpp
+++ b/frameworks/native/services/inputflinger/InputDispatcher.cpp
@@ -2483,15 +2483,16 @@ bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args } void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { -#if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " + ALOGE("zch----in notifyMotion"); +#if 1 + ALOGE("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " "action=0x%x, actionButton=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x," "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld", args->eventTime, args->deviceId, args->source, args->policyFlags, args->action, args->actionButton, args->flags, args->metaState, args->buttonState, args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime); for (uint32_t i = 0; i < args->pointerCount; i++) { - ALOGD(" Pointer %d: id=%d, toolType=%d, " + ALOGE(" Pointer %d: id=%d, toolType=%d, " "x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " "orientation=%f",
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
29.wifi连接adb
1. 在目标板上通过使用以太网连接来配置adb守护进程,使用setprop来设置守护进程的端口号
# setprop service.adb.tcp.port 5555
2. 如果以上配置成功,再重启目标板上的adbd服务
# stop adbd
# start adbd 3. 在主机端使用如下命令建立adb连接 export ADBHOST='s ip address> adb kill-server adb start-server adb connect :5555 4. 使用如下命令确认设备连接成功 adb devices 设备连接成功后将出现设备序列号和名称