1 /*
2  * Copyright (C) 2014 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.cts.splitapp;
18 
19 import android.content.ContentProvider;
20 import android.content.ContentValues;
21 import android.database.Cursor;
22 import android.net.Uri;
23 import android.util.Log;
24 
25 import java.lang.reflect.Field;
26 
27 public class FeatureProvider extends ContentProvider {
28     private static final String TAG = "FeatureProvider";
29 
30     public static boolean sCreated = false;
31 
32     @Override
onCreate()33     public boolean onCreate() {
34         Log.d(TAG, "FeatureProvider.onCreate()");
35 
36         sCreated = true;
37 
38         try {
39             // Just reach out and touch
40             final Class<?> test = Class.forName("com.android.cts.splitapp.SplitAppTest");
41             final Field touched = test.getDeclaredField("sFeatureTouched");
42             touched.set(null, true);
43 
44             // Also make sure we can read a resource from the base; we just
45             // stash the value we saw over on the test for them to verify.
46             final Class<?> baseR = Class.forName("com.android.cts.splitapp.BaseR");
47             final int stringId = (int) baseR.getDeclaredField("my_string1").get(null);
48             final Field value = test.getDeclaredField("sFeatureValue");
49             value.set(null, getContext().getResources().getString(stringId));
50 
51         } catch (Throwable t) {
52             // We're okay if anything above fails, since the test later verifies
53             // that we actually touched the boolean.
54             Log.e(TAG, "Failed to communicate back to base", t);
55         }
56 
57         return true;
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         throw new UnsupportedOperationException();
64     }
65 
66     @Override
getType(Uri uri)67     public String getType(Uri uri) {
68         throw new UnsupportedOperationException();
69     }
70 
71     @Override
insert(Uri uri, ContentValues values)72     public Uri insert(Uri uri, ContentValues values) {
73         throw new UnsupportedOperationException();
74     }
75 
76     @Override
delete(Uri uri, String selection, String[] selectionArgs)77     public int delete(Uri uri, String selection, String[] selectionArgs) {
78         throw new UnsupportedOperationException();
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         throw new UnsupportedOperationException();
84     }
85 }
86