Merge "Add new API for handling DB query per subId." into mnc-dev

This commit is contained in:
Sanket Padawe
2015-07-16 05:01:06 +00:00
committed by Android (Google) Code Review
4 changed files with 246 additions and 0 deletions

View File

@@ -21,12 +21,15 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.telephony.Rlog;
import android.os.Handler;
import android.os.Message;
import android.os.ServiceManager;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import com.android.internal.telephony.ISub;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
@@ -247,6 +250,78 @@ public class SubscriptionManager {
*/
public static final String MNC = "mnc";
/**
* TelephonyProvider column name for extreme threat in CB settings
* @hide
*/
public static final String CB_EXTREME_THREAT_ALERT = "enable_cmas_extreme_threat_alerts";
/**
* TelephonyProvider column name for severe threat in CB settings
*@hide
*/
public static final String CB_SEVERE_THREAT_ALERT = "enable_cmas_severe_threat_alerts";
/**
* TelephonyProvider column name for amber alert in CB settings
*@hide
*/
public static final String CB_AMBER_ALERT = "enable_cmas_amber_alerts";
/**
* TelephonyProvider column name for emergency alert in CB settings
*@hide
*/
public static final String CB_EMERGENCY_ALERT = "enable_emergency_alerts";
/**
* TelephonyProvider column name for alert sound duration in CB settings
*@hide
*/
public static final String CB_ALERT_SOUND_DURATION = "alert_sound_duration";
/**
* TelephonyProvider column name for alert reminder interval in CB settings
*@hide
*/
public static final String CB_ALERT_REMINDER_INTERVAL = "alert_reminder_interval";
/**
* TelephonyProvider column name for enabling vibrate in CB settings
*@hide
*/
public static final String CB_ALERT_VIBRATE = "enable_alert_vibrate";
/**
* TelephonyProvider column name for enabling alert speech in CB settings
*@hide
*/
public static final String CB_ALERT_SPEECH = "enable_alert_speech";
/**
* TelephonyProvider column name for ETWS test alert in CB settings
*@hide
*/
public static final String CB_ETWS_TEST_ALERT = "enable_etws_test_alerts";
/**
* TelephonyProvider column name for enable channel50 alert in CB settings
*@hide
*/
public static final String CB_CHANNEL_50_ALERT = "enable_channel_50_alerts";
/**
* TelephonyProvider column name for CMAS test alert in CB settings
*@hide
*/
public static final String CB_CMAS_TEST_ALERT= "enable_cmas_test_alerts";
/**
* TelephonyProvider column name for Opt out dialog in CB settings
*@hide
*/
public static final String CB_OPT_OUT_DIALOG = "show_cmas_opt_out_dialog";
/**
* Broadcast Action: The user has changed one of the default subs related to
* data, phone calls, or sms</p>
@@ -1136,6 +1211,112 @@ public class SubscriptionManager {
return simState;
}
/**
* Store properties associated with SubscriptionInfo in database
* @param subId Subscription Id of Subscription
* @param propKey Column name in database associated with SubscriptionInfo
* @param propValue Value to store in DB for particular subId & column name
* @hide
*/
public static void setSubscriptionProperty(int subId, String propKey, String propValue) {
try {
ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
if (iSub != null) {
iSub.setSubscriptionProperty(subId, propKey, propValue);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Store properties associated with SubscriptionInfo in database
* @param subId Subscription Id of Subscription
* @param propKey Column name in SubscriptionInfo database
* @return Value associated with subId and propKey column in database
* @hide
*/
private static String getSubscriptionProperty(int subId, String propKey,
Context context) {
String resultValue = null;
try {
ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
if (iSub != null) {
resultValue = iSub.getSubscriptionProperty(subId, propKey,
context.getOpPackageName());
}
} catch (RemoteException ex) {
// ignore it
}
return resultValue;
}
/**
* Returns boolean value corresponding to query result.
* @param subId Subscription Id of Subscription
* @param propKey Column name in SubscriptionInfo database
* @param defValue Default boolean value to be returned
* @return boolean result value to be returned
* @hide
*/
public static boolean getBooleanSubscriptionProperty(int subId, String propKey,
boolean defValue, Context context) {
String result = getSubscriptionProperty(subId, propKey, context);
if (result != null) {
try {
return Integer.parseInt(result) == 1;
} catch (NumberFormatException err) {
logd("getBooleanSubscriptionProperty NumberFormat exception");
}
}
return defValue;
}
/**
* Returns integer value corresponding to query result.
* @param subId Subscription Id of Subscription
* @param propKey Column name in SubscriptionInfo database
* @param defValue Default integer value to be returned
* @return integer result value to be returned
* @hide
*/
public static int getIntegerSubscriptionProperty(int subId, String propKey, int defValue,
Context context) {
String result = getSubscriptionProperty(subId, propKey, context);
if (result != null) {
try {
return Integer.parseInt(result);
} catch (NumberFormatException err) {
logd("getBooleanSubscriptionProperty NumberFormat exception");
}
}
return defValue;
}
/**
* Returns the resources associated with Subscription.
* @param context Context object
* @param subId Subscription Id of Subscription who's resources are required
* @return Resources associated with Subscription.
* @hide
*/
public static Resources getResourcesForSubId(Context context, int subId) {
final SubscriptionInfo subInfo =
SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
Configuration config = context.getResources().getConfiguration();
Configuration newConfig = new Configuration();
newConfig.setTo(config);
if (subInfo != null) {
newConfig.mcc = subInfo.getMcc();
newConfig.mnc = subInfo.getMnc();
}
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
DisplayMetrics newMetrics = new DisplayMetrics();
newMetrics.setTo(metrics);
return new Resources(context.getResources().getAssets(), newMetrics, newConfig);
}
/**
* @return true if the sub ID is active. i.e. The sub ID corresponds to a known subscription
* and the SIM providing the subscription is present in a slot and in "LOADED" state.

View File

@@ -172,6 +172,10 @@ interface ISub {
int[] getActiveSubIdList();
void setSubscriptionProperty(int subId, String propKey, String propValue);
String getSubscriptionProperty(int subId, String propKey, String callingPackage);
/**
* Get the SIM state for the slot idx
* @return SIM state as the ordinal of IccCardConstants.State