package cn.yyxx.commsdk.impl.merge.channel.msa;

import android.content.Context;
import android.util.Log;


import com.huawei.hms.ads.identifier.AdvertisingIdClient;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import cn.yyxx.commsdk.base.internal.IMsaDeviceCallback;
import cn.yyxx.commsdk.base.utils.Logger;


/**
 * @author #Suyghur.
 * Created on 2021/04/23
 */
public class MsaDeviceHandler {

    private static final String VERSION = "1.0.25";

    public static String oaid = "";
    public static String vaid = "";
    public static String aaid = "";

    public static void initMsaDeviceIds(Context context, final IMsaDeviceCallback callback)  {
        new Thread(){
            @Override
            public void run() {
                AdvertisingIdClient.Info info = null;
                try {
                    info = AdvertisingIdClient.getAdvertisingIdInfo(context);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (null != info) {
                    if (info.isLimitAdTrackingEnabled()){
                        callback.onIdsRead(-1, "获取oaid失败", null);
                        Log.i("oaid","获取oaid失败");
                    }else {
                        oaid = info.getId();

                        Map<String, String> ids = new HashMap<>();

                        ids.put("oaid", oaid);
                        ids.put("vaid", "");
                        ids.put("aaid", "");

                        callback.onIdsRead(0, "获取MsaIds成功", ids);

                        Log.i("oaid","获取oaid成功，返回结果：" +oaid);
                    }
                }else{
                    Log.i("oaid","不支持获取oaid");
                    callback.onIdsRead(-1, "不支持获取oaid", null);

                }

            }
        }.start();


    }
}
