package android.support.v4.os;

import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.support.v4.os.a;
import androidx.annotation.NonNull;

/* JADX INFO: loaded from: classes.dex */
public class b implements Parcelable {
    public static final Parcelable.Creator<b> CREATOR = new a();
    final Handler mHandler;
    final boolean mLocal;
    android.support.v4.os.a mReceiver;

    class a implements Parcelable.Creator {
        a() {
        }

        @Override // android.os.Parcelable.Creator
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public b createFromParcel(Parcel parcel) {
            return new b(parcel);
        }

        @Override // android.os.Parcelable.Creator
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public b[] newArray(int i2) {
            return new b[i2];
        }
    }

    /* JADX INFO: renamed from: android.support.v4.os.b$b, reason: collision with other inner class name */
    class BinderC0058b extends a.AbstractBinderC0056a {
        BinderC0058b() {
        }

        @Override // android.support.v4.os.a
        public void C(int i2, Bundle bundle) {
            b bVar = b.this;
            Handler handler = bVar.mHandler;
            if (handler != null) {
                handler.post(bVar.new c(i2, bundle));
            } else {
                bVar.onReceiveResult(i2, bundle);
            }
        }
    }

    class c implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final int f2134b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        final Bundle f2135g;

        c(int i2, Bundle bundle) {
            this.f2134b = i2;
            this.f2135g = bundle;
        }

        @Override // java.lang.Runnable
        public void run() {
            b.this.onReceiveResult(this.f2134b, this.f2135g);
        }
    }

    public b(Handler handler) {
        this.mLocal = true;
        this.mHandler = handler;
    }

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    protected void onReceiveResult(int i2, Bundle bundle) {
    }

    public void send(int i2, Bundle bundle) {
        if (this.mLocal) {
            Handler handler = this.mHandler;
            if (handler != null) {
                handler.post(new c(i2, bundle));
                return;
            } else {
                onReceiveResult(i2, bundle);
                return;
            }
        }
        android.support.v4.os.a aVar = this.mReceiver;
        if (aVar != null) {
            try {
                aVar.C(i2, bundle);
            } catch (RemoteException unused) {
            }
        }
    }

    @Override // android.os.Parcelable
    public void writeToParcel(@NonNull Parcel parcel, int i2) {
        synchronized (this) {
            try {
                if (this.mReceiver == null) {
                    this.mReceiver = new BinderC0058b();
                }
                parcel.writeStrongBinder(this.mReceiver.asBinder());
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    b(Parcel parcel) {
        this.mLocal = false;
        this.mHandler = null;
        this.mReceiver = a.AbstractBinderC0056a.E(parcel.readStrongBinder());
    }
}
