public class

UsageTrackerFacilitator

extends java.lang.Object

implements UsageTracker

 java.lang.Object

↳androidx.test.runner.UsageTrackerFacilitator

Gradle dependencies

compile group: 'androidx.test', name: 'runner', version: '1.6.2'

  • groupId: androidx.test
  • artifactId: runner
  • version: 1.6.2

Artifact androidx.test:runner:1.6.2 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:runner com.android.support.test:runner

Androidx class mapping:

androidx.test.runner.UsageTrackerFacilitator android.support.test.runner.UsageTrackerFacilitator

Summary

Constructors
publicUsageTrackerFacilitator(boolean shouldTrackUsage)

publicUsageTrackerFacilitator(RunnerArgs runnerArgs)

Methods
public voidregisterUsageTracker(UsageTracker usageTracker)

public voidsendUsages()

public booleanshouldTrackUsage()

public voidtrackUsage(java.lang.String usage, java.lang.String version)

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

Constructors

public UsageTrackerFacilitator(RunnerArgs runnerArgs)

public UsageTrackerFacilitator(boolean shouldTrackUsage)

Methods

public boolean shouldTrackUsage()

public void registerUsageTracker(UsageTracker usageTracker)

public void trackUsage(java.lang.String usage, java.lang.String version)

public void sendUsages()

Source

/*
 * Copyright (C) 2016 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.test.runner;

import static androidx.test.internal.util.Checks.checkNotNull;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
import androidx.test.internal.runner.RunnerArgs;
import androidx.test.internal.runner.tracker.UsageTracker;
import androidx.test.internal.runner.tracker.UsageTrackerRegistry;

/** @deprecated obsolete and will be removed in the future. */
@Deprecated
public class UsageTrackerFacilitator implements UsageTracker {
  private static final String TAG = "UsageTrackerFacilitator";

  private final boolean shouldTrackUsage;

  /** @hide */
  @RestrictTo(Scope.LIBRARY)
  public UsageTrackerFacilitator(@NonNull RunnerArgs runnerArgs) {
    checkNotNull(runnerArgs, "runnerArgs cannot be null!");

    // If we are being orchestrated, only report for test collection, not subsequent runs.
    if (runnerArgs.orchestratorService != null) {
      shouldTrackUsage = !runnerArgs.disableAnalytics && runnerArgs.listTestsForOrchestrator;
    } else {
      shouldTrackUsage = !runnerArgs.disableAnalytics;
    }
  }

  public UsageTrackerFacilitator(boolean shouldTrackUsage) {
    this.shouldTrackUsage = shouldTrackUsage;
  }

  public boolean shouldTrackUsage() {
    return shouldTrackUsage;
  }

  /** @hide */
  @RestrictTo(Scope.LIBRARY)
  public void registerUsageTracker(@Nullable UsageTracker usageTracker) {
    if (usageTracker != null && shouldTrackUsage()) {
      Log.i(TAG, "Usage tracking enabled");
      UsageTrackerRegistry.registerInstance(usageTracker);
      return;
    }
    // Even though this is the default usage tracker we should not rely on internal
    // implementation details of UsageTrackerRegistry
    Log.i(TAG, "Usage tracking disabled");
    UsageTrackerRegistry.registerInstance(new NoOpUsageTracker());
  }

  @Override
  public void trackUsage(String usage, String version) {
    if (shouldTrackUsage()) {
      UsageTrackerRegistry.getInstance().trackUsage(usage, version);
    }
  }

  @Override
  public void sendUsages() {
    if (shouldTrackUsage()) {
      UsageTrackerRegistry.getInstance().sendUsages();
    }
  }
}