@Nullable
  @SuppressLint("ParcelClassLoader")
  private static Pair<JobCallback, Bundle> extractWrappedBinderFromParcel(Bundle data) {
    Bundle cleanBundle = new Bundle();
    Parcel serialized = toParcel(data);
    JobCallback callback = null;

    try {
      int length = serialized.readInt();
      if (length <= 0) {
        // Empty Bundle
        Log.w(TAG, ERROR_NULL_CALLBACK);
        return null;
      }

      int magic = serialized.readInt();
      if (magic != BUNDLE_MAGIC) {
        // Not a Bundle
        Log.w(TAG, ERROR_NULL_CALLBACK);
        return null;
      }

      int numEntries = serialized.readInt();
      for (int i = 0; i < numEntries; i++) {
        String entryKey = readKey(serialized);
        if (entryKey == null) {
          continue;
        }

        if (!(callback == null && BUNDLE_KEY_CALLBACK.equals(entryKey))) {
          // If it's not the 'callback' key, we can just read it using the standard
          // mechanisms because we're not afraid of rogue BadParcelableExceptions.
          Object value = serialized.readValue(null /* class loader */);
          if (value instanceof String) {
            cleanBundle.putString(entryKey, (String) value);
          } else if (value instanceof Boolean) {
            cleanBundle.putBoolean(entryKey, (boolean) value);
          } else if (value instanceof Integer) {
            cleanBundle.putInt(entryKey, (int) value);
          } else if (value instanceof ArrayList) {
            // The only acceptable ArrayList in a Bundle is one that consists entirely
            // of Parcelables, so this cast is safe.
            @SuppressWarnings("unchecked") // safe by specification
            ArrayList<Parcelable> arrayList = (ArrayList<Parcelable>) value;
            cleanBundle.putParcelableArrayList(entryKey, arrayList);
          } else if (value instanceof Bundle) {
            cleanBundle.putBundle(entryKey, (Bundle) value);
          } else if (value instanceof Parcelable) {
            cleanBundle.putParcelable(entryKey, (Parcelable) value);
          }

          // Move to the next key
          continue;
        }

        int typeTag = serialized.readInt();
        if (typeTag != VAL_PARCELABLE) {
          // If the key is correct ("callback"), but it's not a Parcelable then something
          // went wrong and we should bail.
          Log.w(TAG, ERROR_INVALID_CALLBACK);
          return null;
        }

        String clsname = serialized.readString();
        if (!PENDING_CALLBACK_CLASS.equals(clsname)) {
          // If it's a Parcelable, but not one we recognize then we should not try and
          // unpack it.
          Log.w(TAG, ERROR_INVALID_CALLBACK);
          return null;
        }

        // Instead of trying to instantiate clsname, we'll just read its single member.
        IBinder remote = serialized.readStrongBinder();
        callback = new GooglePlayJobCallback(remote);
      }

      if (callback == null) {
        Log.w(TAG, ERROR_NULL_CALLBACK);
        return null;
      }
      return Pair.create(callback, cleanBundle);
    } finally {
      serialized.recycle();
    }
  }
Bundles are written out in the following format: A header, which consists of:

<ol>
  <li>length (int)
  <li>magic number ({@link #BUNDLE_MAGIC}) (int)
  <li>number of entries (int)
</ol>

<p>Then the map values, each of which looks like this:

<ol>
  <li>string key
  <li>int type marker
  <li>(any) parceled value
</ol>

<p>We're just going to iterate over the map looking for the right key (BUNDLE_KEY_CALLBACK) and
try and read the IBinder straight from the parcelled data. This is entirely dependent on the
implementation of Parcel, but these specific parts of Parcel / Bundle haven't changed since
2008 and newer versions of Android will ship with newer versions of Google Play services which
embed the IBinder directly into the Bundle (no need to deal with the Parcelable issues).
jobdispatcher/src/main/java/com/firebase/jobdispatcher/GooglePlayCallbackExtractor.java