forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use -identifiernamestring for split compat implementation classes
This change adds a @IdentifierNameString annotation to use the -identifiernamestring R8 rule. There are a few limitations to this: - -identifiernamestring only obfuscates the string, it does not actually check that the class exists. - If a field has the annotation, it must be non-final, otherwise javac will inline the constant and R8 won't obfuscate it. - Any field/method must be assigned/called with a String literal, otherwise R8 won't obfuscate the string and there will be issues at runtime. Due to these limitations, I ended up adding a getIdentifierName() method to SplitCompatUtils which returns the obfuscated name of implementation classes for split compat. I also added a PRESUBMIT check to enforce that only string literals are passed to that method. There can be cases where R8 will not fail, but a string variable is silently ignored if it is not a String literal. Bug: 1126301 Change-Id: Ie5216e6a81cdbca71cc117460704ea4d9122fc78 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451388 Commit-Queue: Clark DuVall <cduvall@chromium.org> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/master@{#814212}
- Loading branch information
1 parent
50016ad
commit de297eb
Showing
18 changed files
with
153 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
base/android/java/src/org/chromium/base/annotations/IdentifierNameString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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.base.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation used to mark field that may contain Strings referring to fully qualified class names | ||
* and methods whose arguments may be fully qualified class names. These classes may then be | ||
* obfuscated by R8. A couple caveats when using this: | ||
* - This only obfuscates the string, it does not actually check that the class exists. | ||
* - If a field has this annotation, it must be non-final, otherwise javac will inline the constant | ||
* and R8 won't obfuscate it. | ||
* - Any field/method must be assigned/called with a String literal or a variable R8 can easily | ||
* trace to a String literal. | ||
* | ||
* <p>Usage example:<br> | ||
* {@code | ||
* @IdentifierNameString | ||
* public static final String LOGGING_TAG = "com.google.android.apps.foo.FooActivity"; | ||
* | ||
* // In this example, both className and message are treated as identifier name strings, but will | ||
* // only be obfuscated if the string points to a real class. | ||
* @IdentifierNameString | ||
* public void doSomeLogging(String className, String message) { ... } | ||
* } | ||
*/ | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.CLASS) | ||
public @interface IdentifierNameString {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.