diff --git a/AppCenterLoaderApp/appcenter-loader/src/main/java/com/microsoft/appcenter/loader/AppCenterLoader.java b/AppCenterLoaderApp/appcenter-loader/src/main/java/com/microsoft/appcenter/loader/AppCenterLoader.java index 2a276b69..39898220 100644 --- a/AppCenterLoaderApp/appcenter-loader/src/main/java/com/microsoft/appcenter/loader/AppCenterLoader.java +++ b/AppCenterLoaderApp/appcenter-loader/src/main/java/com/microsoft/appcenter/loader/AppCenterLoader.java @@ -44,7 +44,7 @@ public class AppCenterLoader extends ContentProvider { private static final String APP_SECRET_KEY = "appcenter_app_secret"; private static final String TRANSMISSION_TARGET_TOKEN_KEY = "appcenter_transmission_target_token"; private static final String STARTUP_TYPE_KEY = "appcenter_startup_type"; - private static final String STARTUP_TYPE_SHARED_PREFERENCES_KEY = "start-target-user-defaults-key"; + private static final String STARTUP_TYPE_SHARED_PREFERENCES_KEY = "AppCenter.Unity.StartTargetKey"; private static final String TRUE_VALUE = "True"; private static final String TAG = "AppCenterLoader"; diff --git a/Assets/AppCenter/Plugins/Android/Utility/AndroidUtility.cs b/Assets/AppCenter/Plugins/Android/Utility/AndroidUtility.cs new file mode 100644 index 00000000..0e08c952 --- /dev/null +++ b/Assets/AppCenter/Plugins/Android/Utility/AndroidUtility.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace Assets.AppCenter.Plugins.Android.Utility +{ + class AndroidUtility + { + private static AndroidJavaObject _context; + private static string PREFS_NAME = "AppCenterUserPrefs"; + + public static AndroidJavaObject GetAndroidContext() + { + if (_context != null) + { + return _context; + } + var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); + var activity = unityPlayer.GetStatic("currentActivity"); + _context = activity.Call("getApplicationContext"); + return _context; + } + + public static void SetPreferenceInt(string prefKey, int prefValue) + { + AndroidJavaObject context = GetAndroidContext(); + AndroidJavaObject sharedPreferences = context.Call("getSharedPreferences", new object[] { PREFS_NAME, 0 }); + AndroidJavaObject editor = sharedPreferences.Call("edit"); + editor = editor.Call("putInt", new object[] { prefKey, prefValue }); + editor.Call("apply"); + } + } +} diff --git a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Android/AppCenterInternal.cs b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Android/AppCenterInternal.cs index 0f12858c..1b90ce14 100644 --- a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Android/AppCenterInternal.cs +++ b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Android/AppCenterInternal.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. #if UNITY_ANDROID && !UNITY_EDITOR +using Assets.AppCenter.Plugins.Android.Utility; using System; using System.Collections.Generic; using UnityEngine; @@ -11,8 +12,6 @@ namespace Microsoft.AppCenter.Unity.Internal class AppCenterInternal { private static AndroidJavaClass _appCenter = new AndroidJavaClass("com.microsoft.appcenter.AppCenter"); - private static AndroidJavaObject _context; - private static String PREFS_NAME = "AppCenterUserPrefs"; public static void SetLogLevel(int logLevel) { @@ -132,32 +131,12 @@ namespace Microsoft.AppCenter.Unity.Internal }); } - private static AndroidJavaObject GetAndroidContext() - { - if (_context != null) - { - return _context; - } - var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); - var activity = unityPlayer.GetStatic("currentActivity"); - _context = activity.Call("getApplicationContext"); - return _context; - } - - public static void SetPreferenceInt(string prefKey, int prefValue) { - AndroidJavaObject context = GetAndroidContext(); - AndroidJavaObject sharedPreferences = context.Call("getSharedPreferences", new object[] { PREFS_NAME, 0 }); - AndroidJavaObject editor = sharedPreferences.Call("edit"); - editor = editor.Call("putInt", new object[] { prefKey, prefValue }); - editor.Call("apply"); - } - 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 = GetAndroidContext().GetRawObject() }, + new jvalue { l = AndroidUtility.GetAndroidContext().GetRawObject() }, new jvalue { l = servicesArray } }); } diff --git a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Blank/AppCenterInternal.cs b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Blank/AppCenterInternal.cs index 3d981a7c..3646e851 100644 --- a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Blank/AppCenterInternal.cs +++ b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Blank/AppCenterInternal.cs @@ -37,10 +37,6 @@ namespace Microsoft.AppCenter.Unity.Internal { } - public static void SetPreferenceInt(string prefKey, int prefValue) - { - } - public static void Start(string appSecret, ServiceType[] services) { } diff --git a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Shared/AppCenter.cs b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Shared/AppCenter.cs index b9d7355b..e3b06001 100644 --- a/Assets/AppCenter/Plugins/AppCenterSDK/Core/Shared/AppCenter.cs +++ b/Assets/AppCenter/Plugins/AppCenterSDK/Core/Shared/AppCenter.cs @@ -38,11 +38,6 @@ namespace Microsoft.AppCenter.Unity AppCenterInternal.StartFromLibrary(AppCenterInternal.ServicesToNativeTypes(servicesArray)); } - public static void SetPreferenceInt(string prefKey, int prefValue) - { - AppCenterInternal.SetPreferenceInt(prefKey, prefValue); - } - public static AppCenterTask IsEnabledAsync() { return AppCenterInternal.IsEnabledAsync(); diff --git a/Assets/AppCenter/Plugins/AppCenterSDK/Core/UWP/AppCenterInternal.cs b/Assets/AppCenter/Plugins/AppCenterSDK/Core/UWP/AppCenterInternal.cs index a409f4cb..41cca890 100644 --- a/Assets/AppCenter/Plugins/AppCenterSDK/Core/UWP/AppCenterInternal.cs +++ b/Assets/AppCenter/Plugins/AppCenterSDK/Core/UWP/AppCenterInternal.cs @@ -31,10 +31,6 @@ namespace Microsoft.AppCenter.Unity.Internal UWPAppCenter.Start(appSecret, nativeServiceTypes); } - public static void SetPreferenceInt(string prefKey, int prefValue) - { - } - public static void Start(Type[] services) { var nativeServiceTypes = ServicesToNativeTypes(services); diff --git a/Assets/AppCenter/Plugins/AppCenterSDK/Core/iOS/AppCenterInternal.cs b/Assets/AppCenter/Plugins/AppCenterSDK/Core/iOS/AppCenterInternal.cs index 1842888b..1debd3e1 100644 --- a/Assets/AppCenter/Plugins/AppCenterSDK/Core/iOS/AppCenterInternal.cs +++ b/Assets/AppCenter/Plugins/AppCenterSDK/Core/iOS/AppCenterInternal.cs @@ -28,10 +28,6 @@ namespace Microsoft.AppCenter.Unity.Internal return appcenter_unity_get_log_level(); } - public static void SetPreferenceInt(string prefKey, int prefValue) - { - } - public static string GetSdkVersion() { return appcenter_unity_get_sdk_version(); diff --git a/Assets/AppCenter/Plugins/iOS/Core/AppCenterStarter.original b/Assets/AppCenter/Plugins/iOS/Core/AppCenterStarter.original index 7b955c23..3417a399 100644 --- a/Assets/AppCenter/Plugins/iOS/Core/AppCenterStarter.original +++ b/Assets/AppCenter/Plugins/iOS/Core/AppCenterStarter.original @@ -40,7 +40,7 @@ static NSString *const kMSTargetToken = @"appcenter-transmission-target-token"; static NSString *const kMSCustomLogUrl = @"custom-log-url"; static NSString *const kMSCustomApiUrl = @"custom-api-url"; static NSString *const kMSCustomInstallUrl = @"custom-install-url"; -static NSString *const kMSStartTargetKey = @"start-target-user-defaults-key"; +static NSString *const kMSStartTargetKey = @"MSAppCenterStartTargetUnityKey"; static const int kMSLogLevel = 0/*LOG_LEVEL*/; static const int kMSStartupType = 0/*STARTUP_TYPE*/; diff --git a/Assets/Puppet/PuppetAppCenter.cs b/Assets/Puppet/PuppetAppCenter.cs index ff1f4ec7..58299125 100644 --- a/Assets/Puppet/PuppetAppCenter.cs +++ b/Assets/Puppet/PuppetAppCenter.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using Assets.AppCenter.Plugins.Android.Utility; using Microsoft.AppCenter.Unity; using Microsoft.AppCenter.Unity.Distribute; using Microsoft.AppCenter.Unity.Push; @@ -28,7 +29,8 @@ public class PuppetAppCenter : MonoBehaviour public const string TextAttachmentKey = "text_attachment"; public const string BinaryAttachmentKey = "binary_attachment"; public const string UserIdKey = "user_id"; - private const string StartupModeKey = "start-target-user-defaults-key"; + private const string StartupModeAndroidKey = "AppCenter.Unity.StartTargetKey"; + private const string StartupModeKey = "MSAppCenterStartTargetUnityKey"; public GameObject CustomProperty; public RectTransform PropertiesList; public Toggle DistributeEnabled; @@ -177,7 +179,7 @@ public class PuppetAppCenter : MonoBehaviour PlayerPrefs.SetInt(StartupModeKey, startupMode); PlayerPrefs.Save(); #if UNITY_ANDROID && !UNITY_EDITOR - AppCenter.SetPreferenceInt(StartupModeKey, startupMode); + AndroidUtility.SetPreferenceInt(StartupModeAndroidKey, startupMode); #endif } diff --git a/Assets/Puppet/PuppetTransmission.cs b/Assets/Puppet/PuppetTransmission.cs index 151a10df..6f58e66d 100644 --- a/Assets/Puppet/PuppetTransmission.cs +++ b/Assets/Puppet/PuppetTransmission.cs @@ -345,7 +345,6 @@ public class PuppetTransmission : MonoBehaviour public void TrackEventTypedPropertiesDefaultTransmission() { - var properties = PropertiesHelper.GetTypedProperties(EventPropertiesList); if (properties == null) {