Android 中利用异常来查看函数调用堆栈
在将PowerManagerService.java文件DEBUG_SCREEN_ON打开后,在log发现RuntimeException,仔细查看代码,原来是在setLightBrightness中的debug信息,
特地写下来,以便以后使用.
1.setLightBrightness 函数:
private void setLightBrightness(int mask, int value) {
int brightnessMode = (mAutoBrightessEnabled
? LightsService.BRIGHTNESS_MODE_SENSOR
: LightsService.BRIGHTNESS_MODE_USER);
if ((mask & SCREEN_BRIGHT_BIT) != 0) {
if (DEBUG_SCREEN_ON) {
RuntimeException e = new RuntimeException("here");
e.fillInStackTrace();
Slog.i(TAG, "Set LCD brightness: " + value, e);
}
mLcdLight.setBrightness(value, brightnessMode);
}
if ((mask & BUTTON_BRIGHT_BIT) != 0) {
mButtonLight.setBrightness(value);
}
if ((mask & KEYBOARD_BRIGHT_BIT) != 0) {
mKeyboardLight.setBrightness(value);
}
}
2.log信息:
I/PowerManagerService( 228): java.lang.RuntimeException: here
I/PowerManagerService( 228): at com.android.server.PowerManagerService.setLightBrightness(PowerManagerService.java:2160)
I/PowerManagerService( 228): at com.android.server.PowerManagerService.access$4600(PowerManagerService.java:77)
I/PowerManagerService( 228): at com.android.server.PowerManagerService$BrightnessState.jumpToTargetLocked(PowerManagerService.java:2265)
I/PowerManagerService( 228): at com.android.server.PowerManagerService.setBacklightBrightness(PowerManagerService.java:3049)
I/PowerManagerService( 228): at android.os.IPowerManager$Stub.onTransact(IPowerManager.java:227)
I/PowerManagerService( 228): at android.os.Binder.execTransact(Binder.java:338)
I/PowerManagerService( 228): at dalvik.system.NativeStart.run(Native Method)
补充:移动开发 , Android ,