翰林优商.apk(点击下载) / PlayServicesUtil.java


package com.czhj.sdk.common.utils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.Parcel;
import android.os.RemoteException;
import com.czhj.sdk.logger.SigmobLog;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

public class PlayServicesUtil {

    /* access modifiers changed from: private */
    public static final class AdvertisingConnection implements ServiceConnection {
        boolean a;
        private final LinkedBlockingQueue<IBinder> b;

        private AdvertisingConnection() {
            this.a = false;
            this.b = new LinkedBlockingQueue<>(1);
        }

        /* access modifiers changed from: package-private */
        public IBinder a() throws InterruptedException {
            if (!this.a) {
                this.a = true;
                return this.b.take();
            }
            throw new IllegalStateException();
        }

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            try {
                this.b.put(iBinder);
            } catch (Throwable th) {
                SigmobLog.e(th.getMessage());
            }
        }

        public void onServiceDisconnected(ComponentName componentName) {
        }
    }

    public static class AdvertisingInfo {
        public final String advertisingId;
        public final boolean limitAdTracking;

        AdvertisingInfo(String str, boolean z) {
            this.advertisingId = str;
            this.limitAdTracking = z;
        }
    }

    /* access modifiers changed from: private */
    public static final class AdvertisingInterface implements IInterface {
        private final IBinder a;

        AdvertisingInterface(IBinder iBinder) {
            this.a = iBinder;
        }

        /* access modifiers changed from: package-private */
        public String a() throws RemoteException {
            Parcel obtain = Parcel.obtain();
            Parcel obtain2 = Parcel.obtain();
            try {
                obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                this.a.transact(1, obtain, obtain2, 0);
                obtain2.readException();
                return obtain2.readString();
            } finally {
                obtain2.recycle();
                obtain.recycle();
            }
        }

        public IBinder asBinder() {
            return this.a;
        }

        /* access modifiers changed from: package-private */
        public boolean b() throws RemoteException {
            Parcel obtain = Parcel.obtain();
            Parcel obtain2 = Parcel.obtain();
            try {
                obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                boolean z = true;
                obtain.writeInt(1);
                this.a.transact(2, obtain, obtain2, 0);
                obtain2.readException();
                if (obtain2.readInt() == 0) {
                    z = false;
                }
                return z;
            } finally {
                obtain2.recycle();
                obtain.recycle();
            }
        }
    }

    public static AdvertisingInfo getAdvertisingIdInfo(Context context) throws Exception {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            return null;
        }
        context.getPackageManager().getPackageInfo("com.android.vending", 0);
        AdvertisingConnection advertisingConnection = new AdvertisingConnection();
        Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
        intent.setPackage("com.google.android.gms");
        try {
            if (context.bindService(intent, advertisingConnection, 1)) {
                AdvertisingInterface advertisingInterface = new AdvertisingInterface(advertisingConnection.a());
                return new AdvertisingInfo(advertisingInterface.a(), advertisingInterface.b());
            }
            context.unbindService(advertisingConnection);
            throw new IOException("Google Play connection failed");
        } finally {
            context.unbindService(advertisingConnection);
        }
    }
}