Merge "Fix a possible crash when the listener is null" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-04 13:50:10 +00:00
committed by Android (Google) Code Review
5 changed files with 30 additions and 14 deletions

View File

@@ -30,12 +30,15 @@ public interface OnBlobRetrievedListener {
/** Converts this OnBlobRetrievedListener to a parcelable object */
@NonNull
static IOnBlobRetrievedListener toAIDL(final OnBlobRetrievedListener listener) {
static IOnBlobRetrievedListener toAIDL(@NonNull final OnBlobRetrievedListener listener) {
return new IOnBlobRetrievedListener.Stub() {
@Override
public void onBlobRetrieved(final StatusParcelable statusParcelable, final String l2Key,
final String name, final Blob blob) {
listener.onBlobRetrieved(new Status(statusParcelable), l2Key, name, blob);
// NonNull, but still don't crash the system server if null
if (null != listener) {
listener.onBlobRetrieved(new Status(statusParcelable), l2Key, name, blob);
}
}
};
}

View File

@@ -30,12 +30,15 @@ public interface OnL2KeyResponseListener {
/** Converts this OnL2KeyResponseListener to a parcelable object */
@NonNull
static IOnL2KeyResponseListener toAIDL(final OnL2KeyResponseListener listener) {
static IOnL2KeyResponseListener toAIDL(@NonNull final OnL2KeyResponseListener listener) {
return new IOnL2KeyResponseListener.Stub() {
@Override
public void onL2KeyResponse(final StatusParcelable statusParcelable,
final String l2Key) {
listener.onL2KeyResponse(new Status(statusParcelable), l2Key);
// NonNull, but still don't crash the system server if null
if (null != listener) {
listener.onL2KeyResponse(new Status(statusParcelable), l2Key);
}
}
};
}

View File

@@ -31,15 +31,18 @@ public interface OnNetworkAttributesRetrievedListener {
/** Converts this OnNetworkAttributesRetrievedListener to a parcelable object */
@NonNull
static IOnNetworkAttributesRetrievedListener toAIDL(
final OnNetworkAttributesRetrievedListener listener) {
@NonNull final OnNetworkAttributesRetrievedListener listener) {
return new IOnNetworkAttributesRetrievedListener.Stub() {
@Override
public void onNetworkAttributesRetrieved(final StatusParcelable statusParcelable,
final String l2Key,
final NetworkAttributesParcelable networkAttributesParcelable) {
listener.onNetworkAttributesRetrieved(
new Status(statusParcelable), l2Key,
new NetworkAttributes(networkAttributesParcelable));
// NonNull, but still don't crash the system server if null
if (null != listener) {
listener.onNetworkAttributesRetrieved(
new Status(statusParcelable), l2Key,
new NetworkAttributes(networkAttributesParcelable));
}
}
};
}

View File

@@ -30,14 +30,18 @@ public interface OnSameL3NetworkResponseListener {
/** Converts this OnSameL3NetworkResponseListener to a parcelable object */
@NonNull
static IOnSameL3NetworkResponseListener toAIDL(final OnSameL3NetworkResponseListener listener) {
static IOnSameL3NetworkResponseListener toAIDL(
@NonNull final OnSameL3NetworkResponseListener listener) {
return new IOnSameL3NetworkResponseListener.Stub() {
@Override
public void onSameL3NetworkResponse(final StatusParcelable statusParcelable,
final SameL3NetworkResponseParcelable sameL3NetworkResponseParcelable) {
listener.onSameL3NetworkResponse(
new Status(statusParcelable),
new SameL3NetworkResponse(sameL3NetworkResponseParcelable));
// NonNull, but still don't crash the system server if null
if (null != listener) {
listener.onSameL3NetworkResponse(
new Status(statusParcelable),
new SameL3NetworkResponse(sameL3NetworkResponseParcelable));
}
}
};
}

View File

@@ -17,6 +17,7 @@
package android.net.ipmemorystore;
import android.annotation.NonNull;
import android.annotation.Nullable;
/**
* A listener for the IpMemoryStore to return a status to a client.
@@ -30,11 +31,13 @@ public interface OnStatusListener {
/** Converts this OnStatusListener to a parcelable object */
@NonNull
static IOnStatusListener toAIDL(final OnStatusListener listener) {
static IOnStatusListener toAIDL(@Nullable final OnStatusListener listener) {
return new IOnStatusListener.Stub() {
@Override
public void onComplete(final StatusParcelable statusParcelable) {
listener.onComplete(new Status(statusParcelable));
if (null != listener) {
listener.onComplete(new Status(statusParcelable));
}
}
};
}