diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c163765..b7d062f 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1152,17 +1152,22 @@
         // ACTION_DIAL intent, which is available to any app since it puts up
         // the UI before it does anything.
 
-        String url = createTelUrl(number);
-        if (url == null) {
-            return;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            String url = createTelUrl(number);
+            if (url == null) {
+                return;
+            }
 
-        // PENDING: should we just silently fail if phone is offhook or ringing?
-        PhoneConstants.State state = mCM.getState(subId);
-        if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
-            Intent  intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            mApp.startActivity(intent);
+            // PENDING: should we just silently fail if phone is offhook or ringing?
+            PhoneConstants.State state = mCM.getState(subId);
+            if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
+                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                mApp.startActivity(intent);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1183,29 +1188,34 @@
             return;
         }
 
-        String url = createTelUrl(number);
-        if (url == null) {
-            return;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            String url = createTelUrl(number);
+            if (url == null) {
+                return;
+            }
 
-        boolean isValid = false;
-        final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
-        if (slist != null) {
-            for (SubscriptionInfo subInfoRecord : slist) {
-                if (subInfoRecord.getSubscriptionId() == subId) {
-                    isValid = true;
-                    break;
+            boolean isValid = false;
+            final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
+            if (slist != null) {
+                for (SubscriptionInfo subInfoRecord : slist) {
+                    if (subInfoRecord.getSubscriptionId() == subId) {
+                        isValid = true;
+                        break;
+                    }
                 }
             }
-        }
-        if (isValid == false) {
-            return;
-        }
+            if (!isValid) {
+                return;
+            }
 
-        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
-        intent.putExtra(SUBSCRIPTION_KEY, subId);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        mApp.startActivity(intent);
+            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
+            intent.putExtra(SUBSCRIPTION_KEY, subId);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mApp.startActivity(intent);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -1227,7 +1237,13 @@
             EventLog.writeEvent(0x534e4554, "67862398", -1, "");
             throw new SecurityException("MODIFY_PHONE_STATE permission required.");
         }
-        return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public void answerRingingCall() {
@@ -1240,7 +1256,13 @@
         // but that can probably wait till the big TelephonyManager API overhaul.
         // For now, protect this call with the MODIFY_PHONE_STATE permission.
         enforceModifyPermission();
-        sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -1300,11 +1322,16 @@
             return false;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return (phone.getState() == PhoneConstants.State.OFFHOOK);
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return (phone.getState() == PhoneConstants.State.OFFHOOK);
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1320,11 +1347,16 @@
             return false;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return (phone.getState() == PhoneConstants.State.RINGING);
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return (phone.getState() == PhoneConstants.State.RINGING);
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1340,11 +1372,16 @@
             return false;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return (phone.getState() == PhoneConstants.State.IDLE);
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return (phone.getState() == PhoneConstants.State.IDLE);
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1373,9 +1410,15 @@
 
     public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
         enforceModifyPermission();
-        final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
-        checkSimPin.start();
-        return checkSimPin.unlockSim(null, pin);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
+            checkSimPin.start();
+            return checkSimPin.unlockSim(null, pin);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /** {@hide} */
@@ -1385,9 +1428,15 @@
 
     public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
         enforceModifyPermission();
-        final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
-        checkSimPuk.start();
-        return checkSimPuk.unlockSim(puk, pin);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
+            checkSimPuk.start();
+            return checkSimPuk.unlockSim(puk, pin);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -1498,9 +1547,14 @@
         // No permission check needed here: this call is harmless, and it's
         // needed for the ServiceState.requestStateUpdate() call (which is
         // already intentionally exposed to 3rd parties.)
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.updateServiceLocation();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.updateServiceLocation();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1515,28 +1569,44 @@
                 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
             return false;
         }
-        return isRadioOnForSubscriber(subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return isRadioOnForSubscriber(subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     private boolean isRadioOnForSubscriber(int subId) {
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
     public void toggleRadioOnOff() {
         toggleRadioOnOffForSubscriber(getDefaultSubscription());
-
     }
 
     public void toggleRadioOnOffForSubscriber(int subId) {
         enforceModifyPermission();
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setRadioPower(!isRadioOnForSubscriber(subId));
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setRadioPower(!isRadioOnForSubscriber(subId));
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1546,15 +1616,20 @@
 
     public boolean setRadioForSubscriber(int subId, boolean turnOn) {
         enforceModifyPermission();
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                return false;
+            }
+            if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
+                toggleRadioOnOffForSubscriber(subId);
+            }
+            return true;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        if ((phone.getServiceState().getState() !=
-                ServiceState.STATE_POWER_OFF) != turnOn) {
-            toggleRadioOnOffForSubscriber(subId);
-        }
-        return true;
     }
 
     public boolean needMobileRadioShutdown() {
@@ -1562,23 +1637,35 @@
          * If any of the Radios are available, it will need to be
          * shutdown. So return true if any Radio is available.
          */
-        for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
-            Phone phone = PhoneFactory.getPhone(i);
-            if (phone != null && phone.isRadioAvailable()) return true;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
+                Phone phone = PhoneFactory.getPhone(i);
+                if (phone != null && phone.isRadioAvailable()) return true;
+            }
+            logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
+            return false;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
-        return false;
     }
 
+    @Override
     public void shutdownMobileRadios() {
-        for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
-            logv("Shutting down Phone " + i);
-            shutdownRadioUsingPhoneId(i);
+        enforceModifyPermission();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
+                logv("Shutting down Phone " + i);
+                shutdownRadioUsingPhoneId(i);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
     private void shutdownRadioUsingPhoneId(int phoneId) {
-        enforceModifyPermission();
         Phone phone = PhoneFactory.getPhone(phoneId);
         if (phone != null && phone.isRadioAvailable()) {
             phone.shutdownRadio();
@@ -1587,24 +1674,36 @@
 
     public boolean setRadioPower(boolean turnOn) {
         enforceModifyPermission();
-        final Phone defaultPhone = PhoneFactory.getDefaultPhone();
-        if (defaultPhone != null) {
-            defaultPhone.setRadioPower(turnOn);
-            return true;
-        } else {
-            loge("There's no default phone.");
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone defaultPhone = PhoneFactory.getDefaultPhone();
+            if (defaultPhone != null) {
+                defaultPhone.setRadioPower(turnOn);
+                return true;
+            } else {
+                loge("There's no default phone.");
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
     public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
         enforceModifyPermission();
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setRadioPower(turnOn);
-            return true;
-        } else {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setRadioPower(turnOn);
+                return true;
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1612,13 +1711,19 @@
     @Override
     public boolean enableDataConnectivity() {
         enforceModifyPermission();
-        int subId = mSubscriptionController.getDefaultDataSubId();
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setUserDataEnabled(true);
-            return true;
-        } else {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int subId = mSubscriptionController.getDefaultDataSubId();
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setUserDataEnabled(true);
+                return true;
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1626,23 +1731,34 @@
     @Override
     public boolean disableDataConnectivity() {
         enforceModifyPermission();
-        int subId = mSubscriptionController.getDefaultDataSubId();
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setUserDataEnabled(false);
-            return true;
-        } else {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int subId = mSubscriptionController.getDefaultDataSubId();
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setUserDataEnabled(false);
+                return true;
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
     @Override
     public boolean isDataConnectivityPossible(int subId) {
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.isDataAllowed();
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.isDataAllowed();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1651,20 +1767,32 @@
     }
 
     public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
-      enforceCallPermission();
-      if (!SubscriptionManager.isValidSubscriptionId(subId)) {
-          return;
-      }
-      Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
-      sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
+        enforceCallPermission();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+                return;
+            }
+            Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
+            sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     };
 
     public boolean handlePinMmiForSubscriber(int subId, String dialString) {
         enforceModifyPermission();
-        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+                return false;
+            }
+            return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
     }
 
     public int getCallState() {
@@ -1672,28 +1800,44 @@
     }
 
     public int getCallStateForSlot(int slotIndex) {
-        Phone phone = PhoneFactory.getPhone(slotIndex);
-        return phone == null ? TelephonyManager.CALL_STATE_IDLE :
-            PhoneConstantConversions.convertCallState(phone.getState());
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = PhoneFactory.getPhone(slotIndex);
+            return phone == null ? TelephonyManager.CALL_STATE_IDLE :
+                    PhoneConstantConversions.convertCallState(phone.getState());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public int getDataState() {
-        Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
-        if (phone != null) {
-            return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
-        } else {
-            return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
+            if (phone != null) {
+                return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
+            } else {
+                return PhoneConstantConversions.convertDataState(
+                        PhoneConstants.DataState.DISCONNECTED);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
     @Override
     public int getDataActivity() {
-        Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
-        if (phone != null) {
-            return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
-        } else {
-            return TelephonyManager.DATA_ACTIVITY_NONE;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
+            if (phone != null) {
+                return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
+            } else {
+                return TelephonyManager.DATA_ACTIVITY_NONE;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1706,16 +1850,21 @@
             return null;
         }
 
-        if (DBG_LOC) log("getCellLocation: is active user");
-        Bundle data = new Bundle();
-        Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
-        if (phone == null) {
-            return null;
-        }
-
         WorkSource workSource = getWorkSource(Binder.getCallingUid());
-        phone.getCellLocation(workSource).fillInNotifierBundle(data);
-        return data;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG_LOC) log("getCellLocation: is active user");
+            Bundle data = new Bundle();
+            Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
+            if (phone == null) {
+                return null;
+            }
+
+            phone.getCellLocation(workSource).fillInNotifierBundle(data);
+            return data;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -1735,21 +1884,20 @@
                     == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
                 return "";
             }
+            Phone phone = PhoneFactory.getPhone(phoneId);
+            if (phone != null) {
+                ServiceStateTracker sst = phone.getServiceStateTracker();
+                if (sst != null) {
+                    LocaleTracker lt = sst.getLocaleTracker();
+                    if (lt != null) {
+                        return lt.getCurrentCountry();
+                    }
+                }
+            }
+            return "";
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
-
-        Phone phone = PhoneFactory.getPhone(phoneId);
-        if (phone != null) {
-            ServiceStateTracker sst = phone.getServiceStateTracker();
-            if (sst != null) {
-                LocaleTracker lt = sst.getLocaleTracker();
-                if (lt != null) {
-                    return lt.getCurrentCountry();
-                }
-            }
-        }
-        return "";
     }
 
     @Override
@@ -1761,9 +1909,15 @@
     public void enableLocationUpdatesForSubscriber(int subId) {
         mApp.enforceCallingOrSelfPermission(
                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.enableLocationUpdates();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.enableLocationUpdates();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1776,9 +1930,15 @@
     public void disableLocationUpdatesForSubscriber(int subId) {
         mApp.enforceCallingOrSelfPermission(
                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.disableLocationUpdates();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.disableLocationUpdates();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1802,12 +1962,16 @@
         ArrayList<NeighboringCellInfo> cells = null;
 
         WorkSource workSource = getWorkSource(Binder.getCallingUid());
+
+        final long identity = Binder.clearCallingIdentity();
         try {
             cells = (ArrayList<NeighboringCellInfo>) sendRequest(
                     CMD_HANDLE_NEIGHBORING_CELL, workSource,
                     SubscriptionManager.INVALID_SUBSCRIPTION_ID);
         } catch (RuntimeException e) {
             Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
         return cells;
     }
@@ -1824,19 +1988,30 @@
 
         if (DBG_LOC) log("getAllCellInfo: is active user");
         WorkSource workSource = getWorkSource(Binder.getCallingUid());
-        List<CellInfo> cellInfos = new ArrayList<CellInfo>();
-        for (Phone phone : PhoneFactory.getPhones()) {
-            final List<CellInfo> info = phone.getAllCellInfo(workSource);
-            if (info != null) cellInfos.addAll(info);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            List<CellInfo> cellInfos = new ArrayList<CellInfo>();
+            for (Phone phone : PhoneFactory.getPhones()) {
+                final List<CellInfo> info = phone.getAllCellInfo(workSource);
+                if (info != null) cellInfos.addAll(info);
+            }
+            return cellInfos;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return cellInfos;
     }
 
     @Override
     public void setCellInfoListRate(int rateInMillis) {
         enforceModifyPermission();
         WorkSource workSource = getWorkSource(Binder.getCallingUid());
-        mPhone.setCellInfoListRate(rateInMillis, workSource);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mPhone.setCellInfoListRate(rateInMillis, workSource);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -1850,7 +2025,13 @@
                 mApp, subId, callingPackage, "getImeiForSlot")) {
             return null;
         }
-        return phone.getImei();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return phone.getImei();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -1875,7 +2056,13 @@
                 mApp, subId, callingPackage, "getMeidForSlot")) {
             return null;
         }
-        return phone.getMeid();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return phone.getMeid();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -1900,19 +2087,35 @@
                 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
             return null;
         }
-        return phone.getDeviceSvn();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return phone.getDeviceSvn();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public int getSubscriptionCarrierId(int subId) {
-        final Phone phone = getPhone(subId);
-        return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public String getSubscriptionCarrierName(int subId) {
-        final Phone phone = getPhone(subId);
-        return phone == null ? null : phone.getCarrierName();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? null : phone.getCarrierName();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     //
@@ -1970,11 +2173,16 @@
 
     @Override
     public int getActivePhoneTypeForSlot(int slotIndex) {
-        final Phone phone = PhoneFactory.getPhone(slotIndex);
-        if (phone == null) {
-            return PhoneConstants.PHONE_TYPE_NONE;
-        } else {
-            return phone.getPhoneType();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = PhoneFactory.getPhone(slotIndex);
+            if (phone == null) {
+                return PhoneConstants.PHONE_TYPE_NONE;
+            } else {
+                return phone.getPhoneType();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -1992,11 +2200,17 @@
                 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
             return -1;
         }
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getCdmaEriIconIndex();
-        } else {
-            return -1;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getCdmaEriIconIndex();
+            } else {
+                return -1;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2016,11 +2230,17 @@
                 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
             return -1;
         }
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getCdmaEriIconMode();
-        } else {
-            return -1;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getCdmaEriIconMode();
+            } else {
+                return -1;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2038,11 +2258,17 @@
                 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
             return null;
         }
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getCdmaEriText();
-        } else {
-            return null;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getCdmaEriText();
+            } else {
+                return null;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2053,11 +2279,17 @@
     public String getCdmaMdn(int subId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "getCdmaMdn");
-        final Phone phone = getPhone(subId);
-        if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
-            return phone.getLine1Number();
-        } else {
-            return null;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
+                return phone.getLine1Number();
+            } else {
+                return null;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2068,11 +2300,17 @@
     public String getCdmaMin(int subId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "getCdmaMin");
-        final Phone phone = getPhone(subId);
-        if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
-            return phone.getCdmaMin();
-        } else {
-            return null;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
+                return phone.getCdmaMin();
+            } else {
+                return null;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2080,7 +2318,12 @@
      * Returns true if CDMA provisioning needs to run.
      */
     public boolean needsOtaServiceProvisioning() {
-        return mPhone.needsOtaServiceProvisioning();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return mPhone.needsOtaServiceProvisioning();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2089,9 +2332,15 @@
     @Override
     public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
-        Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
-                new Pair<String, String>(alphaTag, number), new Integer(subId));
-        return success;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
+                    new Pair<String, String>(alphaTag, number), new Integer(subId));
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -2101,11 +2350,17 @@
         if (!TextUtils.equals(callingPackage, systemDialer)) {
             throw new SecurityException("caller must be system dialer");
         }
-        PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
-        if (phoneAccountHandle == null){
-            return null;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
+            if (phoneAccountHandle == null) {
+                return null;
+            }
+            return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
     }
 
     @Override
@@ -2115,6 +2370,7 @@
                 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
             return null;
         }
+
         final long identity = Binder.clearCallingIdentity();
         try {
             return RemoteVvmTaskManager
@@ -2128,31 +2384,54 @@
     public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
             VisualVoicemailSmsFilterSettings settings) {
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
-        VisualVoicemailSmsFilterConfig
-                .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
-                        settings);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
+                    mPhone.getContext(), callingPackage, subId, settings);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
-        VisualVoicemailSmsFilterConfig
-                .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
+                    mPhone.getContext(), callingPackage, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
             String callingPackage, int subId) {
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
-        return VisualVoicemailSmsFilterConfig
-                .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
+                    mPhone.getContext(), callingPackage, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
         enforceReadPrivilegedPermission();
-        return VisualVoicemailSmsFilterConfig
-                .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
+                    mPhone.getContext(), subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -2184,11 +2463,17 @@
     public void setVoiceActivationState(int subId, int activationState) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setVoiceActivationState");
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setVoiceActivationState(activationState);
-        } else {
-            loge("setVoiceActivationState fails with invalid subId: " + subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setVoiceActivationState(activationState);
+            } else {
+                loge("setVoiceActivationState fails with invalid subId: " + subId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2199,11 +2484,17 @@
     public void setDataActivationState(int subId, int activationState) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setDataActivationState");
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setDataActivationState(activationState);
-        } else {
-            loge("setVoiceActivationState fails with invalid subId: " + subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setDataActivationState(activationState);
+            } else {
+                loge("setVoiceActivationState fails with invalid subId: " + subId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2213,11 +2504,17 @@
     @Override
     public int getVoiceActivationState(int subId, String callingPackage) {
         enforceReadPrivilegedPermission();
+
         final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getVoiceActivationState();
-        } else {
-            return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (phone != null) {
+                return phone.getVoiceActivationState();
+            } else {
+                return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2227,11 +2524,17 @@
     @Override
     public int getDataActivationState(int subId, String callingPackage) {
         enforceReadPrivilegedPermission();
+
         final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getDataActivationState();
-        } else {
-            return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (phone != null) {
+                return phone.getDataActivationState();
+            } else {
+                return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2247,11 +2550,16 @@
      */
     @Override
     public int getVoiceMessageCountForSubscriber( int subId) {
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getVoiceMessageCount();
-        } else {
-            return 0;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getVoiceMessageCount();
+            } else {
+                return 0;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2261,8 +2569,13 @@
      */
     @Override
     public boolean isConcurrentVoiceAndDataAllowed(int subId) {
-        final Phone phone = getPhone(subId);
-        return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2278,7 +2591,13 @@
             TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
                     getDefaultSubscription(), "sendDialerSpecialCode");
         }
-        mPhone.sendDialerSpecialCode(inputCode);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mPhone.sendDialerSpecialCode(inputCode);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2289,11 +2608,16 @@
      */
     @Override
     public int getNetworkType() {
-        final Phone phone = getPhone(getDefaultSubscription());
-        if (phone != null) {
-            return phone.getServiceState().getDataNetworkType();
-        } else {
-            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(getDefaultSubscription());
+            if (phone != null) {
+                return phone.getServiceState().getDataNetworkType();
+            } else {
+                return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2307,11 +2631,16 @@
             return TelephonyManager.NETWORK_TYPE_UNKNOWN;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getServiceState().getDataNetworkType();
-        } else {
-            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getServiceState().getDataNetworkType();
+            } else {
+                return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2333,11 +2662,16 @@
             return TelephonyManager.NETWORK_TYPE_UNKNOWN;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getServiceState().getDataNetworkType();
-        } else {
-            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getServiceState().getDataNetworkType();
+            } else {
+                return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2351,11 +2685,16 @@
             return TelephonyManager.NETWORK_TYPE_UNKNOWN;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getServiceState().getVoiceNetworkType();
-        } else {
-            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getServiceState().getVoiceNetworkType();
+            } else {
+                return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2373,11 +2712,16 @@
      */
     @Override
     public boolean hasIccCardUsingSlotIndex(int slotIndex) {
-        final Phone phone = PhoneFactory.getPhone(slotIndex);
-        if (phone != null) {
-            return phone.getIccCard().hasIccCard();
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = PhoneFactory.getPhone(slotIndex);
+            if (phone != null) {
+                return phone.getIccCard().hasIccCard();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2402,11 +2746,16 @@
             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
-        } else {
-            return phone.getLteOnCdmaMode();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
+            } else {
+                return phone.getLteOnCdmaMode();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -2434,17 +2783,28 @@
      * @see android.telephony.TelephonyManager.WifiCallingChoices
      */
     public int getWhenToMakeWifiCalls() {
-        return Settings.System.getInt(mPhone.getContext().getContentResolver(),
-                Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return Settings.System.getInt(mPhone.getContext().getContentResolver(),
+                    Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
+                    getWhenToMakeWifiCallsDefaultPreference());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
      * @see android.telephony.TelephonyManager.WifiCallingChoices
      */
     public void setWhenToMakeWifiCalls(int preference) {
-        if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
-        Settings.System.putInt(mPhone.getContext().getContentResolver(),
-                Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
+            Settings.System.putInt(mPhone.getContext().getContentResolver(),
+                    Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     private static int getWhenToMakeWifiCallsDefaultPreference() {
@@ -2457,24 +2817,32 @@
             int subId, String callingPackage, String aid, int p2) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccOpenLogicalChannel");
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
 
-        if (TextUtils.equals(ISDR_AID, aid)) {
-            // Only allows LPA to open logical channel to ISD-R.
-            mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
-            ComponentInfo bestComponent =
-                    EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
-            if (bestComponent == null
-                    || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
-                loge("The calling package is not allowed to access ISD-R.");
-                throw new SecurityException("The calling package is not allowed to access ISD-R.");
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (TextUtils.equals(ISDR_AID, aid)) {
+                // Only allows LPA to open logical channel to ISD-R.
+                ComponentInfo bestComponent =
+                        EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
+                if (bestComponent == null
+                        || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
+                    loge("The calling package is not allowed to access ISD-R.");
+                    throw new SecurityException(
+                            "The calling package is not allowed to access ISD-R.");
+                }
             }
-        }
 
-        if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
-        IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
-                CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
-        if (DBG) log("iccOpenLogicalChannel: " + response);
-        return response;
+            if (DBG) {
+                log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
+            }
+            IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
+                    CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
+            if (DBG) log("iccOpenLogicalChannel: " + response);
+            return response;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -2482,13 +2850,18 @@
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccCloseLogicalChannel");
 
-        if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
-        if (channel < 0) {
-          return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
+            if (channel < 0) {
+                return false;
+            }
+            Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
+            if (DBG) log("iccCloseLogicalChannel: " + success);
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
-        if (DBG) log("iccCloseLogicalChannel: " + success);
-        return success;
     }
 
     @Override
@@ -2497,27 +2870,32 @@
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccTransmitApduLogicalChannel");
 
-        if (DBG) {
-            log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
-                    " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
-                    " data=" + data);
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) {
+                log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
+                        + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
+                        + p3 + " data=" + data);
+            }
 
-        if (channel < 0) {
-            return "";
-        }
+            if (channel < 0) {
+                return "";
+            }
 
-        IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
-                new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
-        if (DBG) log("iccTransmitApduLogicalChannel: " + response);
+            IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
+                    new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
+            if (DBG) log("iccTransmitApduLogicalChannel: " + response);
 
-        // Append the returned status code to the end of the response payload.
-        String s = Integer.toHexString(
-                (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
-        if (response.payload != null) {
-            s = IccUtils.bytesToHexString(response.payload) + s;
+            // Append the returned status code to the end of the response payload.
+            String s = Integer.toHexString(
+                    (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
+            if (response.payload != null) {
+                s = IccUtils.bytesToHexString(response.payload) + s;
+            }
+            return s;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return s;
     }
 
     @Override
@@ -2525,36 +2903,42 @@
             int command, int p1, int p2, int p3, String data) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccTransmitApduBasicChannel");
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
 
-        if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
-                && TextUtils.equals(ISDR_AID, data)) {
-            // Only allows LPA to select ISD-R.
-            mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
-            ComponentInfo bestComponent =
-                    EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
-            if (bestComponent == null
-                    || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
-                loge("The calling package is not allowed to select ISD-R.");
-                throw new SecurityException("The calling package is not allowed to select ISD-R.");
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
+                    && TextUtils.equals(ISDR_AID, data)) {
+                // Only allows LPA to select ISD-R.
+                ComponentInfo bestComponent =
+                        EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
+                if (bestComponent == null
+                        || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
+                    loge("The calling package is not allowed to select ISD-R.");
+                    throw new SecurityException(
+                            "The calling package is not allowed to select ISD-R.");
+                }
             }
-        }
 
-        if (DBG) {
-            log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
-                    + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
-        }
+            if (DBG) {
+                log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
+                        + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
+            }
 
-        IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
-                new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
-        if (DBG) log("iccTransmitApduBasicChannel: " + response);
+            IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
+                    new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
+            if (DBG) log("iccTransmitApduBasicChannel: " + response);
 
-        // Append the returned status code to the end of the response payload.
-        String s = Integer.toHexString(
-                (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
-        if (response.payload != null) {
-            s = IccUtils.bytesToHexString(response.payload) + s;
+            // Append the returned status code to the end of the response payload.
+            String s = Integer.toHexString(
+                    (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
+            if (response.payload != null) {
+                s = IccUtils.bytesToHexString(response.payload) + s;
+            }
+            return s;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return s;
     }
 
     @Override
@@ -2563,33 +2947,38 @@
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "iccExchangeSimIO");
 
-        if (DBG) {
-            log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
-                p1 + " " + p2 + " " + p3 + ":" + filePath);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) {
+                log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
+                        + p1 + " " + p2 + " " + p3 + ":" + filePath);
+            }
+
+            IccIoResult response =
+                    (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
+                            new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
+                            subId);
+
+            if (DBG) {
+                log("Exchange SIM_IO [R]" + response);
+            }
+
+            byte[] result = null;
+            int length = 2;
+            if (response.payload != null) {
+                length = 2 + response.payload.length;
+                result = new byte[length];
+                System.arraycopy(response.payload, 0, result, 0, response.payload.length);
+            } else {
+                result = new byte[length];
+            }
+
+            result[length - 1] = (byte) response.sw2;
+            result[length - 2] = (byte) response.sw1;
+            return result;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-
-        IccIoResult response =
-            (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
-                    new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
-                    subId);
-
-        if (DBG) {
-          log("Exchange SIM_IO [R]" + response);
-        }
-
-        byte[] result = null;
-        int length = 2;
-        if (response.payload != null) {
-            length = 2 + response.payload.length;
-            result = new byte[length];
-            System.arraycopy(response.payload, 0, result, 0, response.payload.length);
-        } else {
-            result = new byte[length];
-        }
-
-        result[length - 1] = (byte) response.sw2;
-        result[length - 2] = (byte) response.sw1;
-        return result;
     }
 
     /**
@@ -2601,17 +2990,25 @@
                 mApp, subId, callingPackage, "getForbiddenPlmns")) {
             return null;
         }
-        if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
-            loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (appType != TelephonyManager.APPTYPE_USIM
+                    && appType != TelephonyManager.APPTYPE_SIM) {
+                loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
+                return null;
+            }
+            Object response = sendRequest(
+                    CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
+            if (response instanceof String[]) {
+                return (String[]) response;
+            }
+            // Response is an Exception of some kind,
+            // which is signalled to the user as a NULL retval
             return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        Object response = sendRequest(
-            CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
-        if (response instanceof String[]) {
-            return (String[]) response;
-        }
-        // Response is an Exception of some kind, which is signalled to the user as a NULL retval
-        return null;
     }
 
     @Override
@@ -2619,16 +3016,21 @@
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "sendEnvelopeWithStatus");
 
-        IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
-        if (response.payload == null) {
-          return "";
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
+            if (response.payload == null) {
+                return "";
+            }
 
-        // Append the returned status code to the end of the response payload.
-        String s = Integer.toHexString(
-                (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
-        s = IccUtils.bytesToHexString(response.payload) + s;
-        return s;
+            // Append the returned status code to the end of the response payload.
+            String s = Integer.toHexString(
+                    (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
+            s = IccUtils.bytesToHexString(response.payload) + s;
+            return s;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2642,10 +3044,16 @@
     public String nvReadItem(int itemID) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, getDefaultSubscription(), "nvReadItem");
-        if (DBG) log("nvReadItem: item " + itemID);
-        String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
-        if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
-        return value;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("nvReadItem: item " + itemID);
+            String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
+            if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
+            return value;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2660,11 +3068,17 @@
     public boolean nvWriteItem(int itemID, String itemValue) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, getDefaultSubscription(), "nvWriteItem");
-        if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
-        Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
-                new Pair<Integer, String>(itemID, itemValue));
-        if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
-        return success;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
+            Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
+                    new Pair<Integer, String>(itemID, itemValue));
+            if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2678,10 +3092,16 @@
     public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
-        if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
-        Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
-        if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
-        return success;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
+            Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
+            if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2695,10 +3115,16 @@
     public boolean nvResetConfig(int resetType) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, getDefaultSubscription(), "nvResetConfig");
-        if (DBG) log("nvResetConfig: type " + resetType);
-        Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
-        if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
-        return success;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("nvResetConfig: type " + resetType);
+            Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
+            if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public String[] getPcscfAddress(String apnType, String callingPackage) {
@@ -2707,8 +3133,12 @@
             return new String[0];
         }
 
-
-        return mPhone.getPcscfAddress(apnType);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return mPhone.getPcscfAddress(apnType);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2717,7 +3147,13 @@
      */
     public void enableIms(int slotId) {
         enforceModifyPermission();
-        PhoneFactory.getImsResolver().enableIms(slotId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            PhoneFactory.getImsResolver().enableIms(slotId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2726,7 +3162,13 @@
      */
     public void disableIms(int slotId) {
         enforceModifyPermission();
-        PhoneFactory.getImsResolver().disableIms(slotId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            PhoneFactory.getImsResolver().disableIms(slotId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2737,7 +3179,13 @@
     public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
             IImsServiceFeatureCallback callback) {
         enforceModifyPermission();
-        return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2748,7 +3196,13 @@
      */
     public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
         enforceModifyPermission();
-        return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2757,7 +3211,13 @@
      */
     public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
         enforceModifyPermission();
-        return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2766,7 +3226,13 @@
      */
     public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
         enforceModifyPermission();
-        return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2786,8 +3252,13 @@
                 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
                 "setImsService");
 
-        return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
-                isCarrierImsService, packageName);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
+                    isCarrierImsService, packageName);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2804,13 +3275,24 @@
                 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
                 "getImsService");
 
-        return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
-                isCarrierImsService);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
+                    isCarrierImsService);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public void setImsRegistrationState(boolean registered) {
         enforceModifyPermission();
-        mPhone.setImsRegistrationState(registered);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mPhone.setImsRegistrationState(registered);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2821,8 +3303,14 @@
     public void setNetworkSelectionModeAutomatic(int subId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setNetworkSelectionModeAutomatic");
-        if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
-        sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
+            sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2833,14 +3321,20 @@
             boolean persistSelection) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setNetworkSelectionModeManual");
-        OperatorInfo operator = new OperatorInfo(
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            OperatorInfo operator = new OperatorInfo(
                 /* operatorAlphaLong */ "",
                 /* operatorAlphaShort */ "",
-                operatorNumeric);
-        if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
-        ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
-                persistSelection);
-        return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
+                    operatorNumeric);
+            if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
+            ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
+                    persistSelection);
+            return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2850,10 +3344,16 @@
     public CellNetworkScanResult getCellNetworkScanResults(int subId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "getCellNetworkScanResults");
-        if (DBG) log("getCellNetworkScanResults: subId " + subId);
-        CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
-                CMD_PERFORM_NETWORK_SCAN, null, subId);
-        return result;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("getCellNetworkScanResults: subId " + subId);
+            CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
+                    CMD_PERFORM_NETWORK_SCAN, null, subId);
+            return result;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2870,8 +3370,14 @@
             IBinder binder) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "requestNetworkScan");
-        return mNetworkScanRequestTracker.startNetworkScan(
-                request, messenger, binder, getPhone(subId));
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return mNetworkScanRequestTracker.startNetworkScan(
+                    request, messenger, binder, getPhone(subId));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2884,7 +3390,13 @@
     public void stopNetworkScan(int subId, int scanId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "stopNetworkScan");
-        mNetworkScanRequestTracker.stopNetworkScan(scanId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mNetworkScanRequestTracker.stopNetworkScan(scanId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2900,7 +3412,13 @@
             return RILConstants.PREFERRED_NETWORK_MODE;
         }
 
-        return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            // FIXME: need to get SubId from somewhere.
+            return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2913,11 +3431,17 @@
     public int getPreferredNetworkType(int subId) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "getPreferredNetworkType");
-        if (DBG) log("getPreferredNetworkType");
-        int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
-        int networkType = (result != null ? result[0] : -1);
-        if (DBG) log("getPreferredNetworkType: " + networkType);
-        return networkType;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("getPreferredNetworkType");
+            int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
+            int networkType = (result != null ? result[0] : -1);
+            if (DBG) log("getPreferredNetworkType: " + networkType);
+            return networkType;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -2931,14 +3455,21 @@
     public boolean setPreferredNetworkType(int subId, int networkType) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setPreferredNetworkType");
-        if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
-        Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
-        if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
-        if (success) {
-            Settings.Global.putInt(mPhone.getContext().getContentResolver(),
-                    Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
+            Boolean success = (Boolean) sendRequest(
+                    CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
+            if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
+            if (success) {
+                Settings.Global.putInt(mPhone.getContext().getContentResolver(),
+                        Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
+            }
+            return success;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return success;
     }
 
     /**
@@ -2952,14 +3483,20 @@
     @Override
     public int getTetherApnRequired() {
         enforceModifyPermission();
-        int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
-                Settings.Global.TETHER_DUN_REQUIRED, 2);
-        // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
-        // config_tether_apndata.
-        if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
-            dunRequired = 1;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
+                    Settings.Global.TETHER_DUN_REQUIRED, 2);
+            // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
+            // config_tether_apndata.
+            if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
+                dunRequired = 1;
+            }
+            return dunRequired;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return dunRequired;
     }
 
     /**
@@ -2972,14 +3509,20 @@
     public void setUserDataEnabled(int subId, boolean enable) {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, subId, "setUserDataEnabled");
-        int phoneId = mSubscriptionController.getPhoneId(subId);
-        if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
-        Phone phone = PhoneFactory.getPhone(phoneId);
-        if (phone != null) {
-            if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
-            phone.setUserDataEnabled(enable);
-        } else {
-            loge("setUserDataEnabled: no phone for subId=" + subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int phoneId = mSubscriptionController.getPhoneId(subId);
+            if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
+            Phone phone = PhoneFactory.getPhone(phoneId);
+            if (phone != null) {
+                if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
+                phone.setUserDataEnabled(enable);
+            } else {
+                loge("setUserDataEnabled: no phone for subId=" + subId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3017,16 +3560,22 @@
             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                     mApp, subId, "isUserDataEnabled");
         }
-        int phoneId = mSubscriptionController.getPhoneId(subId);
-        if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
-        Phone phone = PhoneFactory.getPhone(phoneId);
-        if (phone != null) {
-            boolean retVal = phone.isUserDataEnabled();
-            if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
-            return retVal;
-        } else {
-            if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int phoneId = mSubscriptionController.getPhoneId(subId);
+            if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
+            Phone phone = PhoneFactory.getPhone(phoneId);
+            if (phone != null) {
+                boolean retVal = phone.isUserDataEnabled();
+                if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
+                return retVal;
+            } else {
+                if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3049,16 +3598,22 @@
             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                     mApp, subId, "isDataEnabled");
         }
-        int phoneId = mSubscriptionController.getPhoneId(subId);
-        if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
-        Phone phone = PhoneFactory.getPhone(phoneId);
-        if (phone != null) {
-            boolean retVal = phone.isDataEnabled();
-            if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
-            return retVal;
-        } else {
-            if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int phoneId = mSubscriptionController.getPhoneId(subId);
+            if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
+            Phone phone = PhoneFactory.getPhone(phoneId);
+            if (phone != null) {
+                boolean retVal = phone.isDataEnabled();
+                if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
+                return retVal;
+            } else {
+                if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3196,45 +3751,50 @@
         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
                 subId, "setLine1NumberForDisplayForSubscriber");
 
-        final String iccId = getIccId(subId);
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final String iccId = getIccId(subId);
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                return false;
+            }
+            final String subscriberId = phone.getSubscriberId();
+
+            if (DBG_MERGE) {
+                Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
+                        + subscriberId + " to " + number);
+            }
+
+            if (TextUtils.isEmpty(iccId)) {
+                return false;
+            }
+
+            final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
+
+            final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
+            if (alphaTag == null) {
+                editor.remove(alphaTagPrefKey);
+            } else {
+                editor.putString(alphaTagPrefKey, alphaTag);
+            }
+
+            // Record both the line number and IMSI for this ICCID, since we need to
+            // track all merged IMSIs based on line number
+            final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
+            final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
+            if (number == null) {
+                editor.remove(numberPrefKey);
+                editor.remove(subscriberPrefKey);
+            } else {
+                editor.putString(numberPrefKey, number);
+                editor.putString(subscriberPrefKey, subscriberId);
+            }
+
+            editor.commit();
+            return true;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        final String subscriberId = phone.getSubscriberId();
-
-        if (DBG_MERGE) {
-            Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
-                    + subscriberId + " to " + number);
-        }
-
-        if (TextUtils.isEmpty(iccId)) {
-            return false;
-        }
-
-        final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
-
-        final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
-        if (alphaTag == null) {
-            editor.remove(alphaTagPrefKey);
-        } else {
-            editor.putString(alphaTagPrefKey, alphaTag);
-        }
-
-        // Record both the line number and IMSI for this ICCID, since we need to
-        // track all merged IMSIs based on line number
-        final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
-        final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
-        if (number == null) {
-            editor.remove(numberPrefKey);
-            editor.remove(subscriberPrefKey);
-        } else {
-            editor.putString(numberPrefKey, number);
-            editor.putString(subscriberPrefKey, subscriberId);
-        }
-
-        editor.commit();
-        return true;
     }
 
     @Override
@@ -3246,17 +3806,22 @@
             return null;
         }
 
-        String iccId = getIccId(subId);
-        if (iccId != null) {
-            String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
-            if (DBG_MERGE) {
-                log("getLine1NumberForDisplay returning " +
-                        mTelephonySharedPreferences.getString(numberPrefKey, null));
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            String iccId = getIccId(subId);
+            if (iccId != null) {
+                String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
+                if (DBG_MERGE) {
+                    log("getLine1NumberForDisplay returning "
+                            + mTelephonySharedPreferences.getString(numberPrefKey, null));
+                }
+                return mTelephonySharedPreferences.getString(numberPrefKey, null);
             }
-            return mTelephonySharedPreferences.getString(numberPrefKey, null);
+            if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
-        return null;
     }
 
     @Override
@@ -3266,12 +3831,17 @@
             return null;
         }
 
-        String iccId = getIccId(subId);
-        if (iccId != null) {
-            String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
-            return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            String iccId = getIccId(subId);
+            if (iccId != null) {
+                String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
+                return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
+            }
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return null;
     }
 
     @Override
@@ -3283,80 +3853,91 @@
                 "getMergedSubscriberIds")) {
             return null;
         }
-        final Context context = mPhone.getContext();
-        final TelephonyManager tele = TelephonyManager.from(context);
-        final SubscriptionManager sub = SubscriptionManager.from(context);
 
-        // Figure out what subscribers are currently active
-        final ArraySet<String> activeSubscriberIds = new ArraySet<>();
-        // Clear calling identity, when calling TelephonyManager, because callerUid must be
-        // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
         final long identity  = Binder.clearCallingIdentity();
         try {
+            final Context context = mPhone.getContext();
+            final TelephonyManager tele = TelephonyManager.from(context);
+            final SubscriptionManager sub = SubscriptionManager.from(context);
+
+            // Figure out what subscribers are currently active
+            final ArraySet<String> activeSubscriberIds = new ArraySet<>();
+            // Clear calling identity, when calling TelephonyManager, because callerUid must be
+            // the process, where TelephonyManager was instantiated.
+            // Otherwise AppOps check will fail.
+
             final int[] subIds = sub.getActiveSubscriptionIdList();
             for (int subId : subIds) {
                 activeSubscriberIds.add(tele.getSubscriberId(subId));
             }
+
+            // First pass, find a number override for an active subscriber
+            String mergeNumber = null;
+            final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
+            for (String key : prefs.keySet()) {
+                if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
+                    final String subscriberId = (String) prefs.get(key);
+                    if (activeSubscriberIds.contains(subscriberId)) {
+                        final String iccId = key.substring(
+                                PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
+                        final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
+                        mergeNumber = (String) prefs.get(numberKey);
+                        if (DBG_MERGE) {
+                            Slog.d(LOG_TAG, "Found line number " + mergeNumber
+                                    + " for active subscriber " + subscriberId);
+                        }
+                        if (!TextUtils.isEmpty(mergeNumber)) {
+                            break;
+                        }
+                    }
+                }
+            }
+
+            // Shortcut when no active merged subscribers
+            if (TextUtils.isEmpty(mergeNumber)) {
+                return null;
+            }
+
+            // Second pass, find all subscribers under that line override
+            final ArraySet<String> result = new ArraySet<>();
+            for (String key : prefs.keySet()) {
+                if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
+                    final String number = (String) prefs.get(key);
+                    if (mergeNumber.equals(number)) {
+                        final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
+                        final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
+                        final String subscriberId = (String) prefs.get(subscriberKey);
+                        if (!TextUtils.isEmpty(subscriberId)) {
+                            result.add(subscriberId);
+                        }
+                    }
+                }
+            }
+
+            final String[] resultArray = result.toArray(new String[result.size()]);
+            Arrays.sort(resultArray);
+            if (DBG_MERGE) {
+                Slog.d(LOG_TAG,
+                        "Found subscribers " + Arrays.toString(resultArray) + " after merge");
+            }
+            return resultArray;
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
-
-        // First pass, find a number override for an active subscriber
-        String mergeNumber = null;
-        final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
-        for (String key : prefs.keySet()) {
-            if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
-                final String subscriberId = (String) prefs.get(key);
-                if (activeSubscriberIds.contains(subscriberId)) {
-                    final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
-                    final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
-                    mergeNumber = (String) prefs.get(numberKey);
-                    if (DBG_MERGE) {
-                        Slog.d(LOG_TAG, "Found line number " + mergeNumber
-                                + " for active subscriber " + subscriberId);
-                    }
-                    if (!TextUtils.isEmpty(mergeNumber)) {
-                        break;
-                    }
-                }
-            }
-        }
-
-        // Shortcut when no active merged subscribers
-        if (TextUtils.isEmpty(mergeNumber)) {
-            return null;
-        }
-
-        // Second pass, find all subscribers under that line override
-        final ArraySet<String> result = new ArraySet<>();
-        for (String key : prefs.keySet()) {
-            if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
-                final String number = (String) prefs.get(key);
-                if (mergeNumber.equals(number)) {
-                    final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
-                    final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
-                    final String subscriberId = (String) prefs.get(subscriberKey);
-                    if (!TextUtils.isEmpty(subscriberId)) {
-                        result.add(subscriberId);
-                    }
-                }
-            }
-        }
-
-        final String[] resultArray = result.toArray(new String[result.size()]);
-        Arrays.sort(resultArray);
-        if (DBG_MERGE) {
-            Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
-        }
-        return resultArray;
     }
 
     @Override
     public boolean setOperatorBrandOverride(int subId, String brand) {
         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
                 subId, "setOperatorBrandOverride");
-        final Phone phone = getPhone(subId);
-        return phone == null ? false : phone.setOperatorBrandOverride(brand);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            return phone == null ? false : phone.setOperatorBrandOverride(brand);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -3364,12 +3945,18 @@
             List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
             List<String> cdmaNonRoamingList) {
         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                return false;
+            }
+            return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
+                    cdmaNonRoamingList);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
-                cdmaNonRoamingList);
     }
 
     @Override
@@ -3426,13 +4013,24 @@
             return RadioAccessFamily.RAF_UNKNOWN;
         }
 
-        return ProxyController.getInstance().getRadioAccessFamily(phoneId);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return ProxyController.getInstance().getRadioAccessFamily(phoneId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public void enableVideoCalling(boolean enable) {
         enforceModifyPermission();
-        ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -3442,50 +4040,97 @@
             return false;
         }
 
-        // Check the user preference and the  system-level IMS setting. Even if the user has
-        // enabled video calling, if IMS is disabled we aren't able to support video calling.
-        // In the long run, we may instead need to check if there exists a connection service
-        // which can support video calling.
-        ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
-        return imsManager.isVtEnabledByPlatform()
-                && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
-                && imsManager.isVtEnabledByUser();
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            // Check the user preference and the  system-level IMS setting. Even if the user has
+            // enabled video calling, if IMS is disabled we aren't able to support video calling.
+            // In the long run, we may instead need to check if there exists a connection service
+            // which can support video calling.
+            ImsManager imsManager =
+                    ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
+            return imsManager.isVtEnabledByPlatform()
+                    && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
+                    && imsManager.isVtEnabledByUser();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
-    public boolean canChangeDtmfToneLength() {
-        return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
+    public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
+        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
+                mApp, subId, callingPackage, "isVideoCallingEnabled")) {
+            return false;
+        }
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            CarrierConfigManager configManager =
+                    (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+            return configManager.getConfigForSubId(mPhone.getSubId())
+                    .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
-    public boolean isWorldPhone() {
-        return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
+    public boolean isWorldPhone(int subId, String callingPackage) {
+        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
+                mApp, subId, callingPackage, "isVideoCallingEnabled")) {
+            return false;
+        }
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            CarrierConfigManager configManager =
+                    (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+            return configManager.getConfigForSubId(mPhone.getSubId())
+                    .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public boolean isTtyModeSupported() {
         TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
-        TelephonyManager telephonyManager =
-                (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
         return telecomManager.isTtySupported();
     }
 
     @Override
     public boolean isHearingAidCompatibilitySupported() {
-        return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public boolean isRttSupported() {
-        boolean isCarrierSupported =
-                mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
-        boolean isDeviceSupported =
-                mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
-        return isCarrierSupported && isDeviceSupported;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
+                    mPhone.getSubId()).getBoolean(
+                    CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
+            boolean isDeviceSupported =
+                    mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
+            return isCarrierSupported && isDeviceSupported;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public boolean isRttEnabled() {
-        return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
-                Settings.Secure.RTT_CALLING_MODE, 0) != 0;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return isRttSupported() && Settings.Secure.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    Settings.Secure.RTT_CALLING_MODE, 0) != 0;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3506,7 +4151,13 @@
                 mApp, subId, callingPackage, "getDeviceId")) {
             return null;
         }
-        return phone.getDeviceId();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return phone.getDeviceId();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3526,18 +4177,28 @@
 
     @Override
     public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
-        return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
      * @return the VoWiFi calling availability.
      */
     public boolean isWifiCallingAvailable(int subId) {
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.isWifiCallingEnabled();
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.isWifiCallingEnabled();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3545,11 +4206,16 @@
      * @return the VoLTE availability.
      */
     public boolean isVolteAvailable(int subId) {
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.isVolteEnabled();
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.isVolteEnabled();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3557,11 +4223,16 @@
      * @return the VT calling availability.
      */
     public boolean isVideoTelephonyAvailable(int subId) {
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.isVideoEnabled();
-        } else {
-            return false;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.isVideoEnabled();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3570,11 +4241,16 @@
      * defined in {@link ImsRegistrationImplBase}.
      */
     public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getImsRegistrationTech();
-        } else {
-            return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getImsRegistrationTech();
+            } else {
+                return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3602,83 +4278,82 @@
 
     @Override
     public String getLocaleFromDefaultSim() {
-        // We query all subscriptions instead of just the active ones, because
-        // this might be called early on in the provisioning flow when the
-        // subscriptions potentially aren't active yet.
-        final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
-        if (slist == null || slist.isEmpty()) {
-            return null;
-        }
-
-        // This function may be called very early, say, from the setup wizard, at
-        // which point we won't have a default subscription set. If that's the case
-        // we just choose the first, which will be valid in "most cases".
-        final int defaultSubId = getDefaultSubscription();
-        SubscriptionInfo info = null;
-        if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
-            info = slist.get(0);
-        } else {
-            for (SubscriptionInfo item : slist) {
-                if (item.getSubscriptionId() == defaultSubId) {
-                    info = item;
-                    break;
-                }
-            }
-
-            if (info == null) {
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            // We query all subscriptions instead of just the active ones, because
+            // this might be called early on in the provisioning flow when the
+            // subscriptions potentially aren't active yet.
+            final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
+            if (slist == null || slist.isEmpty()) {
                 return null;
             }
-        }
 
-        // Try and fetch the locale from the carrier properties or from the SIM language
-        // preferences (EF-PL and EF-LI)...
-        final int mcc = info.getMcc();
-        final Phone defaultPhone = getPhone(info.getSubscriptionId());
-        String simLanguage = null;
-        if (defaultPhone != null) {
-            final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
-            if (localeFromDefaultSim != null) {
-                if (!localeFromDefaultSim.getCountry().isEmpty()) {
-                    if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
-                    return localeFromDefaultSim.toLanguageTag();
-                } else {
-                    simLanguage = localeFromDefaultSim.getLanguage();
+            // This function may be called very early, say, from the setup wizard, at
+            // which point we won't have a default subscription set. If that's the case
+            // we just choose the first, which will be valid in "most cases".
+            final int defaultSubId = getDefaultSubscription();
+            SubscriptionInfo info = null;
+            if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+                info = slist.get(0);
+            } else {
+                for (SubscriptionInfo item : slist) {
+                    if (item.getSubscriptionId() == defaultSubId) {
+                        info = item;
+                        break;
+                    }
+                }
+
+                if (info == null) {
+                    return null;
                 }
             }
-        }
 
-        // The SIM language preferences only store a language (e.g. fr = French), not an
-        // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
-        // the SIM and carrier preferences does not include a country we add the country
-        // determined from the SIM MCC to provide an exact locale.
-        final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
-        if (mccLocale != null) {
-            if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
-            return mccLocale.toLanguageTag();
-        }
+            // Try and fetch the locale from the carrier properties or from the SIM language
+            // preferences (EF-PL and EF-LI)...
+            final int mcc = info.getMcc();
+            final Phone defaultPhone = getPhone(info.getSubscriptionId());
+            String simLanguage = null;
+            if (defaultPhone != null) {
+                final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
+                if (localeFromDefaultSim != null) {
+                    if (!localeFromDefaultSim.getCountry().isEmpty()) {
+                        if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
+                        return localeFromDefaultSim.toLanguageTag();
+                    } else {
+                        simLanguage = localeFromDefaultSim.getLanguage();
+                    }
+                }
+            }
 
-        if (DBG) log("No locale found - returning null");
-        return null;
+            // The SIM language preferences only store a language (e.g. fr = French), not an
+            // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
+            // the SIM and carrier preferences does not include a country we add the country
+            // determined from the SIM MCC to provide an exact locale.
+            final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
+                    simLanguage);
+            if (mccLocale != null) {
+                if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
+                return mccLocale.toLanguageTag();
+            }
+
+            if (DBG) log("No locale found - returning null");
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     private List<SubscriptionInfo> getAllSubscriptionInfoList() {
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return mSubscriptionController.getAllSubInfoList(
-                    mPhone.getContext().getOpPackageName());
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
+        return mSubscriptionController.getAllSubInfoList(
+                mPhone.getContext().getOpPackageName());
     }
 
-    private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return mSubscriptionController.getActiveSubscriptionInfoList(
-                    mPhone.getContext().getOpPackageName());
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
+    /**
+     * NOTE: this method assumes permission checks are done and caller identity has been cleared.
+     */
+    private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
+        return mSubscriptionController.getActiveSubscriptionInfoList(
+                mPhone.getContext().getOpPackageName());
     }
 
     private final ModemActivityInfo mLastModemActivityInfo =
@@ -3695,37 +4370,43 @@
     @Override
     public void requestModemActivityInfo(ResultReceiver result) {
         enforceModifyPermission();
-        ModemActivityInfo ret = null;
-        synchronized (mLastModemActivityInfo) {
-            ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
-                    null);
-            if (isModemActivityInfoValid(info)) {
-                int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
-                for (int i = 0; i < mergedTxTimeMs.length; i++) {
-                    mergedTxTimeMs[i] =
-                            info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            ModemActivityInfo ret = null;
+            synchronized (mLastModemActivityInfo) {
+                ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
+                        null);
+                if (isModemActivityInfoValid(info)) {
+                    int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
+                    for (int i = 0; i < mergedTxTimeMs.length; i++) {
+                        mergedTxTimeMs[i] =
+                                info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
+                    }
+                    mLastModemActivityInfo.setTimestamp(info.getTimestamp());
+                    mLastModemActivityInfo.setSleepTimeMillis(
+                            info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
+                    mLastModemActivityInfo.setIdleTimeMillis(
+                            info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
+                    mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
+                    mLastModemActivityInfo.setRxTimeMillis(
+                            info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
+                    mLastModemActivityInfo.setEnergyUsed(
+                            info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
                 }
-                mLastModemActivityInfo.setTimestamp(info.getTimestamp());
-                mLastModemActivityInfo.setSleepTimeMillis(
-                        info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
-                mLastModemActivityInfo.setIdleTimeMillis(
-                        info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
-                mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
-                mLastModemActivityInfo.setRxTimeMillis(
-                        info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
-                mLastModemActivityInfo.setEnergyUsed(
-                        info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
+                ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
+                        mLastModemActivityInfo.getSleepTimeMillis(),
+                        mLastModemActivityInfo.getIdleTimeMillis(),
+                        mLastModemActivityInfo.getTxTimeMillis(),
+                        mLastModemActivityInfo.getRxTimeMillis(),
+                        mLastModemActivityInfo.getEnergyUsed());
             }
-            ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
-                    mLastModemActivityInfo.getSleepTimeMillis(),
-                    mLastModemActivityInfo.getIdleTimeMillis(),
-                    mLastModemActivityInfo.getTxTimeMillis(),
-                    mLastModemActivityInfo.getRxTimeMillis(),
-                    mLastModemActivityInfo.getEnergyUsed());
+            Bundle bundle = new Bundle();
+            bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
+            result.send(0, bundle);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        Bundle bundle = new Bundle();
-        bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
-        result.send(0, bundle);
     }
 
     // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
@@ -3753,18 +4434,22 @@
      */
     @Override
     public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
-
         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
             return null;
         }
 
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            return null;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                return null;
+            }
 
-        return phone.getServiceState();
+            return phone.getServiceState();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3777,12 +4462,17 @@
      */
     @Override
     public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
-        Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
-        if (phone == null) {
-            phone = mPhone;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
+            if (phone == null) {
+                phone = mPhone;
+            }
 
-        return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
+            return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3806,11 +4496,17 @@
                     mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
                     "setVoicemailRingtoneUri");
         }
-        Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
-        if (phone == null){
-           phone = mPhone;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
+            if (phone == null) {
+                phone = mPhone;
+            }
+            VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
     }
 
     /**
@@ -3822,12 +4518,17 @@
      */
     @Override
     public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
-        Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
-        if (phone == null) {
-            phone = mPhone;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
+            if (phone == null) {
+                phone = mPhone;
+            }
 
-        return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
+            return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3852,11 +4553,16 @@
                     "setVoicemailVibrationEnabled");
         }
 
-        Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
-        if (phone == null){
-            phone = mPhone;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
+            if (phone == null) {
+                phone = mPhone;
+            }
+            VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
     }
 
     /**
@@ -3885,15 +4591,21 @@
      * @throws SecurityException if the caller is not the visual voicemail package.
      */
     private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
-        ComponentName componentName =
-                RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
-        if(componentName == null) {
-            throw new SecurityException("Caller not current active visual voicemail package[null]");
-        }
-        String vvmPackage = componentName.getPackageName();
-        if (!callingPackage.equals(vvmPackage)) {
-            throw new SecurityException("Caller not current active visual voicemail package[" +
-                    vvmPackage + "]");
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            ComponentName componentName =
+                    RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
+            if (componentName == null) {
+                throw new SecurityException(
+                        "Caller not current active visual voicemail package[null]");
+            }
+            String vvmPackage = componentName.getPackageName();
+            if (!callingPackage.equals(vvmPackage)) {
+                throw new SecurityException("Caller not current active visual voicemail package["
+                        + vvmPackage + "]");
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -3908,17 +4620,23 @@
     public String getAidForAppType(int subId, int appType) {
         enforceReadPrivilegedPermission();
         Phone phone = getPhone(subId);
-        if (phone == null) {
-            return null;
-        }
-        String aid = null;
+
+        final long identity = Binder.clearCallingIdentity();
         try {
-            aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
-                    .getApplicationByType(appType).getAid();
-        } catch (Exception e) {
-            Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
+            if (phone == null) {
+                return null;
+            }
+            String aid = null;
+            try {
+                aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
+                        .getApplicationByType(appType).getAid();
+            } catch (Exception e) {
+                Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
+            }
+            return aid;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return aid;
     }
 
     /**
@@ -3931,16 +4649,22 @@
     public String getEsn(int subId) {
         enforceReadPrivilegedPermission();
         Phone phone = getPhone(subId);
-        if (phone == null) {
-            return null;
-        }
-        String esn = null;
+
+        final long identity = Binder.clearCallingIdentity();
         try {
-            esn = phone.getEsn();
-        } catch (Exception e) {
-            Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
+            if (phone == null) {
+                return null;
+            }
+            String esn = null;
+            try {
+                esn = phone.getEsn();
+            } catch (Exception e) {
+                Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
+            }
+            return esn;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return esn;
     }
 
     /**
@@ -3953,16 +4677,22 @@
     public String getCdmaPrlVersion(int subId) {
         enforceReadPrivilegedPermission();
         Phone phone = getPhone(subId);
-        if (phone == null) {
-            return null;
-        }
-        String cdmaPrlVersion = null;
+
+        final long identity = Binder.clearCallingIdentity();
         try {
-            cdmaPrlVersion = phone.getCdmaPrlVersion();
-        } catch (Exception e) {
-            Log.e(LOG_TAG, "Not getting PRLVersion", e);
+            if (phone == null) {
+                return null;
+            }
+            String cdmaPrlVersion = null;
+            try {
+                cdmaPrlVersion = phone.getCdmaPrlVersion();
+            } catch (Exception e) {
+                Log.e(LOG_TAG, "Not getting PRLVersion", e);
+            }
+            return cdmaPrlVersion;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return cdmaPrlVersion;
     }
 
     /**
@@ -3974,7 +4704,13 @@
     public List<TelephonyHistogram> getTelephonyHistograms() {
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
                 mApp, getDefaultSubscription(), "getTelephonyHistograms");
-        return RIL.getTelephonyRILTimingHistograms();
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return RIL.getTelephonyRILTimingHistograms();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -3992,9 +4728,14 @@
             throw new NullPointerException("carriers cannot be null");
         }
 
-        int subId = SubscriptionManager.getSubId(slotIndex)[0];
-        int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
-        return retVal[0];
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int subId = SubscriptionManager.getSubId(slotIndex)[0];
+            int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
+            return retVal[0];
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -4008,8 +4749,14 @@
     @Override
     public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
         enforceReadPrivilegedPermission();
-        int subId = SubscriptionManager.getSubId(slotIndex)[0];
-        return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            int subId = SubscriptionManager.getSubId(slotIndex)[0];
+            return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -4022,6 +4769,8 @@
     public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
         enforceModifyPermission();
         final Phone phone = getPhone(subId);
+
+        final long identity = Binder.clearCallingIdentity();
         if (phone == null) {
             loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
             return;
@@ -4030,6 +4779,8 @@
             phone.carrierActionSetMeteredApnsEnabled(enabled);
         } catch (Exception e) {
             Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4043,6 +4794,8 @@
     public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
         enforceModifyPermission();
         final Phone phone = getPhone(subId);
+
+        final long identity = Binder.clearCallingIdentity();
         if (phone == null) {
             loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
             return;
@@ -4051,6 +4804,8 @@
             phone.carrierActionSetRadioEnabled(enabled);
         } catch (Exception e) {
             Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4067,6 +4822,8 @@
     public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
         enforceModifyPermission();
         final Phone phone = getPhone(subId);
+
+        final long identity = Binder.clearCallingIdentity();
         if (phone == null) {
             loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
             return;
@@ -4075,6 +4832,8 @@
             phone.carrierActionReportDefaultNetworkStatus(report);
         } catch (Exception e) {
             Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4115,14 +4874,19 @@
         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
                 null);
 
-        // NetworkStatsService keeps tracking the active network interface and identity. It
-        // records the delta with the corresponding network identity. We just return the total video
-        // call data usage snapshot since boot.
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getVtDataUsage(perUidStats);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            // NetworkStatsService keeps tracking the active network interface and identity. It
+            // records the delta with the corresponding network identity.
+            // We just return the total video call data usage snapshot since boot.
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                return phone.getVtDataUsage(perUidStats);
+            }
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return null;
     }
 
     /**
@@ -4134,9 +4898,15 @@
     @Override
     public void setPolicyDataEnabled(boolean enabled, int subId) {
         enforceModifyPermission();
-        Phone phone = getPhone(subId);
-        if (phone != null) {
-            phone.setPolicyDataEnabled(enabled);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone phone = getPhone(subId);
+            if (phone != null) {
+                phone.setPolicyDataEnabled(enabled);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4151,13 +4921,18 @@
                 mApp, subId, callingPackage, "getClientRequestStats")) {
             return null;
         }
-
         Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.getClientRequestStats();
-        }
 
-        return null;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (phone != null) {
+                return phone.getClientRequestStats();
+            }
+
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     private WorkSource getWorkSource(int uid) {
@@ -4180,8 +4955,13 @@
         enforceModifyPermission();
         Phone phone = PhoneFactory.getPhone(slotIndex);
 
-        if (phone != null) {
-            phone.setSimPowerState(state);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (phone != null) {
+                phone.setSimPowerState(state);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4209,10 +4989,16 @@
     public boolean getEmergencyCallbackMode(int subId) {
         enforceReadPrivilegedPermission();
         final Phone phone = getPhone(subId);
-        if (phone != null) {
-            return phone.isInEcm();
-        } else {
-            return false;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            if (phone != null) {
+                return phone.isInEcm();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
     }
 
@@ -4225,73 +5011,89 @@
      */
     @Override
     public SignalStrength getSignalStrength(int subId) {
-        Phone p = getPhone(subId);
-        if (p == null) {
-            return null;
-        }
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            Phone p = getPhone(subId);
+            if (p == null) {
+                return null;
+            }
 
-        return p.getSignalStrength();
+            return p.getSignalStrength();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
     public UiccSlotInfo[] getUiccSlotsInfo() {
         enforceReadPrivilegedPermission();
 
-        UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
-        if (slots == null) {
-            Rlog.i(LOG_TAG, "slots is null.");
-            return null;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
+            if (slots == null) {
+                Rlog.i(LOG_TAG, "slots is null.");
+                return null;
+            }
+
+            UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
+            for (int i = 0; i < slots.length; i++) {
+                UiccSlot slot = slots[i];
+                if (slot == null) {
+                    continue;
+                }
+
+                String cardId;
+                UiccCard card = slot.getUiccCard();
+                if (card != null) {
+                    cardId = card.getCardId();
+                } else {
+                    cardId = slot.getIccId();
+                }
+
+                int cardState = 0;
+                switch (slot.getCardState()) {
+                    case CARDSTATE_ABSENT:
+                        cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
+                        break;
+                    case CARDSTATE_PRESENT:
+                        cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
+                        break;
+                    case CARDSTATE_ERROR:
+                        cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
+                        break;
+                    case CARDSTATE_RESTRICTED:
+                        cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
+                        break;
+                    default:
+                        break;
+
+                }
+
+                infos[i] = new UiccSlotInfo(
+                        slot.isActive(),
+                        slot.isEuicc(),
+                        cardId,
+                        cardState,
+                        slot.getPhoneId(),
+                        slot.isExtendedApduSupported());
+            }
+            return infos;
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-
-        UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
-        for (int i = 0; i < slots.length; i++) {
-            UiccSlot slot = slots[i];
-            if (slot == null) {
-                continue;
-            }
-
-            String cardId;
-            UiccCard card = slot.getUiccCard();
-            if (card != null) {
-                cardId = card.getCardId();
-            } else {
-                cardId = slot.getIccId();
-            }
-
-            int cardState = 0;
-            switch (slot.getCardState()) {
-                case CARDSTATE_ABSENT:
-                    cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
-                    break;
-                case CARDSTATE_PRESENT:
-                    cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
-                    break;
-                case CARDSTATE_ERROR:
-                    cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
-                    break;
-                case CARDSTATE_RESTRICTED:
-                    cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
-                    break;
-                default:
-                    break;
-
-            }
-
-            infos[i] = new UiccSlotInfo(
-                    slot.isActive(),
-                    slot.isEuicc(),
-                    cardId,
-                    cardState,
-                    slot.getPhoneId(),
-                    slot.isExtendedApduSupported());
-        }
-        return infos;
     }
 
     @Override
     public boolean switchSlots(int[] physicalSlots) {
         enforceModifyPermission();
-        return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     @Override
@@ -4303,7 +5105,12 @@
             return;
         }
 
-        phone.setRadioIndicationUpdateMode(filters, mode);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            phone.setRadioIndicationUpdateMode(filters, mode);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
@@ -4376,22 +5183,34 @@
     public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
             gid1, String gid2, String plmn, String spn) {
         enforceModifyPermission();
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            loge("setCarrierTestOverride fails with invalid subId: " + subId);
-            return;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                loge("setCarrierTestOverride fails with invalid subId: " + subId);
+                return;
+            }
+            phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
     }
 
     @Override
     public int getCarrierIdListVersion(int subId) {
         enforceReadPrivilegedPermission();
-        final Phone phone = getPhone(subId);
-        if (phone == null) {
-            loge("getCarrierIdListVersion fails with invalid subId: " + subId);
-            return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            final Phone phone = getPhone(subId);
+            if (phone == null) {
+                loge("getCarrierIdListVersion fails with invalid subId: " + subId);
+                return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
+            }
+            return phone.getCarrierIdListVersion();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-        return phone.getCarrierIdListVersion();
     }
 }
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index 74b8e4e..2bcae09 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -568,12 +568,12 @@
     private boolean getBooleanCarrierConfig(String key) {
         PersistableBundle b = PhoneGlobals.getInstance()
                 .getCarrierConfigForSubId(mPhone.getSubId());
-        if (b != null) {
-            return b.getBoolean(key);
-        } else {
-            // Return static default defined in CarrierConfigManager.
-            return CarrierConfigManager.getDefaultConfig().getBoolean(key);
+
+        if (b == null) {
+            b = PhoneGlobals.getInstance().getCarrierConfig();
         }
+
+        return b.getBoolean(key);
     }
 
 
