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.providers.tv;
18 
19 import android.content.ComponentName;
20 import android.content.ContentResolver;
21 import android.content.Context;
22 import android.content.pm.ApplicationInfo;
23 import android.content.pm.PackageManager;
24 import android.content.pm.ServiceInfo;
25 import android.content.res.Resources;
26 import android.test.IsolatedContext;
27 import android.test.RenamingDelegatingContext;
28 import android.test.mock.MockContext;
29 import android.test.mock.MockPackageManager;
30 
31 class MockTvProviderContext extends IsolatedContext {
32     private final Context mBase;
33     private final MockPackageManager mMockPackageManager = new MockPackageManager() {
34         @Override
35         public ServiceInfo getServiceInfo(ComponentName className, int flags) {
36             return null;
37         }
38     };
39 
MockTvProviderContext(ContentResolver resolver, Context base)40     MockTvProviderContext(ContentResolver resolver, Context base) {
41         super(resolver, new RenamingDelegatingContext(new MockContext(), base, "test."));
42         mBase = base;
43     }
44 
45     @Override
getResources()46     public Resources getResources() {
47         return mBase.getResources();
48     }
49 
50     @Override
getPackageManager()51     public PackageManager getPackageManager() {
52         return mMockPackageManager;
53     }
54 
55     @Override
getPackageName()56     public String getPackageName() {
57         return mBase.getPackageName();
58     }
59 
60     @Override
getApplicationInfo()61     public ApplicationInfo getApplicationInfo() {
62         return mBase.getApplicationInfo();
63     }
64 
65     @Override
checkCallingOrSelfPermission(String permission)66     public int checkCallingOrSelfPermission(String permission) {
67         return PackageManager.PERMISSION_GRANTED;
68     }
69 }
70