Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App hibernation🥶

operandoOS
February 24, 2022

App hibernation🥶

operandoOS

February 24, 2022
Tweet

More Decks by operandoOS

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • Shinobu Okano • @operandoOS / shinobu.dart • 10X,

    Inc. / Software Engineer • Flutter / Dart / Android / Automation
  2. ਺ϲ݄ར༻͞Ε͍ͯͳ͍ͬͯ۩ମతͳ਺ࣈ ͸ʁ • ظؒͷ͖͍͠஋Λมߋ͢Δ͜ͱ͸Ͱ͖Δ // ະ࢖༻ظؒͷ͖͍͠஋Λ1෼ʹมߋ adb shell device_config put

    permissions auto_revoke_unused_threshold_millis2 60000 // ઃఆͰ͖͍ͯΔ͔Λ֬ೝ adb shell device_config get permissions auto_revoke_unused_threshold_millis2
  3. Ͳͷ͘Β͍ͷස౓ͰhibernationͷνΣοΫ ͕ߦΘΕΔͷ͔ʁ • ͪ͜Β΋ස౓Λมߋ͢Δ͜ͱ͕Ͱ͖Δ // ࣮ߦपظΛ15෼ʹมߋ adb shell device_config put

    permissions auto_revoke_check_frequency_millis 900000 // ઃఆͰ͖͍ͯΔ͔Λ֬ೝ adb shell device_config get permissions auto_revoke_check_frequency_millis
  4. App usageͬͯͲ͏΍ͬͯΧ΢ϯτͯ͠Δͷ ͔ʁ private final UsageEventListener mUsageEventListener = (userId, event)

    -> { if (!isAppHibernationEnabled()) { return; } final int eventType = event.mEventType; if (eventType == UsageEvents.Event.USER_INTERACTION || eventType == UsageEvents.Event.ACTIVITY_RESUMED || eventType == UsageEvents.Event.APP_COMPONENT_USED) { final String pkgName = event.mPackage; setHibernatingForUser(pkgName, userId, false); setHibernatingGlobally(pkgName, false); } };
  5. ࢀߟίʔυʢ͋Γ͗͢…😇ʣ • https://cs.android.com/android/platform/superproject/+/master:packages/modules/Permission/PermissionController/src/com/android/permissioncontroller/hibernation/ • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/apphibernation/AppHibernationManager.java • https://cs.android.com/android/platform/superproject/+/master:packages/modules/Permission/PermissionController/src/com/android/permissioncontroller/hibernation/HibernationController.kt • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/ •

    https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/AppHibernationService.java • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/AppHibernationShellCommand.java • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/GlobalLevelState.java • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/UserLevelState.java • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/core/java/com/android/server/apphibernation/HibernationStateDiskStore.java • https://cs.android.com/android/platform/superproject/+/master:packages/modules/Permission/PermissionController/src/com/android/permissioncontroller/hibernation/HibernationPolicy.kt • https://cs.android.com/android/platform/superproject/+/master:packages/modules/Permission/PermissionController/src/com/android/permissioncontroller/permission/service/ AutoRevokePermissions.kt • https://cs.android.com/android/platform/superproject/+/master:packages/apps/Settings/src/com/android/settings/applications/HibernatedAppsPreferenceController.java • https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/apphibernation/AppHibernationManager.java
  6. App hibernationͷ಺෦ߏ଄Ͳ͏ௐ΂͔ͨ • DroidKaigi 2021 ʮͰ͖ΔʂAndroid Framework Code Readingʯ •

    https://speakerdeck.com/operando/dekiru-android-framework- code-reading • https://www.youtube.com/watch? v=44ChiZXry1E&list=PLaOdaBFokChxuuWf0eXWaf5H35R1Aroaz • ͪ͜ΒΛͥͻࢀߟʹ🙏