Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | */ |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 16 | |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 17 | package com.android.documentsui; |
| 18 | |
Ben Lin | b3c4f12 | 2017-03-21 11:35:14 -0700 | [diff] [blame] | 19 | import android.app.AuthenticationRequiredException; |
Ben Lin | 42b83bf | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 20 | import android.app.PendingIntent; |
Ben Lin | 42b83bf | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 22 | import android.database.Cursor; |
| 23 | import android.database.MatrixCursor; |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 24 | import android.os.Bundle; |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 25 | import android.provider.DocumentsContract; |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 26 | |
| 27 | import java.io.FileNotFoundException; |
| 28 | |
| 29 | /** |
Ben Lin | f8f06e9 | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 30 | * Provides data view that exercises some of the more esoteric functionality...like display of INFO |
| 31 | * and ERROR messages. |
| 32 | * <p> |
| 33 | * Do not use this provider for automated testing. |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 34 | */ |
Steve McKay | f840797 | 2017-02-03 09:42:52 -0800 | [diff] [blame] | 35 | public class DemoProvider extends TestRootProvider { |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 36 | |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 37 | public static final String DIR_INFO = "show info"; |
| 38 | public static final String DIR_ERROR = "show error"; |
| 39 | public static final String DIR_ERROR_AND_INFO = "show both error and info"; |
| 40 | public static final String DIR_THROW = "throw a nice exception"; |
| 41 | public static final String DIR_AUTH = "throw a authentication exception"; |
| 42 | |
| 43 | public static final String MSG_INFO = "All files in this root support settings."; |
| 44 | public static final String MSG_ERROR = "I'm an error. Don't judge me."; |
| 45 | public static final String MSG_ERROR_AND_INFO = "ERROR: Both ERROR and INFO returned."; |
| 46 | |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 47 | private static final String ROOT_ID = "demo-root"; |
Steve McKay | f840797 | 2017-02-03 09:42:52 -0800 | [diff] [blame] | 48 | private static final String ROOT_DOC_ID = "root0"; |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 49 | |
Steve McKay | f840797 | 2017-02-03 09:42:52 -0800 | [diff] [blame] | 50 | public DemoProvider() { |
| 51 | super("Demo Root", ROOT_ID, 0, ROOT_DOC_ID); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Cursor queryDocument(String documentId, String[] projection) |
| 56 | throws FileNotFoundException { |
Steve McKay | f840797 | 2017-02-03 09:42:52 -0800 | [diff] [blame] | 57 | MatrixCursor c = createDocCursor(projection); |
| 58 | Bundle extras = c.getExtras(); |
| 59 | extras.putString( |
| 60 | DocumentsContract.EXTRA_INFO, |
| 61 | "This provider is for feature demos only. Do not use from automated tests."); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 62 | addFolder(c, documentId); |
| 63 | return c; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Cursor queryChildDocuments( |
| 68 | String parentDocumentId, String[] projection, String sortOrder) |
| 69 | throws FileNotFoundException { |
Steve McKay | f840797 | 2017-02-03 09:42:52 -0800 | [diff] [blame] | 70 | MatrixCursor c = createDocCursor(projection); |
| 71 | Bundle extras = c.getExtras(); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 72 | |
| 73 | switch (parentDocumentId) { |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 74 | case DIR_INFO: |
| 75 | extras.putString(DocumentsContract.EXTRA_INFO, MSG_INFO); |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 76 | addFolder(c, "folder"); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 77 | addFile(c, "zzz"); |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 78 | for (int i = 0; i < 100; i++) { |
Jon Mann | 253a992 | 2017-03-21 18:53:27 -0700 | [diff] [blame] | 79 | addFile(c, "" + i, DocumentsContract.Document.FLAG_SUPPORTS_SETTINGS); |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 80 | } |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 81 | break; |
| 82 | |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 83 | case DIR_ERROR: |
| 84 | extras.putString(DocumentsContract.EXTRA_ERROR, MSG_ERROR); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 85 | break; |
| 86 | |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 87 | case DIR_ERROR_AND_INFO: |
| 88 | extras.putString(DocumentsContract.EXTRA_INFO, MSG_INFO); |
| 89 | extras.putString(DocumentsContract.EXTRA_ERROR, MSG_ERROR_AND_INFO); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 90 | break; |
| 91 | |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 92 | case DIR_THROW: |
Ben Lin | 7b38f34 | 2016-12-14 11:52:35 -0800 | [diff] [blame] | 93 | throw new RuntimeException(); |
| 94 | |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 95 | case DIR_AUTH: |
Ben Lin | a40e6e3 | 2017-05-09 23:59:43 +0000 | [diff] [blame] | 96 | Intent intent = new Intent("com.android.documentsui.test.action.AUTHENTICATE"); |
| 97 | PendingIntent pIntent = PendingIntent.getActivity(getContext(), |
Zemiao Zhu | d00f87c | 2021-01-21 12:05:54 -0800 | [diff] [blame] | 98 | AbstractActionHandler.CODE_AUTHENTICATION, intent, |
| 99 | PendingIntent.FLAG_IMMUTABLE); |
Ben Lin | b3c4f12 | 2017-03-21 11:35:14 -0700 | [diff] [blame] | 100 | throw new AuthenticationRequiredException(new UnsupportedOperationException(), |
Ben Lin | a40e6e3 | 2017-05-09 23:59:43 +0000 | [diff] [blame] | 101 | pIntent); |
Ben Lin | 42b83bf | 2017-01-27 17:15:48 -0800 | [diff] [blame] | 102 | |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 103 | default: |
Steve McKay | b9373d0 | 2018-05-07 15:56:35 -0700 | [diff] [blame] | 104 | addFolder(c, DIR_INFO); |
| 105 | addFolder(c, DIR_ERROR); |
| 106 | addFolder(c, DIR_ERROR_AND_INFO); |
| 107 | addFolder(c, DIR_THROW); |
| 108 | addFolder(c, DIR_AUTH); |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 109 | break; |
| 110 | } |
| 111 | |
| 112 | return c; |
| 113 | } |
Steve McKay | ee7d587 | 2016-11-17 13:59:00 -0800 | [diff] [blame] | 114 | } |
Steve McKay | 33e03e8 | 2017-02-03 12:37:29 -0800 | [diff] [blame] | 115 | |