package com.hh.arome;

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

import com.hh.lib_ampe.utils.AromeInvoker;
import com.hh.lib_base.BaseApplication;

/**
 * Description: $
 * @author xwh
 * time 2024/8/19
 **/
public class MyApp extends BaseApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        String processName = null;
        try {
            processName = getCurrentProcessName(this);
        }catch (Exception e ){}
        if (processName != null) {
            boolean defaultProcess = processName.equals("com.hh.arome");
            // 默认的主进程启动时初始化应用
            if (!defaultProcess) {
                return;
            }
        }
        AromeInvoker.init(this); //主进程初始化Arome
    }
    public static String getCurrentProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == pid) {
                return processInfo.processName;
            }
        }
        return null;
    }
}
