package com.oo.seex.oo_statistics_lib.utils.utdid.utils;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.Random;

public class PhoneInfiUtils {

    public PhoneInfiUtils() {

    }

    public static final String getUniqueID() {
        int t1 = (int) (System.currentTimeMillis() / 1000L);
        int t2 = (int) System.nanoTime();
        int t3 = (new Random()).nextInt();
        int t4 = (new Random()).nextInt();
        byte[] b1 = IntUtils.getBytes(t1);
        byte[] b2 = IntUtils.getBytes(t2);
        byte[] b3 = IntUtils.getBytes(t3);
        byte[] b4 = IntUtils.getBytes(t4);
        byte[] bUniqueID = new byte[16];
        System.arraycopy(b1, 0, bUniqueID, 0, 4);
        System.arraycopy(b2, 0, bUniqueID, 4, 4);
        System.arraycopy(b3, 0, bUniqueID, 8, 4);
        System.arraycopy(b4, 0, bUniqueID, 12, 4);
        return Base64.encodeToString(bUniqueID, 2);
    }

    public static String getImei(Context context) {
        String imei = null;
        if (context != null) {
            try {
                TelephonyManager e = (TelephonyManager) context.getSystemService("phone");
                if (e != null) {
                    imei = e.getDeviceId();
                }
            } catch (Exception var3) {
                ;
            }
        }

        if (StringUtils.isEmpty(imei)) {
            imei = getUniqueID();
        }

        return imei;
    }

    public static String getImsi(Context context) {
        String imsi = null;
        if (context != null) {
            try {
                TelephonyManager e = (TelephonyManager) context.getSystemService("phone");
                if (e != null) {
                    imsi = e.getSubscriberId();
                }
            } catch (Exception var3) {
                ;
            }
        }

        if (StringUtils.isEmpty(imsi)) {
            imsi = getUniqueID();
        }

        return imsi;
    }
}