1 /* 2 * Copyright (c) 2015, Motorola Mobility LLC 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * - Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * - Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * - Neither the name of Motorola Mobility nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 * DAMAGE. 27 */ 28 29 package com.android.service.ims.presence; 30 31 import android.content.Context; 32 import android.telephony.SubscriptionInfo; 33 import android.telephony.SubscriptionManager; 34 import android.telephony.ims.ProvisioningManager; 35 36 import com.android.ims.internal.Logger; 37 38 import java.util.List; 39 40 public class PresenceSetting { 41 private static Logger logger = Logger.getLogger("PresenceSetting"); 42 private static Context sContext = null; 43 44 // Default result for getCapabilityPollInterval in seconds, equates to 7 days. 45 private static final long DEFAULT_CAPABILITY_POLL_INTERVAL_SEC = 604800L; 46 // Default result for getCapabilityCacheExpiration in seconds, equates to 90 days. 47 private static final long DEFAULT_CAPABILITY_CACHE_EXPIRATION_SEC = 604800L; 48 // Default result for getPublishTimer in seconds, equates to 20 minutes. 49 private static final int DEFAULT_PUBLISH_TIMER_SEC = 1200; 50 // Default result for getPublishTimerExtended in seconds, equates to 1 day. 51 private static final int DEFAULT_PUBLISH_TIMER_EXTENDED_SEC = 86400; 52 // Default result for getMaxNumberOfEntriesInRequestContainedList, 100 entries. 53 private static final int DEFAULT_NUM_ENTRIES_IN_RCL = 100; 54 // Default result for getCapabilityPollListSubscriptionExpiration in seconds, equates to 30 55 // seconds. 56 private static final int DEFAULT_CAPABILITY_POLL_LIST_SUB_EXPIRATION_SEC = 30; 57 58 init(Context context)59 public static void init(Context context) { 60 sContext = context; 61 } 62 getCapabilityPollInterval(int subId)63 public static long getCapabilityPollInterval(int subId) { 64 long value = -1; 65 if (sContext != null) { 66 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 67 return DEFAULT_CAPABILITY_POLL_INTERVAL_SEC; 68 } 69 try { 70 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 71 value = pm.getProvisioningIntValue( 72 ProvisioningManager.KEY_RCS_CAPABILITIES_POLL_INTERVAL_SEC); 73 } catch (Exception ex) { 74 logger.warn("getCapabilityPollInterval, exception = " + ex.getMessage()); 75 } 76 } 77 if (value <= 0) { 78 value = DEFAULT_CAPABILITY_POLL_INTERVAL_SEC; 79 logger.error("Failed to get CapabilityPollInterval, the default: " + value); 80 } 81 return value; 82 } 83 getCapabilityCacheExpiration(int subId)84 public static long getCapabilityCacheExpiration(int subId) { 85 long value = -1; 86 if (sContext != null) { 87 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 88 return DEFAULT_CAPABILITY_CACHE_EXPIRATION_SEC; 89 } 90 try { 91 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 92 value = pm.getProvisioningIntValue( 93 ProvisioningManager.KEY_RCS_CAPABILITIES_CACHE_EXPIRATION_SEC); 94 } catch (Exception ex) { 95 logger.warn("getCapabilityCacheExpiration, exception = " + ex.getMessage()); 96 } 97 } 98 if (value <= 0) { 99 value = DEFAULT_CAPABILITY_CACHE_EXPIRATION_SEC; 100 logger.error("Failed to get CapabilityCacheExpiration, the default: " + value); 101 } 102 return value; 103 } 104 getPublishTimer(int subId)105 public static int getPublishTimer(int subId) { 106 int value = -1; 107 if (sContext != null) { 108 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 109 return DEFAULT_PUBLISH_TIMER_SEC; 110 } 111 try { 112 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 113 value = pm.getProvisioningIntValue(ProvisioningManager.KEY_RCS_PUBLISH_TIMER_SEC); 114 } catch (Exception ex) { 115 logger.warn("getPublishTimer, exception = " + ex.getMessage()); 116 } 117 } 118 if (value <= 0) { 119 value = DEFAULT_PUBLISH_TIMER_SEC; 120 logger.error("Failed to get PublishTimer, the default: " + value); 121 } 122 return value; 123 } 124 getPublishTimerExtended(int subId)125 public static int getPublishTimerExtended(int subId) { 126 int value = -1; 127 if (sContext != null) { 128 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 129 return DEFAULT_PUBLISH_TIMER_EXTENDED_SEC; 130 } 131 try { 132 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 133 value = pm.getProvisioningIntValue( 134 ProvisioningManager. 135 KEY_RCS_PUBLISH_OFFLINE_AVAILABILITY_TIMER_SEC); 136 } catch (Exception ex) { 137 logger.warn("getPublishTimerExtended, exception = " + ex.getMessage()); 138 } 139 } 140 if (value <= 0) { 141 value = DEFAULT_PUBLISH_TIMER_EXTENDED_SEC; 142 logger.error("Failed to get PublishTimerExtended, the default: " + value); 143 } 144 return value; 145 } 146 getMaxNumberOfEntriesInRequestContainedList(int subId)147 public static int getMaxNumberOfEntriesInRequestContainedList(int subId) { 148 int value = -1; 149 if (sContext != null) { 150 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 151 return DEFAULT_NUM_ENTRIES_IN_RCL; 152 } 153 try { 154 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 155 value = pm.getProvisioningIntValue( 156 ProvisioningManager.KEY_RCS_MAX_NUM_ENTRIES_IN_RCL); 157 } catch (Exception ex) { 158 logger.warn("getMaxNumberOfEntriesInRequestContainedList, exception = " 159 + ex.getMessage()); 160 } 161 } 162 if (value <= 0) { 163 value = DEFAULT_NUM_ENTRIES_IN_RCL; 164 logger.error("Failed to get MaxNumEntriesInRCL, the default: " + value); 165 } 166 return value; 167 } 168 getCapabilityPollListSubscriptionExpiration(int subId)169 public static int getCapabilityPollListSubscriptionExpiration(int subId) { 170 int value = -1; 171 if (sContext != null) { 172 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 173 return DEFAULT_CAPABILITY_POLL_LIST_SUB_EXPIRATION_SEC; 174 } 175 try { 176 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 177 value = pm.getProvisioningIntValue( 178 ProvisioningManager.KEY_RCS_CAPABILITY_POLL_LIST_SUB_EXP_SEC); 179 } catch (Exception ex) { 180 logger.warn("getMaxNumberOfEntriesInRequestContainedList, exception = " 181 + ex.getMessage()); 182 } 183 } 184 if (value <= 0) { 185 value = DEFAULT_CAPABILITY_POLL_LIST_SUB_EXPIRATION_SEC; 186 logger.error("Failed to get CapabPollListSubExp, the default: " + value); 187 } 188 return value; 189 } 190 191 /** 192 * Get VoLte provisioning configuration for the default voice subscription. 193 * @return {@link ProvisioningManager#PROVISIONING_VALUE_ENABLED} if VoLTE is provisioned, 194 * {@link ProvisioningManager#PROVISIONING_VALUE_DISABLED} if VoLTE is not provisioned, and 195 * {@link ProvisioningManager#PROVISIONING_RESULT_UNKNOWN} if there is no value set. 196 */ getVoLteProvisioningConfig(int subId)197 public static int getVoLteProvisioningConfig(int subId) { 198 try { 199 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 200 return pm.getProvisioningIntValue( 201 ProvisioningManager.KEY_VOLTE_PROVISIONING_STATUS); 202 } catch (Exception e) { 203 logger.warn("getVoLteProvisioningConfig, exception accessing ProvisioningManager, " 204 + "exception=" + e.getMessage()); 205 return ProvisioningManager.PROVISIONING_RESULT_UNKNOWN; 206 } 207 } 208 209 /** 210 * Get VT provisioning configuration for the default voice subscription. 211 * @return {@link ProvisioningManager#PROVISIONING_VALUE_ENABLED} if VT is provisioned, 212 * {@link ProvisioningManager#PROVISIONING_VALUE_DISABLED} if VT is not provisioned, nd 213 * * {@link ProvisioningManager#PROVISIONING_RESULT_UNKNOWN} if there is no value set. 214 */ getVtProvisioningConfig(int subId)215 public static int getVtProvisioningConfig(int subId) { 216 try { 217 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 218 return pm.getProvisioningIntValue( 219 ProvisioningManager.KEY_VT_PROVISIONING_STATUS); 220 } catch (Exception e) { 221 logger.warn("getVtProvisioningConfig, exception accessing ProvisioningManager, " 222 + "exception=" + e.getMessage()); 223 return ProvisioningManager.PROVISIONING_RESULT_UNKNOWN; 224 } 225 } 226 227 /** 228 * Get EAB provisioning configuration for the default voice subscription. 229 * @return {@link ProvisioningManager#PROVISIONING_VALUE_ENABLED} if EAB is provisioned, 230 * {@link ProvisioningManager#PROVISIONING_VALUE_DISABLED} if EAB is not provisioned, nd 231 * * {@link ProvisioningManager#PROVISIONING_RESULT_UNKNOWN} if there is no value set. 232 */ getEabProvisioningConfig(int subId)233 public static int getEabProvisioningConfig(int subId) { 234 try { 235 ProvisioningManager pm = ProvisioningManager.createForSubscriptionId(subId); 236 return pm.getProvisioningIntValue( 237 ProvisioningManager.KEY_EAB_PROVISIONING_STATUS); 238 } catch (Exception e) { 239 logger.warn("getEabProvisioningConfig, exception accessing ProvisioningManager, " 240 + "exception=" + e.getMessage()); 241 return ProvisioningManager.PROVISIONING_RESULT_UNKNOWN; 242 } 243 } 244 getDefaultSubscriptionId()245 public static int getDefaultSubscriptionId() { 246 SubscriptionManager sm = sContext.getSystemService(SubscriptionManager.class); 247 if (sm == null) return SubscriptionManager.INVALID_SUBSCRIPTION_ID; 248 List<SubscriptionInfo> infos = sm.getActiveSubscriptionInfoList(); 249 if (infos == null || infos.isEmpty()) { 250 // There are no active subscriptions right now. 251 return SubscriptionManager.INVALID_SUBSCRIPTION_ID; 252 } 253 // This code does not support MSIM unfortunately, so only provide presence on the default 254 // voice subscription that the user chose. 255 int defaultSub = SubscriptionManager.getDefaultVoiceSubscriptionId(); 256 if (!SubscriptionManager.isValidSubscriptionId(defaultSub)) { 257 // The voice sub may not have been specified, in this case, use the default data. 258 defaultSub = SubscriptionManager.getDefaultDataSubscriptionId(); 259 } 260 // If the user has no default set, just pick the first as backup. 261 if (!SubscriptionManager.isValidSubscriptionId(defaultSub)) { 262 for (SubscriptionInfo info : infos) { 263 if (!info.isOpportunistic()) { 264 defaultSub = info.getSubscriptionId(); 265 break; 266 } 267 } 268 } 269 return defaultSub; 270 } 271 } 272 273