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.photopicker.data
18 
19 import android.content.ContentResolver
20 import android.net.Uri
21 import android.provider.MediaStore
22 
23 /**
24  * Provides URI constants and helper functions.
25  */
26 internal const val MEDIA_PROVIDER_AUTHORITY = MediaStore.AUTHORITY
27 private const val UPDATE_PATH_SEGMENT = "update"
28 private const val AVAILABLE_PROVIDERS_PATH_SEGMENT = "available_providers"
29 private const val MEDIA_PATH_SEGMENT = "media"
30 private const val ALBUM_PATH_SEGMENT = "album"
31 
<lambda>null32 private val pickerUri: Uri = Uri.Builder().apply {
33     scheme(ContentResolver.SCHEME_CONTENT)
34     authority(MEDIA_PROVIDER_AUTHORITY)
35     appendPath("picker_internal")
36     appendPath("v2")
37 }.build()
38 
39 /**
40  * URI for available providers resource.
41  */
<lambda>null42 val AVAILABLE_PROVIDERS_URI: Uri = pickerUri.buildUpon().apply {
43     appendPath(AVAILABLE_PROVIDERS_PATH_SEGMENT)
44 }.build()
45 
46 /**
47  * URI that receives [ContentProvider] change notifications for available provider updates.
48  */
<lambda>null49 val AVAILABLE_PROVIDERS_CHANGE_NOTIFICATION_URI: Uri = pickerUri.buildUpon().apply {
50     appendPath(AVAILABLE_PROVIDERS_PATH_SEGMENT)
51     appendPath(UPDATE_PATH_SEGMENT)
52 }.build()
53 
54 /**
55  * URI for media metadata.
56  */
<lambda>null57 val MEDIA_URI: Uri = pickerUri.buildUpon().apply {
58     appendPath(MEDIA_PATH_SEGMENT)
59 }.build()
60 
61 /**
62  * URI that receives [ContentProvider] change notifications for media updates.
63  */
<lambda>null64 val MEDIA_CHANGE_NOTIFICATION_URI: Uri = MEDIA_URI.buildUpon().apply {
65     appendPath(UPDATE_PATH_SEGMENT)
66 }.build()
67 
68 /**
69  * URI for album metadata.
70  */
<lambda>null71 val ALBUM_URI: Uri = pickerUri.buildUpon().apply {
72     appendPath(ALBUM_PATH_SEGMENT)
73 }.build()
74 
75 /**
76  * URI that receives [ContentProvider] change notifications for album media updates.
77  */
<lambda>null78 val ALBUM_CHANGE_NOTIFICATION_URI: Uri = ALBUM_URI.buildUpon().apply {
79     appendPath(UPDATE_PATH_SEGMENT)
80 }.build()
81 
getAlbumMediaUrinull82 fun getAlbumMediaUri(albumId: String): Uri {
83     return ALBUM_URI.buildUpon().apply {
84         appendPath(albumId)
85     }.build()
86 }
87