com.amanotes.gdk 0.1.21 → 0.2.2
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.
- package/CHANGELOG.md +5 -5
- package/Editor/AmaGDKEditor.cs +91 -46
- package/Editor/AmaGDKManager.cs +26 -27
- package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +133 -103
- package/Editor/Utils/AmaGDKEditor.GUI.cs +54 -51
- package/Editor/Utils/AmaGDKEditor.Utils.cs +2 -3
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AmaPassport.ATTSupport.unitypackage +0 -0
- package/Packages/AmaPassport.ATTSupport.unitypackage.meta +7 -0
- package/Packages/AmaPassport.AdvertisingID.unitypackage +0 -0
- package/Packages/AmaPassport.AdvertisingID.unitypackage.meta +7 -0
- package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta +1 -1
- package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
- package/Runtime/AmaGDK.Adapters.cs +13 -14
- package/Runtime/AmaGDK.Ads.cs +523 -151
- package/Runtime/AmaGDK.AmaPassport.cs +433 -0
- package/Runtime/AmaGDK.AmaPassport.cs.meta +11 -0
- package/Runtime/AmaGDK.Analytics.cs +78 -89
- package/Runtime/AmaGDK.Config.cs +23 -19
- package/Runtime/AmaGDK.Internal.SemVer.cs +11 -29
- package/Runtime/AmaGDK.Internal.cs +16 -11
- package/Runtime/AmaGDK.RemoteConfig.cs +32 -23
- package/Runtime/AmaGDK.UserProfile.cs +5 -8
- package/Runtime/AmaGDK.Utils.cs +40 -50
- package/Runtime/AmaGDK.WebUtils.cs +42 -42
- package/Runtime/AmaGDK.cs +70 -20
- package/Runtime/AssemblyInfo.cs +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using Amanotes.Core.Internal;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.Networking;
|
|
7
|
+
using static Amanotes.Core.Internal.Logging;
|
|
8
|
+
|
|
9
|
+
namespace Amanotes.Core.Internal
|
|
10
|
+
{
|
|
11
|
+
[Serializable]
|
|
12
|
+
public class AmaPassportConfig
|
|
13
|
+
{
|
|
14
|
+
public string secretKey;
|
|
15
|
+
public bool enableAmaPassport;
|
|
16
|
+
public bool injectLocation;
|
|
17
|
+
public bool injectAdvertisingId;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public partial class ConfigAsset
|
|
21
|
+
{
|
|
22
|
+
public AmaPassportConfig amaPassport;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public class AmaPassportSupport
|
|
26
|
+
{
|
|
27
|
+
public static void SetAdvertisingID(string id)
|
|
28
|
+
{
|
|
29
|
+
var device = AmaGDK.User.amaPassport.device;
|
|
30
|
+
switch (Application.platform)
|
|
31
|
+
{
|
|
32
|
+
case RuntimePlatform.IPhonePlayer:
|
|
33
|
+
device.idfa = id;
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
case RuntimePlatform.Android:
|
|
37
|
+
device.gaid = id;
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
default:
|
|
41
|
+
LogWarning("Unsupported platform: " + Application.platform);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static void SetAmaDeviceId(string id)
|
|
47
|
+
{
|
|
48
|
+
AmaGDK.User.amaPassport.device.amaDeviceId = id;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
namespace Amanotes.Core
|
|
53
|
+
{
|
|
54
|
+
public partial class AmaGDK //AmaPassport
|
|
55
|
+
{
|
|
56
|
+
public partial class UserProfile
|
|
57
|
+
{
|
|
58
|
+
[SerializeField]
|
|
59
|
+
internal AmaPassportInfo amaPassport = new AmaPassportInfo();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
[Serializable]
|
|
63
|
+
internal class AmaPassportInfo
|
|
64
|
+
{
|
|
65
|
+
[SerializeField] internal DeviceInfo device = new DeviceInfo();
|
|
66
|
+
[SerializeField] internal SocialInfo social = new SocialInfo();
|
|
67
|
+
|
|
68
|
+
public long expireTime;
|
|
69
|
+
public string accessToken = "";
|
|
70
|
+
public string refreshToken = "";
|
|
71
|
+
|
|
72
|
+
internal bool isTokenExpired()
|
|
73
|
+
{
|
|
74
|
+
if (DateTimeOffset.Now.ToUnixTimeMilliseconds() >= expireTime)
|
|
75
|
+
{
|
|
76
|
+
accessToken = "";
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
[Serializable]
|
|
85
|
+
internal class DeviceInfo
|
|
86
|
+
{
|
|
87
|
+
public string amaId = "";
|
|
88
|
+
public string amaDeviceId;
|
|
89
|
+
|
|
90
|
+
public string androidId;
|
|
91
|
+
public string deviceModel;
|
|
92
|
+
public string deviceName;
|
|
93
|
+
public int graphicsDeviceId;
|
|
94
|
+
public int graphicsDeviceVendorId;
|
|
95
|
+
public string operatingSystem;
|
|
96
|
+
public string processorType;
|
|
97
|
+
public int systemMemorySize;
|
|
98
|
+
|
|
99
|
+
public string firebaseUserPseudoId;
|
|
100
|
+
public string appsflyerId;
|
|
101
|
+
public string ironsourceId;
|
|
102
|
+
|
|
103
|
+
public string ipAddress;
|
|
104
|
+
public Location location = new Location();
|
|
105
|
+
public string country;
|
|
106
|
+
public string idfa;
|
|
107
|
+
public string gaid;
|
|
108
|
+
public string idfv;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
[Serializable]
|
|
112
|
+
internal class Location
|
|
113
|
+
{
|
|
114
|
+
public string lat;
|
|
115
|
+
public string lon;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[Serializable]
|
|
119
|
+
internal class SocialInfo
|
|
120
|
+
{
|
|
121
|
+
public string socialToken;
|
|
122
|
+
public string socialPlatform;
|
|
123
|
+
|
|
124
|
+
internal bool hasLinkSocial
|
|
125
|
+
{
|
|
126
|
+
get { return !string.IsNullOrEmpty(socialPlatform); }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
[Serializable]
|
|
131
|
+
internal class GeoDataRes
|
|
132
|
+
{
|
|
133
|
+
public string country;
|
|
134
|
+
public string lat;
|
|
135
|
+
public string lon;
|
|
136
|
+
public string query;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public partial class AmaPassport //Token
|
|
140
|
+
{
|
|
141
|
+
private const string API_URL = "https://passport.staging.amanotes.io/api/v3/";
|
|
142
|
+
private const string PASSPORT_URL = API_URL + "passport/";
|
|
143
|
+
private const string TOKEN_URL = API_URL + "token/";
|
|
144
|
+
|
|
145
|
+
private const string GET_AMA_ID_URL = PASSPORT_URL + "get-ama-id";
|
|
146
|
+
private const string SOCIAL_UNLINK_URL = PASSPORT_URL + "logout";
|
|
147
|
+
private const string INIT_URL = TOKEN_URL + "init";
|
|
148
|
+
private const string REFRESH_URL = TOKEN_URL + "refresh-token";
|
|
149
|
+
|
|
150
|
+
[Serializable] class TokenData
|
|
151
|
+
{
|
|
152
|
+
public string expiresIn;
|
|
153
|
+
public string accessToken;
|
|
154
|
+
public string refreshToken;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
[Serializable] class AmaIDData
|
|
158
|
+
{
|
|
159
|
+
public string amaId;
|
|
160
|
+
public string amaDeviceId;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static IEnumerator RequestTokenRoutine()
|
|
164
|
+
{
|
|
165
|
+
var appSecret = Config.amaPassport.secretKey;
|
|
166
|
+
var passport = User.amaPassport;
|
|
167
|
+
var isRefresh = !string.IsNullOrEmpty(passport.refreshToken);
|
|
168
|
+
|
|
169
|
+
var request = new JsonWebRequest<TokenData>(
|
|
170
|
+
isRefresh ? REFRESH_URL : INIT_URL,
|
|
171
|
+
isRefresh ? JsonUtils.KeyValueToJson("refreshToken", passport.refreshToken)
|
|
172
|
+
: JsonUtils.KeyValueToJson("appSecret", appSecret)
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
yield return _instance.StartCoroutine(request.Send());
|
|
176
|
+
|
|
177
|
+
var data = request.data;
|
|
178
|
+
if (data == null){
|
|
179
|
+
Debug.LogWarning("data should not be null!");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
var expireTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() + int.Parse(data.expiresIn);
|
|
183
|
+
Log("RequestTokenRoutine complete --> accessToken = " + data.accessToken);
|
|
184
|
+
|
|
185
|
+
// Update & save
|
|
186
|
+
passport.accessToken = data.accessToken;
|
|
187
|
+
passport.refreshToken = data.refreshToken;
|
|
188
|
+
passport.expireTime = expireTime;
|
|
189
|
+
User.Save();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static IEnumerator GetAmaIDRoutine()
|
|
193
|
+
{
|
|
194
|
+
var passport = User.amaPassport;
|
|
195
|
+
if (string.IsNullOrEmpty(passport.accessToken) || passport.isTokenExpired())
|
|
196
|
+
{
|
|
197
|
+
yield return _instance.StartCoroutine(RequestTokenRoutine());
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var requestData = new Dictionary<string, object>()
|
|
201
|
+
{
|
|
202
|
+
{"amaId", passport.device.amaId},
|
|
203
|
+
{"social", passport.social},
|
|
204
|
+
{"ids", passport.device}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
var request = new JsonWebRequest<AmaIDData>(
|
|
208
|
+
GET_AMA_ID_URL,
|
|
209
|
+
JsonUtils.DictionaryToJson(requestData),
|
|
210
|
+
passport.accessToken
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
yield return _instance.StartCoroutine(request.Send());
|
|
214
|
+
var data = request.data;
|
|
215
|
+
|
|
216
|
+
Log("GetAmaIDRoutine complete --> amaId = " + data.amaId);
|
|
217
|
+
// Update & Save
|
|
218
|
+
passport.device.amaId = data.amaId;
|
|
219
|
+
OnGetAmaIdComplete?.Invoke(data.amaId);
|
|
220
|
+
User.Save();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static IEnumerator UnlinkSocialRoutine()
|
|
224
|
+
{
|
|
225
|
+
var amaPassport = User.amaPassport;
|
|
226
|
+
if (string.IsNullOrEmpty(amaPassport.accessToken) || amaPassport.isTokenExpired())
|
|
227
|
+
{
|
|
228
|
+
yield return _instance.StartCoroutine(RequestTokenRoutine());
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var social = amaPassport.social;
|
|
232
|
+
social.socialPlatform = string.Empty;
|
|
233
|
+
social.socialToken = string.Empty;
|
|
234
|
+
|
|
235
|
+
var request = new JsonWebRequest<AmaIDData>(
|
|
236
|
+
SOCIAL_UNLINK_URL,
|
|
237
|
+
JsonUtils.KeyValueToJson("ids", amaPassport.device),
|
|
238
|
+
amaPassport.accessToken
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
yield return _instance.StartCoroutine(request.Send());
|
|
242
|
+
var data = request.data;
|
|
243
|
+
|
|
244
|
+
// Update & Save
|
|
245
|
+
Log("[Unlink] amaId: " + data.amaId);
|
|
246
|
+
amaPassport.device.amaId = data.amaId;
|
|
247
|
+
User.Save();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Internal static
|
|
251
|
+
private static void LinkSocialAccount(string platform, string token)
|
|
252
|
+
{
|
|
253
|
+
if (User.amaPassport.social.hasLinkSocial)
|
|
254
|
+
{
|
|
255
|
+
LogWarning("Social has been linked");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (string.IsNullOrEmpty(AmaId))
|
|
260
|
+
{
|
|
261
|
+
OnGetAmaIdComplete += LinkSocialRequestAmaId;
|
|
262
|
+
void LinkSocialRequestAmaId(string amaId)
|
|
263
|
+
{
|
|
264
|
+
OnGetAmaIdComplete -= LinkSocialRequestAmaId;
|
|
265
|
+
if (string.IsNullOrEmpty(amaId))
|
|
266
|
+
{
|
|
267
|
+
LogWarning("Can not link social");
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
SendLinkSocial(platform, token);
|
|
271
|
+
}
|
|
272
|
+
RequestAmaID();
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
SendLinkSocial(platform, token);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private static void SendLinkSocial(string platform, string token)
|
|
280
|
+
{
|
|
281
|
+
SocialInfo social = User.amaPassport.social;
|
|
282
|
+
social.socialPlatform = platform;
|
|
283
|
+
social.socialToken = token;
|
|
284
|
+
_instance.StartCoroutine(GetAmaIDRoutine());
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private static void DoRequestAmaID()
|
|
288
|
+
{
|
|
289
|
+
isInQueue = false;
|
|
290
|
+
_instance.StartCoroutine(GetAmaIDRoutine());
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
public partial class AmaPassport //Support
|
|
295
|
+
{
|
|
296
|
+
|
|
297
|
+
internal static void GetLocation(Action oncomplete)
|
|
298
|
+
{
|
|
299
|
+
_instance.StartCoroutine(GetIP(oncomplete));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private static IEnumerator GetIP(Action onComplete)
|
|
303
|
+
{
|
|
304
|
+
UnityWebRequest request = UnityWebRequest.Get("http://ip-api.com/json");
|
|
305
|
+
yield return request.SendWebRequest();
|
|
306
|
+
if (string.IsNullOrWhiteSpace(request.error))
|
|
307
|
+
{
|
|
308
|
+
string json = request.downloadHandler.text.Trim();
|
|
309
|
+
var geoData = JsonUtility.FromJson<GeoDataRes>(json);
|
|
310
|
+
if (geoData == null)
|
|
311
|
+
{
|
|
312
|
+
onComplete?.Invoke();
|
|
313
|
+
yield break;
|
|
314
|
+
}
|
|
315
|
+
DeviceInfo device = User.amaPassport.device;
|
|
316
|
+
device.country = geoData.country;
|
|
317
|
+
device.ipAddress = geoData.query;
|
|
318
|
+
device.location = new Location() { lat = geoData.lat, lon = geoData.lon };
|
|
319
|
+
}
|
|
320
|
+
else
|
|
321
|
+
{
|
|
322
|
+
LogWarning("Get location failed: " + request.error);
|
|
323
|
+
}
|
|
324
|
+
Log("Get GeoData completed");
|
|
325
|
+
onComplete?.Invoke();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
public partial class AmaPassport // public APIs
|
|
330
|
+
{
|
|
331
|
+
static ActionQueue actionQueue;
|
|
332
|
+
public static Action<Action> GetAdvertisingIdHook;
|
|
333
|
+
public static Action<Action> GetLocationHook;
|
|
334
|
+
public static Action<Action> ATTHook;
|
|
335
|
+
public static Action<string> OnGetAmaIdComplete;
|
|
336
|
+
private static bool isInQueue = false;
|
|
337
|
+
|
|
338
|
+
public static string AmaId
|
|
339
|
+
{
|
|
340
|
+
get { return User.amaPassport.device.amaId; }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
public static void LinkWithFacebook(string accessToken)
|
|
344
|
+
{
|
|
345
|
+
LinkSocialAccount("facebook", accessToken);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public static void LinkWithGoogle(string idToken)
|
|
349
|
+
{
|
|
350
|
+
LinkSocialAccount("google", idToken);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
public static void LinkWithApple(string identityToken)
|
|
354
|
+
{
|
|
355
|
+
LinkSocialAccount("apple", identityToken);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public static void UnlinkSocialAccount()
|
|
359
|
+
{
|
|
360
|
+
if (!User.amaPassport.social.hasLinkSocial)
|
|
361
|
+
{
|
|
362
|
+
LogWarning("Social has not linked");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (string.IsNullOrEmpty(AmaId))
|
|
367
|
+
{
|
|
368
|
+
LogWarning("No available AmaId to unlink");
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
_instance.StartCoroutine(UnlinkSocialRoutine());
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
public static void RequestAmaID()
|
|
376
|
+
{
|
|
377
|
+
var config = Config.amaPassport;
|
|
378
|
+
var device = User.amaPassport.device;
|
|
379
|
+
|
|
380
|
+
if (string.IsNullOrEmpty(config.secretKey))
|
|
381
|
+
{
|
|
382
|
+
LogWarning($"Invalid secretKey: {config.secretKey}");
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (!config.enableAmaPassport)
|
|
387
|
+
{
|
|
388
|
+
LogWarning("AmaPassport is disabled!");
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (!string.IsNullOrEmpty(device.amaId))
|
|
393
|
+
{
|
|
394
|
+
Log($"AmaId is already exist: {device.amaId}");
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
GetDeviceInfo(DoRequestAmaID);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
static void GetDeviceInfo(Action getDeviceInfoComplete)
|
|
402
|
+
{
|
|
403
|
+
if (isInQueue)
|
|
404
|
+
{
|
|
405
|
+
LogWarning("Request AmaId under process");
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
isInQueue = true;
|
|
409
|
+
|
|
410
|
+
var device = User.amaPassport.device;
|
|
411
|
+
device.deviceModel = SystemInfo.deviceModel;
|
|
412
|
+
device.deviceName = SystemInfo.deviceName;
|
|
413
|
+
device.processorType = SystemInfo.processorType;
|
|
414
|
+
device.systemMemorySize = SystemInfo.systemMemorySize;
|
|
415
|
+
device.graphicsDeviceId = SystemInfo.graphicsDeviceID;
|
|
416
|
+
device.graphicsDeviceVendorId = SystemInfo.graphicsDeviceVendorID;
|
|
417
|
+
device.operatingSystem = SystemInfo.operatingSystem;
|
|
418
|
+
if (Application.platform == RuntimePlatform.Android)
|
|
419
|
+
device.androidId = SystemInfo.deviceUniqueIdentifier;
|
|
420
|
+
else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
|
421
|
+
device.idfv = SystemInfo.deviceUniqueIdentifier;
|
|
422
|
+
|
|
423
|
+
var config = Config.amaPassport;
|
|
424
|
+
actionQueue = new ActionQueue(getDeviceInfoComplete);
|
|
425
|
+
actionQueue.EnqueueAction(ATTHook);
|
|
426
|
+
|
|
427
|
+
if (config.injectLocation) actionQueue.EnqueueAction(GetLocationHook ?? GetLocation);
|
|
428
|
+
if (config.injectAdvertisingId) actionQueue.EnqueueAction(GetAdvertisingIdHook);
|
|
429
|
+
actionQueue.StartQueue();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|