• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
<lambda>null2  * 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.permissiontypes.api
17 
18 import android.health.connect.FetchDataOriginsPriorityOrderResponse
19 import android.health.connect.HealthConnectManager
20 import android.health.connect.HealthDataCategory
21 import androidx.core.os.asOutcomeReceiver
22 import com.android.healthconnect.controller.service.IoDispatcher
23 import com.android.healthconnect.controller.shared.HealthDataCategoryInt
24 import com.android.healthconnect.controller.shared.app.AppInfoReader
25 import com.android.healthconnect.controller.shared.app.AppMetadata
26 import com.android.healthconnect.controller.shared.usecase.BaseUseCase
27 import com.android.healthconnect.controller.shared.usecase.UseCaseResults
28 import javax.inject.Inject
29 import javax.inject.Singleton
30 import kotlinx.coroutines.CoroutineDispatcher
31 import kotlinx.coroutines.suspendCancellableCoroutine
32 
33 @Deprecated("This won't be used once the NEW_INFORMATION_ARCHITECTURE feature is enabled.")
34 @Singleton
35 class LoadPriorityListUseCase
36 @Inject
37 constructor(
38     private val healthConnectManager: HealthConnectManager,
39     private val appInfoReader: AppInfoReader,
40     @IoDispatcher private val dispatcher: CoroutineDispatcher
41 ) : BaseUseCase<@HealthDataCategoryInt Int, List<AppMetadata>>(dispatcher), ILoadPriorityListUseCase {
42 
43     /** Returns list of [AppMetadata]s for given [HealthDataCategory] in priority order. */
44     override suspend fun execute(input: @HealthDataCategoryInt Int): List<AppMetadata> {
45         val dataOriginPriorityOrderResponse: FetchDataOriginsPriorityOrderResponse =
46             suspendCancellableCoroutine { continuation ->
47                 healthConnectManager.fetchDataOriginsPriorityOrder(
48                     input, Runnable::run, continuation.asOutcomeReceiver())
49             }
50         return dataOriginPriorityOrderResponse.dataOriginsPriorityOrder.map { dataOrigin ->
51             appInfoReader.getAppMetadata(dataOrigin.packageName)
52         }
53     }
54 }
55 
56 interface ILoadPriorityListUseCase {
invokenull57     suspend fun invoke(input: @HealthDataCategoryInt Int) : UseCaseResults<List<AppMetadata>>
58 
59     suspend fun execute(input: @HealthDataCategoryInt Int) : List<AppMetadata>
60 }
61