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

WorkManager Stableに向けての所感

WorkManager Stableに向けての所感

2019/3/18に開催されたOtemachi.apk #2の発表資料です。当日はFirebaseJobDispatcher周りについて事実とは異なる発言をしているので修正したものになります。

Yoshihiro WADA

March 18, 2019
Tweet

More Decks by Yoshihiro WADA

Other Decks in Programming

Transcript

  1. WorkManager Stable
    Yoshihiro Wada a.k.a. @e10dokup
    Otemachi.apk #2 - 2019/03/18
    2019/3/20

    View full-size slide

  2. Yoshihiro Wada a.k.a. @e10dokup
    CyberAgant Inc. / Ameba
    Ameba

    View full-size slide

  3. Android Jetpack
    compileSdkVersion 28
    API Play Services JobScheduler/AlermManager/FirebaseJobDispatcher
    FirebaseJobDispatcher 1.0.0-alpha12
    FirebaseJobDispatcher deprecated
    etc
    WorkManager

    View full-size slide

  4. FirebaseJobDispatcher

    View full-size slide

  5. WorkManager Stable 1.0.0
    Released

    View full-size slide

  6. Beta RC Stable
    bug x
    Breaking API Changes 2018/12/12 1.0.0-alpha13
    Codelabs API Changes

    View full-size slide

  7. Worker
    WorkManager
    WorkRequest
    Worker Request WorkManager
    Request WorkManager
    WorkManager
    WorkRequest
    WorkManager

    View full-size slide

  8. Worker
    doWork()
    WorkManager
    ˖ FYUFOET8PSLFSזؙٓأ׾甧ג׷
    ˖ EP8PSL
    ⰻד䗳銲זⳢ椚׾鎸鶢ׅ׷
    ˖ 䧭⸆٥㸣✪ח䘔ׄג8PSLFS3FTVMUTVDDFTT
    GBJMVSF
    ׾鵤ׅ
    8PSLFS
    class MyWorker(
    context: Context, params: WorkerParameters
    ) : Worker(context, params) {
    override fun doWork(): Worker.Result {
    // Կ͔͠Βͷॲཧ
    return Worker.Result.success()
    }
    }

    View full-size slide

  9. WorkRequest optional Worker
    OneTimeWorkRequest - WorkRequest
    PeriodicWorkRequest - WorkRequest
    WorkManager
    ˖ 8PSLFSח㹋遤ח䗳銲ז⦼׾♷ִ׷
    ˖ %BUBؙٓأ׾CVJME׃׋׮ך׾TFU*OQVU%BUBדTFUׅ׷
    ˖ 8PSLFS⩎דכHFU*OQVU%BUBד《׶⳿ׅ
    8PSL3FRVFTU
    // Workerʹ஋Λ༩͑Δ
    val data = Data.Builder().putString("KEY", "VALUE").build()
    OneTimeWorkRequest.Builder(MyWorker::class.java)
    .setInputData(data)
    .build()
    // WorkerͰ஋ΛऔΓग़͢
    getInputData().getString("KEY")

    View full-size slide

  10. WorkManager WorkRequest enqueue
    WorkManager
    // Workerに値を与える
    val data = Data.Builder().putString(“KEY”, “VALUE”).build()
    OneTimeWorkRequest.Builder(MyWorker::class.java)
    .setInputData(data)
    .build()
    // Workerで値を取り出す
    getInputData().getString(“KEY”)
    ˖ 8PSL.BOBHFSFORVFVFׅ׷׌ֽ
    欰䧭׃׋8PSL3FRVFTUך㹋遤
    workManager = WorkManager.getInstance()
    val data = Data.Builder().putString("KEY", "VALUE").build()
    val request = OneTimeWorkRequest.Builder(MyWorker::class.java)
    .setInputData(data)
    .build()
    workManager.enqueue(request)

    View full-size slide

  11. potatotips
    8PSL.BOBHFS
    :PTIJIJSP8BEBBLB!FEPLVQ
    BU1PUBUPUJQT
    ְתׁ׵
    https://bit.ly/2UF3k4Q

    View full-size slide

  12. WorkManager
    Executor Constraints

    View full-size slide

  13. DB Worker
    GreedyScheduler ThreadPool
    JobSchedulers
    createBestAvailableBackgroundScheduler
    API Level 23 JobSchedulers
    Google Play Services FirebaseJobDispatcher
    AlermManager + BroadCastReceiver
    Executor
    ref: https://speakerdeck.com/takahirom/workmanager (58P)

    View full-size slide

  14. DB Worker
    GreedyScheduler ThreadPool
    JobSchedulers
    createBestAvailableBackgroundScheduler
    API Level 23 JobSchedulers
    AlermManager + BroadCastReceiver
    Executor
    ref: https://speakerdeck.com/takahirom/workmanager (58P)

    View full-size slide

  15. Constraints
    WorkRequest
    Constraints
    ˖ 8PSL3FRVFTU׾⡲׷媮ꥡד$POTUSBJOU׾♷ִ׷ֿהד㹋遤儗חⵖ秈׾⸇ִ׵׸׷
    8PSLך㹋遤朐䡾׾ⵖꣲ׃׋ְ
    // ୺຤͕ॆిதͰ͋Δ੍໿ΛՃ͑Δ
    val constraints = Constraints.Builder()
    .setRequiresCharging(true)
    .build()
    continuation = continuation.then(
    OneTimeWorkRequest.Builder(AWorker::class.java)
    .setConstraints(constraints)
    .build()
    )

    View full-size slide

  16. WorkManager Constraints
    NetworkType -
    BatterNotLow -
    Charging -
    StorageNotLow -
    DeviceIdle - Doze Idle API23
    Constraints

    View full-size slide

  17. WorkManager Constraints
    NetworkType -
    BatterNotLow -
    Charging -
    StorageNotLow -
    DeviceIdle - Doze Idle API23
    Constraints
    ConstraintController Tracker Constraints

    View full-size slide

  18. WorkManager Constraints
    NetworkType -
    BatterNotLow -
    Charging -
    StorageNotLow -
    DeviceIdle - Doze Idle API23
    Constraints
    ConstraintController Tracker Constraints

    View full-size slide

  19. Constrains Builder Charging
    Constraints WorkManager
    TaskExecuter Worker WorkerFactory
    Tracker ConstraintController
    Charging Constraint
    public @NonNull Builder setRequiresCharging(boolean requiresCharging) {
    this.mRequiresCharging = requiresCharging;
    return this;
    }

    View full-size slide

  20. BatteryChargingController
    Room DB Charging Constraint
    BatteryChargingTracker
    ACTION_BATTERY_CHANGED intent ACTION_CHARGING /
    ACTION_POWER_CONNECTED
    Tracker Constraint Back-o
    Worker
    Charging Constraint

    View full-size slide

  21. https://android.googlesource.com/platform/frameworks/support/+/androidx-
    master-dev/work/workmanager/src/main/java/androidx/work/impl/constraints
    BatteryNotLow 15% ACTION_BATTERY_OKAY/LOW
    NetworkType ConnectivityManager METERED CONNECTED
    ROAMING
    StorageNotLow ACTION_DEVICE_STORAGE_OK / LOW
    API 26 AndroidManifest BroadcastReceiver deprecated
    BroadcastReceiver
    Constraints

    View full-size slide

  22. Executor Constraints
    Firebase JobDispatcher WorkManager migrating
    https://developer.android.com/topic/libraries/architecture/workmanager/
    migrating-fb

    View full-size slide