Panagiotis Triantafyllou

commit from cosmote part 2

...@@ -34,7 +34,7 @@ android { ...@@ -34,7 +34,7 @@ android {
34 34
35 dependencies { 35 dependencies {
36 //------------------------------ Support -----------------------------// 36 //------------------------------ Support -----------------------------//
37 - api 'androidx.appcompat:appcompat:1.4.1' 37 + api 'androidx.appcompat:appcompat:1.5.1'
38 api 'androidx.recyclerview:recyclerview:1.2.1' 38 api 'androidx.recyclerview:recyclerview:1.2.1'
39 api 'androidx.cardview:cardview:1.0.0' 39 api 'androidx.cardview:cardview:1.0.0'
40 api "androidx.security:security-crypto:1.1.0-alpha03" // For minSDK 23 use 1.0.0, for minSDK 21 use 1.1.0 that is currently in alpha 40 api "androidx.security:security-crypto:1.1.0-alpha03" // For minSDK 23 use 1.0.0, for minSDK 21 use 1.1.0 that is currently in alpha
...@@ -47,8 +47,8 @@ dependencies { ...@@ -47,8 +47,8 @@ dependencies {
47 api 'com.google.firebase:firebase-messaging' 47 api 'com.google.firebase:firebase-messaging'
48 48
49 //------------------------------ GMS -----------------------------// 49 //------------------------------ GMS -----------------------------//
50 - api 'com.google.android.gms:play-services-base:18.0.1' 50 + api 'com.google.android.gms:play-services-base:18.1.0'
51 - api 'com.google.android.gms:play-services-location:19.0.1' 51 + api 'com.google.android.gms:play-services-location:21.0.0'
52 52
53 //------------------------------ Work Manager -----------------------------// 53 //------------------------------ Work Manager -----------------------------//
54 api 'androidx.work:work-runtime:2.7.1' 54 api 'androidx.work:work-runtime:2.7.1'
...@@ -59,9 +59,9 @@ dependencies { ...@@ -59,9 +59,9 @@ dependencies {
59 59
60 //------------------------------ Huawei -----------------------------// 60 //------------------------------ Huawei -----------------------------//
61 api 'com.huawei.agconnect:agconnect-core:1.6.5.300' 61 api 'com.huawei.agconnect:agconnect-core:1.6.5.300'
62 - api 'com.huawei.hms:base:6.4.0.302' 62 + api 'com.huawei.hms:base:6.6.0.300'
63 - api 'com.huawei.hms:push:6.3.0.304' 63 + api 'com.huawei.hms:push:6.7.0.300'
64 - api 'com.huawei.hms:ads-identifier:3.4.39.302' 64 + api 'com.huawei.hms:ads-identifier:3.4.56.300'
65 65
66 //------------------------------ SQLCipher -----------------------------// 66 //------------------------------ SQLCipher -----------------------------//
67 api "net.zetetic:android-database-sqlcipher:4.5.0" 67 api "net.zetetic:android-database-sqlcipher:4.5.0"
......
1 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 1 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 + xmlns:tools="http://schemas.android.com/tools"
2 package="ly.warp.sdk"> 3 package="ly.warp.sdk">
3 4
4 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 5 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...@@ -7,6 +8,9 @@ ...@@ -7,6 +8,9 @@
7 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 8 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
8 <uses-permission android:name="android.permission.BLUETOOTH" /> 9 <uses-permission android:name="android.permission.BLUETOOTH" />
9 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 10 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
11 + <uses-permission
12 + android:name="android.permission.REQUEST_INSTALL_PACKAGES"
13 + tools:node="remove" />
10 14
11 <application> 15 <application>
12 <!-- For Huawei Push --> 16 <!-- For Huawei Push -->
...@@ -37,6 +41,11 @@ ...@@ -37,6 +41,11 @@
37 android:permission="android.permission.BIND_JOB_SERVICE" /> 41 android:permission="android.permission.BIND_JOB_SERVICE" />
38 42
39 <service 43 <service
44 + android:name="ly.warp.sdk.services.EventRefreshDeviceTokenService"
45 + android:exported="false"
46 + android:permission="android.permission.BIND_JOB_SERVICE" />
47 +
48 + <service
40 android:name="ly.warp.sdk.services.WarplyBeaconsRangingService" 49 android:name="ly.warp.sdk.services.WarplyBeaconsRangingService"
41 android:exported="false" /> 50 android:exported="false" />
42 51
......
...@@ -1226,6 +1226,42 @@ public enum Warply { ...@@ -1226,6 +1226,42 @@ public enum Warply {
1226 } 1226 }
1227 } 1227 }
1228 1228
1229 + public void requestToServerInternalNew(int method, String url, JSONObject data,
1230 + CallbackReceiver<JSONObject> listener, Object tag) {
1231 + VolleyTransformer vt = new VolleyTransformer(listener);
1232 + String methodName = null;
1233 + switch (method) {
1234 + case 0:
1235 + methodName = "GET";
1236 + break;
1237 + case 1:
1238 + methodName = "POST";
1239 + break;
1240 + case 2:
1241 + methodName = "PUT";
1242 + break;
1243 + case 3:
1244 + methodName = "DELETE";
1245 + break;
1246 + }
1247 + WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
1248 + WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(getWarplyContext()));
1249 + WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(getWarplyContext()));
1250 + WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
1251 + if (data != null) {
1252 + try {
1253 + WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
1254 + } catch (JSONException e) {
1255 + WarpUtils.warn(
1256 + "[WARP Trace] Failed conversting JSON to string", e);
1257 + }
1258 + }
1259 + WarpUtils.log("**********************************************************");
1260 + WarplyJsonObjectRequest request = new WarplyJsonObjectRequest(method, url, data, vt, vt);
1261 + request.setTag(tag);
1262 + mRequestQueue.add(request);
1263 + }
1264 +
1229 public static void initBeaconsApplicationIfNeed() { 1265 public static void initBeaconsApplicationIfNeed() {
1230 1266
1231 try { 1267 try {
...@@ -1444,6 +1480,35 @@ public enum Warply { ...@@ -1444,6 +1480,35 @@ public enum Warply {
1444 private void postToServerInternal(String warplyPath, JSONArray data, 1480 private void postToServerInternal(String warplyPath, JSONArray data,
1445 CallbackReceiver<JSONObject> listener, Object tag) { 1481 CallbackReceiver<JSONObject> listener, Object tag) {
1446 String url = buildWarplyRequestUrl(warplyPath); 1482 String url = buildWarplyRequestUrl(warplyPath);
1483 +
1484 + JSONArray tempAnalytics = new JSONArray();
1485 + JSONArray tempDeviceInfo = new JSONArray();
1486 + JSONArray tempOther = new JSONArray();
1487 + if (data.length() > 0) {
1488 + for (int i = 0; i < data.length(); i++) {
1489 + JSONObject microappItem = data.optJSONObject(i);
1490 + if (microappItem != null) {
1491 + if (microappItem.has("inapp_analytics")) {
1492 + tempAnalytics.put(microappItem);
1493 + } else if (microappItem.has("device_info") || microappItem.has("application_data")) {
1494 + tempDeviceInfo.put(microappItem);
1495 + } else {
1496 + tempOther.put(microappItem);
1497 + }
1498 + }
1499 + }
1500 + }
1501 +
1502 + if (tempAnalytics != null && tempAnalytics.length() > 0) {
1503 + url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext.get()) + "/";
1504 + }
1505 + if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
1506 + url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext.get()) + "/";
1507 + }
1508 + if (tempOther != null && tempOther.length() > 0) {
1509 + url = buildWarplyRequestUrl(warplyPath);
1510 + }
1511 +
1447 requestToServerInternal(Method.POST, url, data, listener, tag); 1512 requestToServerInternal(Method.POST, url, data, listener, tag);
1448 } 1513 }
1449 1514
...@@ -1541,6 +1606,11 @@ public enum Warply { ...@@ -1541,6 +1606,11 @@ public enum Warply {
1541 } 1606 }
1542 } 1607 }
1543 1608
1609 + public void getSingleCampaign(JSONObject data, String url,
1610 + CallbackReceiver<JSONObject> listener, Object tag) {
1611 + requestToServerInternalNew(Method.GET, url, data, listener, tag);
1612 + }
1613 +
1544 // callback receivers 1614 // callback receivers
1545 private CallbackReceiver<JSONObject> mRegistrationCallBackReceiver = new CallbackReceiver<JSONObject>() { 1615 private CallbackReceiver<JSONObject> mRegistrationCallBackReceiver = new CallbackReceiver<JSONObject>() {
1546 @Override 1616 @Override
......
1 +package ly.warp.sdk.services;
2 +
3 +import android.content.Context;
4 +
5 +import androidx.annotation.NonNull;
6 +import androidx.work.Worker;
7 +import androidx.work.WorkerParameters;
8 +
9 +import ly.warp.sdk.Warply;
10 +
11 +/**
12 + * Created by Panagiotis Triantafyllou on 27/09/2022.
13 + */
14 +public class EventRefreshDeviceTokenService extends Worker {
15 +
16 + public EventRefreshDeviceTokenService(@NonNull Context context, @NonNull WorkerParameters workerParams) {
17 + super(context, workerParams);
18 + }
19 +
20 + @NonNull
21 + @Override
22 + public Result doWork() {
23 + Warply.INSTANCE.postDeviceInfoData();
24 +
25 + return Result.success();
26 + }
27 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -51,6 +51,8 @@ import android.view.animation.ScaleAnimation; ...@@ -51,6 +51,8 @@ import android.view.animation.ScaleAnimation;
51 51
52 import androidx.security.crypto.EncryptedSharedPreferences; 52 import androidx.security.crypto.EncryptedSharedPreferences;
53 import androidx.security.crypto.MasterKey; 53 import androidx.security.crypto.MasterKey;
54 +import androidx.work.OneTimeWorkRequest;
55 +import androidx.work.WorkManager;
54 56
55 import org.apache.http.client.HttpClient; 57 import org.apache.http.client.HttpClient;
56 import org.apache.http.client.methods.HttpRequestBase; 58 import org.apache.http.client.methods.HttpRequestBase;
...@@ -65,8 +67,10 @@ import java.nio.charset.Charset; ...@@ -65,8 +67,10 @@ import java.nio.charset.Charset;
65 import java.security.GeneralSecurityException; 67 import java.security.GeneralSecurityException;
66 import java.security.MessageDigest; 68 import java.security.MessageDigest;
67 import java.security.NoSuchAlgorithmException; 69 import java.security.NoSuchAlgorithmException;
70 +import java.util.concurrent.TimeUnit;
68 import java.util.zip.GZIPInputStream; 71 import java.util.zip.GZIPInputStream;
69 72
73 +import ly.warp.sdk.services.EventRefreshDeviceTokenService;
70 import ly.warp.sdk.utils.constants.WarpConstants; 74 import ly.warp.sdk.utils.constants.WarpConstants;
71 75
72 public class WarpUtils { 76 public class WarpUtils {
...@@ -398,6 +402,9 @@ public class WarpUtils { ...@@ -398,6 +402,9 @@ public class WarpUtils {
398 SharedPreferences.Editor editor = getPreferences(context).edit(); 402 SharedPreferences.Editor editor = getPreferences(context).edit();
399 editor.putString(PREFERENCES_KEY_DEVICE_TOKEN, token); 403 editor.putString(PREFERENCES_KEY_DEVICE_TOKEN, token);
400 editor.apply(); 404 editor.apply();
405 +
406 + OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventRefreshDeviceTokenService.class).setInitialDelay(1, TimeUnit.MINUTES).build();
407 + WorkManager.getInstance(context).enqueue(mywork);
401 } 408 }
402 409
403 public static boolean getHasApplicationInfo(Context context) { 410 public static boolean getHasApplicationInfo(Context context) {
......
...@@ -97,6 +97,7 @@ import ly.warp.sdk.io.request.WarplyValidateCouponRequest; ...@@ -97,6 +97,7 @@ import ly.warp.sdk.io.request.WarplyValidateCouponRequest;
97 import ly.warp.sdk.io.request.WarplyVerifyOTPRequest; 97 import ly.warp.sdk.io.request.WarplyVerifyOTPRequest;
98 import ly.warp.sdk.io.request.WarplyVerifyTicketRequest; 98 import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
99 import ly.warp.sdk.utils.WarpUtils; 99 import ly.warp.sdk.utils.WarpUtils;
100 +import ly.warp.sdk.utils.WarplyProperty;
100 import ly.warp.sdk.utils.constants.WarpConstants; 101 import ly.warp.sdk.utils.constants.WarpConstants;
101 102
102 /** 103 /**
...@@ -1309,4 +1310,58 @@ public class WarplyManager { ...@@ -1309,4 +1310,58 @@ public class WarplyManager {
1309 }, 1310 },
1310 request.getSignature())); 1311 request.getSignature()));
1311 } 1312 }
1313 +
1314 + public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<NewCampaignList> receiver) {
1315 + WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
1316 + WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
1317 + WarpUtils.log("**************************************************");
1318 + Warply.postReceiveMicroappData(WarpConstants.MICROAPP_NEW_CAMPAIGNS, true, "campaignsPersonalized", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
1319 + @Override
1320 + public void onSuccess(NewCampaignList result) {
1321 + receiver.onSuccess(result);
1322 + }
1323 +
1324 + @Override
1325 + public void onFailure(int errorCode) {
1326 + if (errorCode == 401) {
1327 + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
1328 + @Override
1329 + public void onSuccess(JSONObject result) {
1330 + int status = result.optInt("status", 2);
1331 + if (status == 1)
1332 + getCampaignsPersonalized(request, receiver);
1333 + else
1334 + receiver.onFailure(status);
1335 + }
1336 +
1337 + @Override
1338 + public void onFailure(int errorCode) {
1339 + receiver.onFailure(errorCode);
1340 + }
1341 + });
1342 + } else
1343 + receiver.onFailure(errorCode);
1344 + }
1345 + },
1346 + request.getSignature()));
1347 + }
1348 +
1349 + public static void getSingleCampaign(String sessionUuid) {
1350 + WarpUtils.log("************* WARPLY Get Event Request ********************");
1351 + WarpUtils.log("[WARP Trace] WARPLY Get Event Request is active");
1352 + WarpUtils.log("**************************************************");
1353 + String url = WarplyProperty.getBaseUrl(Warply.getWarplyContext()) + WarpConstants.BASE_REMOTE_PAGE_URL + sessionUuid;
1354 + Warply.INSTANCE.getSingleCampaign(null, url,
1355 + new CallbackReceiver<JSONObject>() {
1356 + @Override
1357 + public void onSuccess(JSONObject result) {
1358 +
1359 + }
1360 +
1361 + @Override
1362 + public void onFailure(int errorCode) {
1363 +
1364 + }
1365 + }, null);
1366 + }
1312 } 1367 }
......