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