public class

TracingControllerImpl

extends TracingController

 java.lang.Object

androidx.webkit.TracingController

↳androidx.webkit.internal.TracingControllerImpl

Gradle dependencies

compile group: 'androidx.webkit', name: 'webkit', version: '1.12.0-rc01'

  • groupId: androidx.webkit
  • artifactId: webkit
  • version: 1.12.0-rc01

Artifact androidx.webkit:webkit:1.12.0-rc01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.webkit:webkit com.android.support:webkit

Overview

Implementation of TracingController. This class uses either the framework, the WebView APK, or both, to implement TracingController functionality.

Summary

Constructors
publicTracingControllerImpl()

Methods
public abstract booleanisTracing()

Returns whether the WebView framework is tracing.

public abstract voidstart(TracingConfig tracingConfig)

Starts tracing all webviews.

public abstract booleanstop(java.io.OutputStream outputStream, java.util.concurrent.Executor executor)

Stops tracing and flushes tracing data to the specified outputStream.

from TracingControllergetInstance
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TracingControllerImpl()

Methods

public abstract boolean isTracing()

Returns whether the WebView framework is tracing.

Returns:

True if tracing is enabled.

public abstract void start(TracingConfig tracingConfig)

Starts tracing all webviews. Depending on the trace mode in traceConfig specifies how the trace events are recorded.

For tracing modes and the events are recorded using an internal buffer and flushed to the outputStream when TracingController.stop(OutputStream, Executor) is called.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.TRACING_CONTROLLER_BASIC_USAGE.

Parameters:

tracingConfig: Configuration options to use for tracing.

public abstract boolean stop(java.io.OutputStream outputStream, java.util.concurrent.Executor executor)

Stops tracing and flushes tracing data to the specified outputStream. The data is sent to the specified output stream in json format typically in chunks by invoking write. On completion the close method is called.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.TRACING_CONTROLLER_BASIC_USAGE.

Parameters:

outputStream: The output stream the tracing data will be sent to. If null the tracing data will be discarded.
executor: The Executor on which the outputStream write and close methods will be invoked. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use . To dispatch events through a shared thread pool, you can use .

Returns:

false if the WebView framework was not tracing at the time of the call, true otherwise.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.webkit.internal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.webkit.TracingConfig;
import androidx.webkit.TracingController;

import org.chromium.support_lib_boundary.TracingControllerBoundaryInterface;

import java.io.OutputStream;
import java.util.concurrent.Executor;

/**
 * Implementation of {@link TracingController}.
 * This class uses either the framework, the WebView APK, or both, to implement
 * {@link TracingController} functionality.
 */
public class TracingControllerImpl extends TracingController {
    private android.webkit.TracingController mFrameworksImpl;
    private TracingControllerBoundaryInterface mBoundaryInterface;

    public TracingControllerImpl() {
        final ApiFeature.P feature = WebViewFeatureInternal.TRACING_CONTROLLER_BASIC_USAGE;
        if (feature.isSupportedByFramework()) {
            mFrameworksImpl = ApiHelperForP.getTracingControllerInstance();
            mBoundaryInterface = null;
        } else if (feature.isSupportedByWebView()) {
            mFrameworksImpl = null;
            mBoundaryInterface = WebViewGlueCommunicator.getFactory().getTracingController();
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @RequiresApi(28)
    private android.webkit.TracingController getFrameworksImpl() {
        if (mFrameworksImpl == null) {
            mFrameworksImpl = ApiHelperForP.getTracingControllerInstance();
        }
        return mFrameworksImpl;
    }

    private TracingControllerBoundaryInterface getBoundaryInterface() {
        if (mBoundaryInterface == null) {
            mBoundaryInterface = WebViewGlueCommunicator.getFactory().getTracingController();
        }
        return mBoundaryInterface;
    }

    @Override
    public boolean isTracing() {
        final ApiFeature.P feature = WebViewFeatureInternal.TRACING_CONTROLLER_BASIC_USAGE;
        if (feature.isSupportedByFramework()) {
            return ApiHelperForP.isTracing(getFrameworksImpl());
        } else if (feature.isSupportedByWebView()) {
            return getBoundaryInterface().isTracing();
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @Override
    public void start(@NonNull TracingConfig tracingConfig) {
        if (tracingConfig == null) {
            throw new IllegalArgumentException("Tracing config must be non null");
        }

        final ApiFeature.P feature = WebViewFeatureInternal.TRACING_CONTROLLER_BASIC_USAGE;
        if (feature.isSupportedByFramework()) {
            ApiHelperForP.start(getFrameworksImpl(), tracingConfig);
        } else if (feature.isSupportedByWebView()) {
            getBoundaryInterface().start(tracingConfig.getPredefinedCategories(),
                    tracingConfig.getCustomIncludedCategories(), tracingConfig.getTracingMode());
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @Override
    public boolean stop(@Nullable OutputStream outputStream, @NonNull Executor executor) {
        final ApiFeature.P feature = WebViewFeatureInternal.TRACING_CONTROLLER_BASIC_USAGE;
        if (feature.isSupportedByFramework()) {
            return ApiHelperForP.stop(getFrameworksImpl(), outputStream, executor);
        } else if (feature.isSupportedByWebView()) {
            return getBoundaryInterface().stop(outputStream, executor);
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }
}