Add more consistent null checks
This change moves the null check into the service implementation. Since exceptions on oneway binder interfaces are ignored (across process), the code was changed to just return early instead. This also adds a couple of Objects.requireNonNull() assertions in TetheringManager to assert the existing @NonNull annotation. Test: TH Bug: 337167681 Change-Id: I5301ed084bb26c2f910041e9b25314f8181718d1
This commit is contained in:
parent
2d68bc2135
commit
0692aff5c5
3 changed files with 9 additions and 6 deletions
|
|
@ -1353,6 +1353,9 @@ public class TetheringManager {
|
|||
@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
public void registerTetheringEventCallback(@NonNull Executor executor,
|
||||
@NonNull TetheringEventCallback callback) {
|
||||
Objects.requireNonNull(executor);
|
||||
Objects.requireNonNull(callback);
|
||||
|
||||
final String callerPkg = mContext.getOpPackageName();
|
||||
Log.i(TAG, "registerTetheringEventCallback caller:" + callerPkg);
|
||||
|
||||
|
|
@ -1507,6 +1510,8 @@ public class TetheringManager {
|
|||
Manifest.permission.ACCESS_NETWORK_STATE
|
||||
})
|
||||
public void unregisterTetheringEventCallback(@NonNull final TetheringEventCallback callback) {
|
||||
Objects.requireNonNull(callback);
|
||||
|
||||
final String callerPkg = mContext.getOpPackageName();
|
||||
Log.i(TAG, "unregisterTetheringEventCallback caller:" + callerPkg);
|
||||
|
||||
|
|
|
|||
|
|
@ -2400,9 +2400,6 @@ public class Tethering {
|
|||
hasCallingPermission(NETWORK_SETTINGS)
|
||||
|| hasCallingPermission(PERMISSION_MAINLINE_NETWORK_STACK)
|
||||
|| hasCallingPermission(NETWORK_STACK);
|
||||
if (callback == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
mHandler.post(() -> {
|
||||
mTetheringEventCallbacks.register(callback, new CallbackCookie(hasListPermission));
|
||||
final TetheringCallbackStartedParcel parcel = new TetheringCallbackStartedParcel();
|
||||
|
|
@ -2440,9 +2437,6 @@ public class Tethering {
|
|||
|
||||
/** Unregister tethering event callback */
|
||||
void unregisterTetheringEventCallback(ITetheringEventCallback callback) {
|
||||
if (callback == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
mHandler.post(() -> {
|
||||
mTetheringEventCallbacks.unregister(callback);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -163,6 +163,8 @@ public class TetheringService extends Service {
|
|||
@Override
|
||||
public void registerTetheringEventCallback(ITetheringEventCallback callback,
|
||||
String callerPkg) {
|
||||
// Silently ignore call if the callback is null. This can only happen via reflection.
|
||||
if (callback == null) return;
|
||||
try {
|
||||
if (!hasTetherAccessPermission()) {
|
||||
callback.onCallbackStopped(TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION);
|
||||
|
|
@ -175,6 +177,8 @@ public class TetheringService extends Service {
|
|||
@Override
|
||||
public void unregisterTetheringEventCallback(ITetheringEventCallback callback,
|
||||
String callerPkg) {
|
||||
// Silently ignore call if the callback is null. This can only happen via reflection.
|
||||
if (callback == null) return;
|
||||
try {
|
||||
if (!hasTetherAccessPermission()) {
|
||||
callback.onCallbackStopped(TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION);
|
||||
|
|
|
|||
Loading…
Reference in a new issue