blob: 776ec6a43c8d2c2ed343fc5f63464d52d45d0974 [file] [log] [blame]
Brad Ebinger792729e2019-12-09 16:12:57 -08001/*
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
17package com.android;
18
19import static org.mockito.ArgumentMatchers.anyInt;
20import static org.mockito.Mockito.doReturn;
21
22import android.content.BroadcastReceiver;
23import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
26import android.os.Handler;
27import android.os.PersistableBundle;
28import android.telecom.TelecomManager;
29import android.telephony.CarrierConfigManager;
30import android.telephony.SubscriptionManager;
31import android.telephony.TelephonyManager;
32import android.test.mock.MockContext;
33
34import org.mockito.Mock;
35import org.mockito.MockitoAnnotations;
36
37public class TestContext extends MockContext {
38
39 @Mock CarrierConfigManager mMockCarrierConfigManager;
40 @Mock TelecomManager mMockTelecomManager;
41 @Mock TelephonyManager mMockTelephonyManager;
42 @Mock SubscriptionManager mMockSubscriptionManager;
43
44 private PersistableBundle mCarrierConfig = new PersistableBundle();
45
46 public TestContext() {
47 MockitoAnnotations.initMocks(this);
48 doReturn(mCarrierConfig).when(mMockCarrierConfigManager).getConfigForSubId(anyInt());
49 }
50
51 @Override
52 public Context getApplicationContext() {
53 return this;
54 }
55
56 @Override
57 public String getPackageName() {
58 return "com.android.phone.tests";
59 }
60
61 @Override
62 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
63 return null;
64 }
65
66 @Override
67 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags) {
68 return null;
69 }
70
71 @Override
72 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
73 String broadcastPermission, Handler scheduler) {
74 return null;
75 }
76
77 @Override
78 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
79 String broadcastPermission, Handler scheduler, int flags) {
80 return null;
81 }
82
83 @Override
84 public Object getSystemService(String name) {
85 switch (name) {
86 case (Context.CARRIER_CONFIG_SERVICE) : {
87 return mMockCarrierConfigManager;
88 }
89 case (Context.TELECOM_SERVICE) : {
90 return mMockTelecomManager;
91 }
92 case (Context.TELEPHONY_SERVICE) : {
93 return mMockTelephonyManager;
94 }
95 case (Context.TELEPHONY_SUBSCRIPTION_SERVICE) : {
96 return mMockSubscriptionManager;
97 }
98 }
99 return null;
100 }
101
102 @Override
103 public String getSystemServiceName(Class<?> serviceClass) {
104 if (serviceClass == CarrierConfigManager.class) {
105 return Context.CARRIER_CONFIG_SERVICE;
106 }
107 if (serviceClass == TelecomManager.class) {
108 return Context.TELECOM_SERVICE;
109 }
110 if (serviceClass == TelephonyManager.class) {
111 return Context.TELEPHONY_SERVICE;
112 }
113 if (serviceClass == SubscriptionManager.class) {
114 return Context.TELEPHONY_SUBSCRIPTION_SERVICE;
115 }
116 return null;
117 }
118
119 public PersistableBundle getCarrierConfig() {
120 return mCarrierConfig;
121 }
122}