hch
2023-12-04 87c30b3995c5ccbad64eb965181af9ee4ec16420
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.secondworld.sdk.command;
 
 
import android.app.AlertDialog;
 
import com.secondworld.sdk.GameAppProxy;
import com.secondworld.sdk.MySdkMgr;
import com.secondworld.sdk.PlatformDiff;
import com.secondworld.sdk.PlatformSdkMgr;
import com.secondworld.sdk.UnityMsgHandler;
import com.secondworld.sdk.utils.CodeA2U;
import com.secondworld.sdk.utils.CodeU2A;
import com.secondworld.sdk.utils.DeviceUtil;
import com.secondworld.sdk.utils.LogUtil;
import com.unity3d.player.UnityPlayer;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import java.util.HashMap;
import java.util.Map;
 
 
/**
 * 游戏初始化
 */
public class CmdInit implements ICommand {
 
    @Override
    public int getCode() {
        return CodeU2A.Init;
    }
 
    @Override
    public void process(JSONObject json) throws JSONException {
        GameAppProxy.appId = json.getString("appID");
 
        long size = DeviceUtil.getTotalRAMSize() / 1024 / 1024;
        LogUtil.debug("CmdInit", "内存:" + size + " mb");
        if (size < 1024) {
            LogUtil.w("CmdInit", "检测设备内存不满足运行程序标准,内存:" + size + " mb");
            AlertDialog.Builder _builder = new AlertDialog.Builder(UnityPlayer.currentActivity);
            _builder.setTitle("警告");
            _builder.setCancelable(false);
            _builder.setMessage("您的设备运行内存不满足要求,无法正常运行游戏");
            _builder.setPositiveButton("确定", (dialogInterface, i) -> {
                GameAppProxy.appExit();
            });
            _builder.show();
            return;
        }
        //发送设备信息
        Map<String, Object> _msgStruct = new HashMap<>();
        _msgStruct.put("userAgent", System.getProperty("http.agent"));
        _msgStruct.put("mac", DeviceUtil.getUniqueID());
        _msgStruct.put("imei", "");
        _msgStruct.put("android_id", DeviceUtil.getUniqueID());
        _msgStruct.put("unique_id", DeviceUtil.getUniqueID());
        _msgStruct.put("memoryTotal", size);
        UnityMsgHandler.sendMessageToUnity(CodeA2U.DeviceInfo,_msgStruct);
        //通知sdk初始化完成
        _msgStruct.clear();
        _msgStruct.put("channelPlatform", PlatformDiff.I.platformName());
        UnityMsgHandler.sendMessageToUnity(CodeA2U.SdkInitComplete,_msgStruct);
        MySdkMgr.I.sdkInitState = PlatformSdkMgr.SdkInitState.SUCCEED;
        LogUtil.debug("CmdInit", "Sdk初始化完成");
    }
}