Java Code Examples for android.os.Trace#traceEnd()

The following examples show how to use android.os.Trace#traceEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessRecord.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: WindowTracing.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: Session.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: GraphicsStatsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void deleteOldBuffers() {
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "deleting old graphicsstats buffers");
    synchronized (mFileAccessLock) {
        File[] files = mGraphicsStatsDir.listFiles();
        if (files == null || files.length <= 3) {
            return;
        }
        long[] sortedDates = new long[files.length];
        for (int i = 0; i < files.length; i++) {
            try {
                sortedDates[i] = Long.parseLong(files[i].getName());
            } catch (NumberFormatException ex) {
                // Skip unrecognized folders
            }
        }
        if (sortedDates.length <= 3) {
            return;
        }
        Arrays.sort(sortedDates);
        for (int i = 0; i < sortedDates.length - 3; i++) {
            deleteRecursiveLocked(new File(mGraphicsStatsDir, Long.toString(sortedDates[i])));
        }
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
 
Example 5
Source File: NetworkStatsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: NetworkManagementService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setUidOnMeteredNetworkList(int uid, boolean blacklist, boolean enable) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);

    // silently discard when control disabled
    // TODO: eventually migrate to be always enabled
    if (!mBandwidthControlEnabled) return;

    final String chain = blacklist ? "naughtyapps" : "niceapps";
    final String suffix = enable ? "add" : "remove";

    synchronized (mQuotaLock) {
        boolean oldEnable;
        SparseBooleanArray quotaList;
        synchronized (mRulesLock) {
            quotaList = blacklist ? mUidRejectOnMetered : mUidAllowOnMetered;
            oldEnable = quotaList.get(uid, false);
        }
        if (oldEnable == enable) {
            // TODO: eventually consider throwing
            return;
        }

        Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "inetd bandwidth");
        try {
            mConnector.execute("bandwidth", suffix + chain, uid);
            synchronized (mRulesLock) {
                if (enable) {
                    quotaList.put(uid, true);
                } else {
                    quotaList.delete(uid);
                }
            }
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
        }
    }
}
 
Example 7
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setHalInteractiveModeLocked(boolean enable) {
    if (enable != mHalInteractiveModeEnabled) {
        if (DEBUG) {
            Slog.d(TAG, "Setting HAL interactive mode to " + enable);
        }
        mHalInteractiveModeEnabled = enable;
        Trace.traceBegin(Trace.TRACE_TAG_POWER, "setHalInteractive(" + enable + ")");
        try {
            nativeSetInteractive(enable);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        }
    }
}
 
Example 8
Source File: TimingsTraceLog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * End tracing previously {@link #traceBegin(String) started} section.
 * Also {@link #logDuration logs} the duration.
 */
public void traceEnd() {
    assertSameThread();
    Trace.traceEnd(mTraceTag);
    if (!DEBUG_BOOT_TIME) {
        return;
    }
    if (mStartTimes.peek() == null) {
        Slog.w(mTag, "traceEnd called more times than traceBegin");
        return;
    }
    Pair<String, Long> event = mStartTimes.pop();
    logDuration(event.first, (SystemClock.elapsedRealtime() - event.second));
}
 
Example 9
Source File: StopActivityItem.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(ClientTransactionHandler client, IBinder token,
        PendingTransactionActions pendingActions) {
    Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
    client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions,
            true /* finalStateRequest */, "STOP_ACTIVITY_ITEM");
    Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}
 
Example 10
Source File: DisplayContent.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Updates the layer assignment of windows on this display. */
void assignWindowLayers(boolean setLayoutNeeded) {
    Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
    assignChildLayers(getPendingTransaction());
    if (setLayoutNeeded) {
        setLayoutNeeded();
    }

    // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
    // the application of this transaction until the animation pass triggers
    // prepareSurfaces. This allows us to synchronize Z-ordering changes with
    // the hiding and showing of surfaces.
    scheduleAnimation();
    Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 12
Source File: LoadedApk.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public final Runnable getRunnable() {
    return () -> {
        final BroadcastReceiver receiver = mReceiver;
        final boolean ordered = mOrdered;

        if (ActivityThread.DEBUG_BROADCAST) {
            int seq = mCurIntent.getIntExtra("seq", -1);
            Slog.i(ActivityThread.TAG, "Dispatching broadcast " + mCurIntent.getAction()
                    + " seq=" + seq + " to " + mReceiver);
            Slog.i(ActivityThread.TAG, "  mRegistered=" + mRegistered
                    + " mOrderedHint=" + ordered);
        }

        final IActivityManager mgr = ActivityManager.getService();
        final Intent intent = mCurIntent;
        if (intent == null) {
            Log.wtf(TAG, "Null intent being dispatched, mDispatched=" + mDispatched
                    + ": run() previously called at "
                    + Log.getStackTraceString(mPreviousRunStacktrace));
        }

        mCurIntent = null;
        mDispatched = true;
        mPreviousRunStacktrace = new Throwable("Previous stacktrace");
        if (receiver == null || intent == null || mForgotten) {
            if (mRegistered && ordered) {
                if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG,
                        "Finishing null broadcast to " + mReceiver);
                sendFinished(mgr);
            }
            return;
        }

        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveReg");
        try {
            ClassLoader cl = mReceiver.getClass().getClassLoader();
            intent.setExtrasClassLoader(cl);
            intent.prepareToEnterProcess();
            setExtrasClassLoader(cl);
            receiver.setPendingResult(this);
            receiver.onReceive(mContext, intent);
        } catch (Exception e) {
            if (mRegistered && ordered) {
                if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG,
                        "Finishing failed broadcast to " + mReceiver);
                sendFinished(mgr);
            }
            if (mInstrumentation == null ||
                    !mInstrumentation.onException(mReceiver, e)) {
                Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                throw new RuntimeException(
                        "Error receiving broadcast " + intent
                                + " in " + mReceiver, e);
            }
        }

        if (receiver.getPendingResult() != null) {
            finish();
        }
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    };
}
 
Example 13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@UnsupportedAppUsage
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, null);

    // 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;
}
 
Example 14
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the global power state based on dirty bits recorded in mDirty.
 *
 * This is the main function that performs power state transitions.
 * We centralize them here so that we can recompute the power state completely
 * each time something important changes, and ensure that we do it the same
 * way each time.  The point is to gather all of the transition logic here.
 */
private void updatePowerStateLocked() {
    if (!mSystemReady || mDirty == 0) {
        return;
    }
    if (!Thread.holdsLock(mLock)) {
        Slog.wtf(TAG, "Power manager lock was not held when calling updatePowerStateLocked");
    }

    Trace.traceBegin(Trace.TRACE_TAG_POWER, "updatePowerState");
    try {
        // Phase 0: Basic state updates.
        updateIsPoweredLocked(mDirty);
        updateStayOnLocked(mDirty);
        updateScreenBrightnessBoostLocked(mDirty);

        // Phase 1: Update wakefulness.
        // Loop because the wake lock and user activity computations are influenced
        // by changes in wakefulness.
        final long now = SystemClock.uptimeMillis();
        int dirtyPhase2 = 0;
        for (;;) {
            int dirtyPhase1 = mDirty;
            dirtyPhase2 |= dirtyPhase1;
            mDirty = 0;

            updateWakeLockSummaryLocked(dirtyPhase1);
            updateUserActivitySummaryLocked(now, dirtyPhase1);
            if (!updateWakefulnessLocked(dirtyPhase1)) {
                break;
            }
        }

        // Phase 2: Lock profiles that became inactive/not kept awake.
        updateProfilesLocked(now);

        // Phase 3: Update display power state.
        final boolean displayBecameReady = updateDisplayPowerStateLocked(dirtyPhase2);

        // Phase 4: Update dream state (depends on display ready signal).
        updateDreamLocked(dirtyPhase2, displayBecameReady);

        // Phase 5: Send notifications, if needed.
        finishWakefulnessChangeIfNeededLocked();

        // Phase 6: Update suspend blocker.
        // Because we might release the last suspend blocker here, we need to make sure
        // we finished everything else first!
        updateSuspendBlockerLocked();
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_POWER);
    }
}
 
Example 15
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 16
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 17
Source File: WebViewFactory.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static Context getWebViewContextAndSetProvider() throws MissingWebViewPackageException {
    Application initialApplication = AppGlobals.getInitialApplication();
    try {
        WebViewProviderResponse response = null;
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW,
                "WebViewUpdateService.waitForAndGetProvider()");
        try {
            response = getUpdateService().waitForAndGetProvider();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
        if (response.status != LIBLOAD_SUCCESS
                && response.status != LIBLOAD_FAILED_WAITING_FOR_RELRO) {
            throw new MissingWebViewPackageException("Failed to load WebView provider: "
                    + getWebViewPreparationErrorReason(response.status));
        }
        // Register to be killed before fetching package info - so that we will be
        // killed if the package info goes out-of-date.
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "ActivityManager.addPackageDependency()");
        try {
            ActivityManager.getService().addPackageDependency(
                    response.packageInfo.packageName);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
        // Fetch package info and verify it against the chosen package
        PackageInfo newPackageInfo = null;
        PackageManager pm = initialApplication.getPackageManager();
        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "PackageManager.getPackageInfo()");
        try {
            newPackageInfo = pm.getPackageInfo(
                response.packageInfo.packageName,
                PackageManager.GET_SHARED_LIBRARY_FILES
                | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
                // Make sure that we fetch the current provider even if its not
                // installed for the current user
                | PackageManager.MATCH_UNINSTALLED_PACKAGES
                // Fetch signatures for verification
                | PackageManager.GET_SIGNATURES
                // Get meta-data for meta data flag verification
                | PackageManager.GET_META_DATA);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }

        // Validate the newly fetched package info, throws MissingWebViewPackageException on
        // failure
        verifyPackageInfo(response.packageInfo, newPackageInfo);

        ApplicationInfo ai = newPackageInfo.applicationInfo;
        fixupStubApplicationInfo(ai, pm);

        Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW,
                "initialApplication.createApplicationContext");
        try {
            // Construct an app context to load the Java code into the current app.
            Context webViewContext = initialApplication.createApplicationContext(
                    ai,
                    Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            sPackageInfo = newPackageInfo;
            return webViewContext;
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
        }
    } catch (RemoteException | PackageManager.NameNotFoundException e) {
        throw new MissingWebViewPackageException("Failed to load WebView provider: " + e);
    }
}
 
Example 18
Source File: WindowStateAnimator.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Choose the correct animation and set it to the passed WindowState.
 * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
 *      then the animation will be app_starting_exit. Any other value loads the animation from
 *      the switch statement below.
 * @param isEntrance The animation type the last time this was called. Used to keep from
 *      loading the same animation twice.
 * @return true if an animation has been loaded.
 */
boolean applyAnimationLocked(int transit, boolean isEntrance) {
    if (mWin.isSelfAnimating() && mAnimationIsEntrance == isEntrance) {
        // If we are trying to apply an animation, but already running
        // an animation of the same type, then just leave that one alone.
        return true;
    }

    if (isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
        mWin.getDisplayContent().adjustForImeIfNeeded();
        mWin.setDisplayLayoutNeeded();
        mService.mWindowPlacerLocked.requestTraversal();
    }

    // Only apply an animation if the display isn't frozen.  If it is
    // frozen, there is no reason to animate and it can cause strange
    // artifacts when we unfreeze the display if some different animation
    // is running.
    Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "WSA#applyAnimationLocked");
    if (mWin.mToken.okToAnimate()) {
        int anim = mPolicy.selectAnimationLw(mWin, transit);
        int attr = -1;
        Animation a = null;
        if (anim != 0) {
            a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
        } else {
            switch (transit) {
                case WindowManagerPolicy.TRANSIT_ENTER:
                    attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
                    break;
                case WindowManagerPolicy.TRANSIT_EXIT:
                    attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
                    break;
                case WindowManagerPolicy.TRANSIT_SHOW:
                    attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
                    break;
                case WindowManagerPolicy.TRANSIT_HIDE:
                    attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
                    break;
            }
            if (attr >= 0) {
                a = mService.mAppTransition.loadAnimationAttr(mWin.mAttrs, attr, TRANSIT_NONE);
            }
        }
        if (DEBUG_ANIM) Slog.v(TAG,
                "applyAnimation: win=" + this
                + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
                + " a=" + a
                + " transit=" + transit
                + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
        if (a != null) {
            if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
            mWin.startAnimation(a);
            mAnimationIsEntrance = isEntrance;
        }
    } else {
        mWin.cancelAnimation();
    }

    if (!isEntrance && mWin.mAttrs.type == TYPE_INPUT_METHOD) {
        mWin.getDisplayContent().adjustForImeIfNeeded();
    }

    Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
    return isAnimationSet();
}
 
Example 19
Source File: AppWindowToken.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
        boolean isVoiceInteraction) {

    if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
        if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
            Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
                    + " atoken=" + this);
        }
        cancelAnimation();
        return false;
    }

    // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
    // to animate and it can cause strange artifacts when we unfreeze the display if some
    // different animation is running.
    Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
    if (okToAnimate()) {
        final AnimationAdapter adapter;
        final TaskStack stack = getStack();
        mTmpPoint.set(0, 0);
        mTmpRect.setEmpty();
        if (stack != null) {
            stack.getRelativePosition(mTmpPoint);
            stack.getBounds(mTmpRect);
            mTmpRect.offsetTo(0, 0);
        }

        // Delaying animation start isn't compatible with remote animations at all.
        if (mService.mAppTransition.getRemoteAnimationController() != null
                && !mSurfaceAnimator.isAnimationStartDelayed()) {
            adapter = mService.mAppTransition.getRemoteAnimationController()
                    .createAnimationAdapter(this, mTmpPoint, mTmpRect);
        } else {
            final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
            if (a != null) {
                adapter = new LocalAnimationAdapter(
                        new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
                                mService.mAppTransition.canSkipFirstFrame(),
                                mService.mAppTransition.getAppStackClipMode(),
                                true /* isAppAnimation */),
                        mService.mSurfaceAnimationRunner);
                if (a.getZAdjustment() == Animation.ZORDER_TOP) {
                    mNeedsZBoost = true;
                }
                mTransit = transit;
                mTransitFlags = mService.mAppTransition.getTransitFlags();
            } else {
                adapter = null;
            }
        }
        if (adapter != null) {
            startAnimation(getPendingTransaction(), adapter, !isVisible());
            if (adapter.getShowWallpaper()) {
                mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
            }
        }
    } else {
        cancelAnimation();
    }
    Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);

    return isReallyAnimating();
}
 
Example 20
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
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;
}