package com.android.launcher3.accessibility;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;

import com.android.launcher3.R;
import com.android.launcher3.debug.CustomDialog;
import com.android.launcher3.manager.LauncherManager;
import com.android.launcher3.util.PermissionUtil;
import com.android.launcher3.util.UIExecutor;

/**
 * 开机自启动接收器
 */
public class AutoRunReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context mContext, Intent intent) {

        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            //PermissionUtil.initLauncherIconIsShow(mContext,true);
            Intent intent2 = new Intent(mContext, ListenerAppService.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                mContext.startForegroundService(intent2);
            } else {
                mContext.startService(intent2);
            }
            try {
                if (LauncherManager.mCustomDialog == null) {
                    LauncherManager.mCustomDialog = new CustomDialog(mContext, R.layout.activity_clock_alarm);
                    LauncherManager.mCustomDialog.show();
                    Log.i("launch_debug_show", "开机显示了进度条");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            //重启之后启动桌面
            LauncherManager.getInstance().backLauncherHome(mContext.getApplicationContext());
        }
    }
}
