From 7a043b351b43e963605afef6ab76a52ae3a9270e Mon Sep 17 00:00:00 2001 From: Tammo Spalink Date: Tue, 25 Aug 2009 16:15:50 +0800 Subject: [PATCH] Make Phone.updateServiceLocation acquire a one-shot wake lock. Phone.updateServiceLocation() is the internal routine triggered by external calls to CellLocation.requestLocationUpdate(). addresses bug http://b/issue?id=1724246 Change-Id: Id3d5cab1a77df12d3e94373a58ae94688a8630c6 --- .../com/android/internal/telephony/Phone.java | 12 ++----- .../internal/telephony/PhoneProxy.java | 4 +-- .../telephony/ServiceStateTracker.java | 35 +++++++++++++++++-- .../internal/telephony/cdma/CDMAPhone.java | 12 +++---- .../cdma/CdmaServiceStateTracker.java | 28 ++++----------- .../internal/telephony/gsm/GSMPhone.java | 4 +-- .../telephony/gsm/GsmServiceStateTracker.java | 23 ++++-------- 7 files changed, 58 insertions(+), 60 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/Phone.java b/telephony/java/com/android/internal/telephony/Phone.java index e818175e173b6..5203d3f5a98e5 100644 --- a/telephony/java/com/android/internal/telephony/Phone.java +++ b/telephony/java/com/android/internal/telephony/Phone.java @@ -1189,17 +1189,9 @@ public interface Phone { List getCurrentDataConnectionList (); /** - * Udpate LAC and CID in service state for currnet GSM netowrk registration - * - * If get different LAC and/or CID, notifyServiceState will be sent - * - * @param - * On failure, - * (((AsyncResult)response.obj).result) == null and - * (((AsyncResult)response.obj).exception) being an instance of - * com.android.internal.telephony.gsm.CommandException + * Update the ServiceState CellLocation for current network registration. */ - void updateServiceLocation(Message response); + void updateServiceLocation(); /** * Enable location update notifications. diff --git a/telephony/java/com/android/internal/telephony/PhoneProxy.java b/telephony/java/com/android/internal/telephony/PhoneProxy.java index 86832784c9853..711a48c8050f6 100644 --- a/telephony/java/com/android/internal/telephony/PhoneProxy.java +++ b/telephony/java/com/android/internal/telephony/PhoneProxy.java @@ -566,8 +566,8 @@ public class PhoneProxy extends Handler implements Phone { return mActivePhone.getCurrentDataConnectionList(); } - public void updateServiceLocation(Message response) { - mActivePhone.updateServiceLocation(response); + public void updateServiceLocation() { + mActivePhone.updateServiceLocation(); } public void enableLocationUpdates() { diff --git a/telephony/java/com/android/internal/telephony/ServiceStateTracker.java b/telephony/java/com/android/internal/telephony/ServiceStateTracker.java index cc134509b217e..6892998479f82 100644 --- a/telephony/java/com/android/internal/telephony/ServiceStateTracker.java +++ b/telephony/java/com/android/internal/telephony/ServiceStateTracker.java @@ -226,12 +226,43 @@ public abstract class ServiceStateTracker extends Handler { setPowerStateToDesired(); } - public void enableLocationUpdates() { + /** + * These two flags manage the behavior of the cell lock -- the + * lock should be held if either flag is true. The intention is + * to allow temporary aquisition of the lock to get a single + * update. Such a lock grab and release can thus be made to not + * interfere with more permanent lock holds -- in other words, the + * lock will only be released if both flags are false, and so + * releases by temporary users will only affect the lock state if + * there is no continuous user. + */ + private boolean mWantContinuousLocationUpdates; + private boolean mWantSingleLocationUpdate; + + public void enableSingleLocationUpdate() { + if (mWantSingleLocationUpdate || mWantContinuousLocationUpdates) return; + mWantSingleLocationUpdate = true; cm.setLocationUpdates(true, obtainMessage(EVENT_LOCATION_UPDATES_ENABLED)); } + public void enableLocationUpdates() { + if (mWantSingleLocationUpdate || mWantContinuousLocationUpdates) return; + mWantContinuousLocationUpdates = true; + cm.setLocationUpdates(true, obtainMessage(EVENT_LOCATION_UPDATES_ENABLED)); + } + + protected void disableSingleLocationUpdate() { + mWantSingleLocationUpdate = false; + if (!mWantSingleLocationUpdate && !mWantContinuousLocationUpdates) { + cm.setLocationUpdates(false, null); + } + } + public void disableLocationUpdates() { - cm.setLocationUpdates(false, null); + mWantContinuousLocationUpdates = false; + if (!mWantSingleLocationUpdate && !mWantContinuousLocationUpdates) { + cm.setLocationUpdates(false, null); + } } public abstract void handleMessage(Message msg); diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java index ff06bc0de4bc5..dfc488948bf98 100755 --- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java +++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java @@ -500,8 +500,8 @@ public class CDMAPhone extends PhoneBase { Log.e(LOG_TAG, "method setCallWaiting is NOT supported in CDMA!"); } - public void updateServiceLocation(Message response) { - mSST.getLacAndCid(response); + public void updateServiceLocation() { + mSST.enableSingleLocationUpdate(); } public void setDataRoamingEnabled(boolean enable) { @@ -661,6 +661,10 @@ public class CDMAPhone extends PhoneBase { mSST.enableLocationUpdates(); } + public void disableLocationUpdates() { + mSST.disableLocationUpdates(); + } + /** * @deprecated */ @@ -741,10 +745,6 @@ public class CDMAPhone extends PhoneBase { } } - public void disableLocationUpdates() { - mSST.disableLocationUpdates(); - } - public boolean getIccRecordsLoaded() { return mRuimRecords.getRecordsLoaded(); } diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java index 46e360b15965d..9ac78eb1ba0b8 100644 --- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java +++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java @@ -279,12 +279,6 @@ final class CdmaServiceStateTracker extends ServiceStateTracker { cdmaForSubscriptionInfoReadyRegistrants.remove(h); } - public void - getLacAndCid(Message onComplete) { - cm.getRegistrationState(obtainMessage( - EVENT_GET_LOC_DONE_CDMA, onComplete)); - } - @Override public void handleMessage (Message msg) { AsyncResult ar; @@ -377,22 +371,14 @@ final class CdmaServiceStateTracker extends ServiceStateTracker { } } - // Only update if cell location really changed. - if (cellLoc.getBaseStationId() != baseStationData[0] - || cellLoc.getBaseStationLatitude() != baseStationData[1] - || cellLoc.getBaseStationLongitude() != baseStationData[2]) { - cellLoc.setCellLocationData(baseStationData[0], - baseStationData[1], - baseStationData[2]); - phone.notifyLocationChanged(); - } + cellLoc.setCellLocationData(baseStationData[0], + baseStationData[1], baseStationData[2]); + phone.notifyLocationChanged(); } - if (ar.userObj != null) { - AsyncResult.forMessage(((Message) ar.userObj)).exception - = ar.exception; - ((Message) ar.userObj).sendToTarget(); - } + // Release any temporary cell lock, which could have been + // aquired to allow a single-shot location update. + disableSingleLocationUpdate(); break; case EVENT_POLL_STATE_REGISTRATION_CDMA: @@ -487,7 +473,7 @@ final class CdmaServiceStateTracker extends ServiceStateTracker { ar = (AsyncResult) msg.obj; if (ar.exception == null) { - getLacAndCid(null); + cm.getRegistrationState(obtainMessage(EVENT_GET_LOC_DONE_CDMA, null)); } break; diff --git a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java index ac7331ecd1efd..2fc2e13414d30 100755 --- a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java +++ b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java @@ -1099,8 +1099,8 @@ public class GSMPhone extends PhoneBase { return mDataConnection.getAllDataConnections(); } - public void updateServiceLocation(Message response) { - mSST.getLacAndCid(response); + public void updateServiceLocation() { + mSST.enableSingleLocationUpdate(); } public void enableLocationUpdates() { diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java index 65463e5ee6f73..003899bd3f6fe 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java @@ -314,11 +314,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker { return mDataRoaming; } - public void getLacAndCid(Message onComplete) { - cm.getRegistrationState(obtainMessage( - EVENT_GET_LOC_DONE, onComplete)); - } - public void handleMessage (Message msg) { AsyncResult ar; int[] ints; @@ -391,19 +386,13 @@ final class GsmServiceStateTracker extends ServiceStateTracker { Log.w(LOG_TAG, "error parsing location: " + ex); } } - - // only update if lac or cid changed - if (cellLoc.getCid() != cid || cellLoc.getLac() != lac) { - cellLoc.setLacAndCid(lac, cid); - phone.notifyLocationChanged(); - } + cellLoc.setLacAndCid(lac, cid); + phone.notifyLocationChanged(); } - if (ar.userObj != null) { - AsyncResult.forMessage(((Message) ar.userObj)).exception - = ar.exception; - ((Message) ar.userObj).sendToTarget(); - } + // Release any temporary cell lock, which could have been + // aquired to allow a single-shot location update. + disableSingleLocationUpdate(); break; case EVENT_POLL_STATE_REGISTRATION: @@ -451,7 +440,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker { ar = (AsyncResult) msg.obj; if (ar.exception == null) { - getLacAndCid(null); + cm.getRegistrationState(obtainMessage(EVENT_GET_LOC_DONE, null)); } break;