• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.car.ui.core;
18 
19 import android.content.ContentProvider;
20 import android.content.Context;
21 import android.test.IsolatedContext;
22 import android.test.mock.MockContentResolver;
23 import android.test.mock.MockContext;
24 
25 public class ResolverRenamingMockContext extends IsolatedContext {
26 
27     /**
28      * The renaming prefix.
29      */
30     private static final String PREFIX = "test.";
31 
32 
33     /**
34      * The resolver.
35      */
36     private static final MockContentResolver RESOLVER = new MockContentResolver();
37 
38     /**
39      * Constructor.
40      */
ResolverRenamingMockContext(Context context)41     public ResolverRenamingMockContext(Context context) {
42         super(RESOLVER, new DelegatedMockContext(context));
43     }
44 
getResolver()45     public MockContentResolver getResolver() {
46         return RESOLVER;
47     }
48 
addProvider(String name, ContentProvider provider)49     public void addProvider(String name, ContentProvider provider) {
50         RESOLVER.addProvider(name, provider);
51     }
52 
53     /**
54      * The DelegatedMockContext.
55      */
56     private static class DelegatedMockContext extends MockContext {
57 
58         private Context mDelegatedContext;
59 
DelegatedMockContext(Context context)60         DelegatedMockContext(Context context) {
61             mDelegatedContext = context;
62         }
63 
64         @Override
getPackageName()65         public String getPackageName() {
66             return "com.android.car.ui.test";
67         }
68     }
69 
70 }
71