summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Malcolm Chen <refuhoo@google.com> 2018-08-03 17:24:07 -0700
committer Malcolm Chen <refuhoo@google.com> 2018-08-15 17:00:48 -0700
commitbd4ae76753f699c91c38678b3ffc475687664d4e (patch)
tree8e55100d8170393fddbd992eb0e543e19e2021e9
parentd5dc5a7168711f36553e85315842d7b64f8bfea2 (diff)
Abstract set APIs in SubscriptionManager
Put common codes of set APIs in Subscription into an unified method. So that later it's easier to add APIs. Bug: 112167869 Test: unittest Change-Id: Idd2312c98fc178f078c75937ba2d8c2e414f3c3a Merged-In: Idd2312c98fc178f078c75937ba2d8c2e414f3c3a
-rw-r--r--telephony/java/android/telephony/SubscriptionManager.java108
1 files changed, 39 insertions, 69 deletions
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 17e7c49f6289..8aa5bf659be2 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -301,7 +301,7 @@ public class SubscriptionManager {
* <P>Type: TEXT (String)</P>
* @hide
*/
- public static final String CARD_ID = "card_id";
+ public static final String CARD_ID = "card_id";
/**
* TelephonyProvider column name for the encoded {@link UiccAccessRule}s from
@@ -1051,24 +1051,9 @@ public class SubscriptionManager {
*/
public int setIconTint(int tint, int subId) {
if (VDBG) logd("[setIconTint]+ tint:" + tint + " subId:" + subId);
- if (!isValidSubscriptionId(subId)) {
- logd("[setIconTint]- fail");
- return -1;
- }
-
- int result = 0;
-
- try {
- ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
- if (iSub != null) {
- result = iSub.setIconTint(tint, subId);
- }
- } catch (RemoteException ex) {
- // ignore it
- }
-
- return result;
-
+ return setSubscriptionPropertyHelper(subId, "setIconTint",
+ (iSub)-> iSub.setIconTint(tint, subId)
+ );
}
/**
@@ -1096,24 +1081,9 @@ public class SubscriptionManager {
logd("[setDisplayName]+ displayName:" + displayName + " subId:" + subId
+ " nameSource:" + nameSource);
}
- if (!isValidSubscriptionId(subId)) {
- logd("[setDisplayName]- fail");
- return -1;
- }
-
- int result = 0;
-
- try {
- ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
- if (iSub != null) {
- result = iSub.setDisplayNameUsingSrc(displayName, subId, nameSource);
- }
- } catch (RemoteException ex) {
- // ignore it
- }
-
- return result;
-
+ return setSubscriptionPropertyHelper(subId, "setDisplayName",
+ (iSub)-> iSub.setDisplayNameUsingSrc(displayName, subId, nameSource)
+ );
}
/**
@@ -1124,24 +1094,13 @@ public class SubscriptionManager {
* @hide
*/
public int setDisplayNumber(String number, int subId) {
- if (number == null || !isValidSubscriptionId(subId)) {
+ if (number == null) {
logd("[setDisplayNumber]- fail");
return -1;
}
-
- int result = 0;
-
- try {
- ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
- if (iSub != null) {
- result = iSub.setDisplayNumber(number, subId);
- }
- } catch (RemoteException ex) {
- // ignore it
- }
-
- return result;
-
+ return setSubscriptionPropertyHelper(subId, "setDisplayNumber",
+ (iSub)-> iSub.setDisplayNumber(number, subId)
+ );
}
/**
@@ -1153,23 +1112,9 @@ public class SubscriptionManager {
*/
public int setDataRoaming(int roaming, int subId) {
if (VDBG) logd("[setDataRoaming]+ roaming:" + roaming + " subId:" + subId);
- if (roaming < 0 || !isValidSubscriptionId(subId)) {
- logd("[setDataRoaming]- fail");
- return -1;
- }
-
- int result = 0;
-
- try {
- ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
- if (iSub != null) {
- result = iSub.setDataRoaming(roaming, subId);
- }
- } catch (RemoteException ex) {
- // ignore it
- }
-
- return result;
+ return setSubscriptionPropertyHelper(subId, "setDataRoaming",
+ (iSub)->iSub.setDataRoaming(roaming, subId)
+ );
}
/**
@@ -1994,4 +1939,29 @@ public class SubscriptionManager {
}
return false;
}
+
+ private interface CallISubMethodHelper {
+ int callMethod(ISub iSub) throws RemoteException;
+ }
+
+ private int setSubscriptionPropertyHelper(int subId, String methodName,
+ CallISubMethodHelper helper) {
+ if (!isValidSubscriptionId(subId)) {
+ logd("[" + methodName + "]" + "- fail");
+ return -1;
+ }
+
+ int result = 0;
+
+ try {
+ ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
+ if (iSub != null) {
+ result = helper.callMethod(iSub);
+ }
+ } catch (RemoteException ex) {
+ // ignore it
+ }
+
+ return result;
+ }
}