Merge "Check success before registering DeathRecipient"

This commit is contained in:
Hall Liu
2017-10-20 23:10:09 +00:00
committed by Gerrit Code Review
2 changed files with 52 additions and 34 deletions

View File

@@ -118,14 +118,8 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub {
}
final int uid = Binder.getCallingUid();
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
return initialize(subscriptionId, new MbmsDownloadSessionCallback() {
int result = initialize(subscriptionId, new MbmsDownloadSessionCallback() {
@Override
public void onError(int errorCode, String message) {
try {
@@ -153,6 +147,17 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub {
}
}
});
if (result == MbmsErrors.SUCCESS) {
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
}
return result;
}
/**
@@ -251,17 +256,6 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub {
throw new NullPointerException("Callback must not be null");
}
DeathRecipient deathRecipient = new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, downloadRequest.getSubscriptionId());
mDownloadCallbackBinderMap.remove(callback.asBinder());
mDownloadCallbackDeathRecipients.remove(callback.asBinder());
}
};
mDownloadCallbackDeathRecipients.put(callback.asBinder(), deathRecipient);
callback.asBinder().linkToDeath(deathRecipient, 0);
DownloadStateCallback exposedCallback = new FilteredDownloadStateCallback(callback, flags) {
@Override
protected void onRemoteException(RemoteException e) {
@@ -269,9 +263,23 @@ public class MbmsDownloadServiceBase extends IMbmsDownloadService.Stub {
}
};
mDownloadCallbackBinderMap.put(callback.asBinder(), exposedCallback);
int result = registerStateCallback(downloadRequest, exposedCallback);
return registerStateCallback(downloadRequest, exposedCallback);
if (result == MbmsErrors.SUCCESS) {
DeathRecipient deathRecipient = new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, downloadRequest.getSubscriptionId());
mDownloadCallbackBinderMap.remove(callback.asBinder());
mDownloadCallbackDeathRecipients.remove(callback.asBinder());
}
};
mDownloadCallbackDeathRecipients.put(callback.asBinder(), deathRecipient);
callback.asBinder().linkToDeath(deathRecipient, 0);
mDownloadCallbackBinderMap.put(callback.asBinder(), exposedCallback);
}
return result;
}
/**

View File

@@ -70,14 +70,8 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
}
final int uid = Binder.getCallingUid();
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
return initialize(new MbmsStreamingSessionCallback() {
int result = initialize(new MbmsStreamingSessionCallback() {
@Override
public void onError(final int errorCode, final String message) {
try {
@@ -105,6 +99,17 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
}
}
}, subscriptionId);
if (result == MbmsErrors.SUCCESS) {
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
}
return result;
}
@@ -161,14 +166,8 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
}
final int uid = Binder.getCallingUid();
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
return startStreaming(subscriptionId, serviceId, new StreamingServiceCallback() {
int result = startStreaming(subscriptionId, serviceId, new StreamingServiceCallback() {
@Override
public void onError(final int errorCode, final String message) {
try {
@@ -215,6 +214,17 @@ public class MbmsStreamingServiceBase extends IMbmsStreamingService.Stub {
}
}
});
if (result == MbmsErrors.SUCCESS) {
callback.asBinder().linkToDeath(new DeathRecipient() {
@Override
public void binderDied() {
onAppCallbackDied(uid, subscriptionId);
}
}, 0);
}
return result;
}
/**