com.amanotes.gdk 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/Packages/AmaGDKConfig.unitypackage +0 -0
  3. package/Packages/AmaGDKExample.unitypackage +0 -0
  4. package/Packages/AmaGDKTest.unitypackage +0 -0
  5. package/{Tests/TestScene00.unity.meta → Packages/AmaGDKTest.unitypackage.meta} +1 -1
  6. package/Packages/AppsflyerAdapter_v6.5.4.unitypackage +0 -0
  7. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  8. package/Runtime/AmaGDK.Adapters.cs +28 -47
  9. package/Runtime/AmaGDK.Analytics.cs +120 -23
  10. package/Runtime/AmaGDK.Config.cs +1 -1
  11. package/Runtime/AmaGDK.Internal.cs +12 -4
  12. package/Runtime/AmaGDK.RemoteConfig.cs +116 -0
  13. package/{Tests/Runtime/AmaGDKCoreTest.cs.meta → Runtime/AmaGDK.RemoteConfig.cs.meta} +1 -1
  14. package/Runtime/AmaGDK.UserProfile.cs +10 -11
  15. package/Runtime/AmaGDK.Utils.cs +196 -7
  16. package/Runtime/AmaGDK.WebUtils.cs +106 -17
  17. package/Runtime/AmaGDK.cs +21 -18
  18. package/Runtime/AmaPassport/AmaGDK.AmaPassport.cs +444 -0
  19. package/{Tests/Runtime/MigrationTest.cs.meta → Runtime/AmaPassport/AmaGDK.AmaPassport.cs.meta} +1 -1
  20. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdCallback.java +7 -0
  21. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdCallback.java.meta +32 -0
  22. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.cs +96 -0
  23. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.cs.meta +11 -0
  24. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.java +79 -0
  25. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.java.meta +32 -0
  26. package/{Tests/Runtime.meta → Runtime/AmaPassport/Plugins/Android.meta} +1 -1
  27. package/Runtime/AmaPassport/Plugins/iOS/KeyChain.cs +59 -0
  28. package/Runtime/AmaPassport/Plugins/iOS/KeyChain.cs.meta +11 -0
  29. package/Runtime/AmaPassport/Plugins/iOS/KeyChainPlugin.mm +52 -0
  30. package/Runtime/AmaPassport/Plugins/iOS/KeyChainPlugin.mm.meta +33 -0
  31. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.h +281 -0
  32. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.h.meta +33 -0
  33. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.m +1393 -0
  34. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.m.meta +33 -0
  35. package/Runtime/AmaPassport/Plugins/iOS.meta +8 -0
  36. package/{Tests/Editor.meta → Runtime/AmaPassport/Plugins.meta} +1 -1
  37. package/{Tests.meta → Runtime/AmaPassport.meta} +1 -1
  38. package/package.json +5 -2
  39. package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
  40. package/Tests/Editor/AmaGDK.Editor.Test.asmdef +0 -23
  41. package/Tests/Editor/AmaGDK.Editor.Test.asmdef.meta +0 -7
  42. package/Tests/Runtime/AmaGDK.Test.asmdef +0 -20
  43. package/Tests/Runtime/AmaGDK.Test.asmdef.meta +0 -7
  44. package/Tests/Runtime/AmaGDKCoreTest.cs +0 -228
  45. package/Tests/Runtime/MigrationTest.cs +0 -165
  46. package/Tests/TestScene00.unity +0 -125
  47. package/Tests/TestScene01.unity +0 -199
  48. package/Tests/TestScene01.unity.meta +0 -7
  49. package/Tests/TestScene02.unity +0 -209
  50. package/Tests/TestScene02.unity.meta +0 -7
  51. package/Tests/TestScene03.unity +0 -599
  52. package/Tests/TestScene03.unity.meta +0 -7
@@ -1,6 +1,8 @@
1
1
  using System;
2
+ using System.Collections;
2
3
  using System.Collections.Generic;
3
4
  using System.IO;
5
+ using System.Text;
4
6
  using UnityEngine;
5
7
 
6
8
  using static Amanotes.Core.Internal.Logging;
@@ -39,6 +41,54 @@ namespace Amanotes.Core.Internal
39
41
  }
40
42
  }
41
43
 
44
+ internal static void SaveAppend(string fileName, IEnumerable<string> contents)
45
+ {
46
+ if (string.IsNullOrWhiteSpace(fileName))
47
+ {
48
+ LogWarningOnce($"File name must be not null or empty");
49
+ return;
50
+ }
51
+
52
+ if (contents == null || !contents.GetEnumerator().MoveNext())
53
+ {
54
+ LogWarningOnce($"Content for {fileName} is empty");
55
+ }
56
+
57
+ string path = GetPath(fileName);
58
+ try
59
+ {
60
+ File.AppendAllLines(path, contents);
61
+ }
62
+ catch (Exception ex)
63
+ {
64
+ LogWarningOnce(path + "\n" + ex);
65
+ }
66
+ }
67
+
68
+ internal static void SaveAppend(string fileName, string content)
69
+ {
70
+ if (string.IsNullOrWhiteSpace(fileName))
71
+ {
72
+ LogWarningOnce($"File name must be not null or empty");
73
+ return;
74
+ }
75
+
76
+ if (string.IsNullOrWhiteSpace(content))
77
+ {
78
+ LogWarningOnce($"Content for {fileName} is empty");
79
+ }
80
+
81
+ string path = GetPath(fileName);
82
+ try
83
+ {
84
+ File.AppendAllText(path, content);
85
+ }
86
+ catch (Exception ex)
87
+ {
88
+ LogWarningOnce(path + "\n" + ex);
89
+ }
90
+ }
91
+
42
92
  internal static string Load(string fileName)
43
93
  {
44
94
  string content = "";
@@ -117,15 +167,9 @@ namespace Amanotes.Core.Internal
117
167
 
118
168
  foreach (var action in actions)
119
169
  {
120
- if (action == null)
121
- {
122
- LogWarning("action is null!");
123
- continue;
124
- }
170
+ if (action == null) continue;
125
171
  queue.Enqueue(action);
126
172
  }
127
-
128
- ProcessQueue();
129
173
  }
130
174
 
131
175
  private void ProcessQueue()
@@ -154,6 +198,11 @@ namespace Amanotes.Core.Internal
154
198
  onComplete?.Invoke();
155
199
  }
156
200
 
201
+ public void StartQueue()
202
+ {
203
+ ProcessQueue();
204
+ }
205
+
157
206
  private void ActionCompleted()
158
207
  {
159
208
  isProcessing = false;
@@ -185,4 +234,144 @@ namespace Amanotes.Core.Internal
185
234
  FileUtils.Save(fileName, json);
186
235
  }
187
236
  }
237
+
238
+ internal static class JsonUtils
239
+ {
240
+ public static string TupleToJson(params (string key, object value)[] parameters)
241
+ {
242
+ Dictionary<string, object> tupleToDict = new Dictionary<string, object>();
243
+ foreach (var item in parameters)
244
+ {
245
+ tupleToDict.Add(item.key, item.value);
246
+ }
247
+ return DictionaryToJson(tupleToDict);
248
+ }
249
+
250
+ public static string KeyValueToJson(string key, object value)
251
+ {
252
+ return DictionaryToJson(new Dictionary<string, object>() { { key, value } });
253
+ }
254
+
255
+ public static string DictionaryToJson(IDictionary inputDict, bool format = false)
256
+ {
257
+ if (inputDict == null)
258
+ return "{}";
259
+
260
+ StringBuilder jsonSb = new StringBuilder();
261
+ jsonSb.Append("{");
262
+ var isFirstElement = true;
263
+
264
+ foreach (DictionaryEntry entry in inputDict)
265
+ {
266
+ if (entry.Key == null || string.IsNullOrEmpty(entry.Key.ToString()))
267
+ {
268
+ continue;
269
+ }
270
+ var key = entry.Key.ToString();
271
+ var value = entry.Value;
272
+
273
+ if (isFirstElement)
274
+ isFirstElement = false;
275
+ else
276
+ jsonSb.Append(",");
277
+
278
+ jsonSb.AppendFormat("{0}\"{1}\":", format ? "\n" : "", key);
279
+ AppendJsonValue(ref jsonSb, key, value, format);
280
+
281
+ }
282
+
283
+ jsonSb.AppendFormat("{0}{1}", format ? "\n" : "", "}");
284
+
285
+ return jsonSb.ToString();
286
+ }
287
+
288
+ private static void GetJsonIListValue(ref StringBuilder jsonSb, string key, IList list, bool format)
289
+ {
290
+ jsonSb.Append("[");
291
+ var isFirstElement = true;
292
+
293
+ foreach (var item in list)
294
+ {
295
+ if (isFirstElement)
296
+ isFirstElement = false;
297
+ else
298
+ jsonSb.Append(",");
299
+
300
+ if (format)
301
+ jsonSb.AppendLine();
302
+ AppendJsonValue(ref jsonSb, key, item, format);
303
+ }
304
+
305
+ if (format)
306
+ {
307
+ jsonSb.AppendLine();
308
+ }
309
+ jsonSb.Append("]");
310
+ }
311
+
312
+ private static void AppendJsonValue(ref StringBuilder jsonSb, string key, object value, bool format)
313
+ {
314
+ if (value == null)
315
+ {
316
+ jsonSb.Append("null");
317
+ }
318
+ if (value is string)
319
+ {
320
+ jsonSb.Append($"\"{value}\"");
321
+ }
322
+ else if (value is int || value is float || value is double || value is long)
323
+ {
324
+ jsonSb.Append($"{value}");
325
+ }
326
+ else if (value is bool)
327
+ {
328
+ jsonSb.Append((bool)value ? "true" : "false");
329
+ }
330
+ else if (value is IDictionary)
331
+ {
332
+ jsonSb.Append($"{DictionaryToJson((IDictionary)value, format)}");
333
+ }
334
+ else if (value is IList || value is Array)
335
+ {
336
+ GetJsonIListValue(ref jsonSb, key, (IList)value, format);
337
+ }
338
+ else
339
+ {
340
+ jsonSb.Append($"{JsonUtility.ToJson(value, format)}");
341
+ }
342
+ }
343
+
344
+ //public static T[] FromJsonToArray<T>(string json)
345
+ //{
346
+ // if (!json.StartsWith("{\"items\":"))
347
+ // {
348
+ // json = $"{{\"items\":{json}}}";
349
+ // }
350
+ // Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(json);
351
+ // return wrapper.items;
352
+ //}
353
+
354
+ //public static T FromJsonToObject<T>(string json)
355
+ //{
356
+ // return JsonUtility.FromJson<T>(json);
357
+ //}
358
+
359
+ //public static string ToJson<T>(T[] array)
360
+ //{
361
+ // Wrapper<T> wrapper = new Wrapper<T>();
362
+ // wrapper.items = array;
363
+ // return JsonUtility.ToJson(wrapper);
364
+ //}
365
+
366
+ //public static string ToJson<T>(T obj)
367
+ //{
368
+ // return JsonUtility.ToJson(obj);
369
+ //}
370
+
371
+ //[Serializable]
372
+ //private class Wrapper<T>
373
+ //{
374
+ // public T[] items;
375
+ //}
376
+ }
188
377
  }
@@ -1,17 +1,105 @@
1
- using System.Collections;
2
- using UnityEngine.Networking;
3
- using System;
1
+ using System.Collections;
2
+ using UnityEngine.Networking;
3
+ using System;
4
4
  using System.Collections.Generic;
5
+ using UnityEngine;
5
6
  using static Amanotes.Core.Internal.Logging;
6
7
 
7
8
  namespace Amanotes.Core.Internal
8
- {
9
- internal class WebUtils
9
+ {
10
+ public class JsonWebRequest<T> : UnityWebRequest where T : class
10
11
  {
11
- public static void PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
12
+
13
+ [Serializable]
14
+ internal class ResponseError
15
+ {
16
+ public string error;
17
+ public string message;
18
+ public string statusCode;
19
+ }
20
+
21
+ [Serializable]
22
+ internal class ResponseT
12
23
  {
13
- AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
24
+ public T data;
25
+ public ResponseError error = null;
26
+ }
27
+
28
+ private string requestJson;
29
+ private string requestHeader;
30
+ public T data;
31
+ public bool isResponseError;
32
+
33
+ public JsonWebRequest(string url, string json, string header = "") : base(url, "POST")
34
+ {
35
+ requestJson = json;
36
+ requestHeader = header;
37
+ }
38
+
39
+ public JsonWebRequest<T> SetRequestHeader(Dictionary<string, string> headers)
40
+ {
41
+ foreach (KeyValuePair<string, string> kvp in headers)
42
+ {
43
+ SetRequestHeader(kvp.Key, kvp.Value);
44
+ }
45
+ return this;
46
+ }
47
+
48
+ public new IEnumerator Send()
49
+ {
50
+ byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(requestJson);
51
+ uploadHandler = new UploadHandlerRaw(bodyRaw);
52
+ downloadHandler = new DownloadHandlerBuffer();
53
+ SetRequestHeader(new Dictionary<string, string>
54
+ {
55
+ {"Authorization", $"bearer {requestHeader}"},
56
+ {"Content-Type", "application/json"},
57
+ {"api-token", requestHeader}
58
+ });
59
+ yield return SendWebRequest();
60
+
61
+ var httpError = result == Result.ConnectionError || result == Result.ProtocolError;
62
+ if (httpError)
63
+ {
64
+ LogWarning($"{url} returned {responseCode}: {error}");
65
+ yield break;
66
+ }
67
+
68
+ try
69
+ {
70
+ string result = downloadHandler.text;
71
+ var response = JsonUtility.FromJson<ResponseT>(result);
72
+ if (response == null)
73
+ {
74
+ LogWarning("Response parse fail???\n" + result);
75
+ yield break;
76
+ }
77
+
78
+ if (!string.IsNullOrEmpty(response.error?.message))
79
+ {
80
+ LogWarning($"server return error: errorMessage = {response.error?.message}");
81
+ isResponseError = true;
82
+ yield break;
83
+ }
84
+
85
+ data = response.data;
86
+ }
87
+ catch (Exception ex)
88
+ {
89
+ LogWarning($"Error parsing {typeof(T)}: {ex.Message}\n");
90
+ isResponseError = true;
91
+ yield break;
92
+ }
14
93
  }
94
+ }
95
+
96
+
97
+ internal class WebUtils
98
+ {
99
+ public static Coroutine PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
100
+ {
101
+ return AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
102
+ }
15
103
 
16
104
  static IEnumerator PostJsonCoroutine(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
17
105
  {
@@ -29,15 +117,16 @@ namespace Amanotes.Core.Internal
29
117
  webRequest.downloadHandler = new DownloadHandlerBuffer();
30
118
  yield return webRequest.SendWebRequest();
31
119
 
32
- if (webRequest.result != UnityWebRequest.Result.Success)
33
- {
34
- LogWarning("POST request failed: " + webRequest.error);
35
- onComplete?.Invoke(false, webRequest.error);
36
- }
37
- else
38
- {
39
- onComplete?.Invoke(true, webRequest.downloadHandler.text);
40
- }
120
+ if (webRequest.result != UnityWebRequest.Result.Success)
121
+ {
122
+ onComplete?.Invoke(false, webRequest.error);
123
+
124
+ }
125
+ else
126
+ {
127
+ onComplete?.Invoke(true, webRequest.downloadHandler.text);
128
+ }
129
+ yield return null;
41
130
  }
42
- }
131
+ }
43
132
  }
package/Runtime/AmaGDK.cs CHANGED
@@ -12,24 +12,26 @@ namespace Amanotes.Core
12
12
  {
13
13
  public partial class AmaGDK : MonoBehaviour
14
14
  {
15
- public const string VERSION = "0.1.18";
15
+ public const string VERSION = "0.1.19";
16
16
 
17
17
  internal static AmaGDK _instance;
18
18
  internal static event Action _frameUpdate;
19
+ internal static Status _status = Status.None;
20
+ internal static Action _onReadyCallback;
21
+ internal static bool _allowInit = false;
22
+ public bool autoInit = true;
23
+
19
24
  private static ConfigAsset _config = null;
20
- internal static ConfigAsset Config {
21
- get {
25
+ internal static ConfigAsset Config
26
+ {
27
+ get
28
+ {
22
29
  if (_config != null) return _config;
23
30
  _config = Resources.Load<ConfigAsset>("AmaGDKConfig");
24
31
  // if (_config == null) LogWarningOnce(CONFIG_NOT_FOUND);
25
32
  return _config;
26
33
  }
27
34
  }
28
-
29
- internal static Status _status = Status.None;
30
- internal static Action _onReadyCallback;
31
- internal static bool _allowInit = false;
32
- public bool autoInit = true;
33
35
 
34
36
  void Awake()
35
37
  {
@@ -52,7 +54,7 @@ namespace Amanotes.Core
52
54
  _allowInit = _allowInit || autoInit;
53
55
  StartCoroutine(InitRoutine());
54
56
  }
55
-
57
+
56
58
  IEnumerator InitRoutine()
57
59
  {
58
60
  if (Config == null)
@@ -62,7 +64,7 @@ namespace Amanotes.Core
62
64
 
63
65
  float time = 0;
64
66
  float timeout = 3;
65
-
67
+
66
68
  var counter = 0;
67
69
  const int INIT_TOLERANCE = 10 * 60;
68
70
  const int INIT_WARN_CYCLE = 5 * 60;
@@ -81,10 +83,10 @@ namespace Amanotes.Core
81
83
  _status = Status.Initialize;
82
84
 
83
85
  // sort on priority
84
- Adapter.listAdapters.Sort((a1, a2)=> a1.initOrder.CompareTo(a2.initOrder));
86
+ Adapter.listAdapters.Sort((a1, a2) => a1.initOrder.CompareTo(a2.initOrder));
85
87
  foreach (var adapter in Adapter.listAdapters)
86
88
  {
87
- Log($"Initing {adapter.id} --> initOrder: {adapter.initOrder}");
89
+ Log($"Initing {adapter.adapterId} --> initOrder: {adapter.initOrder}");
88
90
  adapter.Init();
89
91
 
90
92
  while (!adapter.IsReady)
@@ -92,16 +94,17 @@ namespace Amanotes.Core
92
94
  time += Time.deltaTime;
93
95
  yield return null;
94
96
  if (time <= timeout) continue;
95
- LogWarningOnce($"{adapter.id} init time out: {timeout}");
97
+ LogWarningOnce($"{adapter.adapterId} init time out: {timeout}");
96
98
  }
97
99
 
98
- Log($"Adapter {adapter.id} inited!");
100
+ Log($"Adapter {adapter.adapterId} inited!");
99
101
  }
100
102
 
101
103
  // Init modules (Adapter managers)
102
104
  Analytics.Init();
105
+ RemoteConfig.Init();
103
106
  //Ads.Init();
104
-
107
+
105
108
  _status = Status.Ready;
106
109
  _onReadyCallback?.Invoke();
107
110
  _onReadyCallback = null;
@@ -143,11 +146,11 @@ namespace Amanotes.Core
143
146
  _allowInit = true;
144
147
 
145
148
  if (_instance != null) return;
146
- var sdk = new GameObject("AmaGDK5");
149
+ var sdk = new GameObject("AmaGDK");
147
150
  _instance = sdk.AddComponent<AmaGDK>();
148
151
  }
149
152
 
150
-
153
+
151
154
 
152
155
  public static void SetOnReadyCallback(Action onReady)
153
156
  {
@@ -170,7 +173,7 @@ namespace Amanotes.Core
170
173
  public const string FIREBASE_REMOTE_CONFIG = "FirebaseRemoteConfig";
171
174
  public const string APPSFLYER = "AppsFlyer";
172
175
  public const string IRONSOURCE = "IronSource";
173
- public const string REVENUECAT = "RevenueCat";
176
+ public const string REVENUECAT = "RevenueCat";
174
177
  }
175
178
  }
176
179
  }