List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.mjhram.geodata.GpsLoggingService.java
private void SetAlarmForNextPoint() { tracer.debug("Set alarm for " + AppSettings.getMinimumLoggingInterval() + " seconds"); Intent i = new Intent(this, GpsLoggingService.class); i.putExtra(IntentConstants.GET_NEXT_POINT, true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);/*from ww w. ja v a2 s .c o m*/ nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AppSettings.getMinimumLoggingInterval() * 1000, pi); }
From source file:com.android.server.MountService.java
/** * Callback from NativeDaemonConnector/*ww w . ja va 2 s . c om*/ */ public boolean onEvent(int code, String raw, String[] cooked) { if (DEBUG_EVENTS) { StringBuilder builder = new StringBuilder(); builder.append("onEvent::"); builder.append(" raw= " + raw); if (cooked != null) { builder.append(" cooked = "); for (String str : cooked) { builder.append(" " + str); } } Slog.i(TAG, builder.toString()); } if (code == VoldResponseCode.VolumeStateChange) { /* * One of the volumes we're managing has changed state. * Format: "NNN Volume <label> <path> state changed * from <old_#> (<old_str>) to <new_#> (<new_str>)" */ notifyVolumeStateChange(cooked[2], cooked[3], Integer.parseInt(cooked[7]), Integer.parseInt(cooked[10])); } else if (code == VoldResponseCode.VolumeUuidChange) { // Format: nnn <label> <path> <uuid> final String path = cooked[2]; final String uuid = (cooked.length > 3) ? cooked[3] : null; final StorageVolume vol = mVolumesByPath.get(path); if (vol != null) { vol.setUuid(uuid); } } else if (code == VoldResponseCode.VolumeUserLabelChange) { // Format: nnn <label> <path> <label> final String path = cooked[2]; final String userLabel = (cooked.length > 3) ? cooked[3] : null; final StorageVolume vol = mVolumesByPath.get(path); if (vol != null) { vol.setUserLabel(userLabel); } } else if ((code == VoldResponseCode.VolumeDiskInserted) || (code == VoldResponseCode.VolumeDiskRemoved) || (code == VoldResponseCode.VolumeBadRemoval)) { // FMT: NNN Volume <label> <mountpoint> disk inserted (<major>:<minor>) // FMT: NNN Volume <label> <mountpoint> disk removed (<major>:<minor>) // FMT: NNN Volume <label> <mountpoint> bad removal (<major>:<minor>) String action = null; final String label = cooked[2]; final String path = cooked[3]; int major = -1; int minor = -1; try { String devComp = cooked[6].substring(1, cooked[6].length() - 1); String[] devTok = devComp.split(":"); major = Integer.parseInt(devTok[0]); minor = Integer.parseInt(devTok[1]); } catch (Exception ex) { Slog.e(TAG, "Failed to parse major/minor", ex); } final StorageVolume volume; final String state; synchronized (mVolumesLock) { volume = mVolumesByPath.get(path); state = mVolumeStates.get(path); } if (code == VoldResponseCode.VolumeDiskInserted) { new Thread("MountService#VolumeDiskInserted") { @Override public void run() { try { int rc; if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) { Slog.w(TAG, String.format("Insertion mount failed (%d)", rc)); } } catch (Exception ex) { Slog.w(TAG, "Failed to mount media on insertion", ex); } } }.start(); } else if (code == VoldResponseCode.VolumeDiskRemoved) { /* * This event gets trumped if we're already in BAD_REMOVAL state */ if (getVolumeState(path).equals(Environment.MEDIA_BAD_REMOVAL)) { return true; } /* Send the media unmounted event first */ if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first"); updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED); sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL); if (DEBUG_EVENTS) Slog.i(TAG, "Sending media removed"); updatePublicVolumeState(volume, Environment.MEDIA_REMOVED); action = Intent.ACTION_MEDIA_REMOVED; } else if (code == VoldResponseCode.VolumeBadRemoval) { if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first"); /* Send the media unmounted event first */ updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED); sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL); if (DEBUG_EVENTS) Slog.i(TAG, "Sending media bad removal"); updatePublicVolumeState(volume, Environment.MEDIA_BAD_REMOVAL); action = Intent.ACTION_MEDIA_BAD_REMOVAL; } else if (code == VoldResponseCode.FstrimCompleted) { EventLogTags.writeFstrimFinish(SystemClock.elapsedRealtime()); } else { Slog.e(TAG, String.format("Unknown code {%d}", code)); } if (action != null) { sendStorageIntent(action, volume, UserHandle.ALL); } } else { return false; } return true; }
From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java
private void rebuildNotifications() { final long now = SystemClock.elapsedRealtime(); ViewGroup container = mIconsContainer; final int childCount = container.getChildCount(); // Count the number of non-notification fragments // such as unlock or music controls fragments. int start = 0; for (int i = 0; i < childCount; i++) { View child = container.getChildAt(i); Widget fragment = findWidgetByIcon(child); if (fragment instanceof NotifyWidget) { // Those fragments are placed at the begin of layout // so no reason to continue searching. break; } else {//from w w w .j a v a 2 s . co m start++; } } final ArrayList<OpenNotification> list = NotificationPresenter.getInstance().getList(); final int notifyCount = list.size(); final boolean[] notifyUsed = new boolean[notifyCount]; final boolean[] childUsed = new boolean[childCount]; for (int i = start; i < childCount; i++) { View child = container.getChildAt(i); NotifyWidget widget = (NotifyWidget) findWidgetByIcon(child); OpenNotification target = widget.getNotification(); for (int j = 0; j < notifyCount; j++) { OpenNotification n = list.get(j); if (NotificationUtils.hasIdenticalIds(target, n)) { notifyUsed[j] = true; childUsed[i] = true; if (target != n) { widget.setNotification(n); } break; } } } // Re-use free views and remove redundant views. boolean removeAllAfter = false; for (int a = start, j = 0, offset = 0; a < childCount; a++) { if (childUsed[a]) continue; final int i = a + offset; View child = container.getChildAt(i); removing_all_next_views: { if (!removeAllAfter) { for (; j < notifyCount; j++) { if (notifyUsed[j]) continue; assert child != null; notifyUsed[j] = true; NotifyWidget nw = (NotifyWidget) findWidgetByIcon(child); nw.setNotification(list.get(j)); break removing_all_next_views; } } removeAllAfter = true; internalReleaseWidget(child); // Remove widget's icon. container.removeViewAt(i); offset--; } } assert getActivity() != null; LayoutInflater inflater = getActivity().getLayoutInflater(); final int iconSize = getConfig().getIconSizePx(); for (int i = 0; i < notifyCount; i++) { if (notifyUsed[i]) continue; NotifyWidget nw = new NotifyWidget(this, this); if (isResumed()) nw.start(); View iconView = nw.createIconView(inflater, container); ViewUtils.setSize(iconView, iconSize); container.addView(iconView); nw.setNotification(list.get(i)); mWidgetsMap.put(iconView, nw); } // ///////////////////// // ~~ UPDATE HASH MAP ~~ // ///////////////////// HashMap<String, SceneCompat> map = (HashMap<String, SceneCompat>) mScenesMap.clone(); mScenesMap.clear(); for (Widget fragment : mWidgetsMap.values()) { String type = fragment.getClass().getName(); SceneCompat scene = map.get(type); if (scene != null) { fragment.createView(null, null, scene.getView()); } else { ViewGroup sceneView = fragment.createView(inflater, mSceneContainer, null); if (sceneView != null) { scene = new SceneCompat(mSceneContainer, sceneView); map.put(type, scene); } } if (scene != null) { mScenesMap.put(type, scene); } } if (DEBUG) { long delta = SystemClock.elapsedRealtime() - now; Log.d(TAG, "Fragment list updated in " + delta + "ms."); } // Do not animate divider's visibility change on // pause/resume, cause it _somehow_ confuses people. boolean animate = !mResuming; updateDividerVisibility(animate); }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
private void resumeTimer() { if (mCurrentCard != null) { // Resume the card timer first. It internally accounts for the time gap between // suspend and resume. mCurrentCard.resumeTimer();//from ww w . j a va 2s . c o m // Then update and resume the UI timer. Set the base time as if the timer had started // timeTaken() seconds ago. mCardTimer.setBase(SystemClock.elapsedRealtime() - mCurrentCard.timeTaken()); // Don't start the timer if we have already reached the time limit or it will tick over if ((SystemClock.elapsedRealtime() - mCardTimer.getBase()) < mCurrentCard.timeLimit()) { mCardTimer.start(); } } }
From source file:com.yerdy.services.Yerdy.java
private void sendEvents(Context cxt) { if (Math.abs(_lastProgressionReport - SystemClock.elapsedRealtime()) > PROGRESSION_THRESHOLD || _lastProgressionReport < 0) { _lastProgressionReport = SystemClock.elapsedRealtime(); if (!YerdyUtil.networkUnreachable(cxt)) { if (_progressionTracker != null && _progressionTracker.isReadyToReport()) YRDAnalytics.getInstance().reportPlayerProgressionOrFeature(cxt, _progressionTracker.getAndResetProgressionEvents(), YRDAnalytics.PLAYER_PROGRESSION_TYPE); if (_featureMasteryTracker != null && _featureMasteryTracker.isReadyToReport()) YRDAnalytics.getInstance().reportPlayerProgressionOrFeature(cxt, _featureMasteryTracker.getAndResetCounters(), YRDAnalytics.FEATURE_MASTERY_TYPE); if (_eventTracker != null && _eventTracker.isReadyToReport()) YRDAnalytics.getInstance().reportCustomEvent(_applicationContext, _eventTracker.getAndResetCustomEvents()); //YRDAnalytics.getInstance().reportCustomEvent(_applicationContext, name, parameterName, bucketName, 1); }//from ww w .j a v a 2s . c o m } }
From source file:com.youku.player.plugin.MediaPlayerDelegate.java
private void handleSuccessfullyGetVideoUrl(final VideoUrlInfo videoUrlInfo) { videoUrlInfo.mVideoFetchTime = SystemClock.elapsedRealtime(); // Track.play(); Logger.d(LogTag.TAG_PLAYER, "???"); //download subtitle if has subtitle if (mSubtitleDownloadThread != null) { mSubtitleDownloadThread.stopSelf(); mSubtitleDownloadThread = null;/*from w w w . j av a 2 s. co m*/ } mPlayerUiControl.clearSubtitle(); List<Attachment> attachments = videoUrlInfo.getAttachments(); if (attachments != null && attachments.size() > 0) { Logger.d(SubtitleManager.TAG, "handleSuccessfullyGetVideoUrl : downloadSubtitles"); downloadSubtitles(attachments, videoUrlInfo.getVid()); } else { Logger.d(SubtitleManager.TAG, "handleSuccessfullyGetVideoUrl : no subtitle"); mPlayerUiControl.onDownloadSubtitle(null, -1); } }
From source file:com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.java
protected void startReconnectionService(long mediaDurationLeft) { if (!isFeatureEnabled(CastConfiguration.FEATURE_WIFI_RECONNECT)) { return;//from w w w . j a va 2 s . com } LOGD(TAG, "startReconnectionService() for media length lef = " + mediaDurationLeft); long endTime = SystemClock.elapsedRealtime() + mediaDurationLeft; mPreferenceAccessor.saveLongToPreference(PREFS_KEY_MEDIA_END, endTime); Context applicationContext = mContext.getApplicationContext(); Intent service = new Intent(applicationContext, ReconnectionService.class); service.setPackage(applicationContext.getPackageName()); applicationContext.startService(service); }
From source file:com.google.sample.castcompanionlibrary.cast.BaseCastManager.java
protected void startReconnectionService(long mediaDurationLeft) { if (!isFeatureEnabled(FEATURE_WIFI_RECONNECT)) { return;// w ww. j ava 2 s .c o m } LOGD(TAG, "startReconnectionService() for media length lef = " + mediaDurationLeft); long endTime = SystemClock.elapsedRealtime() + mediaDurationLeft; Utils.saveLongToPreference(mContext.getApplicationContext(), PREFS_KEY_MEDIA_END, endTime); Context applicationContext = mContext.getApplicationContext(); Intent service = new Intent(applicationContext, ReconnectionService.class); service.setPackage(applicationContext.getPackageName()); applicationContext.startService(service); }
From source file:androidx.media.MediaController2.java
/** * Gets the current playback position.//w ww. j a v a 2 s. c o m * <p> * This returns the calculated value of the position, based on the difference between the * update time and current time. * * @return position */ public long getCurrentPosition() { synchronized (mLock) { if (!mConnected) { Log.w(TAG, "Session isn't active", new IllegalStateException()); return UNKNOWN_TIME; } if (mPlaybackStateCompat != null) { long timeDiff = SystemClock.elapsedRealtime() - mPlaybackStateCompat.getLastPositionUpdateTime(); long expectedPosition = mPlaybackStateCompat.getPosition() + (long) (mPlaybackStateCompat.getPlaybackSpeed() * timeDiff); return Math.max(0, expectedPosition); } return UNKNOWN_TIME; } }
From source file:com.sim2dial.dialer.InCallActivity.java
private void registerCallDurationTimer(View v, LinphoneCall call) { int callDuration = call.getDuration(); if (callDuration == 0 && call.getState() != State.StreamsRunning) { return;// w w w . j av a 2s.co m } // Chronometer timer = (Chronometer) v.findViewById(R.id.callTimer); if (tim == null) { throw new IllegalArgumentException("no callee_duration view found"); } tim.setBase(SystemClock.elapsedRealtime() - 1000 * callDuration); tim.start(); }