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

Commit 020ccc41 authored by Azhara Assanova's avatar Azhara Assanova Committed by Matt Gilbride
Browse files

Remove errorprone BinderIdentityTokenChecker

The checks in BinderIdentityTokenChecker are implemented in
AndroidFrameworkLintChecker in frameworks/base/tools/lint.

Bug: 157626959
Test: atest error_prone_android_framework_test
Test: m framework-minus-apex
Change-Id: Iac9128dbc7e915a12080e41a66d19f9390e4b58a
parent c16d400f
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -406,10 +406,18 @@ java_library {
    lint: {
        extra_check_modules: ["AndroidFrameworkLintChecker"],
        disabled_checks: ["ApiMightLeakAppVisibility"],
        error_checks: [
            "ClearIdentityCallNotFollowedByTryFinally",
            "NestedClearCallingIdentityCalls",
            "NonFinalTokenOfOriginalCallingIdentity",
            "RestoreIdentityCallNotInFinallyBlock",
            "ResultOfClearIdentityCallNotStoredInVariable",
            "UnusedTokenOfOriginalCallingIdentity",
            "UseOfCallerAwareMethodsWithClearedIdentity",
        ],
    },
    errorprone: {
        javacflags: [
            "-Xep:AndroidFrameworkBinderIdentity:ERROR",
            "-Xep:AndroidFrameworkCompatChange:ERROR",
            "-Xep:AndroidFrameworkUid:ERROR",
        ],
+1 −1
Original line number Diff line number Diff line
@@ -1117,7 +1117,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
     *         calling identity by passing it to
     *         {@link #restoreCallingIdentity}.
     */
    @SuppressWarnings("AndroidFrameworkBinderIdentity")
    @SuppressWarnings("ResultOfClearIdentityCallNotStoredInVariable")
    public final @NonNull CallingIdentity clearCallingIdentity() {
        return new CallingIdentity(Binder.clearCallingIdentity(),
                setCallingAttributionSource(null));
+5 −2
Original line number Diff line number Diff line
@@ -155,7 +155,8 @@ public final class Looper {
    /**
     * Poll and deliver single message, return true if the outer loop should continue.
     */
    @SuppressWarnings("AndroidFrameworkBinderIdentity")
    @SuppressWarnings({"UnusedTokenOfOriginalCallingIdentity",
            "ClearIdentityCallNotFollowedByTryFinally"})
    private static boolean loopOnce(final Looper me,
            final long ident, final int thresholdOverride) {
        Message msg = me.mQueue.next(); // might block
@@ -256,7 +257,9 @@ public final class Looper {
     * Run the message queue in this thread. Be sure to call
     * {@link #quit()} to end the loop.
     */
    @SuppressWarnings("AndroidFrameworkBinderIdentity")
    @SuppressWarnings({"UnusedTokenOfOriginalCallingIdentity",
            "ClearIdentityCallNotFollowedByTryFinally",
            "ResultOfClearIdentityCallNotStoredInVariable"})
    public static void loop() {
        final Looper me = myLooper();
        if (me == null) {
+0 −111
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 com.google.errorprone.bugpatterns.android;

import com.google.errorprone.CompilationTestHelper;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class BinderIdentityCheckerTest {
    private CompilationTestHelper compilationHelper;

    @Before
    public void setUp() {
        compilationHelper = CompilationTestHelper.newInstance(
                BinderIdentityChecker.class, getClass());
    }

    @Test
    public void testValid() {
        compilationHelper
                .addSourceFile("/android/os/Binder.java")
                .addSourceLines("FooService.java",
                        "import android.os.Binder;",
                        "public class FooService {",
                        "  void bar() {",
                        "    final long token = Binder.clearCallingIdentity();",
                        "    try {",
                        "      FooService.class.toString();",
                        "    } finally {",
                        "      Binder.restoreCallingIdentity(token);",
                        "    }",
                        "  }",
                        "}")
                .doTest();
    }

    @Test
    public void testInvalid() {
        compilationHelper
                .addSourceFile("/android/os/Binder.java")
                .addSourceLines("FooService.java",
                        "import android.os.Binder;",
                        "public class FooService {",
                        "  void noRestore() {",
                        "    // BUG: Diagnostic contains:",
                        "    final long token = Binder.clearCallingIdentity();",
                        "    FooService.class.toString();",
                        "  }",
                        "  void noTry() {",
                        "    // BUG: Diagnostic contains:",
                        "    final long token = Binder.clearCallingIdentity();",
                        "    FooService.class.toString();",
                        "    Binder.restoreCallingIdentity(token);",
                        "  }",
                        "  void noImmediateTry() {",
                        "    // BUG: Diagnostic contains:",
                        "    final long token = Binder.clearCallingIdentity();",
                        "    FooService.class.toString();",
                        "    try {",
                        "      FooService.class.toString();",
                        "    } finally {",
                        "      Binder.restoreCallingIdentity(token);",
                        "    }",
                        "  }",
                        "  void noFinally() {",
                        "    // BUG: Diagnostic contains:",
                        "    final long token = Binder.clearCallingIdentity();",
                        "    try {",
                        "      FooService.class.toString();",
                        "    } catch (Exception ignored) { }",
                        "  }",
                        "  void noFinal() {",
                        "    // BUG: Diagnostic contains:",
                        "    long token = Binder.clearCallingIdentity();",
                        "    try {",
                        "      FooService.class.toString();",
                        "    } finally {",
                        "      Binder.restoreCallingIdentity(token);",
                        "    }",
                        "  }",
                        "  void noRecording() {",
                        "    // BUG: Diagnostic contains:",
                        "    Binder.clearCallingIdentity();",
                        "    FooService.class.toString();",
                        "  }",
                        "  void noWork() {",
                        "    // BUG: Diagnostic contains:",
                        "    final long token = Binder.clearCallingIdentity();",
                        "  }",
                        "}")
                .doTest();
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -47,13 +47,12 @@ public class ClearCallingIdentityContext implements SafeCloseable {
        return new ClearCallingIdentityContext();
    }

    @SuppressWarnings("AndroidFrameworkBinderIdentity")
    @SuppressWarnings("ResultOfClearIdentityCallNotStoredInVariable")
    private ClearCallingIdentityContext() {
        mRestoreKey = Binder.clearCallingIdentity();
    }

    @Override
    @SuppressWarnings("AndroidFrameworkBinderIdentity")
    public void close() {
        Binder.restoreCallingIdentity(mRestoreKey);
    }
Loading