Panagiotis Triantafyllou

version 4.5.3

......@@ -32,13 +32,13 @@ public class SplashActivity extends BaseActivity {
@Override
public void onWarplyInitTimeOut() {
showToast("Warply initialization timeout!");
finish();
checkForAppUpdate();
}
@Override
public void onWarplyPermissionsDenied() {
showToast("Warply permissions denied!");
// onWarplyReady();
checkForAppUpdate();
}
});
}
......@@ -55,7 +55,7 @@ public class SplashActivity extends BaseActivity {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// }
private void checkForAppUpdate(){
private void checkForAppUpdate() {
Warply.checkForAppUpdate(SplashActivity.this, new SimpleCallbackReceiver<Boolean>() {
@Override
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.2'
PUBLISH_VERSION = '4.5.3'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......@@ -48,6 +48,7 @@ dependencies {
//------------------------------ GMS -----------------------------//
api 'com.google.android.gms:play-services-base:18.0.1'
api 'com.google.android.gms:play-services-location:19.0.1'
//------------------------------ Work Manager -----------------------------//
api 'androidx.work:work-runtime:2.7.1'
......
......@@ -39,7 +39,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import java.util.Random;
import java.security.SecureRandom;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
......@@ -75,6 +75,7 @@ public class WarpViewActivity extends WarpBaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WarplySessionManager.onCreateActivity(this);
initViews();
Warply.getInitializer(this).init();
setPageAccordingToIntent();
......@@ -203,7 +204,7 @@ public class WarpViewActivity extends WarpBaseActivity {
if (Build.VERSION.SDK_INT >= 21) {
return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1);
} else {
Random rand = new Random();
SecureRandom rand = new SecureRandom();
return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN;
}
}
......
......@@ -84,11 +84,11 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener {
if (response.optJSONObject("context") != null) {
if (response.optJSONObject("context").optJSONObject("device_status") != null) {
WarpUtils.setIsWarped(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("warped"));
WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token"));
WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved"));
// WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token"));
// WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved"));
WarpUtils.setDeviceId(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_id"));
WarpUtils.setIsDeviceIdSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_id_saved"));
WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved"));
// WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved"));
if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info") != null) {
WarpUtils.setAppDataObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info"));
WarpUtils.setSDKVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("sdk_version"));
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
......@@ -34,7 +34,9 @@ import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import java.util.HashMap;
import java.util.Map;
public class LocationChangedReceiver extends BroadcastReceiver {
......@@ -44,9 +46,6 @@ public class LocationChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Log.i("Location receiver", Integer.toString(counter++));
isAppShutDown = WarplyLocationManager.waprplyContext == null;
/**
......@@ -64,23 +63,14 @@ public class LocationChangedReceiver extends BroadcastReceiver {
}
if (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED)) {
new WarplyPreferences(context).saveUpdateLocationServiceStatus("on");
Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// context.startForegroundService(new Intent(context, UpdateUserLocationService.class)
// .putExtra("LOCATION_KEY", location));
// } else {
// context.startService(new Intent(context, UpdateUserLocationService.class)
// .putExtra("LOCATION_KEY", location));
// }
UpdateUserLocationService.enqueueWork(context, new Intent(context, UpdateUserLocationService.class)
.putExtra("LOCATION_KEY", location));
Map<String, Object> mLocValues = new HashMap<>();
mLocValues.put("latitude", location.getLatitude());
mLocValues.put("longitude", location.getLongitude());
UpdateUserLocationService.scheduleWork(context, mLocValues);
}
}
}
}
\ No newline at end of file
......
......@@ -28,8 +28,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
......@@ -98,6 +98,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
GCMRegistrar.setRegistrationId(this, s);
WarpUtils.setDeviceToken(this, s);
}
@Override
......@@ -146,7 +147,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
if (Build.VERSION.SDK_INT >= 21) {
return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1);
} else {
Random rand = new Random();
SecureRandom rand = new SecureRandom();
return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN;
}
}
......@@ -164,7 +165,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID());
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (!TextUtils.isEmpty(pc.getSessionUUID())) {
......@@ -297,7 +298,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
public void showNotification(Context context, String title, String ticker,
String message, Intent newIntent, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
WarpUtils.log("Showing notification with tag: " + tag + " and id: "
+ id);
......@@ -343,7 +344,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (id > 0) {
uid = id;
......
......@@ -39,7 +39,7 @@ import android.os.SystemClock;
import androidx.core.app.NotificationCompat;
import android.util.Log;
import java.util.Random;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
import ly.warp.sdk.utils.GCMRegistrar;
......@@ -74,7 +74,7 @@ public abstract class GCMBaseIntentService extends IntentService {
// instance counter
private static int sCounter = 0;
private static final Random sRandom = new Random();
private static final SecureRandom sRandom = new SecureRandom();
private static final int MAX_BACKOFF_MS = (int) TimeUnit.SECONDS
.toMillis(3600); // 1 hour
......
......@@ -14,7 +14,6 @@ import android.media.RingtoneManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
import androidx.core.app.NotificationCompat;
......@@ -33,9 +32,9 @@ import org.json.JSONObject;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
......@@ -91,18 +90,15 @@ public class HMSBaseMessagingService extends HmsMessageService {
// ===========================================================
// URLThread class
// ===========================================================
public static class URLThread extends Thread
{
public static class URLThread extends Thread {
private String urlString = "";
public URLThread(String url)
{
public URLThread(String url) {
this.urlString = url;
}
@Override
public void run()
{
public void run() {
try {
URL url;
HttpURLConnection urlConnection = null;
......@@ -138,7 +134,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
public void onNewToken(String s, Bundle bundle) {
super.onNewToken(s, bundle);
GCMRegistrar.setRegistrationId(this, s);
Log.v("HUAWEI TOKEN", "receive token:" + s);
WarpUtils.setDeviceToken(this, s);
}
@Override
......@@ -146,7 +142,6 @@ public class HMSBaseMessagingService extends HmsMessageService {
super.onMessageReceived(remoteMessage);
JSONObject data = new JSONObject(remoteMessage.getDataOfMap());
Log.v("DATA", "data is " + data);
if (data == null || !data.has("loyalty-action")) {
return;
}
......@@ -197,7 +192,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
if (Build.VERSION.SDK_INT >= 21) {
return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1);
} else {
Random rand = new Random();
SecureRandom rand = new SecureRandom();
return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN;
}
}
......@@ -215,7 +210,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID());
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (!TextUtils.isEmpty(pc.getSessionUUID())) {
......@@ -346,7 +341,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
public void showNotification(Context context, String title, String ticker,
String message, Intent newIntent, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
WarpUtils.log("Showing notification with tag: " + tag + " and id: "
+ id);
......@@ -392,7 +387,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (id > 0) {
uid = id;
......@@ -544,7 +539,7 @@ public class HMSBaseMessagingService extends HmsMessageService {
private static Bitmap loadDrawable(final String urlString) {
if (urlString == null || TextUtils.isEmpty(urlString))
return null;
return null;
// alternative solution to thread but only in debug mode
// StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
......@@ -569,10 +564,10 @@ public class HMSBaseMessagingService extends HmsMessageService {
public static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException {
Bundle bundle = new Bundle();
Iterator iter = jsonObject.keys();
while(iter.hasNext()){
String key = (String)iter.next();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = jsonObject.getString(key);
bundle.putString(key,value);
bundle.putString(key, value);
}
return bundle;
}
......
......@@ -52,8 +52,8 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.security.SecureRandom;
import java.util.List;
import java.util.Random;
import ly.warp.sdk.Warply;
import ly.warp.sdk.activities.WarpViewActivity;
......@@ -145,7 +145,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID());
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (!TextUtils.isEmpty(pc.getSessionUUID())) {
......@@ -277,7 +277,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
public void showNotification(Context context, String title, String ticker,
String message, Intent newIntent, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
WarpUtils.log("Showing notification with tag: " + tag + " and id: "
+ id);
......@@ -323,7 +323,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) {
Random randomGenerator = new Random();
SecureRandom randomGenerator = new SecureRandom();
int uid = randomGenerator.nextInt(1000);
if (id > 0) {
uid = id;
......
......@@ -32,6 +32,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
......@@ -91,7 +92,12 @@ public class WarpInAppNotificationService extends WarpBaseIntentService {
.putExtra(KEY_SUBTITLE, mNotificationSubtitle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
builder.setContentIntent(pendingIntent);
// builder.setFullScreenIntent(pendingIntent, true); // Heads up notification, always visible OR setPriority to HIGH and setContentIntent
NotificationManager nm = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
......@@ -106,14 +112,24 @@ public class WarpInAppNotificationService extends WarpBaseIntentService {
.putExtra(KEY_TITLE, title)
.putExtra(KEY_SUBTITLE, subtitle)
.putExtra(KEY_HEADS_UP, isHeadsUpNotification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
}
public static void cancelInAppNotificationAlarm(Context context, @NonNull int uid) {
Intent notifyIntent = new Intent(context, WarplyInAppNotificationReceiver.class).putExtra(KEY_UID, uid);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
......
......@@ -2,10 +2,18 @@ package ly.warp.sdk.utils;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import ly.warp.sdk.dexter.listener.DexterError;
......@@ -13,25 +21,15 @@ import ly.warp.sdk.dexter.listener.PermissionDeniedResponse;
import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
import ly.warp.sdk.utils.constants.WarpConstants;
public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequestPermissionsResultCallback */{
public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequestPermissionsResultCallback*/ {
// ===========================================================
// Constants
// ===========================================================
// private final String PREF_KEY_DENIED_PERMISSION_COUNT = "pref_key_denied_permissions_count";
private final long INIT_TIME_OUT = 1000 * 20;
private final long INIT_ATTEMPTS = 3;
// permissions
// private static final String[] DANGEROUS_PERMISSIONS = {
// android.Manifest.permission.ACCESS_FINE_LOCATION,
// android.Manifest.permission.ACCESS_COARSE_LOCATION,
// Manifest.permission.READ_PHONE_STATE,
// Manifest.permission.WRITE_EXTERNAL_STORAGE
// };
//
// private final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
private final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 3001;
private boolean mPermissionsResultRequested = false;
// ===========================================================
......@@ -39,10 +37,9 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
// ===========================================================
private Context mContext;
// private Activity mPermissionsActivity;
private Activity mPermissionsActivity;
private WarplyInitCallback mInitCallback;
private WarplyReadyCallback mReadyCallback;
// private WarplyPreferences mPreferences;
private static volatile Handler mMainThreadHandler;
private static volatile AtomicBoolean stopThreadLock;
......@@ -57,7 +54,6 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
this.mContext = context;
this.mReadyCallback = readyCallback;
this.mInitCallback = initCallback;
// this.mPreferences = new WarplyPreferences(mContext);
if (mMainThreadHandler == null) {
mMainThreadHandler = new Handler(Looper.getMainLooper());
......@@ -105,15 +101,14 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
// @Override
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//
// switch (requestCode) {
// case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS:
//
// if (permissions.length > 0) {
// Map<String, Integer> results = new HashMap<>();
// for (String permission : DANGEROUS_PERMISSIONS) {
// for (String permission : PermissionsUtil.DANGEROUS_PERMISSIONS) {
// results.put(permission, PackageManager.PERMISSION_GRANTED);
// }
//
// for (int i = 0; i < permissions.length; i++) {
// results.put(permissions[i], grantResults[i]);
// }
......@@ -128,10 +123,8 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
//
// if (mReadyCallback != null && mPermissionsActivity != null) {
// if (stillNeedRequest) {
// //mPermissionsActivity.finish();
// mReadyCallback.onWarplyPermissionsDenied();
// }
// // else {onResume() after close dialog of permission -> initWithPermissions()}
// }
// mPermissionsResultRequested = true;
// }
......@@ -179,6 +172,23 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
}
public synchronized void initWithPermissions(Activity activity) {
// this.mPermissionsActivity = activity;
//
// int result;
// List<String> listPermissionsNeeded = new ArrayList<>();
// for (String p : PermissionsUtil.DANGEROUS_PERMISSIONS) {
// result = ContextCompat.checkSelfPermission(activity, p);
// if (result != PackageManager.PERMISSION_GRANTED) {
// listPermissionsNeeded.add(p);
// }
// }
//
// if (!listPermissionsNeeded.isEmpty()) {
// ActivityCompat.requestPermissions(activity, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
//// init();
// }
// init();
PermissionsUtil permUtil = new PermissionsUtil(
activity,
new PermissionsUtil.PermissionCallback() {
......@@ -188,6 +198,7 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
if (mReadyCallback != null)
mReadyCallback.onWarplyPermissionsDenied();
}
@Override
public void onPermissionsGranted() {
mPermissionsResultRequested = true;
......@@ -195,47 +206,19 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
@Override
public void onError(DexterError error) {
if (error.toString().equals("REQUEST_ONGOING"))
return;
onPermissionDenied(null);
}
},
null //Requests all dangerous permissions
);
if(permUtil.requestNeeded() && !mPermissionsResultRequested){
if (permUtil.requestNeeded() && !mPermissionsResultRequested) {
permUtil.requestPermissions();
}
else{
} else {
mPermissionsResultRequested = true;
init();
}
// this.mPermissionsActivity = activity;
// final List<String> deniedPermissionsList = new ArrayList<>();
// for (String permission : DANGEROUS_PERMISSIONS) {
// if (ContextCompat.checkSelfPermission(mPermissionsActivity, permission)
// != PackageManager.PERMISSION_GRANTED) {
// deniedPermissionsList.add(permission);
// }
// }
// if (deniedPermissionsList.size() == 0 || mPermissionsResultRequested) {
//
// // reset warply initialization if was initialized
// // with wrong parameters without permissions or with another permissions count
// int oldDeniedPermissionsCount = mPreferences.getInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size());
// if (deniedPermissionsList.size() != oldDeniedPermissionsCount) {
// WarpUtils.invalidateRegistrationWarply(mContext);
// }
// mPreferences.saveInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size());
// init();
// } else {
// mPermissionsResultRequested = false;
// //TODO: restore permission request
//// ActivityCompat.requestPermissions(mPermissionsActivity,
//// deniedPermissionsList.toArray(new String[deniedPermissionsList.size()]),
//// REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
// mPreferences.saveInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size());
// init();
// }
}
// ===========================================================
......
......@@ -30,7 +30,7 @@ public class WarpConstants {
/**
* The version of the SDK installed in the device
*/
public static final String SDK_VERSION = "4.5.2";
public static final String SDK_VERSION = "4.5.3";
/**
* The URL of the server where it should ping
......
......@@ -32,6 +32,9 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.LocationManager;
import android.os.Build;
import androidx.work.WorkManager;
import java.util.List;
......@@ -97,11 +100,13 @@ public class WarplyLocationManager {
public void onError(DexterError error) {
onPermissionDenied(null);
}
@Override
public void onPermissionDenied(List<PermissionDeniedResponse> denied) {
if(denied != null && denied.size() < 2)//1 location permission accepted
if (denied != null && denied.size() < 2)//1 location permission accepted
onPermissionsGranted();
}
@Override
public void onPermissionsGranted() {
/*
......@@ -124,14 +129,14 @@ public class WarplyLocationManager {
}
};
try{
try {
new PermissionsUtil(
act,
callback,
PermissionsUtil.PERMISSION_LOCATION_COARSE,
PermissionsUtil.PERMISSION_LOCATION_FINE
).requestPermissions();
}catch (Exception e){
} catch (Exception e) {
if (BuildConfig.DEBUG)
e.printStackTrace();
}
......@@ -182,9 +187,15 @@ public class WarplyLocationManager {
public static void stopReportingLocation(Context wContext) {
if (locationManager != null) {
locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0,
new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0,
new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE));
} else {
locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0,
new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT));
}
}
disableLocationChangedReceiver(wContext);
......@@ -197,10 +208,17 @@ public class WarplyLocationManager {
enableLocationChangedReceiver();
if (wContext != null) {
final PendingIntent locationListenerPendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0,
new Intent(wContext, LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
} else {
locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0,
new Intent(wContext, LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT);
}
final PendingIntent locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0,
new Intent(wContext, LocationChangedReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT);
final LocationManager lm = (LocationManager) wContext.getSystemService(Context.LOCATION_SERVICE);
if (lm != null) {
......@@ -212,11 +230,13 @@ public class WarplyLocationManager {
public void onError(DexterError error) {
onPermissionDenied(null);
}
@Override
public void onPermissionDenied(List<PermissionDeniedResponse> denied) {
if(denied != null && denied.size() < 2)//1 location permission accepted
if (denied != null && denied.size() < 2)//1 location permission accepted
onPermissionsGranted();
}
@Override
public void onPermissionsGranted() {
try {
......@@ -323,6 +343,7 @@ public class WarplyLocationManager {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
new WarplyPreferences(wContext).saveLocationChangedReceiverStatus("off");
WorkManager.getInstance(Warply.getWarplyContext()).cancelAllWorkByTag(UpdateUserLocationService.TAG);
}
private static void enableConnectivityChangedReceiver() {
......
......@@ -54,7 +54,7 @@ public class WarplySessionManager {
*/
public static void onCreateActivity(Activity activity) {
synchronized (_activities) {
Warply.getInitializer(activity).init();
// Warply.getInitializer(activity).init();
_activities.add(activity);
if (_activities.size() == 1)
onApplicationStart();
......@@ -74,7 +74,7 @@ public class WarplySessionManager {
*/
public static void onStartActivity(Activity activity) {
synchronized (_activities) {
Warply.getInitializer(activity).init();
// Warply.getInitializer(activity).init();
_activities.add(activity);
if (_activities.size() == 1)
onApplicationEnterForeground();
......@@ -106,14 +106,14 @@ public class WarplySessionManager {
private static void onApplicationEnterForeground() {
Warply.onApplicationEnterForeground();
_receiver = new ConnectivityReceiver();
_receiver.startTracking();
// _receiver = new ConnectivityReceiver();
// _receiver.startTracking();
}
private static void onApplicationEnterBackground() {
Warply.onApplicationEnterBackground();
if (_receiver != null)
_receiver.stopTracking();
// if (_receiver != null)
// _receiver.stopTracking();
}
private static class ConnectivityReceiver extends BroadcastReceiver {
......