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
diff --git a/Android.bp b/Android.bp
index 7db16f6..a828472 100644
--- a/Android.bp
+++ b/Android.bp
@@ -406,10 +406,18 @@
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",
],
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index 5584f45..da486ee 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -1117,7 +1117,7 @@
* calling identity by passing it to
* {@link #restoreCallingIdentity}.
*/
- @SuppressWarnings("AndroidFrameworkBinderIdentity")
+ @SuppressWarnings("ResultOfClearIdentityCallNotStoredInVariable")
public final @NonNull CallingIdentity clearCallingIdentity() {
return new CallingIdentity(Binder.clearCallingIdentity(),
setCallingAttributionSource(null));
diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java
index 8c98362..a529ac6 100644
--- a/core/java/android/os/Looper.java
+++ b/core/java/android/os/Looper.java
@@ -155,7 +155,8 @@
/**
* 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 @@
* 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) {
diff --git a/errorprone/tests/java/com/google/errorprone/bugpatterns/android/BinderIdentityCheckerTest.java b/errorprone/tests/java/com/google/errorprone/bugpatterns/android/BinderIdentityCheckerTest.java
deleted file mode 100644
index 9448344..0000000
--- a/errorprone/tests/java/com/google/errorprone/bugpatterns/android/BinderIdentityCheckerTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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();
- }
-}
diff --git a/media/java/android/media/permission/ClearCallingIdentityContext.java b/media/java/android/media/permission/ClearCallingIdentityContext.java
index 2d58b24..be55e3d 100644
--- a/media/java/android/media/permission/ClearCallingIdentityContext.java
+++ b/media/java/android/media/permission/ClearCallingIdentityContext.java
@@ -47,13 +47,12 @@
return new ClearCallingIdentityContext();
}
- @SuppressWarnings("AndroidFrameworkBinderIdentity")
+ @SuppressWarnings("ResultOfClearIdentityCallNotStoredInVariable")
private ClearCallingIdentityContext() {
mRestoreKey = Binder.clearCallingIdentity();
}
@Override
- @SuppressWarnings("AndroidFrameworkBinderIdentity")
public void close() {
Binder.restoreCallingIdentity(mRestoreKey);
}
diff --git a/services/Android.bp b/services/Android.bp
index 1e4ce19..ca76da6 100644
--- a/services/Android.bp
+++ b/services/Android.bp
@@ -13,7 +13,6 @@
plugins: ["error_prone_android_framework"],
errorprone: {
javacflags: [
- // "-Xep:AndroidFrameworkBinderIdentity:ERROR",
"-Xep:AndroidFrameworkCompatChange:ERROR",
// "-Xep:AndroidFrameworkUid:ERROR",
"-Xep:SelfEquals:ERROR",
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 2f4554f..b2c3ce6 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1551,12 +1551,11 @@
return mContext.getSystemService(UsbManager.class);
}
- @SuppressWarnings("AndroidFrameworkBinderIdentity")
+ @SuppressWarnings("ResultOfClearIdentityCallNotStoredInVariable")
long binderClearCallingIdentity() {
return Binder.clearCallingIdentity();
}
- @SuppressWarnings("AndroidFrameworkBinderIdentity")
void binderRestoreCallingIdentity(long token) {
Binder.restoreCallingIdentity(token);
}