package com.foxx.androidcast.dev;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.foxx.androidcast.BuildConfig;

/**
 * Debug: wake on {@link DevInstallWakeHelper#ACTION_PREPARE_FOR_DEPLOY} (before adb install)
 * and relaunch UI on {@link Intent#ACTION_MY_PACKAGE_REPLACED}.
 */
public final class DebugDeployWakeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (!BuildConfig.DEBUG || intent == null) {
            return;
        }
        String action = intent.getAction();
        if (DevInstallWakeHelper.ACTION_PREPARE_FOR_DEPLOY.equals(action)) {
            DevInstallWakeHelper.wakeForDeploy(context, "prepare-broadcast");
            return;
        }
        if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
            DevInstallWakeHelper.wakeForDeploy(context, "package-replaced");
            DevInstallWakeHelper.launchMainAfterDeploy(context);
        }
    }
}
