1 /*
2  * Copyright (C) 2021 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 android.app.stubs
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() = true
26 
27     override fun openAssetFile(uri: Uri, mode: String): AssetFileDescriptor? {
28         val assets = context?.assets
29         val filename = uri.lastPathSegment
30         if (mode == "r" && assets != null && filename != null) {
31             return assets.openFd(filename)
32         }
33         return super.openAssetFile(uri, mode)
34     }
35 
querynull36     override fun query(
37         uri: Uri,
38         projection: Array<String>?,
39         selection: String?,
40         selectionArgs: Array<String>?,
41         sortOrder: String?
42     ): Cursor = throw UnsupportedOperationException()
43 
44     override fun getType(uri: Uri): String? = null
45 
46     override fun insert(uri: Uri, values: ContentValues?): Uri =
47             throw UnsupportedOperationException()
48 
49     override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int =
50             throw UnsupportedOperationException()
51 
52     override fun update(
53         uri: Uri,
54         values: ContentValues?,
55         selection: String?,
56         selectionArgs: Array<String>?
57     ): Int = throw UnsupportedOperationException()
58 }