onKeyStatus_(keyStatusMap) {
    goog.asserts.assert(this.streamingEngine_, 'Cannot be called in src= mode');

    const event = shaka.Player.makeEvent_(
        shaka.util.FakeEvent.EventName.KeyStatusChanged);
    this.dispatchEvent(event);

    let keyIds = Object.keys(keyStatusMap);
    if (keyIds.length == 0) {
      shaka.log.warning(
          'Got a key status event without any key statuses, so we don\'t ' +
          'know the real key statuses. If we don\'t have all the keys, ' +
          'you\'ll need to set restrictions so we don\'t select those tracks.');
    }

    // Non-standard version of global key status. Modify it to match standard
    // behavior.
    if (keyIds.length == 1 && keyIds[0] == '') {
      keyIds = ['00'];
      keyStatusMap = {'00': keyStatusMap['']};
    }

    // If EME is using a synthetic key ID, the only key ID is '00' (a single 0
    // byte).  In this case, it is only used to report global success/failure.
    // See note about old platforms in: https://bit.ly/2tpez5Z
    const isGlobalStatus = keyIds.length == 1 && keyIds[0] == '00';
    if (isGlobalStatus) {
      shaka.log.warning(
          'Got a synthetic key status event, so we don\'t know the real key ' +
          'statuses. If we don\'t have all the keys, you\'ll need to set ' +
          'restrictions so we don\'t select those tracks.');
    }

    const restrictedStatuses = shaka.media.ManifestFilterer.restrictedStatuses;
    let tracksChanged = false;

    goog.asserts.assert(this.drmEngine_, 'drmEngine should be non-null here.');

    // Only filter tracks for keys if we have some key statuses to look at.
    if (keyIds.length) {
      const currentKeySystem = this.keySystem();
      const clearKeys = shaka.util.MapUtils.asMap(this.config_.drm.clearKeys);

      for (const variant of this.manifest_.variants) {
        const streams = shaka.util.StreamUtils.getVariantStreams(variant);

        for (const stream of streams) {
          const originalAllowed = variant.allowedByKeySystem;

          // Only update if we have key IDs for the stream.  If the keys aren't
          // all present, then the track should be restricted.
          if (stream.keyIds.size) {
            // If we are not using clearkeys, and the stream has drmInfos we
            // only want to check the keyIds of the keySystem we are using.
            // Other keySystems might have other keyIds that might not be
            // valid in this case. This can happen in HLS if the manifest
            // has Widevine with keyIds and PlayReady without keyIds and we are
            // using PlayReady.
            if (stream.drmInfos.length && !clearKeys.size) {
              for (const drmInfo of stream.drmInfos) {
                if (drmInfo.keyIds.size &&
                    drmInfo.keySystem == currentKeySystem) {
                  variant.allowedByKeySystem = true;

                  for (const keyId of drmInfo.keyIds) {
                    const keyStatus =
                        keyStatusMap[isGlobalStatus ? '00' : keyId];
                    if (keyStatus || this.drmEngine_.hasManifestInitData()) {
                      variant.allowedByKeySystem =
                          variant.allowedByKeySystem &&
                          !!keyStatus &&
                          !restrictedStatuses.includes(keyStatus);
                    } // if (keyStatus || this.drmEngine_.hasManifestInitData())
                  } // for (const keyId of drmInfo.keyIds)
                } // if (drmInfo.keyIds.size && ...
              } // for (const drmInfo of stream.drmInfos
            } else {
              variant.allowedByKeySystem = true;

              for (const keyId of stream.keyIds) {
                const keyStatus = keyStatusMap[isGlobalStatus ? '00' : keyId];
                if (keyStatus || this.drmEngine_.hasManifestInitData()) {
                  variant.allowedByKeySystem = variant.allowedByKeySystem &&
                      !!keyStatus && !restrictedStatuses.includes(keyStatus);
                }
              } // for (const keyId of stream.keyIds)
            } // if (stream.drmInfos.length && !clearKeys.size)
          } // if (stream.keyIds.size)

          if (originalAllowed != variant.allowedByKeySystem) {
            tracksChanged = true;
          }
        }  // for (const stream of streams)
      }  // for (const variant of this.manifest_.variants)
    }  // if (keyIds.size)

    if (tracksChanged) {
      this.onTracksChanged_();
      const variantsUpdated = this.updateAbrManagerVariants_();
      if (!variantsUpdated) {
        return;
      }
    }

    const currentVariant = this.streamingEngine_.getCurrentVariant();
    if (currentVariant && !currentVariant.allowedByKeySystem) {
      shaka.log.debug('Choosing new streams after key status changed');
      this.chooseVariantAndSwitch_();
    }
  }
@param {!Object<string, string>} keyStatusMap A map of hex key IDs to
  statuses.
@private