• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.car.settings.testutils;
18 
19 import android.telephony.SubscriptionInfo;
20 import android.telephony.SubscriptionManager;
21 import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
22 import android.telephony.SubscriptionPlan;
23 
24 import org.robolectric.annotation.Implementation;
25 import org.robolectric.annotation.Implements;
26 import org.robolectric.annotation.Resetter;
27 
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 @Implements(SubscriptionManager.class)
32 public class ShadowSubscriptionManager extends org.robolectric.shadows.ShadowSubscriptionManager {
33 
34     private static SubscriptionInfo sDefaultDataSubscriptionInfo = null;
35 
36     private List<SubscriptionPlan> mSubscriptionPlanList;
37     private List<SubscriptionInfo> mSelectableSubscriptionInfoList;
38     private List<OnSubscriptionsChangedListener> mOnSubscriptionsChangedListeners =
39             new ArrayList<>();
40     private int mCurrentActiveSubscriptionId;
41 
42     @Implementation
getSubscriptionPlans(int subId)43     protected List<SubscriptionPlan> getSubscriptionPlans(int subId) {
44         return mSubscriptionPlanList;
45     }
46 
setSubscriptionPlans(List<SubscriptionPlan> subscriptionPlanList)47     public void setSubscriptionPlans(List<SubscriptionPlan> subscriptionPlanList) {
48         mSubscriptionPlanList = subscriptionPlanList;
49     }
50 
51     @Implementation
getDefaultDataSubscriptionInfo()52     protected SubscriptionInfo getDefaultDataSubscriptionInfo() {
53         return sDefaultDataSubscriptionInfo;
54     }
55 
setDefaultDataSubscriptionInfo(SubscriptionInfo subscriptionInfo)56     public static void setDefaultDataSubscriptionInfo(SubscriptionInfo subscriptionInfo) {
57         sDefaultDataSubscriptionInfo = subscriptionInfo;
58     }
59 
60     @Implementation
getSelectableSubscriptionInfoList()61     protected List<SubscriptionInfo> getSelectableSubscriptionInfoList() {
62         return mSelectableSubscriptionInfoList;
63     }
64 
setSelectableSubscriptionInfoList(List<SubscriptionInfo> infos)65     public void setSelectableSubscriptionInfoList(List<SubscriptionInfo> infos) {
66         mSelectableSubscriptionInfoList = infos;
67     }
68 
69     @Implementation
addOnSubscriptionsChangedListener(OnSubscriptionsChangedListener listener)70     protected void addOnSubscriptionsChangedListener(OnSubscriptionsChangedListener listener) {
71         super.addOnSubscriptionsChangedListener(listener);
72         mOnSubscriptionsChangedListeners.add(listener);
73     }
74 
75     @Implementation
removeOnSubscriptionsChangedListener(OnSubscriptionsChangedListener listener)76     protected void removeOnSubscriptionsChangedListener(OnSubscriptionsChangedListener listener) {
77         super.removeOnSubscriptionsChangedListener(listener);
78         mOnSubscriptionsChangedListeners.remove(listener);
79     }
80 
getOnSubscriptionChangedListeners()81     public List<OnSubscriptionsChangedListener> getOnSubscriptionChangedListeners() {
82         return mOnSubscriptionsChangedListeners;
83 
84     }
85 
86     @Implementation
isActiveSubscriptionId(int subscriptionId)87     protected boolean isActiveSubscriptionId(int subscriptionId) {
88         return mCurrentActiveSubscriptionId == subscriptionId;
89     }
90 
setCurrentActiveSubscriptionId(int subscriptionId)91     public void setCurrentActiveSubscriptionId(int subscriptionId) {
92         mCurrentActiveSubscriptionId = subscriptionId;
93     }
94 
95     @Resetter
reset()96     public static void reset() {
97         org.robolectric.shadows.ShadowSubscriptionManager.reset();
98         sDefaultDataSubscriptionInfo = null;
99     }
100 }
101