Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Anbox wakes up my laptop #1436

Closed
jkufner opened this issue Apr 22, 2020 · 7 comments · Fixed by #1482
Closed

Anbox wakes up my laptop #1436

jkufner opened this issue Apr 22, 2020 · 7 comments · Fixed by #1482

Comments

@jkufner
Copy link

jkufner commented Apr 22, 2020

anbox system-info output
version: 0.0~git20191115-1+b1-Debian
cpu:
  arch:  x86
  brand: Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
  features: 
    - aes
    - sse4_1
    - sse4_2
    - avx
    - avx2
os:
  name: Debian GNU/Linux
  version: 
  snap-based: false
kernel:
  version: Linux version 5.5.0-2-amd64 (debian-kernel@lists.debian.org) (gcc version 9.3.0 (Debian 9.3.0-10)) #1 SMP Debian 5.5.17-1 (2020-04-15)
  binder: true
  ashmem: true
graphics:
  egl:
    vendor: Mesa Project
    version: 1.4
    extensions:
      - EGL_ANDROID_blob_cache
      - EGL_ANDROID_native_fence_sync
      - EGL_CHROMIUM_sync_control
      - EGL_EXT_buffer_age
      - EGL_EXT_create_context_robustness
      - EGL_EXT_image_dma_buf_import
      - EGL_EXT_image_dma_buf_import_modifiers
      - EGL_IMG_context_priority
      - EGL_KHR_config_attribs
      - EGL_KHR_create_context
      - EGL_KHR_create_context_no_error
      - EGL_KHR_fence_sync
      - EGL_KHR_get_all_proc_addresses
      - EGL_KHR_gl_colorspace
      - EGL_KHR_gl_renderbuffer_image
      - EGL_KHR_gl_texture_2D_image
      - EGL_KHR_gl_texture_3D_image
      - EGL_KHR_gl_texture_cubemap_image
      - EGL_KHR_image
      - EGL_KHR_image_base
      - EGL_KHR_image_pixmap
      - EGL_KHR_no_config_context
      - EGL_KHR_reusable_sync
      - EGL_KHR_surfaceless_context
      - EGL_EXT_pixel_format_float
      - EGL_KHR_wait_sync
      - EGL_MESA_configless_context
      - EGL_MESA_drm_image
      - EGL_MESA_image_dma_buf_export
      - EGL_MESA_query_driver
      - EGL_NOK_texture_from_pixmap
      - EGL_WL_bind_wayland_display
  gles2:
    vendor: Intel Open Source Technology Center
    vendor: OpenGL ES 3.1 Mesa 19.3.3
    extensions:
      - GL_EXT_blend_minmax
      - GL_EXT_multi_draw_arrays
      - GL_EXT_texture_filter_anisotropic
      - GL_EXT_texture_compression_s3tc
      - GL_EXT_texture_compression_dxt1
      - GL_EXT_texture_compression_rgtc
      - GL_EXT_texture_format_BGRA8888
      - GL_OES_compressed_ETC1_RGB8_texture
      - GL_OES_depth24
      - GL_OES_element_index_uint
      - GL_OES_fbo_render_mipmap
      - GL_OES_mapbuffer
      - GL_OES_rgb8_rgba8
      - GL_OES_standard_derivatives
      - GL_OES_stencil8
      - GL_OES_texture_3D
      - GL_OES_texture_float
      - GL_OES_texture_float_linear
      - GL_OES_texture_half_float
      - GL_OES_texture_half_float_linear
      - GL_OES_texture_npot
      - GL_OES_vertex_half_float
      - GL_EXT_texture_sRGB_decode
      - GL_OES_EGL_image
      - GL_OES_depth_texture
      - GL_OES_packed_depth_stencil
      - GL_EXT_texture_type_2_10_10_10_REV
      - GL_NV_conditional_render
      - GL_OES_get_program_binary
      - GL_APPLE_texture_max_level
      - GL_EXT_discard_framebuffer
      - GL_EXT_read_format_bgra
      - GL_EXT_frag_depth
      - GL_NV_fbo_color_attachments
      - GL_OES_EGL_image_external
      - GL_OES_EGL_sync
      - GL_OES_vertex_array_object
      - GL_OES_viewport_array
      - GL_ANGLE_texture_compression_dxt3
      - GL_ANGLE_texture_compression_dxt5
      - GL_EXT_occlusion_query_boolean
      - GL_EXT_robustness
      - GL_EXT_texture_rg
      - GL_EXT_unpack_subimage
      - GL_NV_draw_buffers
      - GL_NV_read_buffer
      - GL_NV_read_depth
      - GL_NV_read_depth_stencil
      - GL_NV_read_stencil
      - GL_EXT_draw_buffers
      - GL_EXT_map_buffer_range
      - GL_KHR_debug
      - GL_KHR_robustness
      - GL_OES_depth_texture_cube_map
      - GL_OES_required_internalformat
      - GL_OES_surfaceless_context
      - GL_EXT_color_buffer_float
      - GL_EXT_sRGB_write_control
      - GL_EXT_separate_shader_objects
      - GL_EXT_shader_implicit_conversions
      - GL_EXT_shader_integer_mix
      - GL_EXT_tessellation_point_size
      - GL_EXT_tessellation_shader
      - GL_INTEL_performance_query
      - GL_EXT_base_instance
      - GL_EXT_compressed_ETC1_RGB8_sub_texture
      - GL_EXT_copy_image
      - GL_EXT_draw_buffers_indexed
      - GL_EXT_draw_elements_base_vertex
      - GL_EXT_gpu_shader5
      - GL_EXT_polygon_offset_clamp
      - GL_EXT_primitive_bounding_box
      - GL_EXT_render_snorm
      - GL_EXT_shader_io_blocks
      - GL_EXT_texture_border_clamp
      - GL_EXT_texture_buffer
      - GL_EXT_texture_cube_map_array
      - GL_EXT_texture_norm16
      - GL_EXT_texture_view
      - GL_KHR_blend_equation_advanced
      - GL_KHR_context_flush_control
      - GL_KHR_robust_buffer_access_behavior
      - GL_NV_image_formats
      - GL_OES_copy_image
      - GL_OES_draw_buffers_indexed
      - GL_OES_draw_elements_base_vertex
      - GL_OES_gpu_shader5
      - GL_OES_primitive_bounding_box
      - GL_OES_sample_shading
      - GL_OES_sample_variables
      - GL_OES_shader_io_blocks
      - GL_OES_shader_multisample_interpolation
      - GL_OES_tessellation_point_size
      - GL_OES_tessellation_shader
      - GL_OES_texture_border_clamp
      - GL_OES_texture_buffer
      - GL_OES_texture_cube_map_array
      - GL_OES_texture_stencil8
      - GL_OES_texture_storage_multisample_2d_array
      - GL_OES_texture_view
      - GL_EXT_blend_func_extended
      - GL_EXT_buffer_storage
      - GL_EXT_float_blend
      - GL_EXT_geometry_point_size
      - GL_EXT_geometry_shader
      - GL_EXT_shader_samples_identical
      - GL_KHR_no_error
      - GL_OES_EGL_image_external_essl3
      - GL_OES_geometry_point_size
      - GL_OES_geometry_shader
      - GL_OES_shader_image_atomic
      - GL_EXT_clip_cull_distance
      - GL_EXT_disjoint_timer_query
      - GL_EXT_texture_compression_s3tc_srgb
      - GL_MESA_shader_integer_functions
      - GL_EXT_clip_control
      - GL_EXT_texture_compression_bptc
      - GL_KHR_parallel_shader_compile
      - GL_EXT_shader_framebuffer_fetch_non_coherent
      - GL_EXT_texture_sRGB_R8
      - GL_EXT_texture_shadow_lod
      - GL_MESA_framebuffer_flip_y
      - GL_EXT_demote_to_helper_invocation
      - GL_EXT_depth_clamp
      - GL_EXT_texture_query_lod

Please describe your problem:

When anbox is running, e.g., anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity it wakes up my laptop from suspend. The laptop can be suspended as usual, it goes to sleep with no trouble. However, in a few seconds or a minute it wakes up on its own. When I stop anbox (only the container-manager keeps runnig) and suspend the laptop, it keeps sleeping as it should.

What were you expecting?:

Not waking up my laptop. How it can happen anyway?

Additional info:

Thinkpad Yoga 12, Debian (bullseye), Linux kernel 5.5.0-amd64.

@l0ckpix
Copy link

l0ckpix commented Apr 25, 2020

Same here.

Additional Info:
Manajaro Linux KDE, Kernel 5.6.7-1

@ssz66666
Copy link

It seems that the wake-up behaviour is caused by healthd, which checks the battery status every minute if plugged in/every 10 minutes if on battery. It will wake up the device if suspended.

https://github.com/aosp-mirror/platform_system_core/blob/a325982045057d3011c1b3db247cd53300a14f7d/healthd/healthd.cpp#L264-L276

static void wakealarm_init(void) {
    wakealarm_fd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK);
    if (wakealarm_fd == -1) {
        KLOG_ERROR(LOG_TAG, "wakealarm_init: timerfd_create failed\n");
        return;
    }


    if (healthd_register_event(wakealarm_fd, wakealarm_event))
        KLOG_ERROR(LOG_TAG,
                   "Registration of wakealarm event failed\n");


    wakealarm_set_interval(healthd_config.periodic_chores_interval_fast);
}

Dropping the CAP_WAKE_ALARM capability of the lxc container, by setting

lxc.cap.drop = wake_alarm

i.e. adding

set_config_item("lxc.cap.drop", "wake_alarm");

somewhere in

void LxcContainer::start(const Configuration &configuration) {

seems to mitigate this issue as healthd will fail to create the timer. I'm not sure about any other implication of this change though.

@jkufner
Copy link
Author

jkufner commented Apr 28, 2020

... caused by healthd, which checks the battery status every minute if plugged in/every 10 minutes if on battery.

This seems to be consistent with my observations.

Do we need healthd at all?

@ssz66666
Copy link

... caused by healthd, which checks the battery status every minute if plugged in/every 10 minutes if on battery.

This seems to be consistent with my observations.

Do we need healthd at all?

https://source.android.com/devices/tech/health

Since healthd is a part of the Android core system services, I imagine it would be difficult to remove it without breaking other stuff.

@jkufner
Copy link
Author

jkufner commented Apr 28, 2020

https://source.android.com/devices/tech/health

The figure in Section "Health in Android 8.x shows that apps touch only the Battery Manager and Battery Service. I would expect that these APIs could be mapped to usual Linux APIs or replaced with some stubs (if appropriate). A quick look at android.os.health tells me that most of the stats are not relevant for the most apps so replacing them with a dummy could save more trouble than it makes. (But I don't know this API so maybe this is a complete nonsense.)

@ssz66666
Copy link

I figure another potential problem is an app in anbox can also wake up the host device by using AlarmManager, just like an app can wake up an Android phone. This behaviour isn't specific to healthd. Ultimately they all use the timer syscalls.

@necessarily-equal
Copy link
Contributor

note that it would be possible to include both fixes, if neutralizing healthd is useful

necessarily-equal added a commit to necessarily-equal/anbox that referenced this issue Jun 2, 2020
necessarily-equal added a commit to necessarily-equal/anbox that referenced this issue Jun 2, 2020
closes anbox#1436.

`lxc.cap.drop` existed already in LXC1.0, so I assume this should be
backward compatible.
it-is-a-robot pushed a commit to openeuler-mirror/anbox that referenced this issue Jul 29, 2020
closes anbox/anbox#1436.

`lxc.cap.drop` existed already in LXC1.0, so I assume this should be
backward compatible.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants