下面列出了怎么用android.os.SystemClock的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void run() {
while (!isStopRecord) {
byte[] buffer = new byte[bufferSize];
int readRecord = audioRecord.read(buffer, 0, bufferSize);
if (readRecord > 0) {
if (captureListener != null)
captureListener.onCaptureListener(buffer,readRecord);
if (isDebug) {
Log.d(TAG, "音频采集数据源 -- ".concat(String.valueOf(readRecord)).concat(" -- bytes"));
}
} else {
if (isDebug)
Log.d(TAG, "录音采集异常");
}
//延迟写入 SystemClock -- Android专用
SystemClock.sleep(10);
}
}
@Override
public void fetch(final OkHttpNetworkFetcher.OkHttpNetworkFetchState fetchState, final NetworkFetcher.Callback callback) {
fetchState.submitTime = SystemClock.elapsedRealtime();
final Uri uri = fetchState.getUri();
Map<String, String> requestHeaders = null;
if (fetchState.getContext().getImageRequest() instanceof ReactNetworkImageRequest) {
ReactNetworkImageRequest networkImageRequest = (ReactNetworkImageRequest)
fetchState.getContext().getImageRequest();
requestHeaders = getHeaders(networkImageRequest.getHeaders());
}
if (requestHeaders == null) {
requestHeaders = Collections.emptyMap();
}
final Request request = new Request.Builder()
.cacheControl(new CacheControl.Builder().noStore().build())
.url(uri.toString())
.headers(Headers.of(requestHeaders))
.get()
.build();
fetchWithRequest(fetchState, callback, request);
}
/**
* Start a fake drag of the pager.
*
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
*
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
@Override
public void run() {
long curTime = SystemClock.uptimeMillis();
float progress = Math.min(1f, (float)(curTime - mStartTime) / mTransformAnimationDuration);
float value = mInterpolator.getInterpolation(progress);
mThumbFillPercent = mAlwaysFillThumb ? 1 : ((mFillPercent - mStartFillPercent) * value + mStartFillPercent);
if(progress == 1f)
stopAnimation();
if(mRunning) {
if(getHandler() != null)
getHandler().postAtTime(this, SystemClock.uptimeMillis() + ViewUtil.FRAME_DURATION);
else
stopAnimation();
}
invalidate();
}
private void startRecording() {
disableScreenRotation((Activity)getContext());
setCancelable(false);
setupRecorder();
recorder.start();
toggleRecording.setOnClickListener(v -> stopRecording());
toggleRecording.setBackgroundResource(R.drawable.record_in_progress);
instruction.setText(Localization.get("during.recording"));
recordingProgress.setVisibility(View.VISIBLE);
recordingDuration.setVisibility(View.VISIBLE);
recordingDuration.setBase(SystemClock.elapsedRealtime());
recordingDuration.start();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
void dispatchOnCancelled(LoadTask task, D data) {
onCanceled(data);
if (mCancellingTask == task) {
if (DEBUG) Log.v(TAG, "Cancelled task is now canceled!");
if(Utils.hasJellyBeanMR2()){
rollbackContentChanged();
}
mLastLoadCompleteTime = SystemClock.uptimeMillis();
mCancellingTask = null;
if (DEBUG) Log.v(TAG, "Delivering cancellation");
if(Utils.hasJellyBeanMR2()){
deliverCancellation();
}
executePendingTask();
}
}
@Override
protected AppiumResponse safeHandle(IHttpRequest request) {
final KeyCodeModel model = toModel(request, KeyCodeModel.class);
final int keyCode = model.keycode;
int metaState = model.metastate == null ? 0 : model.metastate;
int flags = model.flags == null ? 0 : model.flags;
final long downTime = SystemClock.uptimeMillis();
final InteractionController interactionController = UiAutomatorBridge.getInstance().getInteractionController();
boolean isSuccessful = interactionController.injectEventSync(new KeyEvent(downTime, downTime,
KeyEvent.ACTION_DOWN, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD,
0, flags));
// https://android.googlesource.com/platform/frameworks/base.git/+/9d83b4783c33f1fafc43f367503e129e5a5047fa%5E%21/#F0
isSuccessful &= interactionController.injectEventSync(new KeyEvent(downTime, SystemClock.uptimeMillis(),
KeyEvent.ACTION_DOWN, keyCode, 1, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD,
0, flags | KeyEvent.FLAG_LONG_PRESS));
isSuccessful &= interactionController.injectEventSync(new KeyEvent(downTime, SystemClock.uptimeMillis(),
KeyEvent.ACTION_UP, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD,
0, flags));
if (!isSuccessful) {
throw new InvalidElementStateException("Cannot inject long press event for key code " + keyCode);
}
return new AppiumResponse(getSessionId(request));
}
/**
* Sets the frame data received from the camera. This adds the previous unused frame buffer
* (if present) back to the camera, and keeps a pending reference to the frame data for
* future use.
*/
void setNextFrame(byte[] data, Camera camera) {
synchronized (mLock) {
if (mPendingFrameData != null) {
camera.addCallbackBuffer(mPendingFrameData.array());
mPendingFrameData = null;
}
if (!mBytesToByteBuffer.containsKey(data)) {
Log.d(TAG,
"Skipping frame. Could not find ByteBuffer associated with the image " +
"data from the camera.");
return;
}
// Timestamp and frame ID are maintained here, which will give downstream code some
// idea of the timing of frames received and when frames were dropped along the way.
mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis;
mPendingFrameId++;
mPendingFrameData = mBytesToByteBuffer.get(data);
// Notify the processor thread if it is waiting on the next frame (see below).
mLock.notifyAll();
}
}
/**
* Copy infos from pjsua call info object to SipCallSession object
*
* @param session the session to copy info to (output)
* @param pjCallInfo the call info from pjsip
* @param service PjSipService Sip service to retrieve pjsip accounts infos
*/
private static void updateSession(SipCallSessionImpl session, pjsua_call_info pjCallInfo,
Context context) {
// Should be unecessary cause we usually copy infos from a valid
session.setCallId(pjCallInfo.getId());
// Nothing to think about here cause we have a
// bijection between int / state
session.setCallState(pjCallInfo.getState().swigValue());
session.setMediaStatus(pjCallInfo.getMedia_status().swigValue());
session.setRemoteContact(PjSipService.pjStrToString(pjCallInfo.getRemote_info()));
session.setConfPort(pjCallInfo.getConf_slot());
// Try to retrieve sip account related to this call
int pjAccId = pjCallInfo.getAcc_id();
session.setAccId(PjSipService.getAccountIdForPjsipId(context, pjAccId));
pj_time_val duration = pjCallInfo.getConnect_duration();
session.setConnectStart(SystemClock.elapsedRealtime() - duration.getSec() * 1000
- duration.getMsec());
}
public boolean startAnimation(int radius) {
if(mThumbCurrentRadius == radius)
return false;
mRadius = radius;
if(getHandler() != null){
resetAnimation();
mRunning = true;
getHandler().postAtTime(this, SystemClock.uptimeMillis() + ViewUtil.FRAME_DURATION);
invalidate();
return true;
}
else {
mThumbCurrentRadius = mRadius;
invalidate();
return false;
}
}
public byte[] poll(int timeout_ms) {
if (isLogEnabled())
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
+ " mDataQueue size is " + mDataQueue.size());
if (mDataQueue.isEmpty())
try {
// block until timeout or data available.
// returns null if timeout.
byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS);
if (dataFromQueue != null) {
if (isLogEnabled())
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
+ SystemClock.uptimeMillis());
} else {
if (isLogEnabled())
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
}
return dataFromQueue;
} catch (InterruptedException e) {
LOG.error("poll: Interrupted waiting for data");
}
return null;
}
@Override
public void onPageLoadStarted(Tab tab, String url) {
if (mCurrentState == STATE_WAITING_LOAD_START) {
mPageLoadStartedTimestamp = SystemClock.elapsedRealtime();
mCurrentState = STATE_WAITING_LOAD_FINISH;
} else if (mCurrentState == STATE_WAITING_LOAD_FINISH) {
if (mCustomTabsConnection != null) {
mCustomTabsConnection.notifyNavigationEvent(
mSession, CustomTabsCallback.NAVIGATION_ABORTED);
mCustomTabsConnection.sendNavigationInfo(
mSession, tab.getUrl(), tab.getTitle(), null);
}
mPageLoadStartedTimestamp = SystemClock.elapsedRealtime();
}
if (mCustomTabsConnection != null) {
mCustomTabsConnection.setSendNavigationInfoForSession(mSession, false);
mCustomTabsConnection.notifyNavigationEvent(
mSession, CustomTabsCallback.NAVIGATION_STARTED);
mScreenshotTakenForCurrentNavigation = false;
}
}
/**
* Gets the proper view to use for a screenshot.
*/
private View getScreenshotView() {
View decorView = viewFetcher.getRecentDecorView(viewFetcher.getWindowDecorViews());
final long endTime = SystemClock.uptimeMillis() + Timeout.getSmallTimeout();
while (decorView == null) {
final boolean timedOut = SystemClock.uptimeMillis() > endTime;
if (timedOut){
return null;
}
sleeper.sleepMini();
decorView = viewFetcher.getRecentDecorView(viewFetcher.getWindowDecorViews());
}
wrapAllGLViews(decorView);
return decorView;
}
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.contains(ALARM_ALERT)) {
// Hide the keyguard
mActive = false;
mAlarmingTimestamp = SystemClock.elapsedRealtime();
requestInactive();
} else if (action.contains(ALARM_DISMISS)
|| action.contains(ALARM_SNOOZE)
|| action.contains(ALARM_DONE)) {
// Show the keyguard
mActive = true;
requestActive();
} else if (mActive) {
// Get mad
Log.w(TAG, "Received an unknown intent=" + intent.getAction()
+ " re-enabling the switch.");
// Show the keyguard
mActive = true;
requestActive();
}
}
@Override
public void doWork() {
final long invalidationDelay = mGifDrawable.mNativeInfoHandle.renderFrame(mGifDrawable.mBuffer);
if (invalidationDelay >= 0) {
mGifDrawable.mNextFrameRenderTime = SystemClock.uptimeMillis() + invalidationDelay;
if (mGifDrawable.isVisible()) {
if (mGifDrawable.mIsRunning && !mGifDrawable.mIsRenderingTriggeredOnDraw) {
mGifDrawable.mExecutor.remove(this);
mGifDrawable.mSchedule = mGifDrawable.mExecutor.schedule(this, invalidationDelay, TimeUnit.MILLISECONDS);
}
}
if (!mGifDrawable.mListeners.isEmpty() && mGifDrawable.getCurrentFrameIndex() == mGifDrawable.mNativeInfoHandle.frameCount - 1) {
mGifDrawable.scheduleSelf(mNotifyListenersTask, mGifDrawable.mNextFrameRenderTime);
}
} else {
mGifDrawable.mNextFrameRenderTime = Long.MIN_VALUE;
mGifDrawable.mIsRunning = false;
}
if (mGifDrawable.isVisible() && !mGifDrawable.mInvalidationHandler.hasMessages(0)) {
mGifDrawable.mInvalidationHandler.sendEmptyMessageAtTime(0, 0);
}
}
/**
* Start a fake drag of the pager.
*
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
*
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
/**
* @return the public downloads directory.
*/
@SuppressWarnings("unused")
@CalledByNative
private static String getDownloadsDirectory() {
// Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615
StrictModeContext unused = null;
try {
unused = StrictModeContext.allowDiskReads();
long time = SystemClock.elapsedRealtime();
String downloadsPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.getPath();
RecordHistogram.recordTimesHistogram("Android.StrictMode.DownloadsDir",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
return downloadsPath;
} finally {
if (unused != null) {
try {
unused.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/**
* Start a fake drag of the pager.
*
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
*
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
public boolean sendMotionEvent(int inputSource, int action, float x, float y) {
if (mInputManager == null || mInjectInputEventMethod == null) {
return false;
}
try {
long when = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(when, when, action, x, y, 1.0f, 1.0f,
0, 1.0f, 1.0f, 0, 0);
event.setSource(inputSource);
mInjectInputEventMethod.invoke(mInputManager, event, 0);
event.recycle();
return true;
} catch (Exception e) {
HJLog.e(e);
}
return false;
}
/**
* Start a fake drag of the pager.
* <p>
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
* <p>
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionY = mLastMotionY = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append('[');
for (int i = 0; i < mCount; i++) {
final long next = i + 1 < mCount ? getTime(i + 1) : SystemClock.uptimeMillis();
if (i != 0) {
buf.append(", ");
}
buf.append(getLux(i));
buf.append(" / ");
buf.append(next - getTime(i));
buf.append("ms");
}
buf.append(']');
return buf.toString();
}
/**
* Waits for a web element.
*
* @param by the By object. Examples are By.id("id") and By.name("name")
* @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
* @param timeout the the amount of time in milliseconds to wait
* @param scroll {@code true} if scrolling should be performed
*/
public WebElement waitForWebElement(final By by, int minimumNumberOfMatches, int timeout, boolean scroll){
final long endTime = SystemClock.uptimeMillis() + timeout;
while (true) {
final boolean timedOut = SystemClock.uptimeMillis() > endTime;
if (timedOut){
searcher.logMatchesFound(by.getValue());
return null;
}
sleeper.sleep();
WebElement webElementToReturn = searcher.searchForWebElement(by, minimumNumberOfMatches);
if(webElementToReturn != null)
return webElementToReturn;
if(scroll) {
scroller.scrollDown();
}
}
}
/**
* Add the idle handler which will run deferred startup tasks in sequence when idle. This can
* be called multiple times by different activities to schedule their own deferred startup
* tasks.
*/
public void queueDeferredTasksOnIdleHandler() {
mMaxTaskDuration = 0;
mDeferredStartupDuration = 0;
Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
@Override
public boolean queueIdle() {
Runnable currentTask = mDeferredTasks.poll();
if (currentTask == null) {
if (mDeferredStartupInitializedForApp) {
mDeferredStartupCompletedForApp = true;
recordDeferredStartupStats();
}
return false;
}
long startTime = SystemClock.uptimeMillis();
currentTask.run();
long timeTaken = SystemClock.uptimeMillis() - startTime;
mMaxTaskDuration = Math.max(mMaxTaskDuration, timeTaken);
mDeferredStartupDuration += timeTaken;
return true;
}
});
}
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
private void loadUrlFromOmniboxMatch(String url, int transition, int matchPosition, int type) {
// loadUrl modifies AutocompleteController's state clearing the native
// AutocompleteResults needed by onSuggestionsSelected. Therefore,
// loadUrl should should be invoked last.
Tab currentTab = getCurrentTab();
String currentPageUrl = getCurrentTabUrl();
WebContents webContents = currentTab != null ? currentTab.getWebContents() : null;
long elapsedTimeSinceModified = mNewOmniboxEditSessionTimestamp > 0
? (SystemClock.elapsedRealtime() - mNewOmniboxEditSessionTimestamp) : -1;
boolean shouldSkipNativeLog = mShowCachedZeroSuggestResults
&& (mDeferredOnSelection != null)
&& !mDeferredOnSelection.shouldLog();
if (!shouldSkipNativeLog) {
mAutocomplete.onSuggestionSelected(matchPosition, type, currentPageUrl,
mUrlFocusedFromFakebox, elapsedTimeSinceModified,
mUrlBar.getAutocompleteLength(),
webContents);
}
loadUrl(url, transition);
}
public static Progress changeProgress(final Progress progress, long writeSize, long totalSize, final Action action) {
progress.totalSize = totalSize;
progress.currentSize += writeSize;
progress.tempSize += writeSize;
long currentTime = SystemClock.elapsedRealtime();
boolean isNotify = (currentTime - progress.lastRefreshTime) >= DokitOkGo.REFRESH_TIME;
if (isNotify || progress.currentSize == totalSize) {
long diffTime = currentTime - progress.lastRefreshTime;
if (diffTime == 0) diffTime = 1;
progress.fraction = progress.currentSize * 1.0f / totalSize;
progress.speed = progress.bufferSpeed(progress.tempSize * 1000 / diffTime);
progress.lastRefreshTime = currentTime;
progress.tempSize = 0;
if (action != null) {
action.call(progress);
}
}
return progress;
}
public void onResume() {
SystemClock.sleep(500);
if (mCamera == null) {
getCamera(SELECTED_CAMERA);
if (needSetVisible && mVideoView != null) {
mVideoView.setVisibility(View.VISIBLE);
} else {
needSetVisible = true;
}
if (mHolder != null && !isPre) {
setStartPreview(mCamera, mHolder);
}
}
wakeLock.acquire();
}
boolean haveContentsChanged() {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Marking contacts as not changed.");
return false;
}
final long startTime = SystemClock.uptimeMillis();
final int contactCount = mManager.getContactCount();
if (contactCount > ContactsDictionaryConstants.MAX_CONTACTS_PROVIDER_QUERY_LIMIT) {
// If there are too many contacts then return false. In this rare case it is impossible
// to include all of them anyways and the cost of rebuilding the dictionary is too high.
// TODO: Sort and check only the most recent contacts?
return false;
}
if (contactCount != mManager.getContactCountAtLastRebuild()) {
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : Count changed from "
+ mManager.getContactCountAtLastRebuild() + " to " + contactCount);
}
return true;
}
final ArrayList<String> names = mManager.getValidNames(Contacts.CONTENT_URI);
if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
return true;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : No change detected in "
+ (SystemClock.uptimeMillis() - startTime) + " ms)");
}
return false;
}
private void waitForNetworkUpdate(long idleTimeoutMillis, long globalTimeoutMillis) {
final long startTimeMillis = SystemClock.uptimeMillis();
long prevTraffic = TrafficStats.getUidTxBytes(uid) + TrafficStats.getUidRxBytes(uid);
boolean idleDetected = false;
long totTraffic = 0;
while (!idleDetected) {
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
final long remainingTimeMillis = globalTimeoutMillis - elapsedTimeMillis;
if (remainingTimeMillis <= 0) {
Util.err("NO_IDLE_TIMEOUT: " + globalTimeoutMillis);
break;
}
try {
Thread.sleep(idleTimeoutMillis);
long currTraffic = TrafficStats.getUidTxBytes(uid) + TrafficStats.getUidRxBytes(uid);
long delta = currTraffic - prevTraffic;
if (delta > 0) {
totTraffic += delta;
prevTraffic = currTraffic;
} else { // idle detected
idleDetected = true;
}
} catch (InterruptedException ie) {
/* ignore */
}
}
if (idleDetected) {
Util.log("Traffic: " + totTraffic);
}
}
@Override
protected void doComplete(JSONObject values) {
Log.d(TAG, "ruolanmingyue:" + values);
Log.d("SDKQQAgentPref", "AuthorSwitch_SDK:" + SystemClock.elapsedRealtime());
initOpenidAndToken(values);
//下面的这个必须放到这个地方,要不然就会出错 哎,,,,,调整了近一个小时,,,,我是服我自己了
updateUserInfo();
}