1 /* 2 * Copyright (C) 2022 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 com.android.interactive; 18 19 import static com.android.interactive.Automator.AUTOMATION_FILE; 20 21 import android.content.ContentProvider; 22 import android.content.ContentValues; 23 import android.database.Cursor; 24 import android.net.Uri; 25 import android.os.CancellationSignal; 26 import android.os.ParcelFileDescriptor; 27 28 import java.io.File; 29 import java.io.FileNotFoundException; 30 31 /** 32 * ContentProvider used to pass the automation apk to a non-system user. 33 */ 34 public final class AutomationFileProvider extends ContentProvider { 35 36 @Override onCreate()37 public boolean onCreate() { 38 return true; 39 } 40 41 @Override getType(Uri uri)42 public String getType(Uri uri) { 43 return "apk"; 44 } 45 46 @Override openFile(Uri uri, String mode)47 public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { 48 return ParcelFileDescriptor.open( 49 new File(AUTOMATION_FILE), 50 ParcelFileDescriptor.MODE_READ_ONLY); 51 } 52 53 @Override openFile(Uri uri, String mode, CancellationSignal signal)54 public ParcelFileDescriptor openFile(Uri uri, String mode, CancellationSignal signal) 55 throws FileNotFoundException { 56 return openFile(uri, mode); 57 } 58 59 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)60 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 61 String sortOrder) { 62 throw new UnsupportedOperationException(); 63 } 64 65 @Override insert(Uri uri, ContentValues values)66 public Uri insert(Uri uri, ContentValues values) { 67 throw new UnsupportedOperationException(); 68 } 69 70 @Override delete(Uri uri, String selection, String[] selectionArgs)71 public int delete(Uri uri, String selection, String[] selectionArgs) { 72 throw new UnsupportedOperationException(); 73 } 74 75 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)76 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 77 throw new UnsupportedOperationException(); 78 } 79 } 80