package com.miraclegarden.smsmessage.xposed;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import de.robv.android.xposed.XposedBridge;

public final class HookForwarder {

    private static final String TAG = "notiMessageHook";

    private HookForwarder() {
    }

    public static void forward(Context context, String packageName, String title,
                               String content, String source) {
        if (context == null || TextUtils.isEmpty(packageName) || TextUtils.isEmpty(content)) {
            return;
        }

        try {
            Intent intent = new Intent(HookBridge.ACTION_HOOK_MESSAGE);
            intent.setPackage(HookBridge.TARGET_APP_PACKAGE);
            intent.putExtra(HookBridge.EXTRA_PACKAGE_NAME, packageName);
            intent.putExtra(HookBridge.EXTRA_TITLE,
                    TextUtils.isEmpty(title) ? packageName : title);
            intent.putExtra(HookBridge.EXTRA_CONTENT, content);
            intent.putExtra(HookBridge.EXTRA_TIMESTAMP, System.currentTimeMillis());
            intent.putExtra(HookBridge.EXTRA_SOURCE, source);
            context.sendBroadcast(intent);
        } catch (Throwable t) {
            XposedBridge.log(TAG + " sendBroadcast failed: " + t.getMessage());
        }
    }
}
