diff --git a/clients/android/src/org/camlistore/CamliActivity.java b/clients/android/src/org/camlistore/CamliActivity.java index 2730b952c..d6216206f 100644 --- a/clients/android/src/org/camlistore/CamliActivity.java +++ b/clients/android/src/org/camlistore/CamliActivity.java @@ -205,14 +205,15 @@ public class CamliActivity extends Activity { public void setUploadStatsText(final String text) throws RemoteException { // We were getting these status updates so quickly that the calls to TextView.setText // were consuming all CPU on the main thread and it was stalling the main thread - // for seconds. Ridiculous. So instead, only update this every 5 milliseconds, - // otherwise wait for the looper to be idle to update it. + // for seconds, sometimes even triggering device freezes. Ridiculous. So instead, + // only update this every 30 milliseconds, otherwise wait for the looper to be idle + // to update it. mHandler.post(new Runnable() { @Override public void run() { mStatusTextWant = text; long now = System.currentTimeMillis(); - if (mLastStatusUpdate < now - 5) { + if (mLastStatusUpdate < now - 30) { mStatusTextCurrent = mStatusTextWant; textStats.setText(mStatusTextWant); mLastStatusUpdate = System.currentTimeMillis(); diff --git a/clients/android/src/org/camlistore/UploadService.java b/clients/android/src/org/camlistore/UploadService.java index d36d3d22e..012e55730 100644 --- a/clients/android/src/org/camlistore/UploadService.java +++ b/clients/android/src/org/camlistore/UploadService.java @@ -71,6 +71,7 @@ public class UploadService extends Service { // thread exits private Notification.Builder mNotificationBuilder; // null until upload is // started/resumed + private int mLastNotificationProgress = 0; // last computed value of the uploaded bytes, to avoid excessive notification updates private final Map mFileBytesRemain = new HashMap(); private final LinkedList mQueueList = new LinkedList(); private final Map mStatValue = new TreeMap(); @@ -410,11 +411,16 @@ public class UploadService extends Service { Notification notification = null; synchronized (this) { if (mNotificationBuilder != null) { - int kBUploaded = (int)(mBytesUploaded / 1024L); - int kBTotal = (int)(mBytesTotal / 1024L); + int progress = (int)(100 * (double)mBytesUploaded/(double)mBytesTotal); - mNotificationBuilder.setProgress(kBTotal, kBUploaded, false); - notification = mNotificationBuilder.build(); + // Only build new notification when progress value actually changes. Some + // devices slow down and finally freeze completely when updating too often. + if (mLastNotificationProgress != progress) { + mLastNotificationProgress = progress; + + mNotificationBuilder.setProgress(100, progress, false); + notification = mNotificationBuilder.build(); + } } try { mCallback.setByteStatus(mBytesUploaded, mBytesInFlight, mBytesTotal); @@ -702,6 +708,7 @@ public class UploadService extends Service { .setContentText("Camlistore uploader running") .setSmallIcon(android.R.drawable.stat_sys_upload); mNotificationManager.notify(NOTIFY_ID_UPLOADING, mNotificationBuilder.build()); + mLastNotificationProgress = -1; mUploading = true; mUploadThread = new UploadThread(UploadService.this, hp, mPrefs.trustedCert(), mPrefs.username(), mPrefs.password());