Make sure Android behaves properly in the background #407

Open
yaronyg opened this Issue Jan 5, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@yaronyg
Member

yaronyg commented Jan 5, 2016

We need to confirm that when we put our code into the background on Android that we will properly reduce power levels, that JXcore will continue running and behaving itself, etc.

This is especially critical for BLE as otherwise we can apparently cause non-trivial drainage on the device's battery.

@yaronyg yaronyg added 0 - Icebox and removed 0 - Icebox labels Jan 5, 2016

@yaronyg yaronyg added this to the New Infra milestone Jan 11, 2016

@tompaana

This comment has been minimized.

Show comment
Hide comment
@tompaana

tompaana Mar 4, 2016

Member

This seems almost duplicate of #413

Member

tompaana commented Mar 4, 2016

This seems almost duplicate of #413

@yaronyg

This comment has been minimized.

Show comment
Hide comment
@yaronyg

yaronyg Mar 4, 2016

Member

Actually it's not. When we are running in the background there are basically two states our code can be in. Awake (which is what this tests) or asleep (either because Android put the whole device into doze mode or just put our app into standby mode). So this bug is intended to make sure we are working well in 'Awake' and #413 is checking when we are in 'Doze' or 'Standby'. The only thing the two bugs share in common is that in both cases we are running in the background.

Member

yaronyg commented Mar 4, 2016

Actually it's not. When we are running in the background there are basically two states our code can be in. Awake (which is what this tests) or asleep (either because Android put the whole device into doze mode or just put our app into standby mode). So this bug is intended to make sure we are working well in 'Awake' and #413 is checking when we are in 'Doze' or 'Standby'. The only thing the two bugs share in common is that in both cases we are running in the background.

@yaronyg yaronyg added 2 - Ready and removed 1 - Backlog labels Mar 14, 2016

@yaronyg

This comment has been minimized.

Show comment
Hide comment
@yaronyg

yaronyg Mar 14, 2016

Member

Please investigate if there is a way for us to automate putting our test app into the background in CI in order to be sure that we are functioning properly with both both Wifi and BLE/Bluetooth when we are in the background.

Member

yaronyg commented Mar 14, 2016

Please investigate if there is a way for us to automate putting our test app into the background in CI in order to be sure that we are functioning properly with both both Wifi and BLE/Bluetooth when we are in the background.

@yaronyg yaronyg added 3 - Working and removed 2 - Ready labels Mar 14, 2016

@tompaana

This comment has been minimized.

Show comment
Hide comment
@tompaana

tompaana Mar 15, 2016

Member

There is no one, simple adb command to put an app into the background. The command for testing the App Standby (adb shell am set-inactive <packageName> true) comes close, but isn't the same thing.

The most straightforward way to accomplish this is to bring another app to foreground: adb shell am start -n com.package.name/com.package.name.ActivityName. However, that may not guarantee that the app formerly running on foreground is - at least immediately - pushed in background.

adb shell top -m <number of processes> can be used to see the processes hogging the most resources - and it has the info whether the app is on foreground or not ("fg" vs "bg")!

Also, another interesting option:

$ adb shell ps | grep <package name> # To find the process ID
$ adb shell am profile <process ID> start <file>
Member

tompaana commented Mar 15, 2016

There is no one, simple adb command to put an app into the background. The command for testing the App Standby (adb shell am set-inactive <packageName> true) comes close, but isn't the same thing.

The most straightforward way to accomplish this is to bring another app to foreground: adb shell am start -n com.package.name/com.package.name.ActivityName. However, that may not guarantee that the app formerly running on foreground is - at least immediately - pushed in background.

adb shell top -m <number of processes> can be used to see the processes hogging the most resources - and it has the info whether the app is on foreground or not ("fg" vs "bg")!

Also, another interesting option:

$ adb shell ps | grep <package name> # To find the process ID
$ adb shell am profile <process ID> start <file>
@tompaana

This comment has been minimized.

Show comment
Hide comment
@tompaana

tompaana Mar 15, 2016

Member

Tested with Nexus 6:

On foreground (receiving advertisements):

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
16966  3   4% S    48 1430032K 225488K  fg u0_a0    com.test.thalitest
 1717  0   1% S    37 1675804K 107092K  bg u0_a28   com.google.android.googlequicksearchbox
  862  0   1% S   106 1748648K 135848K  fg system   system_server
  277  1   1% S    15 162688K  20136K  fg system   /system/bin/surfaceflinger
17532  2   0% R     1   2968K   1180K  fg shell    top
10205  3   0% S    41 1053060K  51956K  fg bluetoot com.android.bluetooth
 1883  0   0% S    56 1325364K 102200K  bg u0_a11   com.google.android.gms
  279  0   0% S    27  38012K   1964K  fg nobody   /system/bin/sensors.qcom
17134  0   0% S     1      0K      0K  fg root     kworker/u8:0
  364  0   0% S     7   8104K    544K  fg shell    /sbin/adbd
16480  1   0% S     1      0K      0K  fg root     kworker/1:2
...

On background (receiving advertisements [confirmed in logcat]):

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
  862  3   2% S   106 1747792K 135412K  fg system   system_server
  277  1   1% S    15 208508K  20136K  fg system   /system/bin/surfaceflinger
 1339  0   1% S    33 1255572K 105748K  fg u0_a24   com.android.systemui
 1717  2   1% S    37 1740124K 111632K  fg u0_a28   com.google.android.googlequicksearchbox
17532  2   0% R     1   2968K   1180K  fg shell    top
  213  1   0% S     1      0K      0K  fg root     irq/163-dwc3
  364  3   0% S     7   8104K    360K  fg shell    /sbin/adbd
  337  3   0% D     1      0K      0K  fg root     mdss_fb0
16966  0   0% S    48 1317120K 197192K  bg u0_a0    com.test.thalitest
10205  3   0% S    41 1053060K  51940K  fg bluetoot com.android.bluetooth
   43  2   0% S     1      0K      0K  fg root     system
...

So drop from 4 % CPU usage to "0 %"

Member

tompaana commented Mar 15, 2016

Tested with Nexus 6:

On foreground (receiving advertisements):

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
16966  3   4% S    48 1430032K 225488K  fg u0_a0    com.test.thalitest
 1717  0   1% S    37 1675804K 107092K  bg u0_a28   com.google.android.googlequicksearchbox
  862  0   1% S   106 1748648K 135848K  fg system   system_server
  277  1   1% S    15 162688K  20136K  fg system   /system/bin/surfaceflinger
17532  2   0% R     1   2968K   1180K  fg shell    top
10205  3   0% S    41 1053060K  51956K  fg bluetoot com.android.bluetooth
 1883  0   0% S    56 1325364K 102200K  bg u0_a11   com.google.android.gms
  279  0   0% S    27  38012K   1964K  fg nobody   /system/bin/sensors.qcom
17134  0   0% S     1      0K      0K  fg root     kworker/u8:0
  364  0   0% S     7   8104K    544K  fg shell    /sbin/adbd
16480  1   0% S     1      0K      0K  fg root     kworker/1:2
...

On background (receiving advertisements [confirmed in logcat]):

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
  862  3   2% S   106 1747792K 135412K  fg system   system_server
  277  1   1% S    15 208508K  20136K  fg system   /system/bin/surfaceflinger
 1339  0   1% S    33 1255572K 105748K  fg u0_a24   com.android.systemui
 1717  2   1% S    37 1740124K 111632K  fg u0_a28   com.google.android.googlequicksearchbox
17532  2   0% R     1   2968K   1180K  fg shell    top
  213  1   0% S     1      0K      0K  fg root     irq/163-dwc3
  364  3   0% S     7   8104K    360K  fg shell    /sbin/adbd
  337  3   0% D     1      0K      0K  fg root     mdss_fb0
16966  0   0% S    48 1317120K 197192K  bg u0_a0    com.test.thalitest
10205  3   0% S    41 1053060K  51940K  fg bluetoot com.android.bluetooth
   43  2   0% S     1      0K      0K  fg root     system
...

So drop from 4 % CPU usage to "0 %"

@yaronyg yaronyg added 2 - Ready and removed 3 - Working labels Mar 17, 2016

@yaronyg

This comment has been minimized.

Show comment
Hide comment
@yaronyg

yaronyg Apr 6, 2016

Member

@tompaana I thought we had some reason for not just moving this to icebox (so we don't forget to fix CI to allow testing in the background) but I don't remember what it is.

Member

yaronyg commented Apr 6, 2016

@tompaana I thought we had some reason for not just moving this to icebox (so we don't forget to fix CI to allow testing in the background) but I don't remember what it is.

@yaronyg yaronyg removed this from the New Infra milestone Jul 11, 2016

@yaronyg yaronyg added 0 - Icebox and removed 2 - Ready labels Jul 11, 2016

@yaronyg yaronyg added this to the V1 milestone Aug 3, 2016

@yaronyg yaronyg added 1 - Backlog and removed 0 - Icebox labels Aug 4, 2016

@yaronyg yaronyg added the Android label Sep 1, 2016

@yaronyg yaronyg added bug and removed 1 - Backlog labels Oct 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment