Showing
16 changed files
with
140 additions
and
132 deletions
... | @@ -32,13 +32,13 @@ public class SplashActivity extends BaseActivity { | ... | @@ -32,13 +32,13 @@ public class SplashActivity extends BaseActivity { |
32 | @Override | 32 | @Override |
33 | public void onWarplyInitTimeOut() { | 33 | public void onWarplyInitTimeOut() { |
34 | showToast("Warply initialization timeout!"); | 34 | showToast("Warply initialization timeout!"); |
35 | - finish(); | 35 | + checkForAppUpdate(); |
36 | } | 36 | } |
37 | 37 | ||
38 | @Override | 38 | @Override |
39 | public void onWarplyPermissionsDenied() { | 39 | public void onWarplyPermissionsDenied() { |
40 | showToast("Warply permissions denied!"); | 40 | showToast("Warply permissions denied!"); |
41 | -// onWarplyReady(); | 41 | + checkForAppUpdate(); |
42 | } | 42 | } |
43 | }); | 43 | }); |
44 | } | 44 | } |
... | @@ -55,7 +55,7 @@ public class SplashActivity extends BaseActivity { | ... | @@ -55,7 +55,7 @@ public class SplashActivity extends BaseActivity { |
55 | // super.onRequestPermissionsResult(requestCode, permissions, grantResults); | 55 | // super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
56 | // } | 56 | // } |
57 | 57 | ||
58 | - private void checkForAppUpdate(){ | 58 | + private void checkForAppUpdate() { |
59 | 59 | ||
60 | Warply.checkForAppUpdate(SplashActivity.this, new SimpleCallbackReceiver<Boolean>() { | 60 | Warply.checkForAppUpdate(SplashActivity.this, new SimpleCallbackReceiver<Boolean>() { |
61 | @Override | 61 | @Override | ... | ... |
... | @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' | ... | @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' |
2 | 2 | ||
3 | ext { | 3 | ext { |
4 | PUBLISH_GROUP_ID = 'ly.warp' | 4 | PUBLISH_GROUP_ID = 'ly.warp' |
5 | - PUBLISH_VERSION = '4.5.2' | 5 | + PUBLISH_VERSION = '4.5.3' |
6 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' | 6 | PUBLISH_ARTIFACT_ID = 'warply-android-sdk' |
7 | } | 7 | } |
8 | 8 | ||
... | @@ -48,6 +48,7 @@ dependencies { | ... | @@ -48,6 +48,7 @@ dependencies { |
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.0.1' |
51 | + api 'com.google.android.gms:play-services-location:19.0.1' | ||
51 | 52 | ||
52 | //------------------------------ Work Manager -----------------------------// | 53 | //------------------------------ Work Manager -----------------------------// |
53 | api 'androidx.work:work-runtime:2.7.1' | 54 | api 'androidx.work:work-runtime:2.7.1' | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -39,7 +39,7 @@ import android.widget.ImageView; | ... | @@ -39,7 +39,7 @@ import android.widget.ImageView; |
39 | import android.widget.ProgressBar; | 39 | import android.widget.ProgressBar; |
40 | import android.widget.RelativeLayout; | 40 | import android.widget.RelativeLayout; |
41 | 41 | ||
42 | -import java.util.Random; | 42 | +import java.security.SecureRandom; |
43 | import java.util.concurrent.ThreadLocalRandom; | 43 | import java.util.concurrent.ThreadLocalRandom; |
44 | import java.util.concurrent.TimeUnit; | 44 | import java.util.concurrent.TimeUnit; |
45 | 45 | ||
... | @@ -75,6 +75,7 @@ public class WarpViewActivity extends WarpBaseActivity { | ... | @@ -75,6 +75,7 @@ public class WarpViewActivity extends WarpBaseActivity { |
75 | @Override | 75 | @Override |
76 | public void onCreate(Bundle savedInstanceState) { | 76 | public void onCreate(Bundle savedInstanceState) { |
77 | super.onCreate(savedInstanceState); | 77 | super.onCreate(savedInstanceState); |
78 | + WarplySessionManager.onCreateActivity(this); | ||
78 | initViews(); | 79 | initViews(); |
79 | Warply.getInitializer(this).init(); | 80 | Warply.getInitializer(this).init(); |
80 | setPageAccordingToIntent(); | 81 | setPageAccordingToIntent(); |
... | @@ -203,7 +204,7 @@ public class WarpViewActivity extends WarpBaseActivity { | ... | @@ -203,7 +204,7 @@ public class WarpViewActivity extends WarpBaseActivity { |
203 | if (Build.VERSION.SDK_INT >= 21) { | 204 | if (Build.VERSION.SDK_INT >= 21) { |
204 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); | 205 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); |
205 | } else { | 206 | } else { |
206 | - Random rand = new Random(); | 207 | + SecureRandom rand = new SecureRandom(); |
207 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; | 208 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; |
208 | } | 209 | } |
209 | } | 210 | } | ... | ... |
... | @@ -84,11 +84,11 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { | ... | @@ -84,11 +84,11 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener { |
84 | if (response.optJSONObject("context") != null) { | 84 | if (response.optJSONObject("context") != null) { |
85 | if (response.optJSONObject("context").optJSONObject("device_status") != null) { | 85 | if (response.optJSONObject("context").optJSONObject("device_status") != null) { |
86 | WarpUtils.setIsWarped(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("warped")); | 86 | WarpUtils.setIsWarped(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("warped")); |
87 | - WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token")); | 87 | +// WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token")); |
88 | - WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved")); | 88 | +// WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved")); |
89 | WarpUtils.setDeviceId(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_id")); | 89 | WarpUtils.setDeviceId(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_id")); |
90 | WarpUtils.setIsDeviceIdSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_id_saved")); | 90 | WarpUtils.setIsDeviceIdSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_id_saved")); |
91 | - WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved")); | 91 | +// WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved")); |
92 | if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info") != null) { | 92 | if (response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info") != null) { |
93 | WarpUtils.setAppDataObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info")); | 93 | WarpUtils.setAppDataObject(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info")); |
94 | WarpUtils.setSDKVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("sdk_version")); | 94 | WarpUtils.setSDKVersion(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optJSONObject("application_info").optString("sdk_version")); | ... | ... |
1 | /* | 1 | /* |
2 | * Copyright 2010-2013 Warply Ltd. All rights reserved. | 2 | * Copyright 2010-2013 Warply Ltd. All rights reserved. |
3 | - * | 3 | + * |
4 | * Redistribution and use in source and binary forms, without modification, are | 4 | * Redistribution and use in source and binary forms, without modification, are |
5 | * permitted provided that the following conditions are met: | 5 | * permitted provided that the following conditions are met: |
6 | - * | 6 | + * |
7 | * 1. Redistributions of source code must retain the above copyright notice, | 7 | * 1. Redistributions of source code must retain the above copyright notice, |
8 | * this list of conditions and the following disclaimer. | 8 | * this list of conditions and the following disclaimer. |
9 | - * | 9 | + * |
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 | * this list of conditions and the following disclaimer in the documentation | 11 | * this list of conditions and the following disclaimer in the documentation |
12 | * and/or other materials provided with the distribution. | 12 | * and/or other materials provided with the distribution. |
13 | - * | 13 | + * |
14 | * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR | 14 | * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
16 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 16 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
... | @@ -34,7 +34,9 @@ import android.content.Context; | ... | @@ -34,7 +34,9 @@ import android.content.Context; |
34 | import android.content.Intent; | 34 | import android.content.Intent; |
35 | import android.location.Location; | 35 | import android.location.Location; |
36 | import android.location.LocationManager; | 36 | import android.location.LocationManager; |
37 | -import android.os.Build; | 37 | + |
38 | +import java.util.HashMap; | ||
39 | +import java.util.Map; | ||
38 | 40 | ||
39 | public class LocationChangedReceiver extends BroadcastReceiver { | 41 | public class LocationChangedReceiver extends BroadcastReceiver { |
40 | 42 | ||
... | @@ -44,9 +46,6 @@ public class LocationChangedReceiver extends BroadcastReceiver { | ... | @@ -44,9 +46,6 @@ public class LocationChangedReceiver extends BroadcastReceiver { |
44 | 46 | ||
45 | @Override | 47 | @Override |
46 | public void onReceive(Context context, Intent intent) { | 48 | public void onReceive(Context context, Intent intent) { |
47 | - | ||
48 | - // Log.i("Location receiver", Integer.toString(counter++)); | ||
49 | - | ||
50 | isAppShutDown = WarplyLocationManager.waprplyContext == null; | 49 | isAppShutDown = WarplyLocationManager.waprplyContext == null; |
51 | 50 | ||
52 | /** | 51 | /** |
... | @@ -64,23 +63,14 @@ public class LocationChangedReceiver extends BroadcastReceiver { | ... | @@ -64,23 +63,14 @@ public class LocationChangedReceiver extends BroadcastReceiver { |
64 | } | 63 | } |
65 | 64 | ||
66 | if (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED)) { | 65 | if (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED)) { |
67 | - | ||
68 | new WarplyPreferences(context).saveUpdateLocationServiceStatus("on"); | 66 | new WarplyPreferences(context).saveUpdateLocationServiceStatus("on"); |
69 | 67 | ||
70 | Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED); | 68 | Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED); |
71 | -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
72 | -// context.startForegroundService(new Intent(context, UpdateUserLocationService.class) | ||
73 | -// .putExtra("LOCATION_KEY", location)); | ||
74 | -// } else { | ||
75 | -// context.startService(new Intent(context, UpdateUserLocationService.class) | ||
76 | -// .putExtra("LOCATION_KEY", location)); | ||
77 | -// } | ||
78 | - | ||
79 | - UpdateUserLocationService.enqueueWork(context, new Intent(context, UpdateUserLocationService.class) | ||
80 | - .putExtra("LOCATION_KEY", location)); | ||
81 | 69 | ||
70 | + Map<String, Object> mLocValues = new HashMap<>(); | ||
71 | + mLocValues.put("latitude", location.getLatitude()); | ||
72 | + mLocValues.put("longitude", location.getLongitude()); | ||
73 | + UpdateUserLocationService.scheduleWork(context, mLocValues); | ||
82 | } | 74 | } |
83 | - | ||
84 | } | 75 | } |
85 | - | 76 | +} |
86 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -28,8 +28,8 @@ import java.io.IOException; | ... | @@ -28,8 +28,8 @@ import java.io.IOException; |
28 | import java.io.InputStream; | 28 | import java.io.InputStream; |
29 | import java.net.HttpURLConnection; | 29 | import java.net.HttpURLConnection; |
30 | import java.net.URL; | 30 | import java.net.URL; |
31 | +import java.security.SecureRandom; | ||
31 | import java.util.List; | 32 | import java.util.List; |
32 | -import java.util.Random; | ||
33 | import java.util.concurrent.ThreadLocalRandom; | 33 | import java.util.concurrent.ThreadLocalRandom; |
34 | import java.util.concurrent.TimeUnit; | 34 | import java.util.concurrent.TimeUnit; |
35 | 35 | ||
... | @@ -98,6 +98,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -98,6 +98,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { |
98 | public void onNewToken(@NonNull String s) { | 98 | public void onNewToken(@NonNull String s) { |
99 | super.onNewToken(s); | 99 | super.onNewToken(s); |
100 | GCMRegistrar.setRegistrationId(this, s); | 100 | GCMRegistrar.setRegistrationId(this, s); |
101 | + WarpUtils.setDeviceToken(this, s); | ||
101 | } | 102 | } |
102 | 103 | ||
103 | @Override | 104 | @Override |
... | @@ -146,7 +147,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -146,7 +147,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { |
146 | if (Build.VERSION.SDK_INT >= 21) { | 147 | if (Build.VERSION.SDK_INT >= 21) { |
147 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); | 148 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); |
148 | } else { | 149 | } else { |
149 | - Random rand = new Random(); | 150 | + SecureRandom rand = new SecureRandom(); |
150 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; | 151 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; |
151 | } | 152 | } |
152 | } | 153 | } |
... | @@ -164,7 +165,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -164,7 +165,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { |
164 | 165 | ||
165 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); | 166 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); |
166 | 167 | ||
167 | - Random randomGenerator = new Random(); | 168 | + SecureRandom randomGenerator = new SecureRandom(); |
168 | 169 | ||
169 | int uid = randomGenerator.nextInt(1000); | 170 | int uid = randomGenerator.nextInt(1000); |
170 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { | 171 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { |
... | @@ -297,7 +298,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -297,7 +298,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { |
297 | public void showNotification(Context context, String title, String ticker, | 298 | public void showNotification(Context context, String title, String ticker, |
298 | String message, Intent newIntent, String tag, int id) { | 299 | String message, Intent newIntent, String tag, int id) { |
299 | 300 | ||
300 | - Random randomGenerator = new Random(); | 301 | + SecureRandom randomGenerator = new SecureRandom(); |
301 | int uid = randomGenerator.nextInt(1000); | 302 | int uid = randomGenerator.nextInt(1000); |
302 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " | 303 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " |
303 | + id); | 304 | + id); |
... | @@ -343,7 +344,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -343,7 +344,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { |
343 | 344 | ||
344 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { | 345 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { |
345 | 346 | ||
346 | - Random randomGenerator = new Random(); | 347 | + SecureRandom randomGenerator = new SecureRandom(); |
347 | int uid = randomGenerator.nextInt(1000); | 348 | int uid = randomGenerator.nextInt(1000); |
348 | if (id > 0) { | 349 | if (id > 0) { |
349 | uid = id; | 350 | uid = id; | ... | ... |
... | @@ -39,7 +39,7 @@ import android.os.SystemClock; | ... | @@ -39,7 +39,7 @@ import android.os.SystemClock; |
39 | import androidx.core.app.NotificationCompat; | 39 | import androidx.core.app.NotificationCompat; |
40 | import android.util.Log; | 40 | import android.util.Log; |
41 | 41 | ||
42 | -import java.util.Random; | 42 | +import java.security.SecureRandom; |
43 | import java.util.concurrent.TimeUnit; | 43 | import java.util.concurrent.TimeUnit; |
44 | 44 | ||
45 | import ly.warp.sdk.utils.GCMRegistrar; | 45 | import ly.warp.sdk.utils.GCMRegistrar; |
... | @@ -74,7 +74,7 @@ public abstract class GCMBaseIntentService extends IntentService { | ... | @@ -74,7 +74,7 @@ public abstract class GCMBaseIntentService extends IntentService { |
74 | // instance counter | 74 | // instance counter |
75 | private static int sCounter = 0; | 75 | private static int sCounter = 0; |
76 | 76 | ||
77 | - private static final Random sRandom = new Random(); | 77 | + private static final SecureRandom sRandom = new SecureRandom(); |
78 | 78 | ||
79 | private static final int MAX_BACKOFF_MS = (int) TimeUnit.SECONDS | 79 | private static final int MAX_BACKOFF_MS = (int) TimeUnit.SECONDS |
80 | .toMillis(3600); // 1 hour | 80 | .toMillis(3600); // 1 hour | ... | ... |
... | @@ -14,7 +14,6 @@ import android.media.RingtoneManager; | ... | @@ -14,7 +14,6 @@ import android.media.RingtoneManager; |
14 | import android.os.Build; | 14 | import android.os.Build; |
15 | import android.os.Bundle; | 15 | import android.os.Bundle; |
16 | import android.text.TextUtils; | 16 | import android.text.TextUtils; |
17 | -import android.util.Log; | ||
18 | import android.widget.RemoteViews; | 17 | import android.widget.RemoteViews; |
19 | 18 | ||
20 | import androidx.core.app.NotificationCompat; | 19 | import androidx.core.app.NotificationCompat; |
... | @@ -33,9 +32,9 @@ import org.json.JSONObject; | ... | @@ -33,9 +32,9 @@ import org.json.JSONObject; |
33 | import java.io.InputStream; | 32 | import java.io.InputStream; |
34 | import java.net.HttpURLConnection; | 33 | import java.net.HttpURLConnection; |
35 | import java.net.URL; | 34 | import java.net.URL; |
35 | +import java.security.SecureRandom; | ||
36 | import java.util.Iterator; | 36 | import java.util.Iterator; |
37 | import java.util.List; | 37 | import java.util.List; |
38 | -import java.util.Random; | ||
39 | import java.util.concurrent.ThreadLocalRandom; | 38 | import java.util.concurrent.ThreadLocalRandom; |
40 | import java.util.concurrent.TimeUnit; | 39 | import java.util.concurrent.TimeUnit; |
41 | 40 | ||
... | @@ -91,18 +90,15 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -91,18 +90,15 @@ public class HMSBaseMessagingService extends HmsMessageService { |
91 | // =========================================================== | 90 | // =========================================================== |
92 | // URLThread class | 91 | // URLThread class |
93 | // =========================================================== | 92 | // =========================================================== |
94 | - public static class URLThread extends Thread | 93 | + public static class URLThread extends Thread { |
95 | - { | ||
96 | private String urlString = ""; | 94 | private String urlString = ""; |
97 | 95 | ||
98 | - public URLThread(String url) | 96 | + public URLThread(String url) { |
99 | - { | ||
100 | this.urlString = url; | 97 | this.urlString = url; |
101 | } | 98 | } |
102 | 99 | ||
103 | @Override | 100 | @Override |
104 | - public void run() | 101 | + public void run() { |
105 | - { | ||
106 | try { | 102 | try { |
107 | URL url; | 103 | URL url; |
108 | HttpURLConnection urlConnection = null; | 104 | HttpURLConnection urlConnection = null; |
... | @@ -138,7 +134,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -138,7 +134,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
138 | public void onNewToken(String s, Bundle bundle) { | 134 | public void onNewToken(String s, Bundle bundle) { |
139 | super.onNewToken(s, bundle); | 135 | super.onNewToken(s, bundle); |
140 | GCMRegistrar.setRegistrationId(this, s); | 136 | GCMRegistrar.setRegistrationId(this, s); |
141 | - Log.v("HUAWEI TOKEN", "receive token:" + s); | 137 | + WarpUtils.setDeviceToken(this, s); |
142 | } | 138 | } |
143 | 139 | ||
144 | @Override | 140 | @Override |
... | @@ -146,7 +142,6 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -146,7 +142,6 @@ public class HMSBaseMessagingService extends HmsMessageService { |
146 | super.onMessageReceived(remoteMessage); | 142 | super.onMessageReceived(remoteMessage); |
147 | 143 | ||
148 | JSONObject data = new JSONObject(remoteMessage.getDataOfMap()); | 144 | JSONObject data = new JSONObject(remoteMessage.getDataOfMap()); |
149 | - Log.v("DATA", "data is " + data); | ||
150 | if (data == null || !data.has("loyalty-action")) { | 145 | if (data == null || !data.has("loyalty-action")) { |
151 | return; | 146 | return; |
152 | } | 147 | } |
... | @@ -197,7 +192,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -197,7 +192,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
197 | if (Build.VERSION.SDK_INT >= 21) { | 192 | if (Build.VERSION.SDK_INT >= 21) { |
198 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); | 193 | return ThreadLocalRandom.current().nextInt(RANDOM_MIN, RANDOM_MAX + 1); |
199 | } else { | 194 | } else { |
200 | - Random rand = new Random(); | 195 | + SecureRandom rand = new SecureRandom(); |
201 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; | 196 | return rand.nextInt((RANDOM_MAX - RANDOM_MIN) + 1) + RANDOM_MIN; |
202 | } | 197 | } |
203 | } | 198 | } |
... | @@ -215,7 +210,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -215,7 +210,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
215 | 210 | ||
216 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); | 211 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); |
217 | 212 | ||
218 | - Random randomGenerator = new Random(); | 213 | + SecureRandom randomGenerator = new SecureRandom(); |
219 | 214 | ||
220 | int uid = randomGenerator.nextInt(1000); | 215 | int uid = randomGenerator.nextInt(1000); |
221 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { | 216 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { |
... | @@ -346,7 +341,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -346,7 +341,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
346 | public void showNotification(Context context, String title, String ticker, | 341 | public void showNotification(Context context, String title, String ticker, |
347 | String message, Intent newIntent, String tag, int id) { | 342 | String message, Intent newIntent, String tag, int id) { |
348 | 343 | ||
349 | - Random randomGenerator = new Random(); | 344 | + SecureRandom randomGenerator = new SecureRandom(); |
350 | int uid = randomGenerator.nextInt(1000); | 345 | int uid = randomGenerator.nextInt(1000); |
351 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " | 346 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " |
352 | + id); | 347 | + id); |
... | @@ -392,7 +387,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -392,7 +387,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
392 | 387 | ||
393 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { | 388 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { |
394 | 389 | ||
395 | - Random randomGenerator = new Random(); | 390 | + SecureRandom randomGenerator = new SecureRandom(); |
396 | int uid = randomGenerator.nextInt(1000); | 391 | int uid = randomGenerator.nextInt(1000); |
397 | if (id > 0) { | 392 | if (id > 0) { |
398 | uid = id; | 393 | uid = id; |
... | @@ -544,7 +539,7 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -544,7 +539,7 @@ public class HMSBaseMessagingService extends HmsMessageService { |
544 | 539 | ||
545 | private static Bitmap loadDrawable(final String urlString) { | 540 | private static Bitmap loadDrawable(final String urlString) { |
546 | if (urlString == null || TextUtils.isEmpty(urlString)) | 541 | if (urlString == null || TextUtils.isEmpty(urlString)) |
547 | - return null; | 542 | + return null; |
548 | 543 | ||
549 | // alternative solution to thread but only in debug mode | 544 | // alternative solution to thread but only in debug mode |
550 | // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | 545 | // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); |
... | @@ -569,10 +564,10 @@ public class HMSBaseMessagingService extends HmsMessageService { | ... | @@ -569,10 +564,10 @@ public class HMSBaseMessagingService extends HmsMessageService { |
569 | public static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { | 564 | public static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { |
570 | Bundle bundle = new Bundle(); | 565 | Bundle bundle = new Bundle(); |
571 | Iterator iter = jsonObject.keys(); | 566 | Iterator iter = jsonObject.keys(); |
572 | - while(iter.hasNext()){ | 567 | + while (iter.hasNext()) { |
573 | - String key = (String)iter.next(); | 568 | + String key = (String) iter.next(); |
574 | String value = jsonObject.getString(key); | 569 | String value = jsonObject.getString(key); |
575 | - bundle.putString(key,value); | 570 | + bundle.putString(key, value); |
576 | } | 571 | } |
577 | return bundle; | 572 | return bundle; |
578 | } | 573 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -52,8 +52,8 @@ import org.json.JSONObject; | ... | @@ -52,8 +52,8 @@ import org.json.JSONObject; |
52 | 52 | ||
53 | import java.io.IOException; | 53 | import java.io.IOException; |
54 | import java.io.InputStream; | 54 | import java.io.InputStream; |
55 | +import java.security.SecureRandom; | ||
55 | import java.util.List; | 56 | import java.util.List; |
56 | -import java.util.Random; | ||
57 | 57 | ||
58 | import ly.warp.sdk.Warply; | 58 | import ly.warp.sdk.Warply; |
59 | import ly.warp.sdk.activities.WarpViewActivity; | 59 | import ly.warp.sdk.activities.WarpViewActivity; |
... | @@ -145,7 +145,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { | ... | @@ -145,7 +145,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { |
145 | 145 | ||
146 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); | 146 | WarpUtils.log("Showing campaign with session UUID: " + pc.getSessionUUID()); |
147 | 147 | ||
148 | - Random randomGenerator = new Random(); | 148 | + SecureRandom randomGenerator = new SecureRandom(); |
149 | 149 | ||
150 | int uid = randomGenerator.nextInt(1000); | 150 | int uid = randomGenerator.nextInt(1000); |
151 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { | 151 | if (!TextUtils.isEmpty(pc.getSessionUUID())) { |
... | @@ -277,7 +277,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { | ... | @@ -277,7 +277,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { |
277 | public void showNotification(Context context, String title, String ticker, | 277 | public void showNotification(Context context, String title, String ticker, |
278 | String message, Intent newIntent, String tag, int id) { | 278 | String message, Intent newIntent, String tag, int id) { |
279 | 279 | ||
280 | - Random randomGenerator = new Random(); | 280 | + SecureRandom randomGenerator = new SecureRandom(); |
281 | int uid = randomGenerator.nextInt(1000); | 281 | int uid = randomGenerator.nextInt(1000); |
282 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " | 282 | WarpUtils.log("Showing notification with tag: " + tag + " and id: " |
283 | + id); | 283 | + id); |
... | @@ -323,7 +323,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { | ... | @@ -323,7 +323,7 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService { |
323 | 323 | ||
324 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { | 324 | public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { |
325 | 325 | ||
326 | - Random randomGenerator = new Random(); | 326 | + SecureRandom randomGenerator = new SecureRandom(); |
327 | int uid = randomGenerator.nextInt(1000); | 327 | int uid = randomGenerator.nextInt(1000); |
328 | if (id > 0) { | 328 | if (id > 0) { |
329 | uid = id; | 329 | uid = id; | ... | ... |
... | @@ -32,6 +32,7 @@ import android.app.PendingIntent; | ... | @@ -32,6 +32,7 @@ import android.app.PendingIntent; |
32 | import android.content.Context; | 32 | import android.content.Context; |
33 | import android.content.Intent; | 33 | import android.content.Intent; |
34 | import android.content.pm.PackageManager; | 34 | import android.content.pm.PackageManager; |
35 | +import android.os.Build; | ||
35 | import android.os.Bundle; | 36 | import android.os.Bundle; |
36 | import androidx.annotation.NonNull; | 37 | import androidx.annotation.NonNull; |
37 | import androidx.core.app.NotificationCompat; | 38 | import androidx.core.app.NotificationCompat; |
... | @@ -91,7 +92,12 @@ public class WarpInAppNotificationService extends WarpBaseIntentService { | ... | @@ -91,7 +92,12 @@ public class WarpInAppNotificationService extends WarpBaseIntentService { |
91 | .putExtra(KEY_SUBTITLE, mNotificationSubtitle); | 92 | .putExtra(KEY_SUBTITLE, mNotificationSubtitle); |
92 | 93 | ||
93 | 94 | ||
94 | - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); | 95 | + PendingIntent pendingIntent; |
96 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
97 | + pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); | ||
98 | + } else { | ||
99 | + pendingIntent = PendingIntent.getBroadcast(this, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
100 | + } | ||
95 | builder.setContentIntent(pendingIntent); | 101 | builder.setContentIntent(pendingIntent); |
96 | // builder.setFullScreenIntent(pendingIntent, true); // Heads up notification, always visible OR setPriority to HIGH and setContentIntent | 102 | // builder.setFullScreenIntent(pendingIntent, true); // Heads up notification, always visible OR setPriority to HIGH and setContentIntent |
97 | NotificationManager nm = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); | 103 | NotificationManager nm = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); |
... | @@ -106,14 +112,24 @@ public class WarpInAppNotificationService extends WarpBaseIntentService { | ... | @@ -106,14 +112,24 @@ public class WarpInAppNotificationService extends WarpBaseIntentService { |
106 | .putExtra(KEY_TITLE, title) | 112 | .putExtra(KEY_TITLE, title) |
107 | .putExtra(KEY_SUBTITLE, subtitle) | 113 | .putExtra(KEY_SUBTITLE, subtitle) |
108 | .putExtra(KEY_HEADS_UP, isHeadsUpNotification); | 114 | .putExtra(KEY_HEADS_UP, isHeadsUpNotification); |
109 | - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); | 115 | + PendingIntent pendingIntent; |
116 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
117 | + pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); | ||
118 | + } else { | ||
119 | + pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
120 | + } | ||
110 | AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | 121 | AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
111 | alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent); | 122 | alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent); |
112 | } | 123 | } |
113 | 124 | ||
114 | public static void cancelInAppNotificationAlarm(Context context, @NonNull int uid) { | 125 | public static void cancelInAppNotificationAlarm(Context context, @NonNull int uid) { |
115 | Intent notifyIntent = new Intent(context, WarplyInAppNotificationReceiver.class).putExtra(KEY_UID, uid); | 126 | Intent notifyIntent = new Intent(context, WarplyInAppNotificationReceiver.class).putExtra(KEY_UID, uid); |
116 | - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT); | 127 | + PendingIntent pendingIntent; |
128 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
129 | + pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE); | ||
130 | + } else { | ||
131 | + pendingIntent = PendingIntent.getBroadcast(context, uid, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT); | ||
132 | + } | ||
117 | AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | 133 | AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
118 | alarmManager.cancel(pendingIntent); | 134 | alarmManager.cancel(pendingIntent); |
119 | pendingIntent.cancel(); | 135 | pendingIntent.cancel(); | ... | ... |
... | @@ -2,10 +2,18 @@ package ly.warp.sdk.utils; | ... | @@ -2,10 +2,18 @@ package ly.warp.sdk.utils; |
2 | 2 | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.content.Context; | 4 | import android.content.Context; |
5 | +import android.content.pm.PackageManager; | ||
5 | import android.os.Handler; | 6 | import android.os.Handler; |
6 | import android.os.Looper; | 7 | import android.os.Looper; |
7 | 8 | ||
9 | +import androidx.annotation.NonNull; | ||
10 | +import androidx.core.app.ActivityCompat; | ||
11 | +import androidx.core.content.ContextCompat; | ||
12 | + | ||
13 | +import java.util.ArrayList; | ||
14 | +import java.util.HashMap; | ||
8 | import java.util.List; | 15 | import java.util.List; |
16 | +import java.util.Map; | ||
9 | import java.util.concurrent.atomic.AtomicBoolean; | 17 | import java.util.concurrent.atomic.AtomicBoolean; |
10 | 18 | ||
11 | import ly.warp.sdk.dexter.listener.DexterError; | 19 | import ly.warp.sdk.dexter.listener.DexterError; |
... | @@ -13,25 +21,15 @@ import ly.warp.sdk.dexter.listener.PermissionDeniedResponse; | ... | @@ -13,25 +21,15 @@ import ly.warp.sdk.dexter.listener.PermissionDeniedResponse; |
13 | import ly.warp.sdk.io.callbacks.WarplyReadyCallback; | 21 | import ly.warp.sdk.io.callbacks.WarplyReadyCallback; |
14 | import ly.warp.sdk.utils.constants.WarpConstants; | 22 | import ly.warp.sdk.utils.constants.WarpConstants; |
15 | 23 | ||
16 | -public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequestPermissionsResultCallback */{ | 24 | +public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequestPermissionsResultCallback*/ { |
17 | 25 | ||
18 | // =========================================================== | 26 | // =========================================================== |
19 | // Constants | 27 | // Constants |
20 | // =========================================================== | 28 | // =========================================================== |
21 | -// private final String PREF_KEY_DENIED_PERMISSION_COUNT = "pref_key_denied_permissions_count"; | ||
22 | 29 | ||
23 | private final long INIT_TIME_OUT = 1000 * 20; | 30 | private final long INIT_TIME_OUT = 1000 * 20; |
24 | private final long INIT_ATTEMPTS = 3; | 31 | private final long INIT_ATTEMPTS = 3; |
25 | - | 32 | + private final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 3001; |
26 | - // permissions | ||
27 | -// private static final String[] DANGEROUS_PERMISSIONS = { | ||
28 | -// android.Manifest.permission.ACCESS_FINE_LOCATION, | ||
29 | -// android.Manifest.permission.ACCESS_COARSE_LOCATION, | ||
30 | -// Manifest.permission.READ_PHONE_STATE, | ||
31 | -// Manifest.permission.WRITE_EXTERNAL_STORAGE | ||
32 | -// }; | ||
33 | -// | ||
34 | -// private final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124; | ||
35 | private boolean mPermissionsResultRequested = false; | 33 | private boolean mPermissionsResultRequested = false; |
36 | 34 | ||
37 | // =========================================================== | 35 | // =========================================================== |
... | @@ -39,10 +37,9 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -39,10 +37,9 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
39 | // =========================================================== | 37 | // =========================================================== |
40 | 38 | ||
41 | private Context mContext; | 39 | private Context mContext; |
42 | -// private Activity mPermissionsActivity; | 40 | + private Activity mPermissionsActivity; |
43 | private WarplyInitCallback mInitCallback; | 41 | private WarplyInitCallback mInitCallback; |
44 | private WarplyReadyCallback mReadyCallback; | 42 | private WarplyReadyCallback mReadyCallback; |
45 | -// private WarplyPreferences mPreferences; | ||
46 | 43 | ||
47 | private static volatile Handler mMainThreadHandler; | 44 | private static volatile Handler mMainThreadHandler; |
48 | private static volatile AtomicBoolean stopThreadLock; | 45 | private static volatile AtomicBoolean stopThreadLock; |
... | @@ -57,7 +54,6 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -57,7 +54,6 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
57 | this.mContext = context; | 54 | this.mContext = context; |
58 | this.mReadyCallback = readyCallback; | 55 | this.mReadyCallback = readyCallback; |
59 | this.mInitCallback = initCallback; | 56 | this.mInitCallback = initCallback; |
60 | -// this.mPreferences = new WarplyPreferences(mContext); | ||
61 | 57 | ||
62 | if (mMainThreadHandler == null) { | 58 | if (mMainThreadHandler == null) { |
63 | mMainThreadHandler = new Handler(Looper.getMainLooper()); | 59 | mMainThreadHandler = new Handler(Looper.getMainLooper()); |
... | @@ -105,15 +101,14 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -105,15 +101,14 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
105 | 101 | ||
106 | // @Override | 102 | // @Override |
107 | // public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | 103 | // public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
108 | -// | ||
109 | // switch (requestCode) { | 104 | // switch (requestCode) { |
110 | // case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: | 105 | // case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: |
111 | -// | ||
112 | // if (permissions.length > 0) { | 106 | // if (permissions.length > 0) { |
113 | // Map<String, Integer> results = new HashMap<>(); | 107 | // Map<String, Integer> results = new HashMap<>(); |
114 | -// for (String permission : DANGEROUS_PERMISSIONS) { | 108 | +// for (String permission : PermissionsUtil.DANGEROUS_PERMISSIONS) { |
115 | // results.put(permission, PackageManager.PERMISSION_GRANTED); | 109 | // results.put(permission, PackageManager.PERMISSION_GRANTED); |
116 | // } | 110 | // } |
111 | +// | ||
117 | // for (int i = 0; i < permissions.length; i++) { | 112 | // for (int i = 0; i < permissions.length; i++) { |
118 | // results.put(permissions[i], grantResults[i]); | 113 | // results.put(permissions[i], grantResults[i]); |
119 | // } | 114 | // } |
... | @@ -128,10 +123,8 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -128,10 +123,8 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
128 | // | 123 | // |
129 | // if (mReadyCallback != null && mPermissionsActivity != null) { | 124 | // if (mReadyCallback != null && mPermissionsActivity != null) { |
130 | // if (stillNeedRequest) { | 125 | // if (stillNeedRequest) { |
131 | -// //mPermissionsActivity.finish(); | ||
132 | // mReadyCallback.onWarplyPermissionsDenied(); | 126 | // mReadyCallback.onWarplyPermissionsDenied(); |
133 | // } | 127 | // } |
134 | -// // else {onResume() after close dialog of permission -> initWithPermissions()} | ||
135 | // } | 128 | // } |
136 | // mPermissionsResultRequested = true; | 129 | // mPermissionsResultRequested = true; |
137 | // } | 130 | // } |
... | @@ -179,6 +172,23 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -179,6 +172,23 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
179 | } | 172 | } |
180 | 173 | ||
181 | public synchronized void initWithPermissions(Activity activity) { | 174 | public synchronized void initWithPermissions(Activity activity) { |
175 | +// this.mPermissionsActivity = activity; | ||
176 | +// | ||
177 | +// int result; | ||
178 | +// List<String> listPermissionsNeeded = new ArrayList<>(); | ||
179 | +// for (String p : PermissionsUtil.DANGEROUS_PERMISSIONS) { | ||
180 | +// result = ContextCompat.checkSelfPermission(activity, p); | ||
181 | +// if (result != PackageManager.PERMISSION_GRANTED) { | ||
182 | +// listPermissionsNeeded.add(p); | ||
183 | +// } | ||
184 | +// } | ||
185 | +// | ||
186 | +// if (!listPermissionsNeeded.isEmpty()) { | ||
187 | +// ActivityCompat.requestPermissions(activity, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS); | ||
188 | +//// init(); | ||
189 | +// } | ||
190 | +// init(); | ||
191 | + | ||
182 | PermissionsUtil permUtil = new PermissionsUtil( | 192 | PermissionsUtil permUtil = new PermissionsUtil( |
183 | activity, | 193 | activity, |
184 | new PermissionsUtil.PermissionCallback() { | 194 | new PermissionsUtil.PermissionCallback() { |
... | @@ -188,6 +198,7 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -188,6 +198,7 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
188 | if (mReadyCallback != null) | 198 | if (mReadyCallback != null) |
189 | mReadyCallback.onWarplyPermissionsDenied(); | 199 | mReadyCallback.onWarplyPermissionsDenied(); |
190 | } | 200 | } |
201 | + | ||
191 | @Override | 202 | @Override |
192 | public void onPermissionsGranted() { | 203 | public void onPermissionsGranted() { |
193 | mPermissionsResultRequested = true; | 204 | mPermissionsResultRequested = true; |
... | @@ -195,47 +206,19 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ | ... | @@ -195,47 +206,19 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ |
195 | 206 | ||
196 | @Override | 207 | @Override |
197 | public void onError(DexterError error) { | 208 | public void onError(DexterError error) { |
209 | + if (error.toString().equals("REQUEST_ONGOING")) | ||
210 | + return; | ||
198 | onPermissionDenied(null); | 211 | onPermissionDenied(null); |
199 | } | 212 | } |
200 | }, | 213 | }, |
201 | null //Requests all dangerous permissions | 214 | null //Requests all dangerous permissions |
202 | ); | 215 | ); |
203 | - if(permUtil.requestNeeded() && !mPermissionsResultRequested){ | 216 | + if (permUtil.requestNeeded() && !mPermissionsResultRequested) { |
204 | permUtil.requestPermissions(); | 217 | permUtil.requestPermissions(); |
205 | - } | 218 | + } else { |
206 | - else{ | ||
207 | mPermissionsResultRequested = true; | 219 | mPermissionsResultRequested = true; |
208 | init(); | 220 | init(); |
209 | } | 221 | } |
210 | - | ||
211 | -// this.mPermissionsActivity = activity; | ||
212 | -// final List<String> deniedPermissionsList = new ArrayList<>(); | ||
213 | -// for (String permission : DANGEROUS_PERMISSIONS) { | ||
214 | -// if (ContextCompat.checkSelfPermission(mPermissionsActivity, permission) | ||
215 | -// != PackageManager.PERMISSION_GRANTED) { | ||
216 | -// deniedPermissionsList.add(permission); | ||
217 | -// } | ||
218 | -// } | ||
219 | - | ||
220 | -// if (deniedPermissionsList.size() == 0 || mPermissionsResultRequested) { | ||
221 | -// | ||
222 | -// // reset warply initialization if was initialized | ||
223 | -// // with wrong parameters without permissions or with another permissions count | ||
224 | -// int oldDeniedPermissionsCount = mPreferences.getInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size()); | ||
225 | -// if (deniedPermissionsList.size() != oldDeniedPermissionsCount) { | ||
226 | -// WarpUtils.invalidateRegistrationWarply(mContext); | ||
227 | -// } | ||
228 | -// mPreferences.saveInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size()); | ||
229 | -// init(); | ||
230 | -// } else { | ||
231 | -// mPermissionsResultRequested = false; | ||
232 | -// //TODO: restore permission request | ||
233 | -//// ActivityCompat.requestPermissions(mPermissionsActivity, | ||
234 | -//// deniedPermissionsList.toArray(new String[deniedPermissionsList.size()]), | ||
235 | -//// REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS); | ||
236 | -// mPreferences.saveInt(PREF_KEY_DENIED_PERMISSION_COUNT, deniedPermissionsList.size()); | ||
237 | -// init(); | ||
238 | -// } | ||
239 | } | 222 | } |
240 | 223 | ||
241 | // =========================================================== | 224 | // =========================================================== | ... | ... |
... | @@ -30,7 +30,7 @@ public class WarpConstants { | ... | @@ -30,7 +30,7 @@ public class WarpConstants { |
30 | /** | 30 | /** |
31 | * The version of the SDK installed in the device | 31 | * The version of the SDK installed in the device |
32 | */ | 32 | */ |
33 | - public static final String SDK_VERSION = "4.5.2"; | 33 | + public static final String SDK_VERSION = "4.5.3"; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * The URL of the server where it should ping | 36 | * The URL of the server where it should ping | ... | ... |
... | @@ -32,6 +32,9 @@ import android.content.Intent; | ... | @@ -32,6 +32,9 @@ import android.content.Intent; |
32 | import android.content.pm.PackageManager; | 32 | import android.content.pm.PackageManager; |
33 | import android.location.Criteria; | 33 | import android.location.Criteria; |
34 | import android.location.LocationManager; | 34 | import android.location.LocationManager; |
35 | +import android.os.Build; | ||
36 | + | ||
37 | +import androidx.work.WorkManager; | ||
35 | 38 | ||
36 | import java.util.List; | 39 | import java.util.List; |
37 | 40 | ||
... | @@ -97,11 +100,13 @@ public class WarplyLocationManager { | ... | @@ -97,11 +100,13 @@ public class WarplyLocationManager { |
97 | public void onError(DexterError error) { | 100 | public void onError(DexterError error) { |
98 | onPermissionDenied(null); | 101 | onPermissionDenied(null); |
99 | } | 102 | } |
103 | + | ||
100 | @Override | 104 | @Override |
101 | public void onPermissionDenied(List<PermissionDeniedResponse> denied) { | 105 | public void onPermissionDenied(List<PermissionDeniedResponse> denied) { |
102 | - if(denied != null && denied.size() < 2)//1 location permission accepted | 106 | + if (denied != null && denied.size() < 2)//1 location permission accepted |
103 | onPermissionsGranted(); | 107 | onPermissionsGranted(); |
104 | } | 108 | } |
109 | + | ||
105 | @Override | 110 | @Override |
106 | public void onPermissionsGranted() { | 111 | public void onPermissionsGranted() { |
107 | /* | 112 | /* |
... | @@ -124,14 +129,14 @@ public class WarplyLocationManager { | ... | @@ -124,14 +129,14 @@ public class WarplyLocationManager { |
124 | } | 129 | } |
125 | }; | 130 | }; |
126 | 131 | ||
127 | - try{ | 132 | + try { |
128 | new PermissionsUtil( | 133 | new PermissionsUtil( |
129 | act, | 134 | act, |
130 | callback, | 135 | callback, |
131 | PermissionsUtil.PERMISSION_LOCATION_COARSE, | 136 | PermissionsUtil.PERMISSION_LOCATION_COARSE, |
132 | PermissionsUtil.PERMISSION_LOCATION_FINE | 137 | PermissionsUtil.PERMISSION_LOCATION_FINE |
133 | ).requestPermissions(); | 138 | ).requestPermissions(); |
134 | - }catch (Exception e){ | 139 | + } catch (Exception e) { |
135 | if (BuildConfig.DEBUG) | 140 | if (BuildConfig.DEBUG) |
136 | e.printStackTrace(); | 141 | e.printStackTrace(); |
137 | } | 142 | } |
... | @@ -182,9 +187,15 @@ public class WarplyLocationManager { | ... | @@ -182,9 +187,15 @@ public class WarplyLocationManager { |
182 | public static void stopReportingLocation(Context wContext) { | 187 | public static void stopReportingLocation(Context wContext) { |
183 | 188 | ||
184 | if (locationManager != null) { | 189 | if (locationManager != null) { |
185 | - locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0, | 190 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { |
186 | - new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class), | 191 | + locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0, |
187 | - PendingIntent.FLAG_UPDATE_CURRENT)); | 192 | + new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class), |
193 | + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE)); | ||
194 | + } else { | ||
195 | + locationManager.removeUpdates(PendingIntent.getBroadcast(Warply.getWarplyContext(), 0, | ||
196 | + new Intent(Warply.getWarplyContext(), LocationChangedReceiver.class), | ||
197 | + PendingIntent.FLAG_UPDATE_CURRENT)); | ||
198 | + } | ||
188 | } | 199 | } |
189 | 200 | ||
190 | disableLocationChangedReceiver(wContext); | 201 | disableLocationChangedReceiver(wContext); |
... | @@ -197,10 +208,17 @@ public class WarplyLocationManager { | ... | @@ -197,10 +208,17 @@ public class WarplyLocationManager { |
197 | enableLocationChangedReceiver(); | 208 | enableLocationChangedReceiver(); |
198 | 209 | ||
199 | if (wContext != null) { | 210 | if (wContext != null) { |
211 | + final PendingIntent locationListenerPendingIntent; | ||
212 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
213 | + locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0, | ||
214 | + new Intent(wContext, LocationChangedReceiver.class), | ||
215 | + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); | ||
216 | + } else { | ||
217 | + locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0, | ||
218 | + new Intent(wContext, LocationChangedReceiver.class), | ||
219 | + PendingIntent.FLAG_UPDATE_CURRENT); | ||
220 | + } | ||
200 | 221 | ||
201 | - final PendingIntent locationListenerPendingIntent = PendingIntent.getBroadcast(wContext, 0, | ||
202 | - new Intent(wContext, LocationChangedReceiver.class), | ||
203 | - PendingIntent.FLAG_UPDATE_CURRENT); | ||
204 | final LocationManager lm = (LocationManager) wContext.getSystemService(Context.LOCATION_SERVICE); | 222 | final LocationManager lm = (LocationManager) wContext.getSystemService(Context.LOCATION_SERVICE); |
205 | 223 | ||
206 | if (lm != null) { | 224 | if (lm != null) { |
... | @@ -212,11 +230,13 @@ public class WarplyLocationManager { | ... | @@ -212,11 +230,13 @@ public class WarplyLocationManager { |
212 | public void onError(DexterError error) { | 230 | public void onError(DexterError error) { |
213 | onPermissionDenied(null); | 231 | onPermissionDenied(null); |
214 | } | 232 | } |
233 | + | ||
215 | @Override | 234 | @Override |
216 | public void onPermissionDenied(List<PermissionDeniedResponse> denied) { | 235 | public void onPermissionDenied(List<PermissionDeniedResponse> denied) { |
217 | - if(denied != null && denied.size() < 2)//1 location permission accepted | 236 | + if (denied != null && denied.size() < 2)//1 location permission accepted |
218 | onPermissionsGranted(); | 237 | onPermissionsGranted(); |
219 | } | 238 | } |
239 | + | ||
220 | @Override | 240 | @Override |
221 | public void onPermissionsGranted() { | 241 | public void onPermissionsGranted() { |
222 | try { | 242 | try { |
... | @@ -323,6 +343,7 @@ public class WarplyLocationManager { | ... | @@ -323,6 +343,7 @@ public class WarplyLocationManager { |
323 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | 343 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
324 | PackageManager.DONT_KILL_APP); | 344 | PackageManager.DONT_KILL_APP); |
325 | new WarplyPreferences(wContext).saveLocationChangedReceiverStatus("off"); | 345 | new WarplyPreferences(wContext).saveLocationChangedReceiverStatus("off"); |
346 | + WorkManager.getInstance(Warply.getWarplyContext()).cancelAllWorkByTag(UpdateUserLocationService.TAG); | ||
326 | } | 347 | } |
327 | 348 | ||
328 | private static void enableConnectivityChangedReceiver() { | 349 | private static void enableConnectivityChangedReceiver() { | ... | ... |
... | @@ -54,7 +54,7 @@ public class WarplySessionManager { | ... | @@ -54,7 +54,7 @@ public class WarplySessionManager { |
54 | */ | 54 | */ |
55 | public static void onCreateActivity(Activity activity) { | 55 | public static void onCreateActivity(Activity activity) { |
56 | synchronized (_activities) { | 56 | synchronized (_activities) { |
57 | - Warply.getInitializer(activity).init(); | 57 | +// Warply.getInitializer(activity).init(); |
58 | _activities.add(activity); | 58 | _activities.add(activity); |
59 | if (_activities.size() == 1) | 59 | if (_activities.size() == 1) |
60 | onApplicationStart(); | 60 | onApplicationStart(); |
... | @@ -74,7 +74,7 @@ public class WarplySessionManager { | ... | @@ -74,7 +74,7 @@ public class WarplySessionManager { |
74 | */ | 74 | */ |
75 | public static void onStartActivity(Activity activity) { | 75 | public static void onStartActivity(Activity activity) { |
76 | synchronized (_activities) { | 76 | synchronized (_activities) { |
77 | - Warply.getInitializer(activity).init(); | 77 | +// Warply.getInitializer(activity).init(); |
78 | _activities.add(activity); | 78 | _activities.add(activity); |
79 | if (_activities.size() == 1) | 79 | if (_activities.size() == 1) |
80 | onApplicationEnterForeground(); | 80 | onApplicationEnterForeground(); |
... | @@ -106,14 +106,14 @@ public class WarplySessionManager { | ... | @@ -106,14 +106,14 @@ public class WarplySessionManager { |
106 | 106 | ||
107 | private static void onApplicationEnterForeground() { | 107 | private static void onApplicationEnterForeground() { |
108 | Warply.onApplicationEnterForeground(); | 108 | Warply.onApplicationEnterForeground(); |
109 | - _receiver = new ConnectivityReceiver(); | 109 | +// _receiver = new ConnectivityReceiver(); |
110 | - _receiver.startTracking(); | 110 | +// _receiver.startTracking(); |
111 | } | 111 | } |
112 | 112 | ||
113 | private static void onApplicationEnterBackground() { | 113 | private static void onApplicationEnterBackground() { |
114 | Warply.onApplicationEnterBackground(); | 114 | Warply.onApplicationEnterBackground(); |
115 | - if (_receiver != null) | 115 | +// if (_receiver != null) |
116 | - _receiver.stopTracking(); | 116 | +// _receiver.stopTracking(); |
117 | } | 117 | } |
118 | 118 | ||
119 | private static class ConnectivityReceiver extends BroadcastReceiver { | 119 | private static class ConnectivityReceiver extends BroadcastReceiver { | ... | ... |
-
Please register or login to post a comment