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

Commit c3e8553e authored by William Escande's avatar William Escande
Browse files

Check permission even on parcelable class

The over-use of parcelable in Bluetooth has a side effect with the
current version of the checker that is intended to ignore those.

By removing the parcelable exemption, I hope to increase developer
awarness on what permission should be enforced on Bluetooth API

Bug: 425449326
Test: m .
Flag: EXEMPT errorprone update
Change-Id: Icff66da70ed610a068604b79a463bf2a614380cc
parent 5a480c2d
Loading
Loading
Loading
Loading
+4 −22
Original line number Diff line number Diff line
@@ -43,10 +43,7 @@ import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.matchers.MethodVisibility.Visibility;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;

@@ -69,13 +66,10 @@ public final class BluetoothPermissionChecker extends BugChecker implements Meth
            methodHasVisibility(Visibility.PUBLIC),
            not(isStatic()),
            not(methodIsConstructor()),
            not(enclosingClass(isInsideParcelable())),
            not(enclosingClass(simpleNameMatches(Pattern.compile(".+Callback$")))),
            not(enclosingClass(isSubtypeOf("android.bluetooth.BluetoothProfileConnector"))),
            not(enclosingClass(isSubtypeOf("android.app.PropertyInvalidatedCache"))));

    private static final Matcher<ClassTree> PARCELABLE_CLASS =
            isSubtypeOf("android.os.Parcelable");
    private static final Matcher<MethodTree> BINDER_METHOD = enclosingClass(
            isSubtypeOf("android.os.IInterface"));

@@ -91,6 +85,10 @@ public final class BluetoothPermissionChecker extends BugChecker implements Meth
            methodIsNamed("finalize"),
            methodIsNamed("equals"),
            methodIsNamed("hashCode"),
            methodIsNamed("writeToParcel"),
            methodIsNamed("describeContents"),
            methodIsNamed("createFromParcel"),
            methodIsNamed("newArray"),
            methodIsNamed("toString"));

    private static final String PERMISSION_ADVERTISE = "android.permission.BLUETOOTH_ADVERTISE";
@@ -196,20 +194,4 @@ public final class BluetoothPermissionChecker extends BugChecker implements Meth
    private boolean isSuppressed(SuppressLint anno) {
        return (anno != null) && !Collections.disjoint(Arrays.asList(anno.value()), allNames());
    }

    private static Matcher<ClassTree> isInsideParcelable() {
        return new Matcher<ClassTree>() {
            @Override
            public boolean matches(ClassTree tree, VisitorState state) {
                final TreePath path = state.getPath();
                for (Tree node : path) {
                    if (node instanceof ClassTree
                            && PARCELABLE_CLASS.matches((ClassTree) node, state)) {
                        return true;
                    }
                }
                return false;
            }
        };
    }
}