From 1a61b586b59243dab6c70984ab4418451f7d78fa Mon Sep 17 00:00:00 2001 From: Naveen Kalla Date: Wed, 3 Mar 2010 18:54:36 -0800 Subject: [PATCH 1/3] Retry pending memory status update to modem when radio is ON. When radio is powered off / airplane mode, memory status updates are ignored by RIL. With this fix, pending memory status updates are sent again when radio is powered back on. --- .../internal/telephony/SMSDispatcher.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/SMSDispatcher.java b/telephony/java/com/android/internal/telephony/SMSDispatcher.java index 53c0bef055519..fc0aa065b0c36 100644 --- a/telephony/java/com/android/internal/telephony/SMSDispatcher.java +++ b/telephony/java/com/android/internal/telephony/SMSDispatcher.java @@ -109,6 +109,12 @@ public abstract class SMSDispatcher extends Handler { /** Stop the sending */ static final protected int EVENT_STOP_SENDING = 10; + /** Memory status reporting is acknowledged by RIL */ + static final protected int EVENT_REPORT_MEMORY_STATUS_DONE = 11; + + /** Radio is ON */ + static final protected int EVENT_RADIO_ON = 12; + protected Phone mPhone; protected Context mContext; protected ContentResolver mResolver; @@ -152,6 +158,7 @@ public abstract class SMSDispatcher extends Handler { private SmsMessageBase.SubmitPduBase mSubmitPduBase; protected boolean mStorageAvailable = true; + protected boolean mReportMemoryStatusPending = false; protected static int getNextConcatenatedRef() { sConcatenatedRef += 1; @@ -235,6 +242,7 @@ public abstract class SMSDispatcher extends Handler { mCm.setOnNewSMS(this, EVENT_NEW_SMS, null); mCm.setOnSmsStatus(this, EVENT_NEW_SMS_STATUS_REPORT, null); mCm.setOnIccSmsFull(this, EVENT_ICC_FULL, null); + mCm.registerForOn(this, EVENT_RADIO_ON, null); // Don't always start message ref at 0. sConcatenatedRef = new Random().nextInt(256); @@ -253,6 +261,7 @@ public abstract class SMSDispatcher extends Handler { mCm.unSetOnNewSMS(this); mCm.unSetOnSmsStatus(this); mCm.unSetOnIccSmsFull(this); + mCm.unregisterForOn(this); } protected void finalize() { @@ -370,6 +379,26 @@ public abstract class SMSDispatcher extends Handler { removeMessages(EVENT_ALERT_TIMEOUT, msg.obj); } break; + + case EVENT_REPORT_MEMORY_STATUS_DONE: + ar = (AsyncResult)msg.obj; + if (ar.exception != null) { + mReportMemoryStatusPending = true; + Log.v(TAG, "Memory status report to modem pending : mStorageAvailable = " + + mStorageAvailable); + } else { + mReportMemoryStatusPending = false; + } + break; + + case EVENT_RADIO_ON: + if (mReportMemoryStatusPending) { + Log.v(TAG, "Sending pending memory status report : mStorageAvailable = " + + mStorageAvailable); + mCm.reportSmsMemoryStatus(mStorageAvailable, + obtainMessage(EVENT_REPORT_MEMORY_STATUS_DONE)); + } + break; } } @@ -940,10 +969,10 @@ public abstract class SMSDispatcher extends Handler { public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_DEVICE_STORAGE_LOW)) { mStorageAvailable = false; - mCm.reportSmsMemoryStatus(false, null); + mCm.reportSmsMemoryStatus(false, obtainMessage(EVENT_REPORT_MEMORY_STATUS_DONE)); } else if (intent.getAction().equals(Intent.ACTION_DEVICE_STORAGE_OK)) { mStorageAvailable = true; - mCm.reportSmsMemoryStatus(true, null); + mCm.reportSmsMemoryStatus(true, obtainMessage(EVENT_REPORT_MEMORY_STATUS_DONE)); } else { // Assume the intent is one of the SMS receive intents that // was sent as an ordered broadcast. Check result and ACK. From 7f2087435edf475bc4e18c422a5baec7d7898d4c Mon Sep 17 00:00:00 2001 From: Josh Bartel Date: Thu, 25 Feb 2010 11:01:44 -0600 Subject: [PATCH 2/3] Rename functions which ought to be named *Locked() Several functions operate on variables to which access needs to be synchronized. However, it happens that the functions in question are only ever called from places which have already synchronized. Therefore, nothing is really wrong, but the functions ought to have 'Locked' appended to their names, to indicate that it is the caller's responsibility to synchronize before calling them. Change-Id: I44e7dc0dff6da9436677cb10908dce41ffeba195 --- .../server/am/ActivityManagerService.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 5f6356d97edb2..1359f663d1b83 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -3566,7 +3566,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (DEBUG_TASKS) Log.v(TAG, "Starting new activity " + r + " in new task " + r.task); newTask = true; - addRecentTask(r.task); + addRecentTaskLocked(r.task); } else if (sourceRecord != null) { if (!addingToTask && @@ -3855,7 +3855,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen } } - private final void addRecentTask(TaskRecord task) { + private final void addRecentTaskLocked(TaskRecord task) { // Remove any existing entries that are the same kind of task. int N = mRecentTasks.size(); for (int i=0; i list = mStickyBroadcasts.get(action); @@ -11616,10 +11616,10 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (actions != null) { while (actions.hasNext()) { String action = (String)actions.next(); - allSticky = getStickies(action, filter, allSticky); + allSticky = getStickiesLocked(action, filter, allSticky); } } else { - allSticky = getStickies(null, filter, allSticky); + allSticky = getStickiesLocked(null, filter, allSticky); } // The first sticky in the list is returned directly back to @@ -13357,7 +13357,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen /** * Returns true if things are idle enough to perform GCs. */ - private final boolean canGcNow() { + private final boolean canGcNowLocked() { return mParallelBroadcasts.size() == 0 && mOrderedBroadcasts.size() == 0 && (mSleeping || (mResumedActivity != null && @@ -13373,7 +13373,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen if (N <= 0) { return; } - if (canGcNow()) { + if (canGcNowLocked()) { while (mProcessesToGc.size() > 0) { ProcessRecord proc = mProcessesToGc.remove(0); if (proc.curRawAdj > VISIBLE_APP_ADJ || proc.reportLowMemory) { @@ -13401,7 +13401,7 @@ public final class ActivityManagerService extends ActivityManagerNative implemen * If all looks good, perform GCs on all processes waiting for them. */ final void performAppGcsIfAppropriateLocked() { - if (canGcNow()) { + if (canGcNowLocked()) { performAppGcsLocked(); return; } From 2ecce34f2f05447bed6d798a4fe906fed4cbd7d9 Mon Sep 17 00:00:00 2001 From: Josh Bartel Date: Thu, 25 Feb 2010 10:55:48 -0600 Subject: [PATCH 3/3] Synchronize access to *Locked() functions Several places were calling *Locked() functions without properly synchronizing. Change-Id: Ie39b6592da8bb5f4a5a1e738c45f228256116ec4 --- .../server/am/ActivityManagerService.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 1359f663d1b83..9e9552aec479b 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -4931,9 +4931,11 @@ public final class ActivityManagerService extends ActivityManagerNative implemen Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null)); intent.putExtra(Intent.EXTRA_UID, pkgUid); - broadcastIntentLocked(null, null, intent, - null, null, 0, null, null, null, - false, false, MY_PID, Process.SYSTEM_UID); + synchronized (this) { + broadcastIntentLocked(null, null, intent, + null, null, 0, null, null, null, + false, false, MY_PID, Process.SYSTEM_UID); + } } catch (RemoteException e) { } } finally { @@ -5668,7 +5670,9 @@ public final class ActivityManagerService extends ActivityManagerNative implemen ArrayList procs = new ArrayList(mProcessesOnHold); for (int ip=0; ip