1 /* 2 * Copyright 2019 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 androidx.work.lint 18 19 import com.android.tools.lint.checks.infrastructure.LintDetectorTest.java 20 import com.android.tools.lint.checks.infrastructure.LintDetectorTest.kotlin 21 import com.android.tools.lint.checks.infrastructure.TestFile 22 23 object Stubs { 24 25 val WORKER_FACTORY: TestFile = 26 kotlin( 27 "androidx/work/WorkerFactory.kt", 28 """ 29 package androidx.work 30 31 open class WorkerFactory 32 """ 33 ) 34 .indented() 35 .within("src") 36 37 val WORK_MANAGER_CONFIGURATION_PROVIDER: TestFile = 38 java( 39 "androidx/work/Configuration.java", 40 """ 41 package androidx.work; 42 43 class Configuration { 44 static class Builder { 45 void setJobSchedulerJobIdRange(int minId, int maxId) { 46 47 } 48 void setWorkerFactory(WorkerFactory factory) { 49 50 } 51 } 52 interface Provider { 53 Configuration getWorkManagerConfiguration(); 54 } 55 } 56 """ 57 ) 58 .indented() 59 .within("src") 60 61 val ANDROID_APPLICATION: TestFile = 62 kotlin( 63 "android/app/Application.kt", 64 """ 65 package android.app 66 open class Application { onCreatenull67 fun onCreate() { 68 69 } 70 } 71 """ 72 ) 73 .indented() 74 .within("src") 75 76 val LISTENABLE_WORKER: TestFile = 77 kotlin( 78 "androidx/work/ListenableWorker.kt", 79 """ 80 package androidx.work 81 82 open class ListenableWorker 83 """ 84 ) 85 .indented() 86 .within("src") 87 88 val RX_WORKER: TestFile = 89 kotlin( 90 "androidx/work/RxWorker.kt", 91 """ 92 package androidx.work 93 94 open class RxWorker: ListenableWorker() { 95 fun setProgress() { 96 97 } 98 99 fun setCompletableProgress() { 100 101 } 102 } 103 """ 104 ) 105 .indented() 106 .within("src") 107 108 val WORK_REQUEST: TestFile = 109 kotlin( 110 "androidx/work/WorkRequest.kt", 111 """ 112 package androidx.work 113 114 open class WorkRequest 115 """ 116 ) 117 .indented() 118 .within("src") 119 120 val ONE_TIME_WORK_REQUEST: TestFile = 121 kotlin( 122 "androidx/work/OneTimeWorkRequest.kt", 123 """ 124 package androidx.work 125 126 class OneTimeWorkRequest: WorkRequest() 127 """ 128 ) 129 .indented() 130 .within("src") 131 132 val PERIODIC_WORK_REQUEST: TestFile = 133 kotlin( 134 "androidx/work/PeriodicWorkRequest.kt", 135 """ 136 package androidx.work 137 138 import androidx.work.ListenableWorker 139 import java.time.Duration 140 import java.util.concurrent.TimeUnit 141 142 class PeriodicWorkRequest: WorkRequest { 143 class Builder { 144 constructor( 145 workerClass: Class<out ListenableWorker?>, 146 repeatInterval: Duration 147 ) 148 constructor( 149 workerClass: Class<out ListenableWorker?>, 150 repeatInterval: Long, 151 repeatIntervalTimeUnit: TimeUnit 152 ){} 153 154 constructor( 155 workerClass: Class<out ListenableWorker?>, 156 repeatInterval: Long, 157 repeatIntervalTimeUnit: TimeUnit, 158 flexInterval: Long, 159 flexIntervalTimeUnit: TimeUnit 160 ) 161 162 constructor( 163 workerClass: Class<out ListenableWorker?>, 164 repeatInterval: Duration, 165 flexInterval: Duration 166 ) 167 } 168 } 169 """ 170 ) 171 .indented() 172 .within("src") 173 174 val CONSTRAINTS: TestFile = 175 java( 176 "androidx/work/Constraints.java", 177 """ 178 package androidx.work; 179 180 class Constraints { 181 public static class Builder { 182 public Builder setRequiresDeviceIdle(boolean requiresDeviceIdle) { 183 return this; 184 } 185 public Builder setRequiresCharging(boolean requiresDeviceIdle) { 186 return this; 187 } 188 } 189 } 190 """ 191 ) 192 .indented() 193 .within("src") 194 195 val NOTIFICATION: TestFile = 196 kotlin( 197 "android/app/Notification.kt", 198 """ 199 package android.app 200 201 class Notification { 202 } 203 """ 204 ) 205 .indented() 206 .within("src") 207 208 val JOB_SERVICE: TestFile = 209 kotlin( 210 "android/app/job/JobService.kt", 211 """ 212 package android.app.job 213 214 open class JobService { 215 216 } 217 """ 218 ) 219 .indented() 220 .within("src") 221 222 val FOREGROUND_INFO: TestFile = 223 java( 224 "androidx/work/ForegroundInfo.java", 225 """ 226 package androidx.work; 227 228 import android.app.Notification; 229 230 public class ForegroundInfo { 231 public ForegroundInfo( 232 int notificationId, 233 Notification notification, 234 int foregroundServiceType) { } 235 } 236 """ 237 ) 238 .indented() 239 .within("src") 240 241 val WORK_MANAGER: TestFile = 242 kotlin( 243 "androidx/work/WorkManager.kt", 244 """ 245 package androidx.work 246 247 interface WorkManager { 248 fun enqueue(request: WorkRequest) 249 fun enqueue(requests: List<WorkRequest>) 250 fun enqueueUniqueWork(name: String, request: PeriodicWorkRequest) 251 } 252 """ 253 ) 254 .indented() 255 .within("src") 256 } 257