Remove obsolete SDK_INT codepaths in tracing
Test: gw :tracing:tracing:build :tracing:tracing:conCh
Change-Id: Icae7027d7af5a17a4d178dd7cb1fe0d6c98849b9
diff --git a/tracing/tracing/lint-baseline.xml b/tracing/tracing/lint-baseline.xml
deleted file mode 100644
index 0391a7b..0000000
--- a/tracing/tracing/lint-baseline.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<issues format="6" by="lint 8.3.0-alpha04" type="baseline" client="gradle" dependencies="false" name="AGP (8.3.0-alpha04)" variant="all" version="8.3.0-alpha04">
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18 && Build.VERSION.SDK_INT < 31) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 19"
- errorLine1=" if (Build.VERSION.SDK_INT >= 18) {"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/Trace.java"/>
- </issue>
-
- <issue
- id="ObsoleteSdkInt"
- message="Unnecessary; SDK_INT is always >= 18"
- errorLine1="@RequiresApi(18)"
- errorLine2="~~~~~~~~~~~~~~~~">
- <location
- file="src/main/java/androidx/tracing/TraceApi18Impl.java"/>
- </issue>
-
-</issues>
diff --git a/tracing/tracing/src/main/java/androidx/tracing/Trace.java b/tracing/tracing/src/main/java/androidx/tracing/Trace.java
index 9a7dcba..d2eef10 100644
--- a/tracing/tracing/src/main/java/androidx/tracing/Trace.java
+++ b/tracing/tracing/src/main/java/androidx/tracing/Trace.java
@@ -96,7 +96,7 @@
* API 31.
*/
public static void forceEnableAppTracing() {
- if (Build.VERSION.SDK_INT >= 18 && Build.VERSION.SDK_INT < 31) {
+ if (Build.VERSION.SDK_INT < 31) {
try {
if (!sHasAppTracingEnabled) {
sHasAppTracingEnabled = true; // only attempt once
@@ -126,9 +126,7 @@
* @param label The name of the code section to appear in the trace.
*/
public static void beginSection(@NonNull String label) {
- if (Build.VERSION.SDK_INT >= 18) {
- TraceApi18Impl.beginSection(truncatedTraceSectionLabel(label));
- }
+ android.os.Trace.beginSection(truncatedTraceSectionLabel(label));
}
/**
@@ -140,9 +138,7 @@
* called from the same thread.
*/
public static void endSection() {
- if (Build.VERSION.SDK_INT >= 18) {
- TraceApi18Impl.endSection();
- }
+ android.os.Trace.endSection();
}
/**
@@ -215,77 +211,69 @@
}
}
- @SuppressWarnings({"JavaReflectionMemberAccess", "ConstantConditions"})
+ @SuppressWarnings({"JavaReflectionMemberAccess", "BanUncheckedReflection"})
private static boolean isEnabledFallback() {
- if (Build.VERSION.SDK_INT >= 18) {
- try {
- if (sIsTagEnabledMethod == null) {
- Field traceTagAppField = android.os.Trace.class.getField("TRACE_TAG_APP");
- sTraceTagApp = traceTagAppField.getLong(null);
- sIsTagEnabledMethod =
- android.os.Trace.class.getMethod("isTagEnabled", long.class);
- }
- return (boolean) sIsTagEnabledMethod.invoke(null, sTraceTagApp);
- } catch (Exception exception) {
- handleException("isTagEnabled", exception);
+ try {
+ if (sIsTagEnabledMethod == null) {
+ Field traceTagAppField = android.os.Trace.class.getField("TRACE_TAG_APP");
+ sTraceTagApp = traceTagAppField.getLong(null);
+ sIsTagEnabledMethod =
+ android.os.Trace.class.getMethod("isTagEnabled", long.class);
}
+ return (boolean) sIsTagEnabledMethod.invoke(null, sTraceTagApp);
+ } catch (Exception exception) {
+ handleException("isTagEnabled", exception);
}
// Never enabled on < API 18
return false;
}
- @SuppressWarnings("JavaReflectionMemberAccess")
+ @SuppressWarnings({"JavaReflectionMemberAccess", "BanUncheckedReflection"})
private static void beginAsyncSectionFallback(@NonNull String methodName, int cookie) {
- if (Build.VERSION.SDK_INT >= 18) {
- try {
- if (sAsyncTraceBeginMethod == null) {
- sAsyncTraceBeginMethod = android.os.Trace.class.getMethod(
- "asyncTraceBegin",
- long.class,
- String.class, int.class
- );
- }
- sAsyncTraceBeginMethod.invoke(null, sTraceTagApp, methodName, cookie);
- } catch (Exception exception) {
- handleException("asyncTraceBegin", exception);
+ try {
+ if (sAsyncTraceBeginMethod == null) {
+ sAsyncTraceBeginMethod = android.os.Trace.class.getMethod(
+ "asyncTraceBegin",
+ long.class,
+ String.class, int.class
+ );
}
+ sAsyncTraceBeginMethod.invoke(null, sTraceTagApp, methodName, cookie);
+ } catch (Exception exception) {
+ handleException("asyncTraceBegin", exception);
}
}
- @SuppressWarnings("JavaReflectionMemberAccess")
+ @SuppressWarnings({"JavaReflectionMemberAccess", "BanUncheckedReflection"})
private static void endAsyncSectionFallback(@NonNull String methodName, int cookie) {
- if (Build.VERSION.SDK_INT >= 18) {
- try {
- if (sAsyncTraceEndMethod == null) {
- sAsyncTraceEndMethod = android.os.Trace.class.getMethod(
- "asyncTraceEnd",
- long.class,
- String.class, int.class
- );
- }
- sAsyncTraceEndMethod.invoke(null, sTraceTagApp, methodName, cookie);
- } catch (Exception exception) {
- handleException("asyncTraceEnd", exception);
+ try {
+ if (sAsyncTraceEndMethod == null) {
+ sAsyncTraceEndMethod = android.os.Trace.class.getMethod(
+ "asyncTraceEnd",
+ long.class,
+ String.class, int.class
+ );
}
+ sAsyncTraceEndMethod.invoke(null, sTraceTagApp, methodName, cookie);
+ } catch (Exception exception) {
+ handleException("asyncTraceEnd", exception);
}
}
- @SuppressWarnings("JavaReflectionMemberAccess")
+ @SuppressWarnings({"JavaReflectionMemberAccess", "BanUncheckedReflection"})
private static void setCounterFallback(@NonNull String counterName, int counterValue) {
- if (Build.VERSION.SDK_INT >= 18) {
- try {
- if (sTraceCounterMethod == null) {
- sTraceCounterMethod = android.os.Trace.class.getMethod(
- "traceCounter",
- long.class,
- String.class,
- int.class
- );
- }
- sTraceCounterMethod.invoke(null, sTraceTagApp, counterName, counterValue);
- } catch (Exception exception) {
- handleException("traceCounter", exception);
+ try {
+ if (sTraceCounterMethod == null) {
+ sTraceCounterMethod = android.os.Trace.class.getMethod(
+ "traceCounter",
+ long.class,
+ String.class,
+ int.class
+ );
}
+ sTraceCounterMethod.invoke(null, sTraceTagApp, counterName, counterValue);
+ } catch (Exception exception) {
+ handleException("traceCounter", exception);
}
}
diff --git a/tracing/tracing/src/main/java/androidx/tracing/TraceApi18Impl.java b/tracing/tracing/src/main/java/androidx/tracing/TraceApi18Impl.java
deleted file mode 100644
index f70646e..0000000
--- a/tracing/tracing/src/main/java/androidx/tracing/TraceApi18Impl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2020 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.tracing;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
-
-/**
- * This is a helper class that handles {@link android.os.Trace} functionality in API >= 18.
- * <p>
- * This class is being defined separately to avoid class verification failures.
- * For more information read https://chromium.googlesource
- * .com/chromium/src/build/+/refs/heads/master/android/docs/class_verification_failures
- * .md#understanding-the-reason-for-the-failure
- */
-@RequiresApi(18)
-final class TraceApi18Impl {
-
- private TraceApi18Impl() {
- // Does nothing
- }
-
- /**
- * Writes a trace message to indicate that a given section of code has begun. This call must
- * be followed by a corresponding call to {@link #endSection()} on the same thread.
- *
- * <p class="note"> At this time the vertical bar character '|', newline character '\n', and
- * null character '\0' are used internally by the tracing mechanism. If sectionName contains
- * these characters they will be replaced with a space character in the trace.
- *
- * @param label The name of the code section to appear in the trace. This may be at
- * most 127 Unicode code units long.
- */
- public static void beginSection(@NonNull String label) {
- android.os.Trace.beginSection(label);
- }
-
- /**
- * Writes a trace message to indicate that a given section of code has ended. This call must
- * be preceded by a corresponding call to {@link #beginSection(String)}. Calling this method
- * will mark the end of the most recently begun section of code, so care must be taken to
- * ensure that beginSection / endSection pairs are properly nested and called from the same
- * thread.
- */
- public static void endSection() {
- android.os.Trace.endSection();
- }
-}