1 /* 2 * Copyright 2018 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 androidx.documentfile.provider; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.provider.DocumentsContract; 22 23 import androidx.annotation.Nullable; 24 import androidx.annotation.RequiresApi; 25 26 @RequiresApi(19) 27 class SingleDocumentFile extends DocumentFile { 28 private Context mContext; 29 private Uri mUri; 30 31 SingleDocumentFile(@Nullable DocumentFile parent, Context context, Uri uri) { 32 super(parent); 33 mContext = context; 34 mUri = uri; 35 } 36 37 @Override 38 public DocumentFile createFile(String mimeType, String displayName) { 39 throw new UnsupportedOperationException(); 40 } 41 42 @Override 43 public DocumentFile createDirectory(String displayName) { 44 throw new UnsupportedOperationException(); 45 } 46 47 @Override 48 public Uri getUri() { 49 return mUri; 50 } 51 52 @Override 53 @Nullable 54 public String getName() { 55 return DocumentsContractApi19.getName(mContext, mUri); 56 } 57 58 @Override 59 @Nullable 60 public String getType() { 61 return DocumentsContractApi19.getType(mContext, mUri); 62 } 63 64 @Override 65 public boolean isDirectory() { 66 return DocumentsContractApi19.isDirectory(mContext, mUri); 67 } 68 69 @Override 70 public boolean isFile() { 71 return DocumentsContractApi19.isFile(mContext, mUri); 72 } 73 74 @Override 75 public boolean isVirtual() { 76 return DocumentsContractApi19.isVirtual(mContext, mUri); 77 } 78 79 @Override 80 public long lastModified() { 81 return DocumentsContractApi19.lastModified(mContext, mUri); 82 } 83 84 @Override 85 public long length() { 86 return DocumentsContractApi19.length(mContext, mUri); 87 } 88 89 @Override 90 public boolean canRead() { 91 return DocumentsContractApi19.canRead(mContext, mUri); 92 } 93 94 @Override 95 public boolean canWrite() { 96 return DocumentsContractApi19.canWrite(mContext, mUri); 97 } 98 99 @Override 100 public boolean delete() { 101 try { 102 return DocumentsContract.deleteDocument(mContext.getContentResolver(), mUri); 103 } catch (Exception e) { 104 return false; 105 } 106 } 107 108 @Override 109 public boolean exists() { 110 return DocumentsContractApi19.exists(mContext, mUri); 111 } 112 113 @Override 114 public DocumentFile[] listFiles() { 115 throw new UnsupportedOperationException(); 116 } 117 118 @Override 119 public boolean renameTo(String displayName) { 120 throw new UnsupportedOperationException(); 121 } 122 } 123