Java Code Examples for android.os.SystemClock.elapsedRealtime()

The following are Jave code examples for showing how to use elapsedRealtime() of the android.os.SystemClock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VirtualHook   File: VAccountManagerService.java   View Source Code Vote up 6 votes
Session(IAccountManagerResponse response, int userId, AuthenticatorInfo info, boolean expectActivityLaunch, boolean stripAuthTokenFromResult, String accountName, boolean authDetailsRequired, boolean updateLastAuthenticatedTime) {
	if (info == null) throw new IllegalArgumentException("accountType is null");
	this.mStripAuthTokenFromResult = stripAuthTokenFromResult;
	this.mResponse = response;
	this.mUserId = userId;
	this.mAuthenticatorInfo = info;
	this.mExpectActivityLaunch = expectActivityLaunch;
	this.mCreationTime = SystemClock.elapsedRealtime();
	this.mAccountName = accountName;
	this.mAuthDetailsRequired = authDetailsRequired;
	this.mUpdateLastAuthenticatedTime = updateLastAuthenticatedTime;
	synchronized (mSessions) {
		mSessions.put(toString(), this);
	}
	if (response != null) {
		try {
			response.asBinder().linkToDeath(this, 0 /* flags */);
		} catch (RemoteException e) {
			mResponse = null;
			binderDied();
		}
	}
}
 
Example 2
Project: q-mail   File: StorageEditor.java   View Source Code Vote up 6 votes
private void commitChanges() {
    long startTime = SystemClock.elapsedRealtime();
    Timber.i("Committing preference changes");
    Runnable committer = new Runnable() {
        public void run() {
            for (String removeKey : removals) {
                storage.remove(removeKey);
            }
            Map<String, String> insertables = new HashMap<String, String>();
            for (Entry<String, String> entry : changes.entrySet()) {
                String key = entry.getKey();
                String newValue = entry.getValue();
                String oldValue = snapshot.get(key);
                if (removals.contains(key) || !newValue.equals(oldValue)) {
                    insertables.put(key, newValue);
                }
            }
            storage.put(insertables);
        }
    };
    storage.doInTransaction(committer);
    long endTime = SystemClock.elapsedRealtime();
    Timber.i("Preferences commit took %d ms", endTime - startTime);

}
 
Example 3
Project: airgram   File: MediaCodecVideoTrackRenderer.java   View Source Code Vote up 6 votes
@Override
protected boolean isReady() {
  if (super.isReady() && (renderedFirstFrame || !codecInitialized()
      || getSourceState() == SOURCE_STATE_READY_READ_MAY_FAIL)) {
    // Ready. If we were joining then we've now joined, so clear the joining deadline.
    joiningDeadlineUs = -1;
    return true;
  } else if (joiningDeadlineUs == -1) {
    // Not joining.
    return false;
  } else if (SystemClock.elapsedRealtime() * 1000 < joiningDeadlineUs) {
    // Joining and still within the joining deadline.
    return true;
  } else {
    // The joining deadline has been exceeded. Give up and clear the deadline.
    joiningDeadlineUs = -1;
    return false;
  }
}
 
Example 4
Project: AndroidMuseumBleManager   File: CycledLeScanner.java   View Source Code Vote up 6 votes
/**
 * check is defter scan
 * @return
 */
private boolean deferScanIfNeeded(){
    long millisecondsUntilStart = nextScanStartTime - SystemClock.elapsedRealtime();
    if (millisecondsUntilStart > 0) {
        if (isPrintCycleTime){
            Logger.d("Waiting to start next Bluetooth scan for another "+millisecondsUntilStart+" milliseconds");
        }
        // Don't actually wait until the next scan time -- only wait up to 1 second.  This
        // allows us to start scanning sooner if a consumer enters the foreground and expects
        // results more quickly.
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (!isPauseScan) {
                    scanLeDevice(true);
                }
            }
        }, millisecondsUntilStart > 1000 ? 1000 : millisecondsUntilStart);
        return true;
    }
    Logger.d("Start cycle scan");
    return false;
}
 
Example 5
Project: boohee_v5.6   File: BsDiffPatchInternal.java   View Source Code Vote up 6 votes
protected static boolean tryRecoverLibraryFiles(Tinker manager, ShareSecurityCheck checker,
                                                Context context, String
                                                        patchVersionDirectory, File
                                                        patchFile, boolean isUpgradePatch) {
    if (manager.isEnabledForNativeLib()) {
        String libMeta = (String) checker.getMetaContentMap().get(ShareConstants.SO_META_FILE);
        if (libMeta == null) {
            TinkerLog.w(TAG, "patch recover, library is not contained", new Object[0]);
            return true;
        }
        long begin = SystemClock.elapsedRealtime();
        long cost = SystemClock.elapsedRealtime() - begin;
        TinkerLog.i(TAG, "recover lib result:%b, cost:%d, isUpgradePatch:%b", Boolean.valueOf
                (patchLibraryExtractViaBsDiff(context, patchVersionDirectory, libMeta,
                        patchFile, isUpgradePatch)), Long.valueOf(cost), Boolean.valueOf
                (isUpgradePatch));
        return patchLibraryExtractViaBsDiff(context, patchVersionDirectory, libMeta,
                patchFile, isUpgradePatch);
    }
    TinkerLog.w(TAG, "patch recover, library is not enabled", new Object[0]);
    return true;
}
 
Example 6
Project: aos-Video   File: RemoteViewsFactoryBase.java   View Source Code Vote up 6 votes
/*****************************************************************
** Addditional API
*****************************************************************/

/*
 * Called when the contents of the cursor(s) used to get the data for this service changes
 */
public void onContentChanged() {
    // We want the provider to handle the event and take care of reloading the data but we don't want the widget
    // to be redrawn too often if the ContentObserver triggers a lot of events => schedule a delayed intent
    // to the provider but make sure to cancel the previous intent which was scheduled so that the provider will only
    // receive one intent after the last event is triggered.

    long currentElapsedRealTime = SystemClock.elapsedRealtime();
    if (DBG) Log.d(TAG, "onContentChanged : elapsed time since the last SHOW_UPDATE_SPINBAR_ACTION was sent = " + (currentElapsedRealTime - mLastShowSpinbarTime));

    if (currentElapsedRealTime - mLastShowSpinbarTime > 1000) {
        // Tell the provider to hide the RollView and show the spinbar
        // NOTE : it should be enough to send this intent once (for instance when onContentChanged() is called
        // for the first time after a while) but it is safer to send it periodically in case another event
        // causes the widget to be redrawn
        setDelayedAlarm(WidgetProviderVideo.SHOW_UPDATE_SPINBAR_ACTION, UPDATE_ACTION_DELAY, false);
        mLastShowSpinbarTime = currentElapsedRealTime;
    }

    if (DBG) Log.d(TAG, "onContentChanged : replace previous RELOAD_ACTION at " + currentElapsedRealTime);
    replacePreviousDelayedAlarm(WidgetProviderVideo.RELOAD_ACTION, RELOAD_ACTION_DELAY);
}
 
Example 7
Project: FastTextView   File: TestListAdapter.java   View Source Code Vote up 5 votes
@Override
public final View getView(int position, View convertView, ViewGroup parent) {
  long start = SystemClock.elapsedRealtime();
  convertView = bindView(position, convertView, parent);
  long end = SystemClock.elapsedRealtime();
  bindCost += (end - start);
  return convertView;
}
 
Example 8
Project: aos-Video   File: MultiBackHintManager.java   View Source Code Vote up 5 votes
/** Must be called each time a BACK press is detected */
public void onBackPressed() {
    long now = SystemClock.elapsedRealtime();
    if (!sHideHint && (now - mPreviousPreviousPressTime < DETECTION_PERIOD)) {
        Toast.makeText(mContext, R.string.leanback_hint_long_press_on_back, Toast.LENGTH_SHORT).show();
        // reset timings to not have toast twice when pressing back 4 times
        mPreviousPressTime = mPreviousPreviousPressTime = 0;
    }
    mPreviousPreviousPressTime = mPreviousPressTime;
    mPreviousPressTime = now;
}
 
Example 9
Project: Achilles_Android   File: CpuMonitor.java   View Source Code Vote up 5 votes
public CpuMonitor(Context context) {
    Log.d(TAG, "CpuMonitor ctor.");
    appContext = context.getApplicationContext();
    userCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
    systemCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
    totalCpuUsage = new MovingAverage(MOVING_AVERAGE_SAMPLES);
    frequencyScale = new MovingAverage(MOVING_AVERAGE_SAMPLES);
    lastStatLogTimeMs = SystemClock.elapsedRealtime();

    scheduleCpuUtilizationTask();
}
 
Example 10
Project: PlusGram   File: ChunkSampleSource.java   View Source Code Vote up 5 votes
@Override
public void onLoadError(Loadable loadable, IOException e) {
  currentLoadableException = e;
  currentLoadableExceptionCount++;
  currentLoadableExceptionTimestamp = SystemClock.elapsedRealtime();
  notifyLoadError(e);
  chunkSource.onChunkLoadError(currentLoadableHolder.chunk, e);
  updateLoadControl();
}
 
Example 11
Project: letv   File: Profiler.java   View Source Code Vote up 5 votes
public long getDurationII() {
    long elapsedRealtime = SystemClock.elapsedRealtime();
    int i = bО041EО041EОО;
    switch ((i * (b041E041EО041EОО + i)) % bОО041E041EОО) {
        case 0:
            break;
        default:
            bО041EО041EОО = b041EО041E041EОО();
            b041E041EО041EОО = 42;
            break;
    }
    return elapsedRealtime - this.mStartTimeII;
}
 
Example 12
Project: buildAPKsSamples   File: CubeWallpaper2.java   View Source Code Vote up 5 votes
CubeEngine() {
    // Create a Paint to draw the lines for our cube
    final Paint paint = mPaint;
    paint.setColor(0xffffffff);
    paint.setAntiAlias(true);
    paint.setStrokeWidth(2);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStyle(Paint.Style.STROKE);

    mStartTime = SystemClock.elapsedRealtime();

    mPrefs = CubeWallpaper2.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
    mPrefs.registerOnSharedPreferenceChangeListener(this);
    onSharedPreferenceChanged(mPrefs, null);
}
 
Example 13
Project: boohee_v5.6   File: AuthDialog.java   View Source Code Vote up 5 votes
public void onReceivedError(WebView webView, int i, String str, String str2) {
    super.onReceivedError(webView, i, str, str2);
    f.c(AuthDialog.a, "-->onReceivedError, errorCode: " + i + " | description: " + str);
    if (!Util.checkNetWork(this.a.l)) {
        this.a.c.onError(new UiError(9001, "当前网络不可用,请稍后重试!", str2));
        this.a.dismiss();
    } else if (this.a.p.startsWith(ServerSetting.DOWNLOAD_QQ_URL)) {
        this.a.c.onError(new UiError(i, str, str2));
        this.a.dismiss();
    } else {
        long elapsedRealtime = SystemClock.elapsedRealtime() - this.a.r;
        if (this.a.o >= 1 || elapsedRealtime >= this.a.s) {
            this.a.k.loadUrl(this.a.b());
            return;
        }
        this.a.o = this.a.o + 1;
        this.a.e.postDelayed(new Runnable(this) {
            final /* synthetic */ LoginWebViewClient a;

            {
                this.a = r1;
            }

            public void run() {
                this.a.a.k.loadUrl(this.a.a.p);
            }
        }, 500);
    }
}
 
Example 14
Project: JobSchedulerCompat   File: JobStoreTest.java   View Source Code Vote up 5 votes
@Test
public void testMassivePeriodClampedOnRead() throws Exception {
    long period = TimeUnit.HOURS.toMillis(2);
    JobInfo job = JobCreator.create(context, 8).setPeriodic(period).setPersisted(true).build();

    long invalidLateRuntimeElapsedMillis = SystemClock.elapsedRealtime() + (period) + period;  // > period.
    long invalidEarlyRuntimeElapsedMillis = invalidLateRuntimeElapsedMillis - period; // Early = (late - period).
    JobStatus jobStatus =
            new JobStatus(job, "noop", invalidEarlyRuntimeElapsedMillis, invalidLateRuntimeElapsedMillis);
    jobStore.add(jobStatus);

    waitForJobStoreWrite();

    JobStore.JobSet jobStatusSet = new JobStore.JobSet();
    jobStore.readJobMapFromDisk(jobStatusSet);
    assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size());
    JobStatus loaded = jobStatusSet.getJobs().iterator().next();

    // Assert early runtime was clamped to be under now + period. We can do <= here b/c we'll
    // call SystemClock.elapsedRealtime after doing the disk i/o.
    long newNowElapsed = SystemClock.elapsedRealtime();
    assertTrue("Early runtime wasn't correctly clamped.",
               loaded.getEarliestRunTimeElapsed() <= newNowElapsed + period);
    // Assert late runtime was clamped to be now + period + flex.
    assertTrue("Early runtime wasn't correctly clamped.",
               loaded.getEarliestRunTimeElapsed() <= newNowElapsed + period);
}
 
Example 15
Project: android-lifecycles   File: LiveDataTimerViewModel.java   View Source Code Vote up 5 votes
public LiveDataTimerViewModel() {
    mInitialTime = SystemClock.elapsedRealtime();
    Timer timer = new Timer();

    // Update the elapsed time every second.
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            final long newValue = (SystemClock.elapsedRealtime() - mInitialTime) / 1000;
            // setValue() cannot be called from a background thread so post to main thread.
            mElapsedTime.postValue(newValue);
        }
    }, ONE_SECOND, ONE_SECOND);

}
 
Example 16
Project: music_player   File: PlayService.java   View Source Code Vote up 5 votes
public void deleteService(int time) {
    if (time != 0) {
        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
        // 设置定时
        int duration = time * 60 * 1000;
        long setTime = duration + SystemClock.elapsedRealtime();
        //设置定时任务
        manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, setTime, pendingIntent(deleteAction));
    } else {
        pause();
        removeNotification();
    }
}
 
Example 17
Project: Exoplayer2Radio   File: HlsPlaylistTracker.java   View Source Code Vote up 5 votes
public boolean isSnapshotValid() {
  if (playlistSnapshot == null) {
    return false;
  }
  long currentTimeMs = SystemClock.elapsedRealtime();
  long snapshotValidityDurationMs = Math.max(30000, C.usToMs(playlistSnapshot.durationUs));
  return playlistSnapshot.hasEndTag
      || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_EVENT
      || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_VOD
      || lastSnapshotLoadMs + snapshotValidityDurationMs > currentTimeMs;
}
 
Example 18
Project: airgram   File: StandaloneMediaClock.java   View Source Code Vote up 4 votes
private long elapsedRealtimeMinus(long toSubtractUs) {
  return SystemClock.elapsedRealtime() * 1000 - toSubtractUs;
}
 
Example 19
Project: Runnest   File: ChallengeReceiverFragment.java   View Source Code Vote up 4 votes
private void updateWarningTextVisibility() {
    if ((SystemClock.elapsedRealtime() - lastUpdateTime) >= TIME_BEFORE_NOTIFY_MISSING_UPDATES) {
        warningText.setVisibility(View.VISIBLE);
    }
}
 
Example 20
Project: chromium-net-for-android   File: CronetUrlRequest.java   View Source Code Vote up 4 votes
private void onResponseStarted() {
    if (mRequestStartTime != null && mTtfbMs == null) {
        mTtfbMs = SystemClock.elapsedRealtime() - mRequestStartTime;
    }
}