byte[] buffer = new byte[NTP_PACKET_SIZE];
DatagramPacket request = new DatagramPacket(buffer, buffer.length, address, NTP_PORT);
- // set mode = 3 (client) and version = 3
+ // set mode = 3 (client) and version = 3
// mode is in low 3 bits of first byte
// version is in bits 3-5 of first byte
buffer[0] = NTP_MODE_CLIENT | (NTP_VERSION << 3);
writeTimeStamp(buffer, TRANSMIT_TIME_OFFSET, requestTime);
socket.send(request);
-
+
// read the response
DatagramPacket response = new DatagramPacket(buffer, buffer.length);
socket.receive(response);
// = (transit + skew - transit + skew)/2
// = (2 * skew)/2 = skew
long clockOffset = ((receiveTime - originateTime) + (transmitTime - responseTime))/2;
- if (Config.LOGD) Log.d(TAG, "round trip: " + roundTripTime + " ms");
- if (Config.LOGD) Log.d(TAG, "clock offset: " + clockOffset + " ms");
+ // if (Config.LOGD) Log.d(TAG, "round trip: " + roundTripTime + " ms");
+ // if (Config.LOGD) Log.d(TAG, "clock offset: " + clockOffset + " ms");
// save our results - use the times on this side of the network latency
// (response rather than request time)
private static final String TESTING_ENABLED_PROPERTY = "persist.throttle.testing";
private static final String TAG = "ThrottleService";
- private static boolean DBG = true;
+ private static final boolean DBG = true;
+ private static final boolean VDBG = false;
private Handler mHandler;
private HandlerThread mThread;
long periodTx = mRecorder.getPeriodTx(0);
long total = periodRx + periodTx;
if (DBG) {
- Slog.d(TAG, "onPollAlarm - now =" + now + ", roaming =" + roaming +
+ Slog.d(TAG, "onPollAlarm - roaming =" + roaming +
", read =" + incRead + ", written =" + incWrite + ", new total =" + total);
}
mLastRead += incRead;
if (mNtpActive) {
long ntpAge = SystemClock.elapsedRealtime() - cachedNtpTimestamp;
if (ntpAge < MAX_NTP_CACHE_AGE) {
+ if (VDBG) Slog.v(TAG, "using cached time");
return cachedNtp + ntpAge;
}
}
if (DBG) Slog.d(TAG, "found Authoritative time - reseting alarm");
mHandler.obtainMessage(EVENT_RESET_ALARM).sendToTarget();
}
- if (DBG) Slog.d(TAG, "using Authoritative time: " + cachedNtp);
+ if (VDBG) Slog.v(TAG, "using Authoritative time: " + cachedNtp);
return cachedNtp;
}
}
long time = System.currentTimeMillis();
- if (DBG) Slog.d(TAG, "using User time: " + time);
+ if (VDBG) Slog.v(TAG, "using User time: " + time);
mNtpActive = false;
return time;
}
// TODO - how would we deal with a dual-IMSI device?
checkForSubscriberId();
boolean startNewPeriod = true;
- if (DBG) {
- Slog.d(TAG, "setting next period to " + start.getTimeInMillis() +
- " --until-- " + end.getTimeInMillis());
- }
+
// if we rolled back in time, toss out
// if we rolled foward, advance to the next
if (end.before(mPeriodStart)) {
if (DBG) {
- Slog.d(TAG, " old start was " + mPeriodStart.getTimeInMillis() + ", wiping");
+ Slog.d(TAG, "next period (" + start.getTimeInMillis() + "," +
+ end.getTimeInMillis() + ") - old start was " +
+ mPeriodStart.getTimeInMillis() + ", wiping");
}
synchronized (mParent) {
mPeriodRxData[mCurrentPeriod] = 0;
}
} else if(start.after(mPeriodEnd)) {
if (DBG) {
- Slog.d(TAG, " old end was " + mPeriodEnd.getTimeInMillis() + ", following");
+ Slog.d(TAG, "next period (" + start.getTimeInMillis() + "," +
+ end.getTimeInMillis() + ") - old end was " +
+ mPeriodEnd.getTimeInMillis() + ", following");
}
synchronized (mParent) {
++mCurrentPeriod;
}
} else {
startNewPeriod = false;
- if (DBG) Slog.d(TAG, " we fit - ammending to last period");
+ if (DBG) {
+ Slog.d(TAG, "next period (" + start.getTimeInMillis() + "," +
+ end.getTimeInMillis() + ") - we fit - ammending to last period");
+ }
}
setPeriodStart(start);
setPeriodEnd(end);
File dataFile;
if (mImsi == null) {
dataFile = useMRUFile(throttleDir);
- Slog.d(TAG, "imsi not available yet, using " + dataFile);
+ if (VDBG) Slog.v(TAG, "imsi not available yet, using " + dataFile);
} else {
String imsiHash = Integer.toString(mImsi.hashCode());
dataFile = new File(throttleDir, imsiHash);
mImsi = mTelephonyManager.getSubscriberId();
if (mImsi == null) return;
- Slog.d(TAG, "finally have imsi - retreiving data");
+ if (DBG) Slog.d(TAG, "finally have imsi - retreiving data");
retrieve();
}
File[] files = dir.listFiles();
if (files.length <= MAX_SIMS_SUPPORTED) return;
- Slog.d(TAG, "Too many data files");
+ if (DBG) Slog.d(TAG, "Too many data files");
do {
File oldest = null;
for (File f : files) {
}
}
if (oldest == null) return;
- Slog.d(TAG, " deleting " + oldest);
+ if (DBG) Slog.d(TAG, " deleting " + oldest);
oldest.delete();
files = dir.listFiles();
} while (files.length > MAX_SIMS_SUPPORTED);