1 /* 2 * Copyright (C) 2020 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 package com.android.test.notificationprovider 17 18 import android.content.ContentProvider 19 import android.content.ContentValues 20 import android.content.res.AssetFileDescriptor 21 import android.database.Cursor 22 import android.net.Uri 23 24 class AssetFileProvider : ContentProvider() { onCreatenull25 override fun onCreate(): Boolean { 26 return true 27 } 28 openAssetFilenull29 override fun openAssetFile(uri: Uri, mode: String): AssetFileDescriptor? { 30 val assets = context?.assets 31 val filename = uri.lastPathSegment 32 if (mode == "r" && assets != null && filename != null) { 33 return assets.openFd(filename) 34 } 35 return super.openAssetFile(uri, mode) 36 } 37 querynull38 override fun query( 39 uri: Uri, 40 projection: Array<String>?, 41 selection: String?, 42 selectionArgs: Array<String>?, 43 sortOrder: String? 44 ): Cursor? { 45 throw UnsupportedOperationException() 46 } 47 getTypenull48 override fun getType(uri: Uri): String? { 49 return null 50 } 51 insertnull52 override fun insert(uri: Uri, values: ContentValues?): Uri? { 53 throw UnsupportedOperationException() 54 } 55 deletenull56 override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int { 57 throw UnsupportedOperationException() 58 } 59 updatenull60 override fun update( 61 uri: Uri, 62 values: ContentValues?, 63 selection: String?, 64 selectionArgs: Array<String>? 65 ): Int { 66 throw UnsupportedOperationException() 67 } 68 }