android.os.Trace#traceBegin ( )源码实例Demo

下面列出了android.os.Trace#traceBegin ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: AlarmManagerService.java
void deliverAlarmsLocked(ArrayList<Alarm> triggerList, long nowELAPSED) {
    mLastAlarmDeliveryTime = nowELAPSED;
    for (int i=0; i<triggerList.size(); i++) {
        Alarm alarm = triggerList.get(i);
        final boolean allowWhileIdle = (alarm.flags&AlarmManager.FLAG_ALLOW_WHILE_IDLE) != 0;
        if (alarm.wakeup) {
          Trace.traceBegin(Trace.TRACE_TAG_POWER, "Dispatch wakeup alarm to " + alarm.packageName);
        } else {
          Trace.traceBegin(Trace.TRACE_TAG_POWER, "Dispatch non-wakeup alarm to " + alarm.packageName);
        }
        try {
            if (localLOGV) {
                Slog.v(TAG, "sending alarm " + alarm);
            }
            if (RECORD_ALARMS_IN_HISTORY) {
                ActivityManager.noteAlarmStart(alarm.operation, alarm.workSource, alarm.uid,
                        alarm.statsTag);
            }
            mDeliveryTracker.deliverLocked(alarm, nowELAPSED, allowWhileIdle);
        } catch (RuntimeException e) {
            Slog.w(TAG, "Failure sending alarm.", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_POWER);
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: SystemServiceManager.java
public void stopUser(final int userHandle) {
    Slog.i(TAG, "Calling onStopUser u" + userHandle);
    final int serviceLen = mServices.size();
    for (int i = 0; i < serviceLen; i++) {
        final SystemService service = mServices.get(i);
        Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onStopUser "
                + service.getClass().getName());
        long time = SystemClock.elapsedRealtime();
        try {
            service.onStopUser(userHandle);
        } catch (Exception ex) {
            Slog.wtf(TAG, "Failure reporting stop of user " + userHandle
                    + " to service " + service.getClass().getName(), ex);
        }
        warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onStopUser");
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: VibratorService.java
private long delayLocked(long duration) {
    Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "delayLocked");
    try {
        long durationRemaining = duration;
        if (duration > 0) {
            final long bedtime = duration + SystemClock.uptimeMillis();
            do {
                try {
                    this.wait(durationRemaining);
                }
                catch (InterruptedException e) { }
                if (mForceStop) {
                    break;
                }
                durationRemaining = bedtime - SystemClock.uptimeMillis();
            } while (durationRemaining > 0);
            return duration - durationRemaining;
        }
        return 0;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR);
    }
}
 
源代码4 项目: android_9.0.0_r45   文件: Session.java
@Override
public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
        int requestedWidth, int requestedHeight, int viewFlags, int flags, long frameNumber,
        Rect outFrame, Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
        Rect outStableInsets, Rect outsets, Rect outBackdropFrame,
        DisplayCutout.ParcelableWrapper cutout, MergedConfiguration mergedConfiguration,
        Surface outSurface) {
    if (false) Slog.d(TAG_WM, ">>>>>> ENTERED relayout from "
            + Binder.getCallingPid());
    Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, mRelayoutTag);
    int res = mService.relayoutWindow(this, window, seq, attrs,
            requestedWidth, requestedHeight, viewFlags, flags, frameNumber,
            outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
            outStableInsets, outsets, outBackdropFrame, cutout,
            mergedConfiguration, outSurface);
    Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
    if (false) Slog.d(TAG_WM, "<<<<<< EXITING relayout to "
            + Binder.getCallingPid());
    return res;
}
 
源代码5 项目: android_9.0.0_r45   文件: ProcessRecord.java
void kill(String reason, boolean noisy) {
    if (!killedByAm) {
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "kill");
        if (mService != null && (noisy || info.uid == mService.mCurOomAdjUid)) {
            mService.reportUidInfoMessageLocked(TAG,
                    "Killing " + toShortString() + " (adj " + setAdj + "): " + reason,
                    info.uid);
        }
        if (pid > 0) {
            EventLog.writeEvent(EventLogTags.AM_KILL, userId, pid, processName, setAdj, reason);
            Process.killProcessQuiet(pid);
            ActivityManagerService.killProcessGroup(uid, pid);
        } else {
            pendingStart = false;
        }
        if (!persistent) {
            killed = true;
            killedByAm = true;
        }
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }
}
 
源代码6 项目: android_9.0.0_r45   文件: WindowTracing.java
void traceStateLocked(String where, WindowManagerService service) {
    if (!isEnabled()) {
        return;
    }
    ProtoOutputStream os = new ProtoOutputStream();
    long tokenOuter = os.start(ENTRY);
    os.write(ELAPSED_REALTIME_NANOS, SystemClock.elapsedRealtimeNanos());
    os.write(WHERE, where);

    Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "writeToProtoLocked");
    try {
        long tokenInner = os.start(WINDOW_MANAGER_SERVICE);
        service.writeToProtoLocked(os, true /* trim */);
        os.end(tokenInner);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
    }
    os.end(tokenOuter);
    appendTraceEntry(os);
    Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
}
 
源代码7 项目: android_9.0.0_r45   文件: NetworkStatsService.java
@Override
public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) {
    Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkUidBytes");
    try {
        return NetworkStatsService.this.getNetworkUidBytes(template, start, end);
    } finally {
        Trace.traceEnd(TRACE_TAG_NETWORK);
    }
}
 
源代码8 项目: android_9.0.0_r45   文件: ActivityRelaunchItem.java
@Override
public void execute(ClientTransactionHandler client, IBinder token,
        PendingTransactionActions pendingActions) {
    if (mActivityClientRecord == null) {
        if (DEBUG_ORDER) Slog.d(TAG, "Activity relaunch cancelled");
        return;
    }
    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityRestart");
    client.handleRelaunchActivity(mActivityClientRecord, pendingActions);
    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
}
 
源代码9 项目: android_9.0.0_r45   文件: KeyguardController.java
/**
 * Called when Keyguard is going away.
 *
 * @param flags See {@link WindowManagerPolicy#KEYGUARD_GOING_AWAY_FLAG_TO_SHADE}
 *              etc.
 */
void keyguardGoingAway(int flags) {
    if (!mKeyguardShowing) {
        return;
    }
    Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway");
    mWindowManager.deferSurfaceLayout();
    try {
        setKeyguardGoingAway(true);
        mWindowManager.prepareAppTransition(TRANSIT_KEYGUARD_GOING_AWAY,
                false /* alwaysKeepCurrent */, convertTransitFlags(flags),
                false /* forceOverride */);
        updateKeyguardSleepToken();

        // Some stack visibility might change (e.g. docked stack)
        mStackSupervisor.resumeFocusedStackTopActivityLocked();
        mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
        mStackSupervisor.addStartingWindowsForVisibleActivities(true /* taskSwitch */);
        mWindowManager.executeAppTransition();
    } finally {
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "keyguardGoingAway: surfaceLayout");
        mWindowManager.continueSurfaceLayout();
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);

        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
    }
}
 
源代码10 项目: android_9.0.0_r45   文件: VibratorService.java
private int runVibrate() {
    Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "runVibrate");
    try {
        try {
            final int zenMode = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.ZEN_MODE);
            if (zenMode != Settings.Global.ZEN_MODE_OFF) {
                try (PrintWriter pw = getOutPrintWriter();) {
                    pw.print("Ignoring because device is on DND mode ");
                    pw.println(DebugUtils.flagsToString(Settings.Global.class, "ZEN_MODE_",
                            zenMode));
                    return 0;
                }
            }
        } catch (SettingNotFoundException e) {
            // ignore
        }

        final long duration = Long.parseLong(getNextArgRequired());
        if (duration > MAX_VIBRATION_MS) {
            throw new IllegalArgumentException("maximum duration is " + MAX_VIBRATION_MS);
        }
        String description = getNextArg();
        if (description == null) {
            description = "Shell command";
        }

        VibrationEffect effect =
                VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE);
        vibrate(Binder.getCallingUid(), description, effect, AudioAttributes.USAGE_UNKNOWN,
                mToken);
        return 0;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR);
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: NetworkStatsService.java
@Override
public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) {
    Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkTotalBytes");
    try {
        return NetworkStatsService.this.getNetworkTotalBytes(template, start, end);
    } finally {
        Trace.traceEnd(TRACE_TAG_NETWORK);
    }
}
 
@Override
public void execute(ClientTransactionHandler client, IBinder token,
        PendingTransactionActions pendingActions) {
    // TODO(lifecycler): detect if PIP or multi-window mode changed and report it here.
    Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged");
    client.handleActivityConfigurationChanged(token, mConfiguration, INVALID_DISPLAY);
    Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}
 
源代码13 项目: android_9.0.0_r45   文件: ResumeActivityItem.java
@Override
public void execute(ClientTransactionHandler client, IBinder token,
        PendingTransactionActions pendingActions) {
    Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityResume");
    client.handleResumeActivity(token, true /* finalStateRequest */, mIsForward,
            "RESUME_ACTIVITY");
    Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}
 
源代码14 项目: android_9.0.0_r45   文件: VibratorService.java
/**
 * Play the waveform.
 *
 * @return true if it finished naturally, false otherwise (e.g. it was canceled).
 */
public boolean playWaveform() {
    Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "playWaveform");
    try {
        synchronized (this) {
            final long[] timings = mWaveform.getTimings();
            final int[] amplitudes = mWaveform.getAmplitudes();
            final int len = timings.length;
            final int repeat = mWaveform.getRepeatIndex();

            int index = 0;
            long onDuration = 0;
            while (!mForceStop) {
                if (index < len) {
                    final int amplitude = amplitudes[index];
                    final long duration = timings[index++];
                    if (duration <= 0) {
                        continue;
                    }
                    if (amplitude != 0) {
                        if (onDuration <= 0) {
                            // Telling the vibrator to start multiple times usually causes
                            // effects to feel "choppy" because the motor resets at every on
                            // command.  Instead we figure out how long our next "on" period
                            // is going to be, tell the motor to stay on for the full
                            // duration, and then wake up to change the amplitude at the
                            // appropriate intervals.
                            onDuration = getTotalOnDuration(timings, amplitudes, index - 1,
                                    repeat);
                            doVibratorOn(onDuration, amplitude, mUid, mUsageHint);
                        } else {
                            doVibratorSetAmplitude(amplitude);
                        }
                    }

                    long waitTime = delayLocked(duration);
                    if (amplitude != 0) {
                        onDuration -= waitTime;
                    }
                } else if (repeat < 0) {
                    break;
                } else {
                    index = repeat;
                }
            }
            return !mForceStop;
        }
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR);
    }
}
 
源代码15 项目: AndroidComponentPlugin   文件: ContextImpl.java
static ContextImpl createActivityContext(ActivityThread mainThread,
        LoadedApk packageInfo, ActivityInfo activityInfo, IBinder activityToken, int displayId,
        Configuration overrideConfiguration) {
    if (packageInfo == null) throw new IllegalArgumentException("packageInfo");

    String[] splitDirs = packageInfo.getSplitResDirs();
    ClassLoader classLoader = packageInfo.getClassLoader();

    if (packageInfo.getApplicationInfo().requestsIsolatedSplitLoading()) {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "SplitDependencies");
        try {
            classLoader = packageInfo.getSplitClassLoader(activityInfo.splitName);
            splitDirs = packageInfo.getSplitPaths(activityInfo.splitName);
        } catch (NameNotFoundException e) {
            // Nothing above us can handle a NameNotFoundException, better crash.
            throw new RuntimeException(e);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    }

    ContextImpl context = new ContextImpl(null, mainThread, packageInfo, activityInfo.splitName,
            activityToken, null, 0, classLoader);

    // Clamp display ID to DEFAULT_DISPLAY if it is INVALID_DISPLAY.
    displayId = (displayId != Display.INVALID_DISPLAY) ? displayId : Display.DEFAULT_DISPLAY;

    final CompatibilityInfo compatInfo = (displayId == Display.DEFAULT_DISPLAY)
            ? packageInfo.getCompatibilityInfo()
            : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;

    final ResourcesManager resourcesManager = ResourcesManager.getInstance();

    // Create the base resources for which all configuration contexts for this Activity
    // will be rebased upon.
    context.setResources(resourcesManager.createBaseActivityResources(activityToken,
            packageInfo.getResDir(),
            splitDirs,
            packageInfo.getOverlayDirs(),
            packageInfo.getApplicationInfo().sharedLibraryFiles,
            displayId,
            overrideConfiguration,
            compatInfo,
            classLoader));
    context.mDisplay = resourcesManager.getAdjustedDisplay(displayId,
            context.getResources());
    return context;
}
 
源代码16 项目: AndroidComponentPlugin   文件: ContextImpl.java
static ContextImpl createActivityContext(ActivityThread mainThread,
        LoadedApk packageInfo, ActivityInfo activityInfo, IBinder activityToken, int displayId,
        Configuration overrideConfiguration) {
    if (packageInfo == null) throw new IllegalArgumentException("packageInfo");

    String[] splitDirs = packageInfo.getSplitResDirs();
    ClassLoader classLoader = packageInfo.getClassLoader();

    if (packageInfo.getApplicationInfo().requestsIsolatedSplitLoading()) {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "SplitDependencies");
        try {
            classLoader = packageInfo.getSplitClassLoader(activityInfo.splitName);
            splitDirs = packageInfo.getSplitPaths(activityInfo.splitName);
        } catch (NameNotFoundException e) {
            // Nothing above us can handle a NameNotFoundException, better crash.
            throw new RuntimeException(e);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
        }
    }

    ContextImpl context = new ContextImpl(null, mainThread, packageInfo, activityInfo.splitName,
            activityToken, null, 0, classLoader);

    // Clamp display ID to DEFAULT_DISPLAY if it is INVALID_DISPLAY.
    displayId = (displayId != Display.INVALID_DISPLAY) ? displayId : Display.DEFAULT_DISPLAY;

    final CompatibilityInfo compatInfo = (displayId == Display.DEFAULT_DISPLAY)
            ? packageInfo.getCompatibilityInfo()
            : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;

    final ResourcesManager resourcesManager = ResourcesManager.getInstance();

    // Create the base resources for which all configuration contexts for this Activity
    // will be rebased upon.
    context.setResources(resourcesManager.createBaseActivityResources(activityToken,
            packageInfo.getResDir(),
            splitDirs,
            packageInfo.getOverlayDirs(),
            packageInfo.getApplicationInfo().sharedLibraryFiles,
            displayId,
            overrideConfiguration,
            compatInfo,
            classLoader));
    context.mDisplay = resourcesManager.getAdjustedDisplay(displayId,
            context.getResources());
    return context;
}
 
源代码17 项目: android_9.0.0_r45   文件: PowerManagerService.java
private boolean wakeUpNoUpdateLocked(long eventTime, String reason, int reasonUid,
        String opPackageName, int opUid) {
    if (DEBUG_SPEW) {
        Slog.d(TAG, "wakeUpNoUpdateLocked: eventTime=" + eventTime + ", uid=" + reasonUid);
    }

    if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE
            || !mBootCompleted || !mSystemReady) {
        return false;
    }

    Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_SCREEN_ON, 0);

    Trace.traceBegin(Trace.TRACE_TAG_POWER, "wakeUp");
    try {
        switch (mWakefulness) {
            case WAKEFULNESS_ASLEEP:
                Slog.i(TAG, "Waking up from sleep (uid=" + reasonUid + " reason=" + reason
                        + ")...");
                break;
            case WAKEFULNESS_DREAMING:
                Slog.i(TAG, "Waking up from dream (uid=" + reasonUid + " reason=" + reason
                        + ")...");
                break;
            case WAKEFULNESS_DOZING:
                Slog.i(TAG, "Waking up from dozing (uid=" + reasonUid + " reason=" + reason
                        + ")...");
                break;
        }

        mLastWakeTime = eventTime;
        setWakefulnessLocked(WAKEFULNESS_AWAKE, 0);

        mNotifier.onWakeUp(reason, reasonUid, opPackageName, opUid);
        userActivityNoUpdateLocked(
                eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, reasonUid);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_POWER);
    }
    return true;
}
 
源代码18 项目: android_9.0.0_r45   文件: PowerManagerService.java
@SuppressWarnings("deprecation")
private boolean goToSleepNoUpdateLocked(long eventTime, int reason, int flags, int uid) {
    if (DEBUG_SPEW) {
        Slog.d(TAG, "goToSleepNoUpdateLocked: eventTime=" + eventTime
                + ", reason=" + reason + ", flags=" + flags + ", uid=" + uid);
    }

    if (eventTime < mLastWakeTime
            || mWakefulness == WAKEFULNESS_ASLEEP
            || mWakefulness == WAKEFULNESS_DOZING
            || !mBootCompleted || !mSystemReady) {
        return false;
    }

    Trace.traceBegin(Trace.TRACE_TAG_POWER, "goToSleep");
    try {
        switch (reason) {
            case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:
                Slog.i(TAG, "Going to sleep due to device administration policy "
                        + "(uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:
                Slog.i(TAG, "Going to sleep due to screen timeout (uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH:
                Slog.i(TAG, "Going to sleep due to lid switch (uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON:
                Slog.i(TAG, "Going to sleep due to power button (uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON:
                Slog.i(TAG, "Going to sleep due to sleep button (uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_HDMI:
                Slog.i(TAG, "Going to sleep due to HDMI standby (uid " + uid +")...");
                break;
            case PowerManager.GO_TO_SLEEP_REASON_ACCESSIBILITY:
                Slog.i(TAG, "Going to sleep by an accessibility service request (uid "
                        + uid +")...");
                break;
            default:
                Slog.i(TAG, "Going to sleep by application request (uid " + uid +")...");
                reason = PowerManager.GO_TO_SLEEP_REASON_APPLICATION;
                break;
        }

        mLastSleepTime = eventTime;
        mSandmanSummoned = true;
        setWakefulnessLocked(WAKEFULNESS_DOZING, reason);

        // Report the number of wake locks that will be cleared by going to sleep.
        int numWakeLocksCleared = 0;
        final int numWakeLocks = mWakeLocks.size();
        for (int i = 0; i < numWakeLocks; i++) {
            final WakeLock wakeLock = mWakeLocks.get(i);
            switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
                case PowerManager.FULL_WAKE_LOCK:
                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
                case PowerManager.SCREEN_DIM_WAKE_LOCK:
                    numWakeLocksCleared += 1;
                    break;
            }
        }
        EventLogTags.writePowerSleepRequested(numWakeLocksCleared);

        // Skip dozing if requested.
        if ((flags & PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE) != 0) {
            reallyGoToSleepNoUpdateLocked(eventTime, uid);
        }
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_POWER);
    }
    return true;
}
 
@Override
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

    if (ENABLE_LOG) {
        Log.d(TAG, "Thread started");
    }

    // Trace this sync instance.  Note, conceptually this should be in
    // SyncStorageEngine.insertStartSyncEvent(), but the trace functions require unique
    // threads in order to track overlapping operations, so we'll do it here for now.
    Trace.traceBegin(Trace.TRACE_TAG_SYNC_MANAGER, mAuthority);

    SyncResult syncResult = new SyncResult();
    ContentProviderClient provider = null;
    try {
        if (isCanceled()) {
            if (ENABLE_LOG) {
                Log.d(TAG, "Already canceled");
            }
            return;
        }
        if (ENABLE_LOG) {
            Log.d(TAG, "Calling onPerformSync...");
        }

        provider = mContext.getContentResolver().acquireContentProviderClient(mAuthority);
        if (provider != null) {
            AbstractThreadedSyncAdapter.this.onPerformSync(mAccount, mExtras,
                    mAuthority, provider, syncResult);
        } else {
            syncResult.databaseError = true;
        }

        if (ENABLE_LOG) {
            Log.d(TAG, "onPerformSync done");
        }

    } catch (SecurityException e) {
        if (ENABLE_LOG) {
            Log.d(TAG, "SecurityException", e);
        }
        AbstractThreadedSyncAdapter.this.onSecurityException(mAccount, mExtras,
                mAuthority, syncResult);
        syncResult.databaseError = true;
    } catch (RuntimeException | Error th) {
        if (ENABLE_LOG) {
            Log.d(TAG, "caught exception", th);
        }
        throw th;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_SYNC_MANAGER);

        if (provider != null) {
            provider.release();
        }
        if (!isCanceled()) {
            mSyncContext.onFinished(syncResult);
        }
        // synchronize so that the assignment will be seen by other threads
        // that also synchronize accesses to mSyncThreads
        synchronized (mSyncThreadLock) {
            mSyncThreads.remove(mThreadsKey);
        }

        if (ENABLE_LOG) {
            Log.d(TAG, "Thread finished");
        }
    }
}
 
源代码20 项目: android_9.0.0_r45   文件: Choreographer.java
void doFrame(long frameTimeNanos, int frame) {
    final long startNanos;
    synchronized (mLock) {
        if (!mFrameScheduled) {
            return; // no work to do
        }

        if (DEBUG_JANK && mDebugPrintNextFrameTimeDelta) {
            mDebugPrintNextFrameTimeDelta = false;
            Log.d(TAG, "Frame time delta: "
                    + ((frameTimeNanos - mLastFrameTimeNanos) * 0.000001f) + " ms");
        }

        long intendedFrameTimeNanos = frameTimeNanos;
        startNanos = System.nanoTime();
        final long jitterNanos = startNanos - frameTimeNanos;
        if (jitterNanos >= mFrameIntervalNanos) {
            final long skippedFrames = jitterNanos / mFrameIntervalNanos;
            if (skippedFrames >= SKIPPED_FRAME_WARNING_LIMIT) {
                Log.i(TAG, "Skipped " + skippedFrames + " frames!  "
                        + "The application may be doing too much work on its main thread.");
            }
            final long lastFrameOffset = jitterNanos % mFrameIntervalNanos;
            if (DEBUG_JANK) {
                Log.d(TAG, "Missed vsync by " + (jitterNanos * 0.000001f) + " ms "
                        + "which is more than the frame interval of "
                        + (mFrameIntervalNanos * 0.000001f) + " ms!  "
                        + "Skipping " + skippedFrames + " frames and setting frame "
                        + "time to " + (lastFrameOffset * 0.000001f) + " ms in the past.");
            }
            frameTimeNanos = startNanos - lastFrameOffset;
        }

        if (frameTimeNanos < mLastFrameTimeNanos) {
            if (DEBUG_JANK) {
                Log.d(TAG, "Frame time appears to be going backwards.  May be due to a "
                        + "previously skipped frame.  Waiting for next vsync.");
            }
            scheduleVsyncLocked();
            return;
        }

        if (mFPSDivisor > 1) {
            long timeSinceVsync = frameTimeNanos - mLastFrameTimeNanos;
            if (timeSinceVsync < (mFrameIntervalNanos * mFPSDivisor) && timeSinceVsync > 0) {
                scheduleVsyncLocked();
                return;
            }
        }

        mFrameInfo.setVsync(intendedFrameTimeNanos, frameTimeNanos);
        mFrameScheduled = false;
        mLastFrameTimeNanos = frameTimeNanos;
    }

    try {
        Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Choreographer#doFrame");
        AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS);

        mFrameInfo.markInputHandlingStart();
        doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos);

        mFrameInfo.markAnimationsStart();
        doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos);

        mFrameInfo.markPerformTraversalsStart();
        doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos);

        doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
    } finally {
        AnimationUtils.unlockAnimationClock();
        Trace.traceEnd(Trace.TRACE_TAG_VIEW);
    }

    if (DEBUG_FRAMES) {
        final long endNanos = System.nanoTime();
        Log.d(TAG, "Frame " + frame + ": Finished, took "
                + (endNanos - startNanos) * 0.000001f + " ms, latency "
                + (startNanos - frameTimeNanos) * 0.000001f + " ms.");
    }
}