1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.deletion.api
17 
18 import android.health.connect.HealthConnectManager
19 import android.health.connect.RecordIdFilter
20 import com.android.healthconnect.controller.deletion.DeletionType.DeleteDataEntry
21 import com.android.healthconnect.controller.service.IoDispatcher
22 import javax.inject.Inject
23 import javax.inject.Singleton
24 import kotlinx.coroutines.CoroutineDispatcher
25 import kotlinx.coroutines.withContext
26 
27 @Singleton
28 @Deprecated("This won't be used once the NEW_INFORMATION_ARCHITECTURE feature is enabled.")
29 class DeleteEntryUseCase
30 @Inject
31 constructor(
32     private val healthConnectManager: HealthConnectManager,
33     @IoDispatcher private val dispatcher: CoroutineDispatcher
34 ) {
invokenull35     suspend fun invoke(deleteEntry: DeleteDataEntry) =
36         withContext(dispatcher) {
37             val recordIdFilter =
38                 RecordIdFilter.fromId(deleteEntry.dataType.recordClass, deleteEntry.id)
39 
40             healthConnectManager.deleteRecords(listOf(recordIdFilter), Runnable::run) {}
41         }
42 }
43