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