1 /* 2 * Copyright (C) 2024 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 com.android.statementservice.domain.worker 18 19 import android.content.Context 20 import androidx.work.Data 21 import androidx.work.OneTimeWorkRequestBuilder 22 import androidx.work.WorkerParameters 23 import kotlinx.coroutines.coroutineScope 24 25 class GroupUpdateV1Worker(appContext: Context, params: WorkerParameters) : 26 BaseRequestWorker(appContext, params) { 27 28 companion object { 29 30 private const val PACKAGE_NAME_KEY = "packageName" 31 buildRequestnull32 fun buildRequest(packageName: String) = OneTimeWorkRequestBuilder<GroupUpdateV1Worker>() 33 .setInputData( 34 Data.Builder() 35 .putString(PACKAGE_NAME_KEY, packageName) 36 .build() 37 ) 38 .build() 39 } 40 41 override suspend fun doWork() = coroutineScope { 42 val packageName = params.inputData.getString(PACKAGE_NAME_KEY)!! 43 updateUriRelativeFilterGroups(packageName) 44 Result.success() 45 } 46 updateUriRelativeFilterGroupsnull47 private fun updateUriRelativeFilterGroups(packageName: String) { 48 val groupUpdates = database.getDomainGroups(packageName) 49 updateUriRelativeFilterGroups( 50 packageName, 51 groupUpdates.associateBy({it.domain}, {it.groups}) 52 ) 53 database.clear(packageName) 54 } 55 }