• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019, 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.car.media.testmediaapp;
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 import android.text.TextUtils;
24 import android.util.Log;
25 
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 
29 public class TmaAssetProvider extends ContentProvider {
30 
31     private static final String TAG = "TmaAssetProvider";
32 
33     private static final String URI_PREFIX = "content://com.android.car.media.testmediaapp.assets/";
34 
35 
buildUriString(String localAssetFilePath)36     public static String buildUriString(String localAssetFilePath) {
37         return URI_PREFIX + localAssetFilePath;
38     }
39 
40     @Override
openAssetFile(Uri uri, String mode)41     public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
42         String file_path = uri.getPath();
43         if (TextUtils.isEmpty(file_path)) throw new FileNotFoundException();
44         try {
45             if (file_path.startsWith("/")) {
46                 file_path = file_path.substring(1);
47             }
48             return getContext().getAssets().openFd(file_path);
49         } catch (IOException e) {
50             Log.e(TAG, "openAssetFile failed: " + e);
51             return null;
52         }
53     }
54 
55     @Override
onCreate()56     public boolean onCreate() {
57         return false;
58     }
59 
60     @Override
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)61     public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
62             String sortOrder) {
63         return null;
64     }
65 
66     @Override
getType(Uri uri)67     public String getType(Uri uri) {
68         return null;
69     }
70 
71     @Override
insert(Uri uri, ContentValues values)72     public Uri insert(Uri uri, ContentValues values) {
73         return null;
74     }
75 
76     @Override
delete(Uri uri, String selection, String[] selectionArgs)77     public int delete(Uri uri, String selection, String[] selectionArgs) {
78         return 0;
79     }
80 
81     @Override
update(Uri uri, ContentValues values, String selection, String[] selectionArgs)82     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
83         return 0;
84     }
85 }
86