Commit 6320d83a authored by Clark DuVall's avatar Clark DuVall Committed by Chromium LUCI CQ

Fix dex verification error in WebLayer.java

The attribution methods are only available in R, so add a ApiHelperForR
class to access them.

Bug: 1085041
Change-Id: Ief6957ad59cd499111c96a7a171eb2dca8e3d609
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570034Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833335}
parent 922af70e
......@@ -99,6 +99,7 @@ android_library("java") {
"org/chromium/weblayer/UrlBarOptions.java",
"org/chromium/weblayer/UserIdentityCallback.java",
"org/chromium/weblayer/VerifiesOnO.java",
"org/chromium/weblayer/VerifiesOnR.java",
"org/chromium/weblayer/WebLayer.java",
"org/chromium/weblayer/WebLayerFileProvider.java",
"org/chromium/weblayer/WebMessage.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.weblayer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The annotated method or class verifies on R, but not below.
*
* The annotated method (or methods on the annotated class) are guaranteed to not be inlined by R8
* on builds targeted below R. This prevents class verification errors (which results in a very slow
* retry-verification-at-runtime) from spreading into other classes on these lower versions.
*
* Note: this is the WebLayer client library version of the annotation from
* org.chromium.base.annotations.
*/
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.CLASS)
/* package */ @interface VerifiesOnR {}
......@@ -273,11 +273,12 @@ public class WebLayer {
// Use the application context as the supplied context may have a shorter lifetime.
mContext = context.getApplicationContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& context.getAttributionTag() != null) {
&& ApiHelperForR.getAttributionTag(context) != null) {
// Getting the application context means we lose any attribution. Use the
// attribution tag from the supplied context so that embedders have a way to set an
// attribution tag.
mContext = mContext.createAttributionContext(context.getAttributionTag());
mContext = ApiHelperForR.createAttributionContext(
mContext, ApiHelperForR.getAttributionTag(context));
}
try {
ClassLoader classLoader = getOrCreateRemoteClassLoader(mContext);
......@@ -835,4 +836,18 @@ public class WebLayer {
}
}
}
@VerifiesOnR
@TargetApi(Build.VERSION_CODES.R)
private static final class ApiHelperForR {
/** See {@link Context.getAttributionTag() }. */
public static String getAttributionTag(Context context) {
return context.getAttributionTag();
}
/** See {@link Context.createAttributionContext(String) }. */
public static Context createAttributionContext(Context context, String tag) {
return context.createAttributionContext(tag);
}
}
}
......@@ -12,3 +12,14 @@
-keepclassmembers,allowobfuscation class ** {
@org.chromium.weblayer.VerifiesOnO <methods>;
}
-keep @interface org.chromium.weblayer.VerifiesOnR
-if @org.chromium.weblayer.VerifiesOnR class * {
*** *(...);
}
-keep,allowobfuscation class <1> {
*** <2>(...);
}
-keepclassmembers,allowobfuscation class ** {
@org.chromium.weblayer.VerifiesOnR <methods>;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment