• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.googlecode.android_scripting.facade.telephony;
18 
19 import android.app.Service;
20 import android.content.Context;
21 import android.telephony.SubscriptionManager;
22 import android.telephony.SubscriptionInfo;
23 
24 import com.googlecode.android_scripting.facade.FacadeManager;
25 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
26 import com.googlecode.android_scripting.rpc.Rpc;
27 import com.googlecode.android_scripting.rpc.RpcParameter;
28 
29 import java.util.List;
30 
31 /**
32  * Exposes SubscriptionManager functionality.
33  */
34 public class SubscriptionManagerFacade extends RpcReceiver {
35 
36     private final Service mService;
37     private final Context mContext;
38     private final SubscriptionManager mSubscriptionManager;
39 
SubscriptionManagerFacade(FacadeManager manager)40     public SubscriptionManagerFacade(FacadeManager manager) {
41         super(manager);
42         mService = manager.getService();
43         mContext = mService.getBaseContext();
44         mSubscriptionManager = SubscriptionManager.from(mContext);
45     }
46 
47     @Rpc(description = "Return the default subscription ID")
subscriptionGetDefaultSubId()48     public Integer subscriptionGetDefaultSubId() {
49         return SubscriptionManager.getDefaultSubscriptionId();
50     }
51 
52     @Rpc(description = "Return the default data subscription ID")
subscriptionGetDefaultDataSubId()53     public Integer subscriptionGetDefaultDataSubId() {
54         return SubscriptionManager.getDefaultDataSubscriptionId();
55     }
56 
57     @Rpc(description = "Set the default data subscription ID")
subscriptionSetDefaultDataSubId( @pcParametername = "subId") Integer subId)58     public void subscriptionSetDefaultDataSubId(
59             @RpcParameter(name = "subId")
60             Integer subId) {
61         mSubscriptionManager.setDefaultDataSubId(subId);
62     }
63 
64     @Rpc(description = "Return the default voice subscription ID")
subscriptionGetDefaultVoiceSubId()65     public Integer subscriptionGetDefaultVoiceSubId() {
66         return SubscriptionManager.getDefaultVoiceSubscriptionId();
67     }
68 
69     @Rpc(description = "Set the default voice subscription ID")
subscriptionSetDefaultVoiceSubId( @pcParametername = "subId") Integer subId)70     public void subscriptionSetDefaultVoiceSubId(
71             @RpcParameter(name = "subId")
72             Integer subId) {
73         mSubscriptionManager.setDefaultVoiceSubId(subId);
74     }
75 
76     @Rpc(description = "Return the default sms subscription ID")
subscriptionGetDefaultSmsSubId()77     public Integer subscriptionGetDefaultSmsSubId() {
78         return SubscriptionManager.getDefaultSmsSubscriptionId();
79     }
80 
81     @Rpc(description = "Set the default sms subscription ID")
subscriptionSetDefaultSmsSubId( @pcParametername = "subId") Integer subId)82     public void subscriptionSetDefaultSmsSubId(
83             @RpcParameter(name = "subId")
84             Integer subId) {
85         mSubscriptionManager.setDefaultSmsSubId(subId);
86     }
87 
88     @Rpc(description = "Return a List of all Subscription Info Records")
subscriptionGetAllSubInfoList()89     public List<SubscriptionInfo> subscriptionGetAllSubInfoList() {
90         return mSubscriptionManager.getAllSubscriptionInfoList();
91     }
92 
93     @Rpc(description = "Return a List of all Active Subscription Info Records")
subscriptionGetActiveSubInfoList()94     public List<SubscriptionInfo> subscriptionGetActiveSubInfoList() {
95         return mSubscriptionManager.getActiveSubscriptionInfoList();
96     }
97 
98     @Rpc(description = "Return the Subscription Info for a Particular Subscription ID")
subscriptionGetSubInfoForSubscriber( @pcParametername = "subId") Integer subId)99     public SubscriptionInfo subscriptionGetSubInfoForSubscriber(
100             @RpcParameter(name = "subId")
101             Integer subId) {
102         return mSubscriptionManager.getActiveSubscriptionInfo(subId);
103     }
104 
105     @Rpc(description = "Set Data Roaming Enabled or Disabled for a particular Subscription ID")
subscriptionSetDataRoaming( @pcParametername = "roaming") Integer roaming, @RpcParameter(name = "subId") Integer subId)106     public Integer subscriptionSetDataRoaming(
107             @RpcParameter(name = "roaming") Integer roaming,
108             @RpcParameter(name = "subId") Integer subId) {
109         if (roaming != SubscriptionManager.DATA_ROAMING_DISABLE) {
110             return mSubscriptionManager.setDataRoaming(
111                     SubscriptionManager.DATA_ROAMING_ENABLE, subId);
112         } else {
113             return mSubscriptionManager.setDataRoaming(
114                     SubscriptionManager.DATA_ROAMING_DISABLE, subId);
115         }
116     }
117 
118     @Override
shutdown()119     public void shutdown() {
120 
121     }
122 }
123