1. 24 Aug, 2018 4 commits
    • spiiroin's avatar
      [usb_moded] Refactor entering/leaving usb mode. JB#41748 · 64350689
      spiiroin authored
      Split mode switching to three layers: Tracking cable connection state,
      choosing target mode, and performing required actions to activate
      the chosen mode.
      
      Try to minimize places where layer borders are crossed - which should
      work also as an enabler for moving blocking actions to separate thread
      later on.
      
      Arrange logic in such manner that usb gadget is always configured as
      being able to serve some function - fallback being the dummy mass_storage
      function used for charging.
      
      Deprecate command line options that serve no useful purpose after the
      changes.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      64350689
    • spiiroin's avatar
      [usb_moded] Drop --android-bootup-function option. JB#41748 · 4f53cf48
      spiiroin authored
      The target is to always have android usb enabled with valid function, so
      this workaround is not relevant anymore.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      4f53cf48
    • spiiroin's avatar
      [usb_moded] Normalize multiline comments · 7a386e38
      spiiroin authored
      Just to make it easier for editor to handle automatic indentation, make
      all C comment continuation lines start with whitespace followed by '*'.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      7a386e38
    • spiiroin's avatar
      [usb_moded] Add configfs support. Fixes JB#42083 · 692c2cb3
      spiiroin authored
      Add custom Makefile for faster smoke-test rebuilds without spending time
      in configure, autotools, document generation and/or rolling rpm packages.
      
      Add multiple include protection to all header files.
      
      Move function prototypes away from header files that included in the
      development package.
      
      Mass rename functions to have a prefix giving context for the function.
      For the most part the prefix is derived from the name of the compilation
      module containing the function.
      
      Mass normalize indentation to four spaces in all source files.
      
      Augment author lists on each source file based on git committers.
      
      Remove "inline" attributes from not-really-inlineable functions.
      
      Remove .gitignore.
      
      Remove unused modules-android.c source file.
      
      Define _GNU_SOURCE for whole build rather than in individual files.
      
      Fix resource leaks here and there.
      
      Try to avoid hard-coding android usb paths.
      
      Add configfs backend for usb cadget configuration.
      
      Probe supported backends (configfs, android usb, or kmod) on usb-moded
      startup and make them mutually exclusive with each other.
      
      Allow configfs and android usb control structures some time to show up
      if usb-moded is started during device bootup.
      
      Refactor udev event listener to utilize a state machine. Simplifies
      book keeping and makes pc/charger detection heuristics easier to control.
      
      Refactor mode selection to utilize three interconnected mini state machines.
      Allows separating logically wanted mode from mode programmed to usb and
      mode exposed over D-Bus.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      692c2cb3
  2. 05 Jun, 2018 3 commits
  3. 28 Mar, 2018 5 commits
  4. 08 Mar, 2018 1 commit
    • spiiroin's avatar
      [android] Do not require android configuration block. Fixes JB#41303 · 7a2607c1
      spiiroin authored
      Usb-moded does android usb initialization only if there is a non-empty
      configuration block in the ini-files. This does not make sense anymore
      as the values defined in the config file are used as fallback solution
      if required data can't be obtained by other means.
      
      If android_usb specific sysfs controls are present on the device, try
      to initialize them regardless of whether ubs-moded configuration files
      contain relevant information or not.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      7a2607c1
  5. 17 Aug, 2017 1 commit
    • spiiroin's avatar
      [debug] Optionally include file/line/function info when logging to stderr · 3420f50a
      spiiroin authored
      When debugging usb-moded it is time consuming to find where the
      various debug messages originate from.
      
      When logging to stderr, prefix the messages with source code
      position info similar as gcc uses for reporting compilation
      issues. This allows browsing usb-moded code with jump to the
      next error functionality available in many text editors.
      
      Since the amount of information passed to logging functions
      is significantly increased, check whether the message would
      be emitted or not before evaluating formatting parameters etc.
      
      Also make variables relating to logging level, type, etc
      available only via accessor functions.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      3420f50a
  6. 11 Aug, 2017 1 commit
  7. 26 Apr, 2017 2 commits
  8. 24 Mar, 2017 3 commits
  9. 13 Mar, 2017 1 commit
    • spiiroin's avatar
      [usb-moded] Use MEEGOLOCK features only when enabled. Fixes MER#1765 · 04e3a753
      spiiroin authored
      The is_in_user_state() is used unconditionally, but it is available only
      when --enable-meegodevlock option has been passed to configure. Also,
      the related "usb_moded-dsme.h" is included both unconditionally and from
      withing a #ifdef MEEGOLOCK block - which hides the configuration problem
      until build proceeds to linking phase.
      
      Make the call is_in_user_state() only if MEEGOLOCK is defined.
      
      Remove the extraneous "usb_moded-dsme.h" include to make such errors
      visible already in compilation stage due to missing prototypes.
      
      Also, make sure the "usb_moded-dsme.h" can't be included without
      warnings unless MEEGOLOCK is defined.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      04e3a753
  10. 14 Feb, 2017 3 commits
  11. 07 Nov, 2016 8 commits
    • spiiroin's avatar
      [usb-moded] Fix issues on exit path. MER#1694 · b3e2f370
      spiiroin authored
      Exiting from mainloop does not work as intended, looks like handle_exit()
      is meant to be called from main() function after mainloop is stopped. What
      happens in practice is that handle_exit() gets called from signal handler
      and it makes exit() without ever returning to main() function - which
      means some cleanup tasks are skipped.
      
      In general: Make cleanup tasks happen on the same logical level where
      initialization is made, re-order init/cleanup tasks according to what
      functional inter dependencies exist and add comments describing why
      things are done when they are done.
      
      Remove handle_exit() function and distribute work it used to do among:
      - usb_moded_stop() - exiting from mainloop
      - usb_moded_cleanup() - releasing usb-mode related state/config data
      - main() - cleaning up init steps made from main()
      
      To make possible ordering issues more visible, refuse to send usb-moded
      dbus signals in situations where the service name is not owned by the
      ubs-moded process.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      b3e2f370
    • spiiroin's avatar
      [logging] Flush output streams relevant for logging · c9055d07
      spiiroin authored
      Mixed use of syslog, stdout, stderr and differences in buffering of
      the streams causes the initial "starting up" message to end up as the
      final output in usb-moded journal when debug level logging is used
      (i.e. when freopen steps are skipped and stdout is not implicitly
      flushed).
      
      Use stderr and flush it before potentially switching to syslog logging.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      c9055d07
    • spiiroin's avatar
      [logging] Use timestamps relative to usb-moded start for stderr logging · 55794637
      spiiroin authored
      Use of wall clock timestamps with microsecond accuracy makes it difficult
      to see where usb-moded is spending time during startup.
      
      Use timestamps that use millisecond accuracy and are relative to usb-moded
      startup time.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      55794637
    • spiiroin's avatar
      [systemd] Use cached SystemBus connection. Fixes MER#1694 · bae87438
      spiiroin authored
      Usb-moded opens and closes a private peer-to-peer dbus connection for each
      systemd unit start/stop it needs to perform. This is relatively heavy
      operation and seems to cause problems with systemd v225 during bootup.
      
      Since usb-moded no longer has any reason to communicate with systemd
      before it can connect to SystemBus, we can drop the private connections
      and use cached SystemBus connection instead.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      bae87438
    • spiiroin's avatar
      [dsme] Make device state tracking asynchronous. MER#1694 · 4e7f9709
      spiiroin authored
      Usb-moded is making repeated blocking device state queries even when the
      component providing the service is not running.
      
      Use cached device state and keep it up to date fully asynchronously by
      tracking dsme service availability and state changes it signals.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      4e7f9709
    • spiiroin's avatar
      [usb-moded] Do not force appsync stop during bootup. MER#1694 · 9b04af27
      spiiroin authored
      Starting/stopping appsync related systemd units is relatively expensive
      task to perform and can cause timing problems during bootup.
      
      As we know the appsync processes have not been started when device is
      booting up, we can skip the explicit stopping when usb-moded is started
      as part of bootup sequence.
      
      Also, when usb-moded is exiting, it should be enough to stop only those
      units that have been started by usb-moded.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      9b04af27
    • spiiroin's avatar
      [appsync] Change appsync_stop() to take boolean parameter · 99f2413d
      spiiroin authored
      It is treated as a boolean, so using matching type improves readability.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      99f2413d
    • spiiroin's avatar
      [dbus] Improve SystemBus connection management. MER#1694 · 3e9e1817
      spiiroin authored
      D-Bus SystemBus connection is made from several places. Explicitly
      from the main() and implicitly from various modules that do ipc
      with other components. This makes it hard to tell when connection
      actually gets made, process wide dbus initialization happens in
      the wrong place and setting up signal matches is delayed by the
      synchronous initialization activity during startup.
      
      Move dbus_threads_init_default() to more appropriate place so that
      it actually is the first libdbus call that gets made.
      
      Handle connecting to SystemBus and installing signal listeners as early
      as possible and claim usb-moded service name separately when usb-moded
      is ready to process requests made over D-Bus.
      
      Add usb_moded_dbus_get_connection() function that other modules can
      use to get reference to the SystemBus connection when/if one has been
      made from the main logic.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      3e9e1817
  12. 02 Nov, 2016 1 commit
  13. 18 Oct, 2016 1 commit
  14. 07 Jul, 2016 3 commits
  15. 26 Apr, 2016 2 commits
    • spiiroin's avatar
      [udev] Suspend proof event reading and processing. Fixes JB#34440 · c982d3b4
      spiiroin authored
      Depending on kernel side usb drivers and charging logic, it is possible
      that device suspends immediately after reporting usb connect / disconnect
      while display is off and autosuspend enabled. That can delay the actions
      that should be made on usb connection state changes.
      
      Acquire a wakelock for the duration of udev event input processing.
      
      Hold a wakelock for a while when usb connection state changes occur.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      c982d3b4
    • spiiroin's avatar
      [udev] Try to ignore false positive cable connects. Contributes to JB#34547 · 2fa5781b
      spiiroin authored
      When connecting charger to usb port, it is sometimes initially detected as
      a pc cable instead of charger. This leads to usb mode selection dialog
      popping up in a situation where mode selection is not possible.
      
      Optionally, when cable connect is seen based on udev events, wait a while
      to see if it gets identified as dedicated charger before invoking actions
      relevant to pc cable connection only.
      
      It is assumed that data reported by udev on usb-moded startup is stable
      and pc cable connection is accepted without delay.
      
      By default usb-moded reacts immediately to pc cable connect events.
      If needed, the default delay can be adjusted via usb-moded command
      line argument -m/--max-cable-delay=<ms>.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      2fa5781b
  16. 04 Apr, 2016 1 commit