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.jobscheduler.cts.shareduid.jobperm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.ContentProvider; 22 import android.content.ContentValues; 23 import android.content.Intent; 24 import android.database.Cursor; 25 import android.net.Uri; 26 import android.os.Bundle; 27 import android.os.ParcelFileDescriptor; 28 29 import java.io.File; 30 import java.io.FileNotFoundException; 31 32 /** 33 * Empty content provider, all permissions are enforced in manifest 34 */ 35 public class JobPermProvider extends ContentProvider { 36 @Override call(@onNull String method, @Nullable String arg, @Nullable Bundle extras)37 public Bundle call(@NonNull String method, @Nullable String arg, @Nullable Bundle extras) { 38 if (method == null) { 39 return null; 40 } 41 switch (method) { 42 case "grant": { 43 Uri uri = extras.getParcelable("uri"); 44 getContext().grantUriPermission(arg, uri, 45 Intent.FLAG_GRANT_READ_URI_PERMISSION | 46 Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 47 return null; 48 } 49 case "revoke": { 50 Uri uri = extras.getParcelable("uri"); 51 getContext().revokeUriPermission(arg, uri, 52 Intent.FLAG_GRANT_READ_URI_PERMISSION | 53 Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 54 return null; 55 56 } 57 } 58 return super.call(method, arg, extras); 59 } 60 61 @Override delete(Uri uri, String selection, String[] selectionArgs)62 public int delete(Uri uri, String selection, String[] selectionArgs) { 63 // do nothing 64 return 0; 65 } 66 67 @Override getType(Uri uri)68 public String getType(Uri uri) { 69 return "got/theMIME"; 70 } 71 72 @Override insert(Uri uri, ContentValues values)73 public Uri insert(Uri uri, ContentValues values) { 74 return null; 75 } 76 77 @Override onCreate()78 public boolean onCreate() { 79 return false; 80 } 81 82 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)83 public Cursor query(Uri uri, String[] projection, String selection, 84 String[] selectionArgs, String sortOrder) { 85 return null; 86 } 87 88 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)89 public int update(Uri uri, ContentValues values, String selection, 90 String[] selectionArgs) { 91 return 0; 92 } 93 94 @Override openFile(Uri uri, String mode)95 public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { 96 return ParcelFileDescriptor.open( 97 new File("/dev/null"), ParcelFileDescriptor.MODE_READ_ONLY); 98 } 99 } 100