1 /* 2 * Copyright (C) 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 android.content; 18 19 import android.database.Cursor; 20 import android.database.MatrixCursor; 21 import android.database.RedactingCursor; 22 import android.net.Uri; 23 import android.util.ArrayMap; 24 25 public class RedactingProvider extends ContentProvider { 26 @Override onCreate()27 public boolean onCreate() { 28 return true; 29 } 30 31 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)32 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 33 String sortOrder) { 34 switch (uri.getLastPathSegment()) { 35 case "missing": { 36 final MatrixCursor cursor = new MatrixCursor( 37 new String[] { "name", "size", "_data" }); 38 cursor.addRow(new Object[] { "foo", 10, "/path/to/foo" }); 39 cursor.addRow(new Object[] { "bar", 20, "/path/to/bar" }); 40 41 final ArrayMap<String, Object> redactions = new ArrayMap<>(); 42 redactions.put("missing", null); 43 return RedactingCursor.create(cursor, redactions); 44 } 45 case "single": { 46 final MatrixCursor cursor = new MatrixCursor( 47 new String[] { "name", "size", "_data" }); 48 cursor.addRow(new Object[] { "foo", 10, "/path/to/foo" }); 49 cursor.addRow(new Object[] { "bar", 20, "/path/to/bar" }); 50 51 final ArrayMap<String, Object> redactions = new ArrayMap<>(); 52 redactions.put("name", null); 53 redactions.put("_data", "/dev/null"); 54 return RedactingCursor.create(cursor, redactions); 55 } 56 case "multiple": { 57 final MatrixCursor cursor = new MatrixCursor( 58 new String[] { "_data", "name", "_data" }); 59 cursor.addRow(new Object[] { "/path", "foo", "/path" }); 60 61 final ArrayMap<String, Object> redactions = new ArrayMap<>(); 62 redactions.put("_data", null); 63 return RedactingCursor.create(cursor, redactions); 64 } 65 } 66 67 throw new UnsupportedOperationException(); 68 } 69 70 @Override getType(Uri uri)71 public String getType(Uri uri) { 72 throw new UnsupportedOperationException(); 73 } 74 75 @Override insert(Uri uri, ContentValues values)76 public Uri insert(Uri uri, ContentValues values) { 77 throw new UnsupportedOperationException(); 78 } 79 80 @Override delete(Uri uri, String selection, String[] selectionArgs)81 public int delete(Uri uri, String selection, String[] selectionArgs) { 82 throw new UnsupportedOperationException(); 83 } 84 85 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)86 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 87 throw new UnsupportedOperationException(); 88 } 89 } 90