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.


Monday, June 2, 2014

Bug - AOSP Gallery crash - commit after onSaveInstanceState

Call Stack
05-27 12:18:24.948  2471  2471 E AndroidRuntime: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)

Root cause:
onSaveInstanceState happen before the commit. The commit caused by orientation changed and the save state caused by another dialog choose from menu force the activity call the sate to save pending changes.

Solution:
1. use commitAllowLose
2. android:configChanges="orientation" in AndroidManifest.xml
3. override the onCreate as below 
public void onCreate() {
    super.onCreate();
    // TODO Put your application initialization code here.
  }