1 /*
2  * Copyright (C) 2024 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.adpf.atom.app;
18 
19 import static android.adpf.atom.common.ADPFAtomTestConstants.CONTENT_COLUMN_KEY;
20 import static android.adpf.atom.common.ADPFAtomTestConstants.CONTENT_COLUMN_VALUE;
21 import static android.adpf.atom.common.ADPFAtomTestConstants.CONTENT_URI_STRING;
22 
23 import static org.junit.Assert.assertEquals;
24 
25 import android.content.ContentProvider;
26 import android.content.ContentValues;
27 import android.database.Cursor;
28 import android.database.MatrixCursor;
29 import android.net.Uri;
30 
31 import androidx.annotation.NonNull;
32 import androidx.annotation.Nullable;
33 
34 public class ADPFAtomTestDataProvider extends ContentProvider {
35 
36     ContentValues mContentValues = new ContentValues();
37 
38     @Override
onCreate()39     public boolean onCreate() {
40         return true;
41     }
42 
43     @Override
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)44     public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
45             String sortOrder) {
46         MatrixCursor cursor = new MatrixCursor(
47                 new String[]{CONTENT_COLUMN_KEY, CONTENT_COLUMN_VALUE});
48         for (String key : mContentValues.keySet()) {
49             cursor.addRow(new Object[]{key, mContentValues.get(key)});
50         }
51         return cursor;
52     }
53 
54     @Nullable
55     @Override
getType(@onNull Uri uri)56     public String getType(@NonNull Uri uri) {
57         return null;
58     }
59 
60     @Nullable
61     @Override
insert(@onNull Uri uri, @Nullable ContentValues values)62     public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
63         assertEquals(uri.toString(), CONTENT_URI_STRING);
64         mContentValues.putAll(values);
65         return uri;
66     }
67 
68     @Override
delete(@onNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs)69     public int delete(@NonNull Uri uri, @Nullable String selection,
70             @Nullable String[] selectionArgs) {
71         return 0;
72     }
73 
74     @Override
update(@onNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs)75     public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
76             @Nullable String[] selectionArgs) {
77         return 0;
78     }
79 }
80