1 /* 2 * Copyright (C) 2022 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 android.photopicker.cts.cloudproviders; 18 19 import static android.photopicker.cts.PickerProviderMediaGenerator.MediaGenerator; 20 import static android.photopicker.cts.PickerProviderMediaGenerator.QueryExtras; 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.photopicker.cts.PickerProviderMediaGenerator; 29 import android.provider.CloudMediaProvider; 30 31 import java.io.FileNotFoundException; 32 33 /** 34 * Implements a cloud {@link CloudMediaProvider} interface over items generated with 35 * {@link MediaGenerator} 36 */ 37 public class CloudProviderSecondary extends CloudMediaProvider { 38 public static final String AUTHORITY = "android.photopicker.cts.cloudproviders.cloud_secondary"; 39 40 private MediaGenerator mMediaGenerator; 41 42 @Override onCreate()43 public boolean onCreate() { 44 mMediaGenerator = PickerProviderMediaGenerator.getMediaGenerator(getContext(), AUTHORITY); 45 return true; 46 } 47 48 @Override onQueryMedia(Bundle extras)49 public Cursor onQueryMedia(Bundle extras) { 50 final QueryExtras queryExtras = new QueryExtras(extras); 51 52 return mMediaGenerator.getMedia(queryExtras.generation, queryExtras.albumId, 53 queryExtras.mimeType, queryExtras.sizeBytes, queryExtras.pageSize); 54 } 55 56 @Override onQueryDeletedMedia(Bundle extras)57 public Cursor onQueryDeletedMedia(Bundle extras) { 58 final QueryExtras queryExtras = new QueryExtras(extras); 59 60 return mMediaGenerator.getDeletedMedia(queryExtras.generation); 61 } 62 63 @Override onQueryAlbums(Bundle extras)64 public Cursor onQueryAlbums(Bundle extras) { 65 final QueryExtras queryExtras = new QueryExtras(extras); 66 67 return mMediaGenerator.getAlbums(queryExtras.mimeType, queryExtras.sizeBytes); 68 } 69 70 @Override onOpenPreview(String mediaId, Point size, Bundle extras, CancellationSignal signal)71 public AssetFileDescriptor onOpenPreview(String mediaId, Point size, Bundle extras, 72 CancellationSignal signal) throws FileNotFoundException { 73 return new AssetFileDescriptor(mMediaGenerator.openMedia(mediaId), 0, 74 AssetFileDescriptor.UNKNOWN_LENGTH); 75 } 76 77 @Override onOpenMedia(String mediaId, Bundle extras, CancellationSignal signal)78 public ParcelFileDescriptor onOpenMedia(String mediaId, Bundle extras, 79 CancellationSignal signal) throws FileNotFoundException { 80 return mMediaGenerator.openMedia(mediaId); 81 } 82 83 @Override onGetMediaCollectionInfo(Bundle extras)84 public Bundle onGetMediaCollectionInfo(Bundle extras) { 85 return mMediaGenerator.getMediaCollectionInfo(); 86 } 87 } 88