Sumir Kataria | 904ba12 | 2017-09-25 13:05:49 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.arch.background.workmanager.model; |
| 18 | |
| 19 | import android.arch.background.workmanager.Work; |
| 20 | import android.arch.persistence.room.ColumnInfo; |
| 21 | import android.arch.persistence.room.Embedded; |
| 22 | import android.arch.persistence.room.Entity; |
| 23 | import android.arch.persistence.room.PrimaryKey; |
| 24 | import android.arch.persistence.room.TypeConverters; |
| 25 | import android.support.annotation.NonNull; |
| 26 | |
| 27 | /** |
| 28 | * Stores information about a logical unit of work. |
| 29 | */ |
| 30 | @Entity |
| 31 | @TypeConverters(Arguments.class) |
| 32 | public class WorkSpec { |
| 33 | |
| 34 | @ColumnInfo(name = "id") |
| 35 | @PrimaryKey |
| 36 | @NonNull |
| 37 | String mId; |
| 38 | |
| 39 | // TODO(xbhatnag) |
| 40 | @ColumnInfo(name = "repeat_duration") |
| 41 | long mRepeatDuration; |
| 42 | |
| 43 | // TODO(xbhatnag) |
| 44 | @ColumnInfo(name = "flex_duration") |
| 45 | long mFlexDuration; |
| 46 | |
| 47 | @ColumnInfo(name = "status") |
| 48 | @Work.WorkStatus |
| 49 | int mStatus = Work.STATUS_ENQUEUED; |
| 50 | |
| 51 | @ColumnInfo(name = "worker_class_name") |
| 52 | String mWorkerClassName; |
| 53 | |
| 54 | @Embedded |
| 55 | Constraints mConstraints = new Constraints.Builder().build(); |
| 56 | |
| 57 | Arguments mArguments = new Arguments(); |
| 58 | |
| 59 | String mTag; |
| 60 | |
| 61 | // TODO(sumir): Should Backoff be disabled by default? |
| 62 | @ColumnInfo(name = "backoff_policy") |
| 63 | @Work.BackoffPolicy |
| 64 | int mBackoffPolicy = Work.BACKOFF_POLICY_EXPONENTIAL; |
| 65 | |
| 66 | @ColumnInfo(name = "backoff_delay_duration") |
| 67 | long mBackoffDelayDuration = Work.DEFAULT_BACKOFF_DELAY_DURATION; |
| 68 | |
| 69 | public WorkSpec(@NonNull String id) { |
| 70 | mId = id; |
| 71 | } |
| 72 | |
| 73 | @NonNull |
| 74 | public String getId() { |
| 75 | return mId; |
| 76 | } |
| 77 | |
| 78 | public void setId(@NonNull String id) { |
| 79 | mId = id; |
| 80 | } |
| 81 | |
| 82 | public long getRepeatDuration() { |
| 83 | return mRepeatDuration; |
| 84 | } |
| 85 | |
| 86 | public void setRepeatDuration(long repeatDuration) { |
| 87 | mRepeatDuration = repeatDuration; |
| 88 | } |
| 89 | |
| 90 | public long getFlexDuration() { |
| 91 | return mFlexDuration; |
| 92 | } |
| 93 | |
| 94 | public void setFlexDuration(long flexDuration) { |
| 95 | mFlexDuration = flexDuration; |
| 96 | } |
| 97 | |
| 98 | public int getStatus() { |
| 99 | return mStatus; |
| 100 | } |
| 101 | |
| 102 | public void setStatus(int status) { |
| 103 | mStatus = status; |
| 104 | } |
| 105 | |
| 106 | public String getWorkerClassName() { |
| 107 | return mWorkerClassName; |
| 108 | } |
| 109 | |
| 110 | public void setWorkerClassName(String workerClassName) { |
| 111 | mWorkerClassName = workerClassName; |
| 112 | } |
| 113 | |
| 114 | public Constraints getConstraints() { |
| 115 | return mConstraints; |
| 116 | } |
| 117 | |
| 118 | public void setConstraints(Constraints constraints) { |
| 119 | mConstraints = constraints; |
| 120 | } |
| 121 | |
| 122 | public Arguments getArguments() { |
| 123 | return mArguments; |
| 124 | } |
| 125 | |
| 126 | public void setArguments(Arguments arguments) { |
| 127 | mArguments = arguments; |
| 128 | } |
| 129 | |
| 130 | public String getTag() { |
| 131 | return mTag; |
| 132 | } |
| 133 | |
| 134 | public void setTag(String tag) { |
| 135 | mTag = tag; |
| 136 | } |
| 137 | |
| 138 | public int getBackoffPolicy() { |
| 139 | return mBackoffPolicy; |
| 140 | } |
| 141 | |
| 142 | public void setBackoffPolicy(int backoffPolicy) { |
| 143 | mBackoffPolicy = backoffPolicy; |
| 144 | } |
| 145 | |
| 146 | public long getBackoffDelayDuration() { |
| 147 | return mBackoffDelayDuration; |
| 148 | } |
| 149 | |
| 150 | public void setBackoffDelayDuration(long backoffDelayDuration) { |
| 151 | mBackoffDelayDuration = backoffDelayDuration; |
| 152 | } |
| 153 | } |