package com.unity3d.player; import android.app.Activity; import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.util.Log; import com.barton.log.GASDKFactory; import com.barton.log.builder.GAConfiguration; import com.barton.log.builder.ParamsBuilder; import com.barton.log.ebarton.BaseUrl; import com.barton.log.ebarton.EventType; import com.barton.log.logapi.IGASDK; import com.facebook.share.model.ShareLinkContent; import com.facebook.share.widget.MessageDialog; import com.facebook.share.widget.ShareDialog; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.tasks.Task; import com.google.android.play.core.review.ReviewException; import com.google.android.play.core.review.ReviewInfo; import com.google.android.play.core.review.ReviewManager; import com.google.android.play.core.review.ReviewManagerFactory; import com.google.android.play.core.review.model.ReviewErrorCode; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.tuyoo.gamesdk.api.SDKAPI; import com.tuyoo.gamesdk.api.SDKCallBack; import com.tuyoo.gamesdk.api.SDKWrapper; import com.tuyoo.gamesdk.api.TuYooClientID; import com.tuyoo.gamesdk.event.data.PayEventData; import com.tuyoo.gamesdk.login.model.SnsInfo; import com.tuyoo.gamesdk.model.InitParam; import com.tuyoo.gamesdk.pay.model.PayType; import com.tuyoo.gamesdk.util.SDKLog; import org.json.JSONException; import org.json.JSONObject; import java.util.HashMap; import java.util.Map; /** * Unified SDKManager for all channels (GooglePlay / Flexion / RuStore). * C# passes the channel string via InitSDK(activity, channel); Java dispatches * internally via switch. All login/link/GA/share logic is shared. * Channel-specific behaviour is limited to: Init, Pay, thirdExtend, Review. */ public class SDKManager { private static final Handler handler = new Handler(Looper.getMainLooper()); private static IGASDK gasdk; private static final String TAG = SDKManager.class.getSimpleName(); private static String curType = TuYooClientID.tyGuest; private static SnsInfo tmpSnsInfo; private static String channel = "GooglePlay"; // Channel SDK adapter public interface IChannelSDKAdapter { default IChannelSDKAdapter loadConfig() { return this; } String getChannel(); void init(); default String normalizeSkuList(String msg) { return msg; } } public interface IPaymentAdapter { void pay(Activity activity, String productId, String productPrice, String productName, String productCount, String prodorderId, String appInfo); void consume(String token); } public interface IProductQueryAdapter { void queryProducts(); void queryProducts(String productIds); } public interface IPendingPurchaseAdapter { void queryPendingPurchases(); } public interface IBillingLifecycleAdapter { void refreshBilling(); } public interface IChannelInfoAdapter { String getStorePageUri(Activity activity); } public interface IReviewAdapter { void review(Activity activity); } private static IChannelSDKAdapter sdkAdapter; public static void queryProductsByIDs(String productIds) { Log.i(TAG, "[FLEXION-SKU-PRICE] queryProductsByIDs productIds=" + productIds + " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getName() : "null")); if (sdkAdapter instanceof IProductQueryAdapter) { ((IProductQueryAdapter) sdkAdapter).queryProducts(productIds); return; } Log.e(TAG, "queryProductsByIDs: no product query adapter"); } public static void ConsumePurchase(String token) { // Log.i(TAG, "ConsumePurchase: token=" + token); if (sdkAdapter instanceof IPaymentAdapter) { ((IPaymentAdapter) sdkAdapter).consume(token); } } public static void QueryPendingPurchases() { Log.i(TAG, "QueryPendingPurchases"); if (sdkAdapter instanceof IPendingPurchaseAdapter) { ((IPendingPurchaseAdapter) sdkAdapter).queryPendingPurchases(); return; } try { JSONObject result = new JSONObject(); result.put("code", 0); result.put("respObj", "[]"); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, "PendingPurchasesResult", result.toString()); } catch (JSONException e) { Log.e(TAG, "QueryPendingPurchases fallback json error: " + e.getMessage()); } } public static void RefreshBillingService() { // Log.i(TAG, "RefreshBillingService"); if (sdkAdapter instanceof IBillingLifecycleAdapter) { ((IBillingLifecycleAdapter) sdkAdapter).refreshBilling(); } } public static void CancelBillingFlow() { Log.w(TAG, "CancelBillingFlow"); } public static String GetStorePageUri() { if (sdkAdapter instanceof IChannelInfoAdapter) { try { return ((IChannelInfoAdapter) sdkAdapter).getStorePageUri(UnityPlayer.currentActivity); } catch (Throwable e) { Log.w(TAG, "GetStorePageUri exception: " + e.getMessage()); } } return ""; } public static boolean IsGooglePlayServicesAvailable() { try { Activity activity = UnityPlayer.currentActivity; if (activity == null) { Log.w(TAG, "IsGooglePlayServicesAvailable: activity is null"); return false; } int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity); boolean available = resultCode == ConnectionResult.SUCCESS; Log.i(TAG, "IsGooglePlayServicesAvailable: available=" + available + " resultCode=" + resultCode); return available; } catch (Exception e) { Log.w(TAG, "IsGooglePlayServicesAvailable exception: " + e.getMessage()); return false; } } // ------------------------------------------------------------------------- // Init with channel helper support // ------------------------------------------------------------------------- public static void InitSDK(Activity activity, String ch) { sdkAdapter = ChannelAdapterManager.createSdkAdapter(activity); sdkAdapter.loadConfig(); channel = sdkAdapter.getChannel(); Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel + " fromCSharp=" + ch + " adapter=" + sdkAdapter.getClass().getName()); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, "SetChannelFromNative", channel); sdkAdapter.init(); } static void initDefault(Activity activity) { activity.runOnUiThread(() -> { SDKAPI.getIns().lightModeEnable(); try { SDKAPI.getIns().init(new InitParam.Builder() .withActivity(activity) .withAppId(ConfigManager.SDK_APPID) .withClientId(ConfigManager.SDK_CLIENTID) .withServerUrl(ConfigManager.SDK_LOGIN_SERVER_URL) .build()); TYUnityActivity.setSdkInited(); SDKAPI.getIns().onActivityStart(activity); SDKAPI.getIns().onActivityResume(activity); notifyInitResult(true, "ok"); } catch (Exception e) { System.out.println("initSDK Exception " + e); notifyInitResult(false, e.getMessage()); } }); } static void notifyInitResult(boolean success, String msg) { try { JSONObject result = new JSONObject(); result.put("code", success ? 0 : 1); result.put("msg", msg); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.INIT_CALLBACK_FUNCTION_NAME, result.toString()); } catch (JSONException e) { Log.e(TAG, "notifyInitResult error: " + e); } } // ------------------------------------------------------------------------- // Login / Callbacks (shared) // ------------------------------------------------------------------------- public static void parseLoginInfo(int i, String s) { try { JSONObject result = new JSONObject(); result.put("code", i); if (i == 0) { JSONObject serverResponse = new JSONObject(s); JSONObject userInfo = serverResponse.getJSONObject("result"); result.put("loginData", userInfo); } else { result.put("errStr", s); } UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, result.toString()); } catch (Exception e) { Log.e(TAG, "SDKManager-parseLoginInfo-Exception" + e); SDKLog.e("SDKManager-parseLoginInfo-Exception" + e); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}"); } } protected static SDKCallBack.Login mLogin = new SDKCallBack.Login() { @Override public void callback(int i, String s) { SDKLog.i("SDKCallBack.Login callback: " + i + " \n" + s); parseLoginInfo(i, s); tmpSnsInfo = null; } }; protected static SDKCallBack.Pay mPay = new SDKCallBack.Pay() { @Override public void callback(int i, String s) { SDKLog.i("SDKCallBack.Pay callback: " + i + " \n" + s); try { JSONObject result = new JSONObject(); result.put("code", i); result.put("respObj", s); result.put("errStr", s); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_CALLBACK_FUNCTION_NAME, result.toString()); } catch (Exception e) { Log.e(TAG, "SDKManager-SDKCallBack.Pay-Exception" + e); SDKLog.e("SDKManager-SDKCallBack.Pay-Exception" + e); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_CALLBACK_FUNCTION_NAME, "{\"code\":1}"); } } }; public static void UnityResetServerUrl(String url) { SDKLog.i("UnityResetServerUrl : " + url); SetDNSIPsEnable(false); SDKAPI.getIns().updateServer(url); } public static void UnityLoginByTokenFun(String token) { SDKLog.i("UnityLoginByTokenFun : " + token); handler.post(() -> SDKAPI.getIns().loginByToken(token, mLogin)); } public static String UnityLoginBySnsInfo() { if (tmpSnsInfo == null) { handler.post(() -> UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}")); return ""; } SDKLog.i("UnityLoginBySns : " + tmpSnsInfo); handler.post(() -> SDKAPI.getIns().loginBySnsInfo(tmpSnsInfo, mLogin)); return tmpSnsInfo.type; } public static void UnityGetIdentityFun(String type) { SDKLog.i("UnityGetIdentityFun : " + type); handler.post(() -> SDKAPI.getIns().loginByType(type, mLogin)); } public static void UnityLogin(String type) { SDKLog.i("UnityLogin : " + type); handler.post(() -> SDKAPI.getIns().loginByType(type, mLogin)); } public static void UnityLogOutByChannel(String type) { SDKLog.i("UnityLoginOut : "); handler.post(() -> SDKAPI.getIns().logout(type)); } // ------------------------------------------------------------------------- // Account linking (shared) // ------------------------------------------------------------------------- public static void LinkAccount(String type, String userId) { SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) -> { if (snscode == SDKCallBack.CODE_SUCCESS && snsInfo != null) { SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg) -> { if (bindcode == SDKCallBack.CODE_SUCCESS) { try { JSONObject result = new JSONObject(); result.put("code", bindcode); result.put("userId", userId); JSONObject serverResponse = new JSONObject(bindmsg); JSONObject userInfo = serverResponse.getJSONObject("result"); result.put("loginData", userInfo); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, result.toString()); } catch (JSONException e) { String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } } else if (bindcode == SDKCallBack.CODE_FAILED) { try { JSONObject bindMsgObj = new JSONObject(bindmsg); JSONObject bindMsgResult = bindMsgObj.getJSONObject("result"); int bindMsgResultCode = bindMsgResult.getInt("code"); if (bindMsgResultCode == 4) { SDKAPI.getIns().checkSnsInfo(snsInfo, (checkcode, checkMsg) -> { if (checkcode != SDKCallBack.CODE_SUCCESS) { Log.w(TAG, checkMsg); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); return; } try { tmpSnsInfo = snsInfo; JSONObject checkMsgObj = new JSONObject(checkMsg); JSONObject checkResult = checkMsgObj.getJSONObject("result"); String bindInfo = checkResult.getString("bindInfo"); int bindUserId = checkResult.getInt("userId"); JSONObject callbackMsg = new JSONObject(); callbackMsg.put("code", -1); callbackMsg.put("userId", bindUserId); callbackMsg.put("bindInfo", bindInfo); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, callbackMsg.toString()); } catch (JSONException e) { Log.i(TAG, e.toString()); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } }); } else { Log.w(TAG, bindmsg); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } } catch (JSONException e) { Log.i(TAG, e.toString()); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } } else { Log.w(TAG, bindmsg); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } }); } else { Log.w(TAG, snsmsg); String msg = "{\"code\":1, \"userId\": 0}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg); } }); } public static void CleanLinkTmpSnsInfo() { tmpSnsInfo = null; } public static void ChangeLinkAccount(String type, int oldUserId, int newUserId) { if (tmpSnsInfo == null) { String msg = "{\"code\":1, \"userId\": 0, \"msg\": \"tmpSnsInfo is null\"}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg); return; } SDKAPI.getIns().unbindBySnsId(tmpSnsInfo, String.valueOf(oldUserId), (unbindCode, unbindMsg) -> { Log.i(TAG, "unbindBySnsId code: " + unbindCode + " msg: " + unbindMsg); if (unbindCode == SDKCallBack.CODE_SUCCESS) { SDKAPI.getIns().bindBySnsId(tmpSnsInfo, String.valueOf(newUserId), (bindCode, bindMsg) -> { Log.i(TAG, "bindBySnsId code: " + bindCode + " msg: " + bindMsg); if (bindCode == SDKCallBack.CODE_SUCCESS) { String msg = "{\"code\":0, \"userId\": " + newUserId + ", \"msg\": \"success\"}"; UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg); } else { String msg = String.format("{\"code\":-1, \"userId\": 0, \"msg\": \"%s\"}", bindMsg); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg); } }); } else { String msg = String.format("{\"code\":1, \"userId\": 0, \"msg\": \"%s\"}", unbindMsg); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg); } }); } public static void LinkCheck(String type) { SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> { if (code == SDKCallBack.CODE_SUCCESS && snsInfo != null) { SDKAPI.getIns().checkSnsInfo(snsInfo, (code1, msg1) -> { if (code1 == SDKCallBack.CODE_SUCCESS && !TextUtils.isEmpty(msg1)) { try { JSONObject jsonObject = new JSONObject(msg1).optJSONObject("result"); if (jsonObject.optString("code").equals("0") && jsonObject.optString("exist").equals("0")) { UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "0"); } else { UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "1"); } } catch (JSONException e) { UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1"); e.printStackTrace(); } } else { UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1"); } }); } else { UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1"); } }); } // ------------------------------------------------------------------------- // Payment channel dispatch // ------------------------------------------------------------------------- public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo) { SDKLog.i("UnityKnow : " + productId); HashMap extraInfo = new HashMap(); extraInfo.put("appInfo", appInfo); SDKAPI.getIns().pay(productId, productName, productCount, Integer.parseInt(ConfigManager.SDK_GAMEID), mPay, prodorderId, extraInfo); } public static void UnityKnowNew(String productId, String productPrice, String productName, String productCount, String prodorderId, String appInfo, String ptype) { String currentChannel = getCurrentChannelForLog(); SDKLog.i("[SDKManager.UnityKnowNew] channel=" + currentChannel + ", adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getName() : "null") + ", ptype=" + ptype + ", productId=" + productId + ", productPrice=" + productPrice + ", productName=" + productName + ", productCount=" + productCount + ", orderId=" + prodorderId); if (sdkAdapter instanceof IPaymentAdapter) { ((IPaymentAdapter) sdkAdapter).pay(UnityPlayer.currentActivity, productId, productPrice, productName, productCount, prodorderId, appInfo); return; } PayEventData.PayData payData = new PayEventData.PayData(); final PayEventData.PayReq mPayReq = new PayEventData.PayReq(); mPayReq.prodId = productId; mPayReq.prodPrice = productPrice; mPayReq.prodName = productName; mPayReq.prodCount = productCount; mPayReq.appInfo = prodorderId; HashMap map = new HashMap(); map.put("appInfo", appInfo); mPayReq.extra = map; payData.payReq = mPayReq; PayType payType = new PayType(); payType.paytype = ptype; SDKLog.i("[SDKManager.UnityKnowNew] payNew payType.paytype=" + payType.paytype); SDKAPI.getIns().payNew(payData, payType, mPay); } private static String getCurrentChannelForLog() { try { if (sdkAdapter != null && !TextUtils.isEmpty(sdkAdapter.getChannel())) { return sdkAdapter.getChannel(); } } catch (Throwable ignored) { } return TextUtils.isEmpty(channel) ? "GooglePlay" : channel; } // ------------------------------------------------------------------------- // thirdExtend with channel helper support // ------------------------------------------------------------------------- public static void thirdExtend() { Log.e(TAG, "thirdExtend called, sdkAdapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getSimpleName() : "null")); if (sdkAdapter instanceof IProductQueryAdapter) { ((IProductQueryAdapter) sdkAdapter).queryProducts(); return; } defaultThirdExtend(); } private static void defaultThirdExtend() { Log.e(TAG, "====>java thirdExtend"); JSONObject jsonObject = new JSONObject(); try { jsonObject.put("action", "ACTION_GET_SKU_DETAILS_LIST"); } catch (JSONException e) { throw new RuntimeException(e); } SDKAPI.getIns().thirdExtend(jsonObject.toString(), new SDKCallBack.Extend() { @Override public void callback(int code, String msg) { Log.e(TAG, "====>thirdExtend code= " + code + " msg= " + msg); try { JSONObject result = new JSONObject(); result.put("code", code); if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) { result.put("respObj", ChannelAdapterManager.normalizeSkuList(msg)); } else { Log.e(TAG, "thirdExtend failed: " + msg); result.put("thirdExtend_errStr", msg); } UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, result.toString()); } catch (Exception e) { SDKLog.e("SDKManager-thirdExtend-Exception" + e); UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, "{\"code\":1}"); } } }); } // ------------------------------------------------------------------------- // GA (shared) // ------------------------------------------------------------------------- protected static IGASDK GetGameGa() { if (gasdk == null) { GAConfiguration.Builder builder = new GAConfiguration.Builder() .withBaseUrl(BaseUrl.INTERNATIONAL) .withContext(SDKWrapper.getInstance().getContext()) .withClientId(ConfigManager.SDK_CLIENTID) .withGameId(ConfigManager.SDK_GAMEID) .withProjectId(ConfigManager.SDK_PROJECTID); gasdk = GASDKFactory.createGASDK(builder.build()); } return gasdk; } public static void SetGaUserInfo(String userId) { Log.e(TAG, "SetGaUserInfo : " + userId); // SDKLog.i("SetGaUserInfo : " + userId); GetGameGa().setUserId(userId); } public static void SetGaCommonInfo(String SetGaCommonInfo) { Log.e(TAG, "SetGaCommonInfo : " + SetGaCommonInfo); // SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo); Gson gson = new Gson(); Map map = gson.fromJson(SetGaCommonInfo, new TypeToken>() {}.getType()); for (String key : map.keySet()) { if (!TextUtils.isEmpty(key) && map.get(key) != null) { GetGameGa().addCommonParameter(key, map.get(key).toString()); } } } public static void GAReportParams(int type, String eventstr, String paramstr) { ParamsBuilder paramsBuilder = ParamsBuilder.newInstance(); Gson gson = new Gson(); Map map = gson.fromJson(paramstr, new TypeToken>() {}.getType()); for (String key : map.keySet()) { if (!TextUtils.isEmpty(key) && map.get(key) != null) { paramsBuilder.append(key, map.get(key).toString()); } } switch (type) { case 2: GetGameGa().track(EventType.COIN, eventstr, paramsBuilder); break; case 3: GetGameGa().track(EventType.PAY, eventstr, paramsBuilder); break; case 4: GetGameGa().track(EventType.GAME, eventstr, paramsBuilder); break; case 5: GetGameGa().track(EventType.LOGIN, eventstr, paramsBuilder); break; case 6: GetGameGa().track(EventType.PUSH, eventstr, paramsBuilder); break; case 7: GetGameGa().track(EventType.ADBOX, eventstr, paramsBuilder); break; case 8: GetGameGa().track(EventType.PREFORMANCE, eventstr, paramsBuilder); break; case 9: GetGameGa().track(EventType.SDK, eventstr, paramsBuilder); break; default: GetGameGa().track(EventType.TRACK, eventstr, paramsBuilder); break; } } // ------------------------------------------------------------------------- // Review channel dispatch // ------------------------------------------------------------------------- public static void Review() { Log.w(TAG, "[ReviewDebug] Review called channel=" + channel); if ("Rustore".equals(channel)) { RuStoreReview(); } else if ("Flexion".equals(channel)) { if (sdkAdapter instanceof IReviewAdapter) { ((IReviewAdapter) sdkAdapter).review(UnityPlayer.currentActivity); } else { Log.w(TAG, "Review skipped: no Flexion review adapter"); } } else { GooglePlayReview(); } } private static void GooglePlayReview() { ReviewManager manager = ReviewManagerFactory.create(SDKWrapper.getInstance().getContext()); Task request = manager.requestReviewFlow(); request.addOnCompleteListener(reqTask -> { if (reqTask.isSuccessful()) { ReviewInfo reviewInfo = reqTask.getResult(); Activity activity = UnityPlayer.currentActivity; manager.launchReviewFlow(activity, reviewInfo); } else { @ReviewErrorCode int reviewErrorCode = ((ReviewException) request.getException()).getErrorCode(); Log.e(TAG, "Review Error code: " + reviewErrorCode); } }); } // RuStore two-step review public interface ReviewResultCallback { void onReviewSuccess(JSONObject result); void onReviewError(int code, String msg); } public static void RequestRustoreReView(ReviewResultCallback callback) { JSONObject json = new JSONObject(); try { json.put("action", "ACTION_REQUEST_REVIEW"); } catch (JSONException e) { throw new RuntimeException(e); } SDKAPI.getIns().thirdExtend(json.toString(), (code, msg) -> { Log.e(TAG, "RequestRustoreReView code=" + code + " msg=" + msg); try { JSONObject result = new JSONObject(); result.put("code", code); if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) { if (callback != null) callback.onReviewSuccess(result); } else { result.put("thirdExtend_errStr", msg); if (callback != null) callback.onReviewError(code, msg); } } catch (Exception e) { SDKLog.e("RequestRustoreReView Exception: " + e); } }); } public static void LaunchRustoreView() { JSONObject json = new JSONObject(); try { json.put("action", "ACTION_LAUNCH_REVIEW"); } catch (JSONException e) { throw new RuntimeException(e); } SDKAPI.getIns().thirdExtend(json.toString(), (code, msg) -> Log.e(TAG, "LaunchRustoreView code=" + code + " msg=" + msg)); } public static void RuStoreReview() { RequestRustoreReView(new ReviewResultCallback() { @Override public void onReviewSuccess(JSONObject result) { LaunchRustoreView(); } @Override public void onReviewError(int code, String msg) { } }); } // ------------------------------------------------------------------------- // Facebook / Messenger share (shared) // ------------------------------------------------------------------------- public static void FBShareLink(String title, String content, String url) { Log.e(TAG, "FBShareLink : " + title + " " + content + " " + url); if (ShareDialog.canShow(ShareLinkContent.class)) { Activity activity = UnityPlayer.currentActivity; ShareDialog dialog = new ShareDialog(activity); ShareLinkContent linkContent = new ShareLinkContent.Builder() .setQuote(content) .setContentUrl(Uri.parse(url)) .build(); dialog.show(linkContent); } else { Log.e(TAG, "FBShareDialog can not show"); } } public static void MessengerShareLink(String title, String content, String url) { Log.e(TAG, "MessengerShareLink : " + title + " " + content + " " + url); if (MessageDialog.canShow(ShareLinkContent.class)) { Activity activity = UnityPlayer.currentActivity; ShareLinkContent linkContent = new ShareLinkContent.Builder() .setQuote(content) .setContentUrl(Uri.parse(url)) .build(); MessageDialog.show(activity, linkContent); } else { Log.e(TAG, "Messenger ShareDialog can not show"); } } public static void SetDNSIPsEnable(boolean enable) { if ("Flexion".equals(channel)) { return; } if(enable) { SetDNSIPs(true, new String[]{ "34.111.1.231", "2600:1901:0:c31b::" }); } else{ SetDNSIPs(false, new String[0]); } } private static void SetDNSIPs(boolean enable, String[] ips) { InvokeSDKAPIStaticMethod("enableDoh", new Class[]{boolean.class}, new Object[]{enable}); InvokeSDKAPIStaticMethod("setHttpDnsIps", new Class[]{String[].class}, new Object[]{ips}); } private static void InvokeSDKAPIStaticMethod(String methodName, Class[] parameterTypes, Object[] args) { try { SDKAPI.class.getMethod(methodName, parameterTypes).invoke(null, args); } catch (NoSuchMethodException ignored) { } catch (Exception e) { throw new RuntimeException(e); } } }