Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9ab0176 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I3bc46f80,Ic3126518

* changes:
  Upgrade AndroidFrameworkUid to be fatal error.
  Refine CompatChanges check and enable as error.
parents c307591a 9af4aea0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -598,6 +598,12 @@ java_library {
        "//frameworks/base/apex/jobscheduler/framework",
        "//frameworks/base/packages/Tethering/tests/unit",
    ],
    errorprone: {
        javacflags: [
            "-Xep:AndroidFrameworkCompatChange:ERROR",
            "-Xep:AndroidFrameworkUid:ERROR",
        ],
    },
}

// This "framework" module is NOT installed to the device. It's
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public final class SelectableTargetInfo implements ChooserTargetInfo {

        // Now fetch app icon and raster with no badging even in work profile
        Bitmap appIcon = mSelectableTargetInfoCommunicator.makePresentationGetter(info)
                .getIconBitmap(UserHandle.getUserHandleForUid(UserHandle.myUserId()));
                .getIconBitmap(android.os.Process.myUserHandle());

        // Raster target drawable with appIcon as a badge
        SimpleIconFactory sif = SimpleIconFactory.obtain(mContext);
+21 −5
Original line number Diff line number Diff line
@@ -17,12 +17,13 @@
package com.google.errorprone.bugpatterns.android;

import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.google.errorprone.bugpatterns.android.TargetSdkChecker.binaryTreeExact;
import static com.google.errorprone.matchers.FieldMatchers.anyFieldInClass;
import static com.google.errorprone.matchers.FieldMatchers.staticField;
import static com.google.errorprone.matchers.Matchers.allOf;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.anything;
import static com.google.errorprone.matchers.Matchers.binaryTree;
import static com.google.errorprone.matchers.Matchers.kindIs;
import static com.google.errorprone.matchers.Matchers.not;

import com.google.auto.service.AutoService;
@@ -34,6 +35,7 @@ import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.sun.source.tree.BinaryTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.Tree.Kind;

/**
 * Each SDK level often has dozens of different behavior changes, which can be
@@ -85,14 +87,28 @@ public final class CompatChangeChecker extends BugChecker implements BinaryTreeM
            staticField("android.os.Build.VERSION_CODES", "O"),
            staticField("android.os.Build.VERSION_CODES", "O_MR1"),
            staticField("android.os.Build.VERSION_CODES", "P"),
            staticField("android.os.Build.VERSION_CODES", "Q"));
            staticField("android.os.Build.VERSION_CODES", "Q"),
            staticField("android.os.Build.VERSION_CODES", "R"));

    private static final Matcher<ExpressionTree> R_VERSION_CODE =
            staticField("android.os.Build.VERSION_CODES", "R");

    private static final Matcher<ExpressionTree> CUR_DEVELOPMENT_VERSION_CODE =
            staticField("android.os.Build.VERSION_CODES", "CUR_DEVELOPMENT");

    private static final Matcher<ExpressionTree> MODERN_VERSION_CODE =
            allOf(VERSION_CODE, not(LEGACY_VERSION_CODE));
            allOf(VERSION_CODE, not(LEGACY_VERSION_CODE), not(CUR_DEVELOPMENT_VERSION_CODE));

    private static final Matcher<ExpressionTree> BOOLEAN_OPERATOR = anyOf(
            kindIs(Kind.LESS_THAN), kindIs(Kind.LESS_THAN_EQUAL),
            kindIs(Kind.GREATER_THAN), kindIs(Kind.GREATER_THAN_EQUAL),
            kindIs(Kind.EQUAL_TO), kindIs(Kind.NOT_EQUAL_TO));

    private static final Matcher<BinaryTree> INVALID = anyOf(
            binaryTree(MODERN_VERSION_CODE, anything()),
            binaryTree(anything(), MODERN_VERSION_CODE));
            allOf(BOOLEAN_OPERATOR, binaryTreeExact(MODERN_VERSION_CODE, anything())),
            allOf(BOOLEAN_OPERATOR, binaryTreeExact(anything(), MODERN_VERSION_CODE)),
            allOf(kindIs(Kind.GREATER_THAN), binaryTreeExact(anything(), R_VERSION_CODE)),
            allOf(kindIs(Kind.LESS_THAN), binaryTreeExact(R_VERSION_CODE, anything())));

    @Override
    public Description matchBinary(BinaryTree tree, VisitorState state) {
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public final class TargetSdkChecker extends BugChecker implements BinaryTreeMatc
        return Description.NO_MATCH;
    }

    private static Matcher<BinaryTree> binaryTreeExact(Matcher<ExpressionTree> left,
    static Matcher<BinaryTree> binaryTreeExact(Matcher<ExpressionTree> left,
            Matcher<ExpressionTree> right) {
        return new Matcher<BinaryTree>() {
            @Override
+22 −9
Original line number Diff line number Diff line
@@ -42,17 +42,17 @@ public class CompatChangeCheckerTest {
                        "public class Example {",
                        "  void test(int targetSdkVersion) {",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion < Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion < Build.VERSION_CODES.S) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion <= Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion <= Build.VERSION_CODES.S) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion > Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion > Build.VERSION_CODES.S) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion >= Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion >= Build.VERSION_CODES.S) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion == Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion == Build.VERSION_CODES.S) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion != Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion != Build.VERSION_CODES.S) { }",
                        "  }",
                        "}")
                .doTest();
@@ -63,18 +63,29 @@ public class CompatChangeCheckerTest {
        compilationHelper
                .addSourceFile("/android/os/Build.java")
                .addSourceLines("Example.java",
                        "import static android.os.Build.VERSION_CODES.R;",
                        "import android.os.Build;",
                        "import static android.os.Build.VERSION_CODES.S;",
                        "public class Example {",
                        "  void test(int targetSdkVersion) {",
                        "    // BUG: Diagnostic contains:",
                        "    boolean indirect = R > targetSdkVersion;",
                        "    boolean indirect = S >= targetSdkVersion;",
                        "    // BUG: Diagnostic contains:",
                        "    if (targetSdkVersion > Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion >= Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion < Build.VERSION_CODES.R) { }",
                        "    if (targetSdkVersion <= Build.VERSION_CODES.R) { }",
                        "    // BUG: Diagnostic contains:",
                        "    if (Build.VERSION_CODES.R < targetSdkVersion) { }",
                        "    if (Build.VERSION_CODES.R <= targetSdkVersion) { }",
                        "    if (Build.VERSION_CODES.R > targetSdkVersion) { }",
                        "    if (Build.VERSION_CODES.R >= targetSdkVersion) { }",
                        "  }",
                        "}")
                .doTest();
    }

    @Test
    public void testLegacyIgnored() {
    public void testIgnored() {
        compilationHelper
                .addSourceFile("/android/os/Build.java")
                .addSourceLines("Example.java",
@@ -82,6 +93,8 @@ public class CompatChangeCheckerTest {
                        "public class Example {",
                        "  void test(int targetSdkVersion) {",
                        "    if (targetSdkVersion < Build.VERSION_CODES.DONUT) { }",
                        "    String result = \"test\" + Build.VERSION_CODES.S;",
                        "    if (targetSdkVersion != Build.VERSION_CODES.CUR_DEVELOPMENT) { }",
                        "  }",
                        "}")
                .doTest();
Loading