app center;增加發送ping的秒

This commit is contained in:
Caiyanpeng committed 2021-11-12 16:21:13 +08:00
1 parent 1bd1ffdb5a
commit d754ff3b15
719 files changed
+34172 -2875

No files matched your search

@@ -0,0 +1,183 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using Assets.AppCenter.Plugins.Android.Utility;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Microsoft.AppCenter.Unity.Internal
{
class AppCenterInternal
{
private static AndroidJavaClass _appCenter = new AndroidJavaClass("com.microsoft.appcenter.AppCenter");
public static void SetLogLevel(int logLevel)
{
_appCenter.CallStatic("setLogLevel", logLevel);
}
public static int GetLogLevel()
{
return _appCenter.CallStatic<int>("getLogLevel");
}
public static bool IsConfigured()
{
return _appCenter.CallStatic<bool>("isConfigured");
}
public static void SetLogUrl(string logUrl)
{
_appCenter.CallStatic("setLogUrl", logUrl);
}
public static void SetUserId(string userId)
{
_appCenter.CallStatic("setUserId", userId);
}
public static string GetSdkVersion()
{
return _appCenter.CallStatic<string>("getSdkVersion");
}
public static void SetNetworkRequestsAllowed(bool isAllowed)
{
_appCenter.CallStatic("setNetworkRequestsAllowed", isAllowed);
}
public static bool IsNetworkRequestsAllowed()
{
return _appCenter.CallStatic<bool>("isNetworkRequestsAllowed");
}
public static AppCenterTask SetEnabledAsync(bool enabled)
{
var future = _appCenter.CallStatic<AndroidJavaObject>("setEnabled", enabled);
return new AppCenterTask(future);
}
public static AppCenterTask<bool> IsEnabledAsync()
{
var future = _appCenter.CallStatic<AndroidJavaObject>("isEnabled");
return new AppCenterTask<bool>(future);
}
public static AppCenterTask<string> GetInstallIdAsync()
{
AndroidJavaObject future = _appCenter.CallStatic<AndroidJavaObject>("getInstallId");
var javaUUIDtask = new AppCenterTask<AndroidJavaObject>(future);
var stringTask = new AppCenterTask<string>();
javaUUIDtask.ContinueWith(t =>
{
var installId = t.Result == null ? null : t.Result.Call<string>("toString");
stringTask.SetResult(installId);
});
return stringTask;
}
public static void SetCustomProperties(AndroidJavaObject properties)
{
_appCenter.CallStatic("setCustomProperties", properties);
}
private static AndroidJavaObject GetAndroidApplication()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
return activity.Call<AndroidJavaObject>("getApplication");
}
public static void SetWrapperSdk(string wrapperSdkVersion,
string wrapperSdkName,
string wrapperRuntimeVersion,
string liveUpdateReleaseLabel,
string liveUpdateDeploymentKey,
string liveUpdatePackageHash)
{
var wrapperSdkObject = new AndroidJavaObject("com.microsoft.appcenter.ingestion.models.WrapperSdk");
wrapperSdkObject.Call("setWrapperSdkVersion", wrapperSdkVersion);
wrapperSdkObject.Call("setWrapperSdkName", wrapperSdkName);
wrapperSdkObject.Call("setWrapperRuntimeVersion", wrapperRuntimeVersion);
wrapperSdkObject.Call("setLiveUpdateReleaseLabel", liveUpdateReleaseLabel);
wrapperSdkObject.Call("setLiveUpdateDeploymentKey", liveUpdateDeploymentKey);
wrapperSdkObject.Call("setLiveUpdatePackageHash", liveUpdatePackageHash);
_appCenter.CallStatic("setWrapperSdk", wrapperSdkObject);
}
public static void Start(string appSecret, Type[] services)
{
var nativeServiceTypes = ServicesToNativeTypes(services);
var rawAppSecretString = AndroidJNI.NewStringUTF(appSecret);
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "start", "(Landroid/app/Application;Ljava/lang/String;[Ljava/lang/Class;)V");
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
{
new jvalue { l = GetAndroidApplication().GetRawObject() },
new jvalue { l = rawAppSecretString },
new jvalue { l = nativeServiceTypes }
});
}
public static void Start(Type[] services)
{
var nativeServiceTypes = ServicesToNativeTypes(services);
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "start", "(Landroid/app/Application;[Ljava/lang/Class;)V");
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
{
new jvalue { l = GetAndroidApplication().GetRawObject() },
new jvalue { l = nativeServiceTypes }
});
}
public static void Start(Type service)
{
var nativeServiceTypes = ServicesToNativeTypes(new[] { service });
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "start", "([Ljava/lang/Class;)V");
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
{
new jvalue { l = nativeServiceTypes }
});
}
public static void StartFromLibrary(IntPtr servicesArray)
{
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "startFromLibrary", "(Landroid/content/Context;[Ljava/lang/Class;)V");
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
{
new jvalue { l = AndroidUtility.GetAndroidContext().GetRawObject() },
new jvalue { l = servicesArray }
});
}
public static IntPtr ServicesToNativeTypes(Type[] services)
{
var nativeTypes = new List<IntPtr>();
foreach (var serviceType in services)
{
serviceType.GetMethod("AddNativeType").Invoke(null, new object[] { nativeTypes });
}
var classClass = AndroidJNI.FindClass("java/lang/Class");
var array = AndroidJNI.NewObjectArray(nativeTypes.Count, classClass, classClass);
for (var i = 0; i < nativeTypes.Count; i++)
{
AndroidJNI.SetObjectArrayElement(array, i, nativeTypes[i]);
}
return array;
}
public static void SetMaxStorageSize(long size)
{
var future = _appCenter.CallStatic<AndroidJavaObject>("setMaxStorageSize", size);
new AppCenterTask<bool>(future).ContinueWith(task =>
{
if (!task.Result)
{
Debug.Log("Failed to set maximum storage size");
}
});
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b052932fad12b45e99d98bdef987081f
timeCreated: 1497286372
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine;
namespace Microsoft.AppCenter.Unity
{
public partial class AppCenterTask
{
public AppCenterTask(AndroidJavaObject javaFuture)
{
var consumer = new UnityAppCenterConsumer<AndroidJavaObject>();
consumer.CompletionCallback = t =>
{
CompletionAction();
};
javaFuture.Call("thenAccept", consumer);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 743be8834c3b3434f83ae6be8b0598b8
timeCreated: 1501260535
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using System;
using System.Threading;
using UnityEngine;
namespace Microsoft.AppCenter.Unity
{
public partial class AppCenterTask<TResult>
{
private ManualResetEvent _completionEvent = new ManualResetEvent(false);
private TResult _result;
private Exception _exception;
private UnityAppCenterConsumer<TResult> _consumer = new UnityAppCenterConsumer<TResult>();
// This will block if it is called before the task is complete
public TResult Result
{
get
{
// Locking in here is both unnecessary and can deadlock.
_completionEvent.WaitOne();
if (_exception == null)
{
return _result;
}
else
{
throw _exception;
}
}
}
public Exception Exception
{
get
{
return _exception;
}
}
public AppCenterTask(AndroidJavaObject javaFuture)
{
_consumer.CompletionCallback = SetResult;
javaFuture.Call("thenAccept", _consumer);
}
internal void SetResult(TResult result)
{
lock (_lockObject)
{
ThrowIfCompleted();
_consumer.CompletionCallback = null;
_result = result;
_completionEvent.Set();
CompletionAction();
}
}
internal void SetException(Exception exception)
{
lock (_lockObject)
{
ThrowIfCompleted();
_consumer.CompletionCallback = null;
_exception = exception;
_completionEvent.Set();
CompletionAction();
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4f35f227321dc4f6f9c684801e5cce3d
timeCreated: 1501260535
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using System;
using UnityEngine;
using Microsoft.AppCenter.Unity.Internal.Utility;
namespace Microsoft.AppCenter.Unity.Internal
{
class CustomPropertiesInternal
{
public static AndroidJavaObject Create()
{
return new AndroidJavaObject("com.microsoft.appcenter.CustomProperties");
}
public static void SetString(AndroidJavaObject properties, string key, string val)
{
properties.Call<AndroidJavaObject>("set", key, val);
}
public static void SetNumber(AndroidJavaObject properties, string key, int val)
{
properties.Call<AndroidJavaObject>("set", key, JavaNumberHelper.Convert(val));
}
public static void SetNumber(AndroidJavaObject properties, string key, long val)
{
properties.Call<AndroidJavaObject>("set", key, JavaNumberHelper.Convert(val));
}
public static void SetNumber(AndroidJavaObject properties, string key, float val)
{
properties.Call<AndroidJavaObject>("set", key, JavaNumberHelper.Convert(val));
}
public static void SetNumber(AndroidJavaObject properties, string key, double val)
{
properties.Call<AndroidJavaObject>("set", key, JavaNumberHelper.Convert(val));
}
public static void SetBool(AndroidJavaObject properties, string key, bool val)
{
properties.Call<AndroidJavaObject>("set", key, val);
}
public static void SetDate(AndroidJavaObject properties, string key, DateTime val)
{
properties.Call<AndroidJavaObject>("set", key, JavaDateHelper.DateTimeConvert(val));
}
public static void Clear(AndroidJavaObject properties, string key)
{
properties.Call<AndroidJavaObject>("clear", key);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 01d13d2a6a4d8490f96dacdc75d302e6
timeCreated: 1498588175
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine;
using System.Threading;
using System;
namespace Microsoft.AppCenter.Unity
{
public class UnityAppCenterConsumer<T> : AndroidJavaProxy
{
internal Action<T> CompletionCallback { get; set; }
internal UnityAppCenterConsumer() : base("com.microsoft.appcenter.utils.async.AppCenterConsumer")
{
}
void accept(T t)
{
if (CompletionCallback != null)
{
CompletionCallback(t);
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4844f0b5e5fec474d80ba40cee8f67ca
timeCreated: 1501260535
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: