diff --git a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs index 472df140..f9572275 100644 --- a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs +++ b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs @@ -168,11 +168,33 @@ private static void AndroidBuildTest(string path, string[] scenes) private static void AssertPluginCompatibility(SequenceConfig config, BuildTarget target) { - PluginImporter pluginImporter = AssetImporter.GetAtPath(AndroidDependencyManager.SecureStoragePluginPath) as PluginImporter; - Assert.IsNotNull(pluginImporter, "Plugin not found at path: " + AndroidDependencyManager.SecureStoragePluginPath); - Assert.AreEqual(config.StoreSessionPrivateKeyInSecureStorage, pluginImporter.GetCompatibleWithPlatform(target)); + string[] files = Directory.GetFiles("Assets", AndroidDependencyManager.SecureStoragePluginFilename, SearchOption.AllDirectories); + string pluginPath = files.FirstOrDefault(); + if (string.IsNullOrWhiteSpace(pluginPath)) + { + files = Directory.GetFiles("Packages", AndroidDependencyManager.SecureStoragePluginFilename, SearchOption.AllDirectories); + pluginPath = files.FirstOrDefault(); + } + + Assert.IsFalse(string.IsNullOrWhiteSpace(pluginPath), $"Secure Storage plugin '{AndroidDependencyManager.SecureStoragePluginFilename}' not found in project."); + + if (pluginPath.StartsWith("Packages")) + { + Debug.Log( + $"Secure Storage plugin found in Packages directory at: {pluginPath}. Skipping the test to see if it is enabled/disabled appropriately based on config because we won't be able to create a {nameof(PluginImporter)}, you can move {AndroidDependencyManager.SecureStoragePluginFilename} to the Assets directory and try again."); + return; + } + + PluginImporter pluginImporter = AssetImporter.GetAtPath(pluginPath) as PluginImporter; + Assert.IsNotNull(pluginImporter, $"Unable to create PluginImporter at path: {pluginPath}"); + + bool expected = config.StoreSessionPrivateKeyInSecureStorage; + bool actual = pluginImporter.GetCompatibleWithPlatform(target); + + Assert.AreEqual(expected, actual, $"Plugin compatibility mismatch. Expected: {expected}, Actual: {actual}"); } + private static void AssertAppropriateScriptingDefines(SequenceConfig config, BuildTarget target) { string defines = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(BuildPipeline.GetBuildTargetGroup(target))); diff --git a/Packages/Sequence-Unity/Editor/AndroidDependencyManager.cs b/Packages/Sequence-Unity/Editor/AndroidDependencyManager.cs index 728f4790..fc1998a2 100644 --- a/Packages/Sequence-Unity/Editor/AndroidDependencyManager.cs +++ b/Packages/Sequence-Unity/Editor/AndroidDependencyManager.cs @@ -1,9 +1,11 @@ -using Sequence.Config; +using System.Collections.Generic; using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; -using UnityEditor.Callbacks; using UnityEngine; +using System.Linq; +using Sequence.Config; +using System.IO; namespace Sequence.Editor { @@ -14,27 +16,48 @@ namespace Sequence.Editor /// public class AndroidDependencyManager : IPreprocessBuildWithReport { - public const string SecureStoragePluginPath = "Packages/xyz.0xsequence.waas-unity/Plugins/Android/AndroidKeyBridge.java"; - + public const string SecureStoragePluginFilename = "AndroidKeyBridge.java"; + + private const string RelevantDocsUrl = + "https://docs.sequence.xyz/sdk/unity/onboard/recovering-sessions#android"; + public int callbackOrder => 0; - + public void OnPreprocessBuild(BuildReport report) { #if UNITY_ANDROID BuildTarget target = report.summary.platform; SequenceConfig config = SequenceConfig.GetConfig(); - - PluginImporter pluginImporter = AssetImporter.GetAtPath(SecureStoragePluginPath) as PluginImporter; + string[] files = Directory.GetFiles("Assets", SecureStoragePluginFilename, SearchOption.AllDirectories); + string pluginPath = files.FirstOrDefault(); + if (string.IsNullOrEmpty(pluginPath)) + { + if (config.StoreSessionPrivateKeyInSecureStorage) + { + ShowWarning($"Secure Storage plugin '{SecureStoragePluginFilename}' not found in project. Please make sure you have imported it via Samples in Package Manager"); + } + return; + } + + PluginImporter pluginImporter = AssetImporter.GetAtPath(pluginPath) as PluginImporter; if (pluginImporter == null) { - Debug.LogWarning($"Plugin not found at path: {SecureStoragePluginPath}"); + ShowWarning($"Unable to create {nameof(PluginImporter)} instance at path: {pluginPath}"); return; } - + pluginImporter.SetCompatibleWithPlatform(target, config.StoreSessionPrivateKeyInSecureStorage); pluginImporter.SaveAndReimport(); + Debug.Log( + $"Secure Storage plugin compatibility set to {config.StoreSessionPrivateKeyInSecureStorage} for path: {pluginPath}"); #endif } + + private void ShowWarning(string warning) + { + Debug.LogWarning(warning); + SequenceWarningPopup.ShowWindow(new List() {warning}, RelevantDocsUrl); + } } -} \ No newline at end of file +} diff --git a/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage.meta b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage.meta new file mode 100644 index 00000000..c2b7a088 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a925fdce6a58341318192029e3f7480b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins.meta b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins.meta new file mode 100644 index 00000000..4b6dafe1 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67c08eabe76b14fa29d08a69d8824664 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/Sequence-Unity/Plugins/Android.meta b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android.meta similarity index 100% rename from Packages/Sequence-Unity/Plugins/Android.meta rename to Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android.meta diff --git a/Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java similarity index 100% rename from Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java rename to Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java diff --git a/Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java.meta b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java.meta similarity index 94% rename from Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java.meta rename to Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java.meta index fc8abc26..f802b11c 100644 --- a/Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java.meta +++ b/Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java.meta @@ -49,11 +49,11 @@ PluginImporter: second: enabled: 0 settings: - CPU: AnyCPU + CPU: None - first: Standalone: OSXUniversal second: - enabled: 1 + enabled: 0 settings: CPU: None - first: @@ -61,17 +61,17 @@ PluginImporter: second: enabled: 0 settings: - CPU: x86 + CPU: None - first: Standalone: Win64 second: enabled: 0 settings: - CPU: x86_64 + CPU: None - first: WebGL: WebGL second: - enabled: 1 + enabled: 0 settings: {} - first: Windows Store Apps: WindowsStoreApps @@ -86,7 +86,7 @@ PluginImporter: - first: iPhone: iOS second: - enabled: 1 + enabled: 0 settings: AddToEmbeddedBinaries: false CPU: AnyCPU diff --git a/Packages/Sequence-Unity/package.json b/Packages/Sequence-Unity/package.json index 1993eee6..07d6a30a 100644 --- a/Packages/Sequence-Unity/package.json +++ b/Packages/Sequence-Unity/package.json @@ -1,6 +1,6 @@ { "name": "xyz.0xsequence.waas-unity", - "version": "4.1.1", + "version": "4.1.2", "displayName": "Sequence Embedded Wallet SDK", "description": "A Unity SDK for Sequence APIs", "unity": "2021.3", @@ -45,6 +45,11 @@ "description": "Basic demo scene showcasing the SDK functionality", "path": "Sequence/Samples~/DemoScene" }, + { + "displayName": "Android Secure Storage", + "description": "Android native code required for secure, Keystore-based, storage", + "path": "Sequence/Samples~/AndroidSecureStorage" + }, { "displayName": "Useful Scripts", "description": "Basic scripts that are helpful for getting started with the SDK",