Panagiotis Triantafyllou

commit from cosmote part 2

......@@ -34,7 +34,7 @@ android {
dependencies {
//------------------------------ Support -----------------------------//
api 'androidx.appcompat:appcompat:1.4.1'
api 'androidx.appcompat:appcompat:1.5.1'
api 'androidx.recyclerview:recyclerview:1.2.1'
api 'androidx.cardview:cardview:1.0.0'
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 {
api 'com.google.firebase:firebase-messaging'
//------------------------------ GMS -----------------------------//
api 'com.google.android.gms:play-services-base:18.0.1'
api 'com.google.android.gms:play-services-location:19.0.1'
api 'com.google.android.gms:play-services-base:18.1.0'
api 'com.google.android.gms:play-services-location:21.0.0'
//------------------------------ Work Manager -----------------------------//
api 'androidx.work:work-runtime:2.7.1'
......@@ -59,9 +59,9 @@ dependencies {
//------------------------------ Huawei -----------------------------//
api 'com.huawei.agconnect:agconnect-core:1.6.5.300'
api 'com.huawei.hms:base:6.4.0.302'
api 'com.huawei.hms:push:6.3.0.304'
api 'com.huawei.hms:ads-identifier:3.4.39.302'
api 'com.huawei.hms:base:6.6.0.300'
api 'com.huawei.hms:push:6.7.0.300'
api 'com.huawei.hms:ads-identifier:3.4.56.300'
//------------------------------ SQLCipher -----------------------------//
api "net.zetetic:android-database-sqlcipher:4.5.0"
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ly.warp.sdk">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
......@@ -7,6 +8,9 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission
android:name="android.permission.REQUEST_INSTALL_PACKAGES"
tools:node="remove" />
<application>
<!-- For Huawei Push -->
......@@ -37,6 +41,11 @@
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="ly.warp.sdk.services.EventRefreshDeviceTokenService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="ly.warp.sdk.services.WarplyBeaconsRangingService"
android:exported="false" />
......
......@@ -1226,6 +1226,42 @@ public enum Warply {
}
}
public void requestToServerInternalNew(int method, String url, JSONObject data,
CallbackReceiver<JSONObject> listener, Object tag) {
VolleyTransformer vt = new VolleyTransformer(listener);
String methodName = null;
switch (method) {
case 0:
methodName = "GET";
break;
case 1:
methodName = "POST";
break;
case 2:
methodName = "PUT";
break;
case 3:
methodName = "DELETE";
break;
}
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(getWarplyContext()));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(getWarplyContext()));
WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
if (data != null) {
try {
WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
} catch (JSONException e) {
WarpUtils.warn(
"[WARP Trace] Failed conversting JSON to string", e);
}
}
WarpUtils.log("**********************************************************");
WarplyJsonObjectRequest request = new WarplyJsonObjectRequest(method, url, data, vt, vt);
request.setTag(tag);
mRequestQueue.add(request);
}
public static void initBeaconsApplicationIfNeed() {
try {
......@@ -1444,6 +1480,35 @@ public enum Warply {
private void postToServerInternal(String warplyPath, JSONArray data,
CallbackReceiver<JSONObject> listener, Object tag) {
String url = buildWarplyRequestUrl(warplyPath);
JSONArray tempAnalytics = new JSONArray();
JSONArray tempDeviceInfo = new JSONArray();
JSONArray tempOther = new JSONArray();
if (data.length() > 0) {
for (int i = 0; i < data.length(); i++) {
JSONObject microappItem = data.optJSONObject(i);
if (microappItem != null) {
if (microappItem.has("inapp_analytics")) {
tempAnalytics.put(microappItem);
} else if (microappItem.has("device_info") || microappItem.has("application_data")) {
tempDeviceInfo.put(microappItem);
} else {
tempOther.put(microappItem);
}
}
}
}
if (tempAnalytics != null && tempAnalytics.length() > 0) {
url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext.get()) + "/";
}
if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext.get()) + "/";
}
if (tempOther != null && tempOther.length() > 0) {
url = buildWarplyRequestUrl(warplyPath);
}
requestToServerInternal(Method.POST, url, data, listener, tag);
}
......@@ -1541,6 +1606,11 @@ public enum Warply {
}
}
public void getSingleCampaign(JSONObject data, String url,
CallbackReceiver<JSONObject> listener, Object tag) {
requestToServerInternalNew(Method.GET, url, data, listener, tag);
}
// callback receivers
private CallbackReceiver<JSONObject> mRegistrationCallBackReceiver = new CallbackReceiver<JSONObject>() {
@Override
......
package ly.warp.sdk.services;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import ly.warp.sdk.Warply;
/**
* Created by Panagiotis Triantafyllou on 27/09/2022.
*/
public class EventRefreshDeviceTokenService extends Worker {
public EventRefreshDeviceTokenService(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {
Warply.INSTANCE.postDeviceInfoData();
return Result.success();
}
}
\ No newline at end of file
......@@ -51,6 +51,8 @@ import android.view.animation.ScaleAnimation;
import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKey;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
......@@ -65,8 +67,10 @@ import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import ly.warp.sdk.services.EventRefreshDeviceTokenService;
import ly.warp.sdk.utils.constants.WarpConstants;
public class WarpUtils {
......@@ -398,6 +402,9 @@ public class WarpUtils {
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putString(PREFERENCES_KEY_DEVICE_TOKEN, token);
editor.apply();
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventRefreshDeviceTokenService.class).setInitialDelay(1, TimeUnit.MINUTES).build();
WorkManager.getInstance(context).enqueue(mywork);
}
public static boolean getHasApplicationInfo(Context context) {
......
......@@ -97,6 +97,7 @@ import ly.warp.sdk.io.request.WarplyValidateCouponRequest;
import ly.warp.sdk.io.request.WarplyVerifyOTPRequest;
import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
......@@ -1309,4 +1310,58 @@ public class WarplyManager {
},
request.getSignature()));
}
public static void getCampaignsPersonalized(WarplyGetCampaignsRequest request, final CallbackReceiver<NewCampaignList> receiver) {
WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(WarpConstants.MICROAPP_NEW_CAMPAIGNS, true, "campaignsPersonalized", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
@Override
public void onSuccess(NewCampaignList result) {
receiver.onSuccess(result);
}
@Override
public void onFailure(int errorCode) {
if (errorCode == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getCampaignsPersonalized(request, receiver);
else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
} else
receiver.onFailure(errorCode);
}
},
request.getSignature()));
}
public static void getSingleCampaign(String sessionUuid) {
WarpUtils.log("************* WARPLY Get Event Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Get Event Request is active");
WarpUtils.log("**************************************************");
String url = WarplyProperty.getBaseUrl(Warply.getWarplyContext()) + WarpConstants.BASE_REMOTE_PAGE_URL + sessionUuid;
Warply.INSTANCE.getSingleCampaign(null, url,
new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
}
@Override
public void onFailure(int errorCode) {
}
}, null);
}
}
......