diff options
author | Nazanin Bakhshi <nazaninb@google.com> | 2019-04-29 17:26:52 -0700 |
---|---|---|
committer | Nazanin Bakhshi <nazaninb@google.com> | 2019-05-03 16:54:46 -0700 |
commit | 61cebb94f76ff05a950032f5963da5113796d2d9 (patch) | |
tree | 3ce5ff968faeaa207b22ca73f4d1d4dc483b019e | |
parent | 7e3ab35728e02d14fcb3eda33a316fd1c268e6b4 (diff) | |
download | telephony-61cebb94f76ff05a950032f5963da5113796d2d9.tar.gz |
update PhoneCfgMgr and PhoneIfcMgr to handle enableModem more accurately
Bug: 130913083
Test: manual
Change-Id: I8e8e8745a71a7cf670de4df5e94cfcfb1483876c
(cherry picked from commit 50e9071147a18f50f0c67212620c14428fe3c25c)
-rw-r--r-- | src/java/com/android/internal/telephony/PhoneConfigurationManager.java | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/java/com/android/internal/telephony/PhoneConfigurationManager.java b/src/java/com/android/internal/telephony/PhoneConfigurationManager.java index d73acd3b38..2771f25f04 100644 --- a/src/java/com/android/internal/telephony/PhoneConfigurationManager.java +++ b/src/java/com/android/internal/telephony/PhoneConfigurationManager.java @@ -30,6 +30,7 @@ import android.util.Log; import java.util.HashMap; import java.util.Map; +import java.util.NoSuchElementException; /** * This class manages phone's configuration which defines the potential capability (static) of the @@ -156,7 +157,7 @@ public class PhoneConfigurationManager { int phoneId = msg.arg1; boolean enabled = (boolean) ar.result; //update the cache each time getModemStatus is requested - mPhoneStatusMap.put(phoneId, enabled); + addToPhoneStatusCache(phoneId, enabled); } else { log(msg.what + " failure. Not updating modem status." + ar.exception); } @@ -186,11 +187,12 @@ public class PhoneConfigurationManager { return; } phone.mCi.enableModem(enable, result); - updatePhoneStatus(phone); } /** * Get phone status (enabled/disabled) + * first query cache, if the status is not in cache, + * add it to cache and return a default value true (non-blocking). * * @param phone which phone to operate on */ @@ -203,24 +205,54 @@ public class PhoneConfigurationManager { int phoneId = phone.getPhoneId(); //use cache if the status has already been updated/queried - if (mPhoneStatusMap.containsKey(phoneId)) { - return mPhoneStatusMap.get(phoneId); - } else { + try { + return getPhoneStatusFromCache(phoneId); + } catch (NoSuchElementException ex) { updatePhoneStatus(phone); - // Return true if modem status is not in cache. For most of case, modem status + // Return true if modem status cannot be retrieved. For most cases, modem status // is on. And for older version modems, GET_MODEM_STATUS and disable modem are not // supported. Modem is always on. + //TODO: this should be fixed in R to support a third status UNKNOWN b/131631629 return true; } } /** + * Get phone status (enabled/disabled) directly from modem, and use a result Message object + * Note: the caller of this method is reponsible to call this in a blocking fashion as well + * as read the results and handle the error case. + * (In order to be consistent, in error case, we should return default value of true; refer + * to #getPhoneStatus method) + * + * @param phone which phone to operate on + * @param result message that will be updated with result + */ + public void getPhoneStatusFromModem(Phone phone, Message result) { + if (phone == null) { + log("getPhoneStatus failed phone is null"); + } + phone.mCi.getModemStatus(result); + } + + /** + * return modem status from cache, NoSuchElementException if phoneId not in cache + * @param phoneId + */ + public boolean getPhoneStatusFromCache(int phoneId) throws NoSuchElementException { + if (mPhoneStatusMap.containsKey(phoneId)) { + return mPhoneStatusMap.get(phoneId); + } else { + throw new NoSuchElementException("phoneId not found: " + phoneId); + } + } + + /** * method to call RIL getModemStatus */ private void updatePhoneStatus(Phone phone) { - Message callback = Message.obtain( + Message result = Message.obtain( mHandler, EVENT_GET_MODEM_STATUS_DONE, phone.getPhoneId(), 0 /**dummy arg*/); - phone.mCi.getModemStatus(callback); + phone.mCi.getModemStatus(result); } /** |