Replace withCleanCallingIdentity with [clear|restore]CallingIdentity

To prevent using @hide method - withCleanCallingIdentity() from
mainline module, use clearCallingIdentity() &
restoreCallingIdentity() instead.

Bug: 172183305
Test: FrameworksNetTests, CtsNetTestCasesLatestSdk
Change-Id: Iccd492741a0a5b1c2531fc5fc1378933b65ae038
This commit is contained in:
lucaslin
2020-12-30 11:54:55 +08:00
parent 67f888738b
commit be80138c19
3 changed files with 78 additions and 41 deletions

View File

@@ -623,32 +623,41 @@ public class ConnectivityDiagnosticsManager {
/** @hide */ /** @hide */
@VisibleForTesting @VisibleForTesting
public void onConnectivityReportAvailable(@NonNull ConnectivityReport report) { public void onConnectivityReportAvailable(@NonNull ConnectivityReport report) {
Binder.withCleanCallingIdentity(() -> { final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mCb.onConnectivityReportAvailable(report); mCb.onConnectivityReportAvailable(report);
}); });
}); } finally {
Binder.restoreCallingIdentity(token);
}
} }
/** @hide */ /** @hide */
@VisibleForTesting @VisibleForTesting
public void onDataStallSuspected(@NonNull DataStallReport report) { public void onDataStallSuspected(@NonNull DataStallReport report) {
Binder.withCleanCallingIdentity(() -> { final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mCb.onDataStallSuspected(report); mCb.onDataStallSuspected(report);
}); });
}); } finally {
Binder.restoreCallingIdentity(token);
}
} }
/** @hide */ /** @hide */
@VisibleForTesting @VisibleForTesting
public void onNetworkConnectivityReported( public void onNetworkConnectivityReported(
@NonNull Network network, boolean hasConnectivity) { @NonNull Network network, boolean hasConnectivity) {
Binder.withCleanCallingIdentity(() -> { final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mCb.onNetworkConnectivityReported(network, hasConnectivity); mCb.onNetworkConnectivityReported(network, hasConnectivity);
}); });
}); } finally {
Binder.restoreCallingIdentity(token);
}
} }
} }

View File

@@ -1832,30 +1832,42 @@ public class ConnectivityManager {
mCallback = new ISocketKeepaliveCallback.Stub() { mCallback = new ISocketKeepaliveCallback.Stub() {
@Override @Override
public void onStarted(int slot) { public void onStarted(int slot) {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mSlot = slot; mSlot = slot;
callback.onStarted(); callback.onStarted();
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
} }
@Override @Override
public void onStopped() { public void onStopped() {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mSlot = null; mSlot = null;
callback.onStopped(); callback.onStopped();
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
mExecutor.shutdown(); mExecutor.shutdown();
} }
@Override @Override
public void onError(int error) { public void onError(int error) {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mSlot = null; mSlot = null;
callback.onError(error); callback.onError(error);
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
mExecutor.shutdown(); mExecutor.shutdown();
} }

View File

@@ -187,38 +187,54 @@ public abstract class SocketKeepalive implements AutoCloseable {
mCallback = new ISocketKeepaliveCallback.Stub() { mCallback = new ISocketKeepaliveCallback.Stub() {
@Override @Override
public void onStarted(int slot) { public void onStarted(int slot) {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> { mExecutor.execute(() -> {
mSlot = slot; mSlot = slot;
callback.onStarted(); callback.onStarted();
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
} }
@Override @Override
public void onStopped() { public void onStopped() {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> { executor.execute(() -> {
mSlot = null; mSlot = null;
callback.onStopped(); callback.onStopped();
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
} }
@Override @Override
public void onError(int error) { public void onError(int error) {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> { executor.execute(() -> {
mSlot = null; mSlot = null;
callback.onError(error); callback.onError(error);
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
} }
@Override @Override
public void onDataReceived() { public void onDataReceived() {
Binder.withCleanCallingIdentity(() -> final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> { executor.execute(() -> {
mSlot = null; mSlot = null;
callback.onDataReceived(); callback.onDataReceived();
})); });
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}; };
} }