Bug 717841 part 1 - Replace Date().getTime() calls with SystemClock.uptimeMillis or System.currentTimeMillis(). r=kats f=dougt a=dougt

This commit is contained in:
Chris Peterson 2012-01-13 11:08:39 -08:00
parent 091b07e6a9
commit 94df92ed70
7 changed files with 27 additions and 27 deletions

View File

@ -47,6 +47,7 @@ import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.provider.Browser;
import android.util.AttributeSet;
import android.util.Base64;
@ -622,12 +623,12 @@ public class AwesomeBarTabs extends TabHost {
mAllPagesCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
ContentResolver resolver = mContext.getContentResolver();
long start = new Date().getTime();
long start = SystemClock.uptimeMillis();
Cursor c = BrowserDB.filter(resolver, constraint, MAX_RESULTS);
c.getCount(); // ensure the query runs at least once
long end = new Date().getTime();
long end = SystemClock.uptimeMillis();
Log.i(LOGTAG, "Got cursor in " + (end - start) + "ms");
return c;

View File

@ -38,8 +38,6 @@
package org.mozilla.gecko;
import java.util.Date;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@ -156,7 +154,7 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
return false;
}
if (new Date().getTime() <= mTimeout) {
if (System.currentTimeMillis() <= mTimeout) {
return false;
}

View File

@ -231,7 +231,7 @@ abstract public class GeckoApp
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
return new String[0];
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - start of getPluginDirectories");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - start of getPluginDirectories");
ArrayList<String> directories = new ArrayList<String>();
PackageManager pm = this.mAppContext.getPackageManager();
@ -357,7 +357,7 @@ abstract public class GeckoApp
}
String [] result = directories.toArray(new String[directories.size()]);
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - end of getPluginDirectories");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - end of getPluginDirectories");
return result;
}
@ -1396,7 +1396,7 @@ abstract public class GeckoApp
System.loadLibrary("mozglue");
mMainHandler = new Handler();
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onCreate");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
if (savedInstanceState != null) {
mLastUri = savedInstanceState.getString(SAVED_STATE_URI);
mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
@ -1512,7 +1512,7 @@ abstract public class GeckoApp
mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - UI almost up");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");
if (!sTryCatchAttached) {
sTryCatchAttached = true;
@ -1580,8 +1580,7 @@ abstract public class GeckoApp
GeckoAppShell.getHandler().postDelayed(new Runnable() {
public void run() {
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - pre checkLaunchState");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");
/*
XXXX see bug 635342
@ -1596,10 +1595,10 @@ abstract public class GeckoApp
return;
}
// it would be good only to do this if MOZ_UPDATER was defined
long startTime = new Date().getTime();
// it would be good only to do this if MOZ_UPDATER was defined
long startTime = SystemClock.uptimeMillis();
checkAndLaunchUpdate();
Log.w(LOGTAG, "checking for an update took " + (new Date().getTime() - startTime) + "ms");
Log.w(LOGTAG, "checking for an update took " + (SystemClock.uptimeMillis() - startTime) + "ms");
checkMigrateProfile();
}
}, 50);
@ -1639,7 +1638,7 @@ abstract public class GeckoApp
@Override
protected void onNewIntent(Intent intent) {
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onNewIntent");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onNewIntent");
if (checkLaunchState(LaunchState.GeckoExiting)) {
// We're exiting and shouldn't try to do anything else just incase
@ -1759,7 +1758,7 @@ abstract public class GeckoApp
@Override
public void onStart()
{
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onStart");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onStart");
Log.i(LOGTAG, "start");
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_START));

View File

@ -47,6 +47,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.SystemClock;
public class GeckoBatteryManager
extends BroadcastReceiver
@ -60,7 +61,7 @@ public class GeckoBatteryManager
private final static double kDefaultRemainingTime = -1.0;
private final static double kUnknownRemainingTime = -1.0;
private static Date sLastLevelChange = new Date(0);
private static long sLastLevelChange = 0;
private static boolean sNotificationsEnabled = false;
private static double sLevel = kDefaultLevel;
private static boolean sCharging = kDefaultCharging;
@ -91,7 +92,7 @@ public class GeckoBatteryManager
sRemainingTime = kUnknownRemainingTime;
// The new remaining time is going to take some time to show up but
// it's the best way to show a not too wrong value.
sLastLevelChange = new Date(0);
sLastLevelChange = 0;
}
// We need two doubles because sLevel is a double.
@ -108,9 +109,10 @@ public class GeckoBatteryManager
sRemainingTime = 0.0;
} else if (sLevel != previousLevel) {
// Estimate remaining time.
if (sLastLevelChange.getTime() != 0) {
Date currentTime = new Date();
long dt = (currentTime.getTime() - sLastLevelChange.getTime()) / 1000;
if (sLastLevelChange != 0) {
// Use elapsedRealtime() because we want to track time across device sleeps.
long currentTime = SystemClock.elapsedRealtime();
long dt = (currentTime - sLastLevelChange) / 1000;
double dLevel = sLevel - previousLevel;
if (sCharging) {
@ -132,7 +134,7 @@ public class GeckoBatteryManager
sLastLevelChange = currentTime;
} else {
// That's the first time we got an update, we can't do anything.
sLastLevelChange = new Date();
sLastLevelChange = SystemClock.elapsedRealtime();
}
}
} else {

View File

@ -40,8 +40,10 @@ package org.mozilla.gecko;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.os.SystemClock;
import android.util.Log;
import android.widget.AbsoluteLayout;
import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintWriter;
@ -92,7 +94,7 @@ public class GeckoThread extends Thread {
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - runGecko");
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - runGecko");
// and then fire us up
try {

View File

@ -38,7 +38,6 @@
package org.mozilla.gecko.db;
import java.io.ByteArrayOutputStream;
import java.util.Date;
import android.content.ContentResolver;
import android.content.ContentValues;
@ -82,7 +81,7 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
// was accessed with a site accessed today getting 120 and a site accessed 119 or more
// days ago getting 1
Browser.BookmarkColumns.VISITS + " * MAX(1, (" +
Browser.BookmarkColumns.DATE + " - " + new Date().getTime() + ") / 86400000 + 120) DESC LIMIT " + limit);
Browser.BookmarkColumns.DATE + " - " + System.currentTimeMillis() + ") / 86400000 + 120) DESC LIMIT " + limit);
return new AndroidDBCursor(c);
}

View File

@ -38,7 +38,6 @@
package org.mozilla.gecko.db;
import java.io.ByteArrayOutputStream;
import java.util.Date;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.History;
@ -96,7 +95,7 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
// was accessed with a site accessed today getting 120 and a site accessed 119 or more
// days ago getting 1
History.VISITS + " * MAX(1, (" +
History.DATE_LAST_VISITED + " - " + new Date().getTime() + ") / 86400000 + 120) DESC");
History.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000 + 120) DESC");
return new LocalDBCursor(c);
}