• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.providers.media.photopicker;
18 
19 import static android.provider.CloudMediaProviderContract.MediaCollectionInfo;
20 import static com.android.providers.media.PickerProviderMediaGenerator.MediaGenerator;
21 
22 import android.content.res.AssetFileDescriptor;
23 import android.database.Cursor;
24 import android.graphics.Point;
25 import android.os.Bundle;
26 import android.os.CancellationSignal;
27 import android.os.ParcelFileDescriptor;
28 import android.provider.CloudMediaProvider;
29 
30 import com.android.providers.media.PickerProviderMediaGenerator;
31 import com.android.providers.media.photopicker.data.CloudProviderQueryExtras;
32 
33 import java.io.FileNotFoundException;
34 
35 /**
36  * Implements the a local {@link CloudMediaProvider} interface over items generated with
37  * {@link MediaGenerator}
38  */
39 public class LocalProvider extends CloudMediaProvider {
40     public static final String AUTHORITY = "com.android.providers.media.photopicker.tests.local";
41 
42     private final MediaGenerator mMediaGenerator =
43             PickerProviderMediaGenerator.getMediaGenerator(AUTHORITY);
44 
45     @Override
onCreate()46     public boolean onCreate() {
47         return true;
48     }
49 
50     @Override
onQueryMedia(Bundle extras)51     public Cursor onQueryMedia(Bundle extras) {
52         final CloudProviderQueryExtras queryExtras =
53                 CloudProviderQueryExtras.fromCloudMediaBundle(extras);
54 
55         return mMediaGenerator.getMedia(queryExtras.getGeneration(), queryExtras.getAlbumId(),
56                 queryExtras.getMimeType(), queryExtras.getSizeBytes());
57     }
58 
59     @Override
onQueryDeletedMedia(Bundle extras)60     public Cursor onQueryDeletedMedia(Bundle extras) {
61         final CloudProviderQueryExtras queryExtras =
62                 CloudProviderQueryExtras.fromCloudMediaBundle(extras);
63 
64         return mMediaGenerator.getDeletedMedia(queryExtras.getGeneration());
65     }
66 
67     @Override
onQueryAlbums(Bundle extras)68     public Cursor onQueryAlbums(Bundle extras) {
69         final CloudProviderQueryExtras queryExtras =
70                 CloudProviderQueryExtras.fromCloudMediaBundle(extras);
71 
72         return mMediaGenerator.getAlbums(queryExtras.getMimeType(), queryExtras.getSizeBytes(),
73                 /* isLocal */ true);
74     }
75 
76     @Override
onOpenPreview(String mediaId, Point size, Bundle extras, CancellationSignal signal)77     public AssetFileDescriptor onOpenPreview(String mediaId, Point size, Bundle extras,
78             CancellationSignal signal) throws FileNotFoundException {
79         throw new UnsupportedOperationException("onOpenPreview not supported");
80     }
81 
82     @Override
onOpenMedia(String mediaId, Bundle extras, CancellationSignal signal)83     public ParcelFileDescriptor onOpenMedia(String mediaId, Bundle extras,
84             CancellationSignal signal) throws FileNotFoundException {
85         throw new UnsupportedOperationException("onOpenMedia not supported");
86     }
87 
88     @Override
onGetMediaCollectionInfo(Bundle extras)89     public Bundle onGetMediaCollectionInfo(Bundle extras) {
90         return mMediaGenerator.getMediaCollectionInfo();
91     }
92 }
93