Bug 1613871 - cancel background task when releasing DRM object. r=snorp

The provision request is executed in background through AsyncTask and will
post the result once finished. However, when the DRM object is released
before onPostExecute() is called, there will be NPE. Use AsyncTask.cancel()
to avoid that.

Differential Revision: https://phabricator.services.mozilla.com/D63526

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Lin 2020-02-20 19:30:15 +00:00
Родитель a985a8926b
Коммит 827ee06469
1 изменённых файлов: 8 добавлений и 3 удалений

Просмотреть файл

@ -47,6 +47,7 @@ public class GeckoMediaDrmBridgeV21 implements GeckoMediaDrm {
private UUID mSchemeUUID;
private Handler mHandler;
PostRequestTask mProvisionTask;
private HandlerThread mHandlerThread;
private ByteBuffer mCryptoSessionId;
@ -259,6 +260,10 @@ public class GeckoMediaDrmBridgeV21 implements GeckoMediaDrm {
@Override
public void release() {
if (DEBUG) Log.d(LOGTAG, "release()");
if (mProvisionTask != null) {
mProvisionTask.cancel(true);
mProvisionTask = null;
}
if (mProvisioningPromiseId > 0) {
onRejectPromise(mProvisioningPromiseId, "Releasing ... reject provisioning session.");
mProvisioningPromiseId = 0;
@ -613,9 +618,9 @@ public class GeckoMediaDrmBridgeV21 implements GeckoMediaDrm {
try {
mProvisioningPromiseId = promiseId;
MediaDrm.ProvisionRequest request = mDrm.getProvisionRequest();
PostRequestTask postTask =
mProvisionTask =
new PostRequestTask(promiseId, request.getDefaultUrl(), request.getData());
postTask.execute();
mProvisionTask.execute();
} catch (Exception e) {
onRejectPromise(promiseId, "Exception happened in startProvisioning !");
mProvisioningPromiseId = 0;
@ -624,7 +629,7 @@ public class GeckoMediaDrmBridgeV21 implements GeckoMediaDrm {
private void onProvisionResponse(final int promiseId, final byte[] response) {
if (DEBUG) Log.d(LOGTAG, "onProvisionResponse()");
mProvisionTask = null;
mProvisioningPromiseId = 0;
boolean success = provideProvisionResponse(response);
if (success) {