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 package com.android.healthconnect.controller.exportimport.api 17 18 import android.net.Uri 19 import android.provider.DocumentsContract 20 21 private const val DOWNLOADS_AUTHORITY = "com.android.providers.downloads.documents" 22 23 /** Document providers for exporting/importing Health Connect data. */ 24 sealed class DocumentProviders { 25 data object Loading : DocumentProviders() 26 27 data object LoadingFailed : DocumentProviders() 28 29 data class WithData(val providers: List<DocumentProvider>) : DocumentProviders() 30 } 31 32 /** Single document provider for exporting/importing Health Connect data. */ 33 data class DocumentProvider(val info: DocumentProviderInfo, val roots: List<DocumentProviderRoot>) 34 35 /** Info for a document provider to display to the user. */ 36 data class DocumentProviderInfo(val title: String, val authority: String, val iconResource: Int) 37 38 /** Root with in a document provider (usually corresponds to an account). */ 39 data class DocumentProviderRoot(val summary: String, val uri: Uri) 40 41 /** Returns true if the given document uri is a local device storage file. */ isLocalFilenull42fun isLocalFile(uri: Uri): Boolean = 43 uri.authority == DocumentsContract.EXTERNAL_STORAGE_PROVIDER_AUTHORITY || 44 uri.authority == DOWNLOADS_AUTHORITY 45