Thursday, April 2, 2015

Screen Capture






Screen capture
  1. SurfaceControl.screenshot(dw, dh, minLayer, maxLayer) (WindowManagerService.java)
  2. public static Bitmap screenshot (SurfaceControl.java)
  3. static jobject nativeScreenshotBitmap (android_view_SurfaceControl.cpp)
  4. pixels->update 
  5. mScreenshot.update
  6. ScreenshotClient::update (SurfaceComposerClient.cpp)
  7. virtual status_t captureScreen (ISurfaceComposer.cpp)
  8. remote()->transact
PS 1  Create outServerChannel and outClientChannel. 
      Each channel has 2 channel objects.

Thursday, June 26, 2014

Bug - Software and Hardware keyboard in wrong state

Root cause :
Input device have to report INPUT_DEVICE_CLASS_ALPHAKEY  So that WMS will check it when computeScreenConfigurationLocked


Notes :
Input Devices update its flag here.
    EventHub::openDeviceLocked (EventHug.cpp)

Call Stack for WMS and IMS
computeScreenConfigurationLocked (WindowManagerService.java)
handleMessage                     (WindowManagerService.java)
notifyHardKeyboardStatusChange    (WindowManagerService.java)        onHardKeyboardStatusChange
onHardKeyboardStatusChange        (InputMethodManagerService.java) MSG_HARD_KEYBOARD_SWITCH_CHANGED
handleMessage                     (InputMethodManagerService.java)
handleHardKeyboardStatusChange   (InputMethodManagerService.java)

Thursday, June 19, 2014

Bug - WatchDog timout


  • RootCause
    • watchdog will schedule a check to acquire the lock, if can't get the lock then report timeout.
W Watchdog: *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in monitor com.android.server.am.ActivityManagerService on foreground thread (android.fg), Blocked in handler on ActivityManager (ActivityManager), Blocked in handler on WindowManager thread (WindowManager)
 W Watchdog: foreground thread stack trace:
 W Watchdog:     at com.android.server.am.ActivityManagerService.monitor(ActivityManagerService.java:16009)
.........
 W Watchdog: ActivityManager stack trace:
 W Watchdog:     at com.android.server.am.ActivityStack$ActivityStackHandler.handleMessage(ActivityStack.java:292)

    •    Usually we can see it if deadlock, trace the traces.txt,  there is a deadlock b/w threads.

"Binder_C" prio=5 tid=58 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x425af1d0 self=0x732d34b0
  | sysTid=1171 nice=-8 sched=0/0 cgrp=apps handle=1932210896
  | state=S schedstat=( 3712885896 3165563645 19485 ) utm=285 stm=85 core=0
  at com.android.server.wm.WindowManagerService.moveTaskToTop(WindowManagerService.java:~4792)
  - waiting to lock <0x424aea70> (a java.util.HashMap) held by tid=57 (Binder_B)
......
"Binder_B" prio=5 tid=57 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x4279b7c8 self=0x6c452620
  | sysTid=1134 nice=0 sched=0/0 cgrp=apps handle=1816469512
  | state=S schedstat=( 5136093661 3481006328 21082 ) utm=419 stm=94 core=0
  at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:~13693)
  - waiting to lock <0x42033500> (a com.android.server.am.ActivityManagerService) held by tid=58 (Binder_C)

    •     Check the source code, you can find below.

     * NOTE: Never call into methods that lock ActivityManagerService while holding this object.
*/
final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
  • Solution.
    • Process/Thread who cause the resource lock should rewrite the code to prevent the case like this.
  • Note about WatchDog
    • Service have to add itself to the monitor by Watchdog.getInstance().addMonitor(this) or addThread. Service also need to implement the monitor function to simply lock the service object itself.
    • If addMonitor, it will be added into the default foreground thread main checker. For others will create a new checker like UiThread, IoThread, Main looper.
    • WatchDog will query the lock and stop if timeout.

Thursday, June 5, 2014

Bug - String Truncate

Root cause: setting of padding or margin is not correct.

Fix: change the setting as below, remove the -30dip

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-30dip" />

More details about padding and margin in http://server2client.com/cssbasics/paddingmargin.html

Tuesday, June 3, 2014

Bug - AOSP Volume panel - Wrong volume after rotate.

Root cause :
voice call and bluetooth are not inaudible. So volume and max will +1 in onVolumeChanged. for these 2 streams.  When orientation changed, it doesn't +1 in the seekbar cause this problem.

Solution :  As below call stack, +1 on volume for these 2 streams in updateSlider.

java.lang.Throwable: stack dump
W/System.err(  897): at java.lang.Thread.dumpStack(Thread.java:489)
W/System.err(  897): at android.view.VolumePanel.updateSlider(VolumePanel.java:475)
W/System.err(  897): at android.view.VolumePanel.updateStates(VolumePanel.java:526)
W/System.err(  897): at android.view.VolumePanel.setLayoutDirection(VolumePanel.java:349)
W/System.err(  897): at android.media.AudioService.handleConfigurationChanged(AudioService.java:4427)
W/System.err(  897): at android.media.AudioService.access$8400(AudioService.java:114)
W/System.err(  897): at android.media.AudioService$AudioServiceBroadcastReceiver.onReceive(AudioService.java:4213)
W/System.err(  897): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
W/System.err(  897): at android.os.Handler.handleCallback(Handler.java:733)
W/System.err(  897): at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err(  897): at android.os.Looper.loop(Looper.java:136)
W/System.err(  897): at com.android.server.ServerThread.initAndLoop(SystemServer.java:1137)

Note :
the AudioServiceBroadcastReceiver extend BroadcastReceiver to receive intent.