• Miao-chen Chou's avatar
    arc/bluetooth: Fix the powered state synchronization between Chrome and Android · bb12724f
    Miao-chen Chou authored
    Since the observation of the local powered state change and the receiver of
    enable/disable requests from Android is in arc_bluetooth_service are in
    arc_setting_service and arc_bluetooth_bridge separately, the power state can
    get out of sync or restore to the wrong state due to the lack of coordination
    between these two pieces of information.
    
    Issues:
    - The powered state can get out-of-sync between Android and Chrome if the power
      state of adapter is repeatedly toggled from Chrome setting.
    - If the powered state is ON before deep suspend/resume, the state will
      turn to OFF after resume and turn immediately back to ON on Chrome. However
      without waiting for the previous disable intent to finish, arc_setting_service
      sends the enable intent right after while Android Bluetooth statck is still
      processing the disable intent. Also there is a 3~4 seconds delay for bringing
      down to complete on Android Bluetooth stack. Besides, the enable intent
      is treated as a no op if the ongoing intent is disable. So after 3~4 seconds
      Android sends a disable request to Chrome while the powered state is ON on
      Chrome, so the powered state fall to the wrong one, disable, instead.
    
    The changes includes:
     - moving the observation of Bluetooth adapter from arc_settings_service
       to arc_bluetooth_bridge,
     - changing the cycle of observing Bluetooth adapter from living along with ARC
       Bluetooth instance to living along with ARC Bluetooth bridge,
     - adding IntentHelperObserver to listen to the OnInstanceReady event and fire
       the initial powered state of Bluetooth to Android via intent,
     - adding two queues and a timer to track the powered state changes initiated by
       either Chrome or Android and to track the completion of the power
       changes initiated by Chrome,
     - and adding helper functions to enqueue/dequeue the power change intents and
       to compress the toggling of state to reduce the intents sent to Android.
    
    BUG=b:62578573
    TEST=(1) On Android start-up, verify that the powered state is synchronized
         between Android and Chrome.
         (2) After Repeatedly toggling Bluetooth powered state, the state
         remains synchronized between Android and Chrome.
         (3) Put device into deep suspend and resume, the state restores to
         the previous state.
    
    Change-Id: I753839e2bb9228703492ebd23703cf8b67494998
    Reviewed-on: https://chromium-review.googlesource.com/580314
    Commit-Queue: Miao-chen Chou <mcchou@chromium.org>
    Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
    Reviewed-by: default avatarRahul Chaturvedi <rkc@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#491556}
    bb12724f
arc_bluetooth_bridge.h 24.5 KB