Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
43 changes: 33 additions & 10 deletions Packages/Sequence-Unity/Editor/AndroidDependencyManager.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -14,27 +16,48 @@ namespace Sequence.Editor
/// </summary>
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<string>() {warning}, RelevantDocsUrl);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Packages/Sequence-Unity/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down