feat(channel): 同步渠道构建配置
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package com.unity3d.player;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ChannelAdapterBase implements SDKManager.IChannelSDKAdapter {
|
||||
private static final String TAG = "ChannelAdapterBase";
|
||||
protected Activity activity;
|
||||
protected String channel = "GooglePlay";
|
||||
|
||||
final ChannelAdapterBase setup(Activity activity, String channel) {
|
||||
this.activity = activity;
|
||||
this.channel = channel;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final SDKManager.IChannelSDKAdapter loadConfig() {
|
||||
applyConfig();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void applyConfig() {
|
||||
applyConfigObject(createConfig());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
SDKManager.initDefault(activity);
|
||||
}
|
||||
|
||||
protected void applyConfigObject(Object source) {
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Field sourceField : source.getClass().getDeclaredFields()) {
|
||||
sourceField.setAccessible(true);
|
||||
try {
|
||||
Object value = sourceField.get(source);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Field targetField = ConfigManager.class.getDeclaredField(sourceField.getName());
|
||||
targetField.setAccessible(true);
|
||||
targetField.set(null, value);
|
||||
Log.i(TAG, "apply config: " + sourceField.getName() + "=" + value);
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
try {
|
||||
Object value = sourceField.get(source);
|
||||
Log.w(TAG, "ignore extra config: " + sourceField.getName() + "=" + value);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "ignore extra config: " + sourceField.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "apply config failed: " + sourceField.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object createConfig() {
|
||||
try {
|
||||
Class<?> configClass = Class.forName(this.getClass().getName() + "$Config");
|
||||
Constructor<?> constructor = configClass.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "create config failed: " + this.getClass().getName(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 045e7597d96519641ae97bf542955d42
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 1
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.unity3d.player;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class ChannelAdapterManager {
|
||||
private static final String TAG = "ChannelAdapterManager";
|
||||
private static final String DEFAULT_CHANNEL = "GooglePlay";
|
||||
private static final String META_CHANNEL = "com.arkgame.ft.channel";
|
||||
|
||||
private static SDKManager.IChannelSDKAdapter adapter;
|
||||
|
||||
public static SDKManager.IChannelSDKAdapter createSdkAdapter(Activity activity) {
|
||||
String channel = readChannel(activity);
|
||||
adapter = createAdapter(channel);
|
||||
if (adapter instanceof ChannelAdapterBase) {
|
||||
((ChannelAdapterBase) adapter).setup(activity, channel);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public static String normalizeSkuList(String msg) {
|
||||
if (adapter == null) {
|
||||
return msg;
|
||||
}
|
||||
return adapter.normalizeSkuList(msg);
|
||||
}
|
||||
|
||||
private static SDKManager.IChannelSDKAdapter createAdapter(String channel) {
|
||||
if (TextUtils.isEmpty(channel) || DEFAULT_CHANNEL.equals(channel)) {
|
||||
return new ChannelAdapterBase();
|
||||
}
|
||||
|
||||
SDKManager.IChannelSDKAdapter adapter = tryCreateAdapter(
|
||||
"com.unity3d.player." + channel + "Adapter");
|
||||
if (adapter != null) {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
return new ChannelAdapterBase();
|
||||
}
|
||||
|
||||
private static SDKManager.IChannelSDKAdapter tryCreateAdapter(String adapterClassName) {
|
||||
try {
|
||||
Class<?> adapterClass = Class.forName(adapterClassName);
|
||||
Constructor<?> constructor = adapterClass.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
Object instance = constructor.newInstance();
|
||||
if (instance instanceof SDKManager.IChannelSDKAdapter) {
|
||||
return (SDKManager.IChannelSDKAdapter) instance;
|
||||
}
|
||||
Log.e(TAG, "adapter does not implement IChannelSDKAdapter: " + adapterClassName);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "create adapter failed: " + adapterClassName, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String readChannel(Activity activity) {
|
||||
if (activity == null) {
|
||||
return DEFAULT_CHANNEL;
|
||||
}
|
||||
|
||||
try {
|
||||
ApplicationInfo appInfo = activity.getPackageManager().getApplicationInfo(
|
||||
activity.getPackageName(),
|
||||
PackageManager.GET_META_DATA);
|
||||
Bundle metaData = appInfo.metaData;
|
||||
if (metaData == null) {
|
||||
return DEFAULT_CHANNEL;
|
||||
}
|
||||
String value = metaData.getString(META_CHANNEL);
|
||||
return TextUtils.isEmpty(value) ? DEFAULT_CHANNEL : value;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "read channel failed", e);
|
||||
return DEFAULT_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.unity3d.player;
|
||||
|
||||
public class ChannelEntry {
|
||||
public static final String CHANNEL = "GooglePlay";
|
||||
|
||||
public static SDKManager.IChannelSDKAdapter createSDKAdapter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String normalizeSkuList(String msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Unified SDKManager for all channels (GooglePlay / Flexion / RuStore / EnjoyPay).
|
||||
* 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.
|
||||
@@ -59,7 +59,17 @@ public class SDKManager {
|
||||
|
||||
// Channel SDK adapter
|
||||
public interface IChannelSDKAdapter {
|
||||
void init(Activity activity);
|
||||
default IChannelSDKAdapter loadConfig() {
|
||||
return this;
|
||||
}
|
||||
|
||||
String getChannel();
|
||||
|
||||
void init();
|
||||
|
||||
default String normalizeSkuList(String msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPaymentAdapter {
|
||||
@@ -82,9 +92,19 @@ public class SDKManager {
|
||||
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;
|
||||
@@ -125,7 +145,17 @@ public class SDKManager {
|
||||
|
||||
public static void CancelBillingFlow() {
|
||||
Log.w(TAG, "CancelBillingFlow");
|
||||
// FlexionSDKAdapter.cancelPurchase();
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -147,29 +177,26 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Init — with channel helper support
|
||||
// Init with channel helper support
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void InitSDK(Activity activity, String ch) {
|
||||
channel = ChannelEntry.CHANNEL;
|
||||
sdkAdapter = ChannelEntry.createSDKAdapter();
|
||||
sdkAdapter = ChannelAdapterManager.createSdkAdapter(activity);
|
||||
sdkAdapter.loadConfig();
|
||||
|
||||
// Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
|
||||
// + " fromCSharp=" + ch
|
||||
// + " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getSimpleName() : "default"));
|
||||
channel = sdkAdapter.getChannel();
|
||||
|
||||
Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
|
||||
+ " fromCSharp=" + ch
|
||||
+ " adapter=" + sdkAdapter.getClass().getName());
|
||||
|
||||
// Sync channel to C# ChannelConfig
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
|
||||
"SetChannelFromNative", channel);
|
||||
|
||||
if (sdkAdapter != null) {
|
||||
sdkAdapter.init(activity);
|
||||
} else {
|
||||
initDefault(activity);
|
||||
}
|
||||
sdkAdapter.init();
|
||||
}
|
||||
|
||||
private static void initDefault(Activity activity) {
|
||||
static void initDefault(Activity activity) {
|
||||
activity.runOnUiThread(() -> {
|
||||
SDKAPI.getIns().lightModeEnable();
|
||||
try {
|
||||
@@ -258,6 +285,7 @@ public class SDKManager {
|
||||
|
||||
public static void UnityResetServerUrl(String url) {
|
||||
SDKLog.i("UnityResetServerUrl : " + url);
|
||||
SetDNSIPsEnable(false);
|
||||
SDKAPI.getIns().updateServer(url);
|
||||
}
|
||||
|
||||
@@ -446,7 +474,7 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Payment — channel dispatch
|
||||
// Payment channel dispatch
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void UnityKnow(String productId, String productName, String productCount,
|
||||
@@ -461,7 +489,9 @@ public class SDKManager {
|
||||
public static void UnityKnowNew(String productId, String productPrice, String productName,
|
||||
String productCount, String prodorderId, String appInfo,
|
||||
String ptype) {
|
||||
SDKLog.i("[SDKManager.UnityKnowNew] channel=" + channel
|
||||
String currentChannel = getCurrentChannelForLog();
|
||||
SDKLog.i("[SDKManager.UnityKnowNew] channel=" + currentChannel
|
||||
+ ", adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getName() : "null")
|
||||
+ ", ptype=" + ptype
|
||||
+ ", productId=" + productId
|
||||
+ ", productPrice=" + productPrice
|
||||
@@ -489,8 +519,19 @@ public class SDKManager {
|
||||
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
|
||||
// thirdExtend with channel helper support
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void thirdExtend() {
|
||||
@@ -518,7 +559,7 @@ public class SDKManager {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("code", code);
|
||||
if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) {
|
||||
result.put("respObj", ChannelEntry.normalizeSkuList(msg));
|
||||
result.put("respObj", ChannelAdapterManager.normalizeSkuList(msg));
|
||||
} else {
|
||||
Log.e(TAG, "thirdExtend failed: " + msg);
|
||||
result.put("thirdExtend_errStr", msg);
|
||||
@@ -594,12 +635,19 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Review — channel dispatch
|
||||
// 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();
|
||||
}
|
||||
@@ -693,4 +741,34 @@ public class SDKManager {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public class TYApp extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SDKAPI.getIns().onApplicationCreate(this);
|
||||
SDKManager.SetDNSIPsEnable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -19,4 +20,5 @@ public class TYApp extends Application {
|
||||
super.attachBaseContext(base);
|
||||
SDKAPI.getIns().onAttachBaseContext(base, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user