Skip to content

Commit 2c87d37

Browse files
Fix/android secure storage plugin setup (#294)
* Move Android secure storage plugin into samples folder so that it can be imported into the assets folder - previously, we were encountering build issues where when secure storage wasn't enabled, we weren't able to toggle this plugin off as it was in the packages folder and immutable; this should fix this issue * Added a check to see if the URL scheme is lowercase; if not, log an error and open our warning popup to indicate that using uppercase characters in the URL scheme may lead to deeplinking issues on certain platforms (e.g. Android) * Cleaner warning logging and show warning popup * Fix how we find the plugin file * Fix platform compile test * Android plugin should only be enabled on Android * Increment package version
1 parent 4ac5832 commit 2c87d37

File tree

8 files changed

+86
-20
lines changed

8 files changed

+86
-20
lines changed

Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,33 @@ private static void AndroidBuildTest(string path, string[] scenes)
168168

169169
private static void AssertPluginCompatibility(SequenceConfig config, BuildTarget target)
170170
{
171-
PluginImporter pluginImporter = AssetImporter.GetAtPath(AndroidDependencyManager.SecureStoragePluginPath) as PluginImporter;
172-
Assert.IsNotNull(pluginImporter, "Plugin not found at path: " + AndroidDependencyManager.SecureStoragePluginPath);
173-
Assert.AreEqual(config.StoreSessionPrivateKeyInSecureStorage, pluginImporter.GetCompatibleWithPlatform(target));
171+
string[] files = Directory.GetFiles("Assets", AndroidDependencyManager.SecureStoragePluginFilename, SearchOption.AllDirectories);
172+
string pluginPath = files.FirstOrDefault();
173+
if (string.IsNullOrWhiteSpace(pluginPath))
174+
{
175+
files = Directory.GetFiles("Packages", AndroidDependencyManager.SecureStoragePluginFilename, SearchOption.AllDirectories);
176+
pluginPath = files.FirstOrDefault();
177+
}
178+
179+
Assert.IsFalse(string.IsNullOrWhiteSpace(pluginPath), $"Secure Storage plugin '{AndroidDependencyManager.SecureStoragePluginFilename}' not found in project.");
180+
181+
if (pluginPath.StartsWith("Packages"))
182+
{
183+
Debug.Log(
184+
$"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.");
185+
return;
186+
}
187+
188+
PluginImporter pluginImporter = AssetImporter.GetAtPath(pluginPath) as PluginImporter;
189+
Assert.IsNotNull(pluginImporter, $"Unable to create PluginImporter at path: {pluginPath}");
190+
191+
bool expected = config.StoreSessionPrivateKeyInSecureStorage;
192+
bool actual = pluginImporter.GetCompatibleWithPlatform(target);
193+
194+
Assert.AreEqual(expected, actual, $"Plugin compatibility mismatch. Expected: {expected}, Actual: {actual}");
174195
}
175196

197+
176198
private static void AssertAppropriateScriptingDefines(SequenceConfig config, BuildTarget target)
177199
{
178200
string defines = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(BuildPipeline.GetBuildTargetGroup(target)));
Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using Sequence.Config;
1+
using System.Collections.Generic;
22
using UnityEditor;
33
using UnityEditor.Build;
44
using UnityEditor.Build.Reporting;
5-
using UnityEditor.Callbacks;
65
using UnityEngine;
6+
using System.Linq;
7+
using Sequence.Config;
8+
using System.IO;
79

810
namespace Sequence.Editor
911
{
@@ -14,27 +16,48 @@ namespace Sequence.Editor
1416
/// </summary>
1517
public class AndroidDependencyManager : IPreprocessBuildWithReport
1618
{
17-
public const string SecureStoragePluginPath = "Packages/xyz.0xsequence.waas-unity/Plugins/Android/AndroidKeyBridge.java";
18-
19+
public const string SecureStoragePluginFilename = "AndroidKeyBridge.java";
20+
21+
private const string RelevantDocsUrl =
22+
"https://docs.sequence.xyz/sdk/unity/onboard/recovering-sessions#android";
23+
1924
public int callbackOrder => 0;
20-
25+
2126
public void OnPreprocessBuild(BuildReport report)
2227
{
2328
#if UNITY_ANDROID
2429
BuildTarget target = report.summary.platform;
2530
SequenceConfig config = SequenceConfig.GetConfig();
26-
27-
PluginImporter pluginImporter = AssetImporter.GetAtPath(SecureStoragePluginPath) as PluginImporter;
2831

32+
string[] files = Directory.GetFiles("Assets", SecureStoragePluginFilename, SearchOption.AllDirectories);
33+
string pluginPath = files.FirstOrDefault();
34+
if (string.IsNullOrEmpty(pluginPath))
35+
{
36+
if (config.StoreSessionPrivateKeyInSecureStorage)
37+
{
38+
ShowWarning($"Secure Storage plugin '{SecureStoragePluginFilename}' not found in project. Please make sure you have imported it via Samples in Package Manager");
39+
}
40+
return;
41+
}
42+
43+
PluginImporter pluginImporter = AssetImporter.GetAtPath(pluginPath) as PluginImporter;
2944
if (pluginImporter == null)
3045
{
31-
Debug.LogWarning($"Plugin not found at path: {SecureStoragePluginPath}");
46+
ShowWarning($"Unable to create {nameof(PluginImporter)} instance at path: {pluginPath}");
3247
return;
3348
}
34-
49+
3550
pluginImporter.SetCompatibleWithPlatform(target, config.StoreSessionPrivateKeyInSecureStorage);
3651
pluginImporter.SaveAndReimport();
52+
Debug.Log(
53+
$"Secure Storage plugin compatibility set to {config.StoreSessionPrivateKeyInSecureStorage} for path: {pluginPath}");
3754
#endif
3855
}
56+
57+
private void ShowWarning(string warning)
58+
{
59+
Debug.LogWarning(warning);
60+
SequenceWarningPopup.ShowWindow(new List<string>() {warning}, RelevantDocsUrl);
61+
}
3962
}
40-
}
63+
}

Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/Plugins/Android/AndroidKeyBridge.java.meta renamed to Packages/Sequence-Unity/Sequence/Samples~/AndroidSecureStorage/Plugins/Android/AndroidKeyBridge.java.meta

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xyz.0xsequence.waas-unity",
3-
"version": "4.1.1",
3+
"version": "4.1.2",
44
"displayName": "Sequence Embedded Wallet SDK",
55
"description": "A Unity SDK for Sequence APIs",
66
"unity": "2021.3",
@@ -45,6 +45,11 @@
4545
"description": "Basic demo scene showcasing the SDK functionality",
4646
"path": "Sequence/Samples~/DemoScene"
4747
},
48+
{
49+
"displayName": "Android Secure Storage",
50+
"description": "Android native code required for secure, Keystore-based, storage",
51+
"path": "Sequence/Samples~/AndroidSecureStorage"
52+
},
4853
{
4954
"displayName": "Useful Scripts",
5055
"description": "Basic scripts that are helpful for getting started with the SDK",

0 commit comments

Comments
 (0)