1 /* 2 * Copyright (C) 2017 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 package com.android.documentsui; 17 18 import static android.provider.DocumentsContract.Document.FLAG_SUPPORTS_SETTINGS; 19 20 import android.database.Cursor; 21 import android.database.MatrixCursor; 22 import android.database.MatrixCursor.RowBuilder; 23 import android.provider.DocumentsContract.Document; 24 import java.io.FileNotFoundException; 25 26 /** 27 * Content Provider for testing the Document Inspector. 28 * 29 * Structure of the provider. 30 * 31 * Top ------------> Middle ------> Bottom -------> Dummy21 50B 32 * openInProvider Dummy1 50B Dummy11 50B Dummy22 150B 33 * test.txt Dummy2 150B Dummy12 150B Dummy23 100B 34 * update.txt Dummy3 100B Dummy13 100B 35 */ 36 public class InspectorProvider extends TestRootProvider { 37 38 public static final String AUTHORITY = "com.android.documentsui.inspectorprovider"; 39 public static final String OPEN_IN_PROVIDER_TEST = "OpenInProviderTest"; 40 public static final String ROOT_ID = "inspector-root"; 41 42 private static final String ROOT_DOC_ID = "root0"; 43 private static final int ROOT_FLAGS = 0; 44 InspectorProvider()45 public InspectorProvider() { 46 super("Inspector Root", ROOT_ID, ROOT_FLAGS, ROOT_DOC_ID); 47 } 48 49 @Override queryDocument(String documentId, String[] projection)50 public Cursor queryDocument(String documentId, String[] projection) 51 throws FileNotFoundException { 52 53 if (OPEN_IN_PROVIDER_TEST.equals(documentId)) { 54 MatrixCursor c = createDocCursor(projection); 55 addFile(c, OPEN_IN_PROVIDER_TEST, FLAG_SUPPORTS_SETTINGS); 56 return c; 57 } 58 59 MatrixCursor c = createDocCursor(projection); 60 addFolder(c, documentId); 61 return c; 62 } 63 64 @Override queryChildDocuments(String s, String[] projection, String s1)65 public Cursor queryChildDocuments(String s, String[] projection, String s1) 66 throws FileNotFoundException { 67 68 if("Top".equals(s)) { 69 MatrixCursor c = createDocCursor(projection); 70 addFolder(c, "Middle"); 71 addFileWithSize(c, "dummy1", 50); 72 addFileWithSize(c, "dummy2", 150); 73 addFileWithSize(c, "dummy3", 100); 74 return c; 75 } 76 else if("Middle".equals(s)) { 77 MatrixCursor c = createDocCursor(projection); 78 addFolder(c, "Bottom"); 79 addFileWithSize(c, "dummy11", 50); 80 addFileWithSize(c, "dummy12", 150); 81 addFileWithSize(c, "dummy13", 100); 82 return c; 83 } 84 else if("Bottom".equals(s)) { 85 MatrixCursor c = createDocCursor(projection); 86 addFileWithSize(c, "dummy21", 50); 87 addFileWithSize(c, "dummy22", 150); 88 addFileWithSize(c, "dummy23", 100); 89 return c; 90 } 91 else { 92 MatrixCursor c = createDocCursor(projection); 93 addFolder(c, "Top"); 94 addFile(c, OPEN_IN_PROVIDER_TEST, FLAG_SUPPORTS_SETTINGS); 95 addFile(c, "test.txt"); 96 addFile(c, "update.txt"); 97 return c; 98 } 99 } 100 addFileWithSize(MatrixCursor c, String id, long size)101 private void addFileWithSize(MatrixCursor c, String id, long size) { 102 final RowBuilder row = c.newRow(); 103 row.add(Document.COLUMN_DOCUMENT_ID, id); 104 row.add(Document.COLUMN_DISPLAY_NAME, id); 105 row.add(Document.COLUMN_SIZE, size); 106 row.add(Document.COLUMN_MIME_TYPE, "text/plain"); 107 row.add(Document.COLUMN_FLAGS, 0); 108 row.add(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis()); 109 } 110 111 112 113 } 114