Android Framework tips

来源:互联网 发布:java oa项目源代码 编辑:程序博客网 时间:2024/06/09 22:19

Dump Device Info

Dump surface information

adb shell dumpsys SurfaceFlinger

Dump window information

1. dump windowadb shell dumpsys window2. dump window with detailsadb shell dumpsys window all3. dump visible windowadb shell dumpsys window visibleDump activity informationadb shell dumpsys activity

Dump Layer

//dump all visible layersadb shell service call SurfaceFlinger 4000 i32 0//dump all visible layers with corresponding buffersadb shell service call SurfaceFlinger 4000 i32 1//Output folder path:adb pull /data/layerdump/

Capture View

import android.graphics.Bitmap;import java.io.FileOutputStream;void captureView(View view, String filename) {    Bitmap bitmap = view.createSnapshot(Bitmap.Config.ARGB_8888, 0, false);    if (bitmap != null) {        try {            FileOutputStream out = new FileOutputStream(filename);            Log.d(TAG, "capture++ " + mWindowAttributes.getTitle());            bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);            Log.d(TAG, "capture-- " + mWindowAttributes.getTitle());        } catch (Exception e) {            Log.d(TAG, "Exception " + mWindowAttributes.getTitle(), new RuntimeException().fillInStackTrace());        }    } else {        Log.d(TAG, "bitmap=null " + mWindowAttributes.getTitle());    }}

Adjust Device ability

Disable HardwareRender

1. adb shell "echo profiler.debug.disable_hw_accel=1 > /data/local.prop" 2. adb shell chmod 644 /data/local.prop3. adb reboot

Set/Get System Properties

1. codeboolean bValue = SystemProperties.getBoolean("view.debug.stopped_false", false);2. getadb shell getprop view.debug.stopped_false3. setadb shell setprop view.debug.stopped_false 1

Enable TouchEvent Logs

// debug gestureDetectoradb shell setprop debug.gesture.verbose 1
// logs like these03-07 11:07:59.840 7016 7016 D InputEventReceiver dispatchInputEvent - MotionEvent { action=ACTION_DOWN, id0=0, x0=322.65366, y0=156.15866, toolType0=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0,  pointerCount=1, historySize=0, eventTime=4595278, downTime=4595278, deviceId=5, source=0x1002 }03-07 11:07:59.840 7016 7016 D GestureDetector MotionEvent { action=ACTION_DOWN, id0=0, x0=322.65366, y0=50.15866, toolType0=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=4595278, downTime=4595278, deviceId=5, source=0x1002 }03-07 11:07:59.840 7016 7016 D GestureDetector et(4595278) MotionEvent.ACTION_DOWN: mDownFocusX=322.65366, mLastFocusX=322.65366, focusX=322.6536603-07 11:07:59.840 7016 7016 D GestureDetector et(4595278) MotionEvent.ACTION_DOWN: onDown()03-07 11:07:59.840 7016 7016 D InputEventReceiver finishInputEvent - MotionEvent { action=ACTION_DOWN, id0=0, x0=322.65366, y0=156.15866, toolType0=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=4595278, downTime=4595278, deviceId=5, source=0x1002 }

Prism landscape mode

adb shell am broadcast -a android.intent.action.DOCK_EVENT --ei android.intent.extra.DOCK_STATE 2recoveryadb shell am broadcast -a android.intent.action.DOCK_EVENT --ei android.intent.extra.DOCK_STATE 1

Hierarchy View

ViewServer[Turn On] adb shell service call window 1 i32 4939[Turn Off] adb shell service call window 2 i32 4939

Debug Focused View

Debug view focus mechanism

Build Modules/Git Usage

Build modules

I think the original way to build framework.jar is not efficient. It needs 19G storage and about 3 hours to build the out folder.
Here is the way to build the necessary files and it only needs about 700MB and about 4 minutes.
It can save our time and storage if you only need framework.jar.
Share the tips for you. You may use the similar way for the modules you need.

[original]. build/envsetup.sh ; partner_setup evitareul EvitareUL_Generic_WWE_DEBUG ; make -j8 PRODUCT-evitareul-userdebug;<framework.jar only>cd framework/basemm –j8 PRODUCT-evitareul-userdebug[Efficient way]. build/envsetup.sh ; partner_setup evitareul EvitareUL_Generic_WWE_DEBUG; add_lunch_combo evitareul-userdebug; lunch evitareul-userdebug; time make -j8 framework<framework.jar only>time mmm -j8 frameworks/base[tips]1. I use “make framework” to build the dependency for framework.jar. However, I can’t use something like “make framework PRODUCT-evitareul-userdebug”. That’s why I need “lunch” to setup TARGET_BUILD_VARIANT=userdebug instead of eng.2. time is optional. I use it to check the build time.[make modules commands]make frameworkmmm frameworks/basemake servicesmake HTCCommonctrlmmm packages/modules/HTCCommonControl/java/make com.htc.resourcesmake android.policy- list all modulesmake modules

git usage

get latest code

$ repo sync# upload your patch START# [format] repo start <name> <path> $ repo start kenzyun customize/base/$ cd customize/base$ git add –i$ git commit# if you want to edit again, type "git commit --amend"$ repo upload# upload your patch END# abandon this commit and get latest code after your patch merged$ repo abandon kenzyun$ repo sync# example1 : whole new patch$ repo start kenzyun customize/base/$ cd customize/base$ git add –i$ git commit$ repo upload# example2 : modify your patch on Gerrit after repo upload$ git add –i$ git commit --amend$ repo upload

Abandon change

# repo abandon <name>$ repo abandon mark

Error handle

# sync error because some files check out$ go to the patch for your module$ git checkout HEAD .# example$ cd customize/base$ git checkout HEAD .$ cd..$ cd ..$ repo sync

Save time while replacing your java file into device

build jar file
U1_Tech._Presentation
Item No. Title(Link) Owner Date
1 Smali mechanism to build framework, Smali Tool Riddle Hsu 22 May 2013
Tips :
You need ViewDebug.java when you want to replace View.java or ViewGroup.java.

disable verification with dexopt

Add this line to /data/local.prop or /system/build.prop    dalvik.vm.dexopt-flags = v=nTips : make sure chmod 644 for local.prop / build.propReference : http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.htmlBy testing on my M7, it takes 3 minutes to do dalvik optimization and verification.After disabling verification, it only takes 1 minute to do optimization.

disable verification with dex2oat

Add this line to /data/local.prop or /system/build.prop    dalvik.vm.dex2oat-flags = --compiler-filter=verify-noneTips : make sure chmod 644 for local.prop / build.propReference : https://github.com/anestisb/oatdump_plus/blob/master/Android.mk

replace odex for RCMS ROM

Smali Tool extended by Kenzyun Chen./odex_build_framework_lite.sh <folderName> <jarFileName>Ex: ./odex_build_framework_lite.sh M7 servicesReference : http://forum.xda-developers.com/galaxy-s2/themes-apps/how-to-manually-deodex-odex-t1208320

Debug flag

ViewRootImpl

DEBUG_INPUT_RESIZE : help to clarify mScrollY value for EditText is covered by IME case.

Others

Check callstack

Java1. set break point by eclipse2. use traceview, and open the trace log by htc LogAnalyzer3. print callstackLog.v(TAG, "dirty.isEmpty()", new RuntimeException().fillInStackTrace());
C++#include <utils/CallStack.h>android::CallStack stack("Tag Name");

Decompile APK

http://changyy.pixnet.net/blog/post/27992240-android-%E9%96%8B%E7%99%BC%E6%95%99%E5%AD%B8%E7%AD%86%E8%A8%98—%E9%97%9C%E6%96%BC%E5%8F%8D%E7%B5%84%E8%AD%AF-android-%E7%A8%8B%E5%BC%8F

ACC customize flag

ACC http://masd:43000/http://10.116.65.253:10101/images/e/e5/New_Customization_API_Guides.pdf/system/customize/ACC/default.xml<app name="Android_App_Framework">       <item type="boolean" name="support_pen_event">true</item></app>adb pull /system/customize/ACC/default.xml

Modify ACC flag steps

1. pull ACC setting xml from device   adb pull /system/customize/ACC/default.xml2. modify or add the key value   example: modify app name="Android_App_Framework", and key name="support_pen_event" to true   <app name="Android_App_Framework">       <item type="boolean" name="support_pen_event">true</item>   </app>   example : modify system, and key name="device_type"   <system>       <item type="integer" name="device_type">1</item>   </system>3. push ACC setting xml to device   adb remount   adb push default.xml /system/customize/ACC/   adb reboot

Dump Message History in ViewRootImpl

StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw);Printer p = new PrintWriterPrinter(pw);mHandler.getLooper().dump(p, "");Slog.i(TAG, sw.toString());
0 0
原创粉丝点击