@glympse-inc/com.glympse.enroute 2.105.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +34 -0
- package/plugin.xml +262 -0
- package/scripts/iosFixPCH.js +38 -0
- package/src/android/BootReceiver.java +13 -0
- package/src/android/EnRoutePlugin.java +1867 -0
- package/src/android/HealthCheckJobService.java +225 -0
- package/src/android/LocationAccuracyChecker.java +49 -0
- package/src/android/ManagerWrapper.java +205 -0
- package/src/android/NotificationService.java +81 -0
- package/src/android/PushReceiver.java +90 -0
- package/src/android/enroute/aars/enrouteapi-aar.gradle +17 -0
- package/src/android/enroute/aars/glympseapi-aar.gradle +17 -0
- package/src/android/enroute/aars/glympseapipush-aar.gradle +17 -0
- package/src/android/enroute/aars/glympseapitoolbox-aar.gradle +17 -0
- package/src/android/gradle/build.gradle +25 -0
- package/src/ios/EnRoutePlugin.h +128 -0
- package/src/ios/EnRoutePlugin.mm +1258 -0
- package/src/ios/EnRouteWrapper.h +30 -0
- package/src/ios/EnRouteWrapper.mm +176 -0
- package/www/Agent.js +48 -0
- package/www/AgentManager.js +422 -0
- package/www/CardMessage.js +49 -0
- package/www/ChatMessage.js +29 -0
- package/www/CustomerMessage.js +18 -0
- package/www/EnRouteManager.js +613 -0
- package/www/EtaPlanner.js +129 -0
- package/www/GlobalConfig.js +13 -0
- package/www/Invite.js +93 -0
- package/www/LatLng.js +28 -0
- package/www/Location.js +63 -0
- package/www/Native.js +215 -0
- package/www/Operation.js +67 -0
- package/www/OrderItem.js +43 -0
- package/www/OrgConfig.js +184 -0
- package/www/Organization.js +88 -0
- package/www/Pickup.js +119 -0
- package/www/PickupArrivalData.js +38 -0
- package/www/PickupManager.js +512 -0
- package/www/Place.js +33 -0
- package/www/Session.js +87 -0
- package/www/SessionManager.js +431 -0
- package/www/Task.js +106 -0
- package/www/TaskManager.js +443 -0
- package/www/Ticket.js +205 -0
- package/www/Track.js +75 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
package com.glympse.enroute.hybrid.android;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.app.PendingIntent;
|
|
5
|
+
import android.app.job.JobParameters;
|
|
6
|
+
import android.app.job.JobService;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.SharedPreferences;
|
|
9
|
+
import android.net.Uri;
|
|
10
|
+
import android.os.Build;
|
|
11
|
+
import android.preference.PreferenceManager;
|
|
12
|
+
import android.provider.Settings;
|
|
13
|
+
|
|
14
|
+
import com.glympse.android.api.GCoreHealthCheck;
|
|
15
|
+
import com.glympse.android.api.GGlympse;
|
|
16
|
+
import com.glympse.android.api.GHealthReport;
|
|
17
|
+
import com.glympse.android.core.GPrimitive;
|
|
18
|
+
import com.glympse.android.api.R;
|
|
19
|
+
import com.glympse.enroute.android.api.GEnRouteHealthCheck;
|
|
20
|
+
import com.glympse.enroute.android.api.GEnRouteManager;
|
|
21
|
+
import com.glympse.enroute.android.api.GOrgConfig;
|
|
22
|
+
import com.glympse.enroute.android.api.GOrganization;
|
|
23
|
+
|
|
24
|
+
import java.util.concurrent.TimeUnit;
|
|
25
|
+
|
|
26
|
+
import androidx.core.app.NotificationChannelCompat;
|
|
27
|
+
import androidx.core.app.NotificationCompat;
|
|
28
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
29
|
+
|
|
30
|
+
@SuppressLint("NewApi")
|
|
31
|
+
public class HealthCheckJobService extends JobService
|
|
32
|
+
{
|
|
33
|
+
private static final int NOTIFICATION_ID = 2105;
|
|
34
|
+
private static final String CHANNEL_ID = "platform_health_channel";
|
|
35
|
+
private static final String FIRST_RUN_TIME = "HealthCheck.firstRunTime";
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public boolean onStartJob(JobParameters params) {
|
|
39
|
+
if ( isFirstDay() )
|
|
40
|
+
{
|
|
41
|
+
markFirstRunTime();
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
GEnRouteManager manager = ManagerWrapper.instance().manager();
|
|
46
|
+
if ( null == manager )
|
|
47
|
+
{
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
GEnRouteHealthCheck enRouteHealthCheck = manager.getEnRouteHealthCheck();
|
|
51
|
+
|
|
52
|
+
GHealthReport healthReport = enRouteHealthCheck.checkLoggedInState();
|
|
53
|
+
GPrimitive value = healthReport.getValue();
|
|
54
|
+
if ( value.getBool() )
|
|
55
|
+
{
|
|
56
|
+
createNotification("User is not logged in", openAppIntent());
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
GGlympse glympse = manager.getGlympse();
|
|
61
|
+
if ( null == glympse )
|
|
62
|
+
{
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
GCoreHealthCheck coreHealthCheck = glympse.getCoreHealthCheck();
|
|
67
|
+
|
|
68
|
+
healthReport = coreHealthCheck.checkNotificationAuth();
|
|
69
|
+
value = healthReport.getValue();
|
|
70
|
+
if ( value.getLong() == 2 || value.getLong() == 4 )
|
|
71
|
+
{
|
|
72
|
+
createNotification("Notifications are turned off", notificationSettingsIntent());
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
healthReport = coreHealthCheck.checkBatteryOptimization();
|
|
77
|
+
value = healthReport.getValue();
|
|
78
|
+
if ( !value.getBool() )
|
|
79
|
+
{
|
|
80
|
+
createNotification("Battery optimization has not been turned off", batteryIntent());
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
GOrganization organization = manager.getOrganization();
|
|
85
|
+
if ( null == organization )
|
|
86
|
+
{
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
GOrgConfig config = organization.getConfig();
|
|
90
|
+
if ( null == config )
|
|
91
|
+
{
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if ( !config.isPickupEnabled() )
|
|
96
|
+
{
|
|
97
|
+
healthReport = coreHealthCheck.checkLocationAuth();
|
|
98
|
+
value = healthReport.getValue();
|
|
99
|
+
if ( value.getLong() == 1 )
|
|
100
|
+
{
|
|
101
|
+
createNotification("Location permission is turned off", locationAuthIntent());
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
ManagerWrapper.instance().scheduleHealthCheck(getApplicationContext()); // reschedule the job
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Override
|
|
111
|
+
public boolean onStopJob(JobParameters params) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private void createNotification(String reason, PendingIntent intent)
|
|
116
|
+
{
|
|
117
|
+
createNotificationChannel();
|
|
118
|
+
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
|
|
119
|
+
.setSmallIcon(R.drawable.notification_00)
|
|
120
|
+
.setContentTitle("We noticed an issue with your app settings")
|
|
121
|
+
.setContentText(reason)
|
|
122
|
+
.setAutoCancel(true)
|
|
123
|
+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
|
124
|
+
|
|
125
|
+
builder.setContentIntent(intent);
|
|
126
|
+
|
|
127
|
+
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
|
128
|
+
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private void createNotificationChannel()
|
|
132
|
+
{
|
|
133
|
+
// Create the NotificationChannel, but only on API 26+ because
|
|
134
|
+
// the NotificationChannel class is new and not in the support library
|
|
135
|
+
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
136
|
+
String description = "Notifies about issues with app settings";
|
|
137
|
+
NotificationChannelCompat.Builder builder = new NotificationChannelCompat.Builder(CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW);
|
|
138
|
+
builder.setName("Glympse Settings");
|
|
139
|
+
builder.setDescription(description);
|
|
140
|
+
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
|
141
|
+
notificationManager.createNotificationChannel(builder.build());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private PendingIntent openAppIntent()
|
|
146
|
+
{
|
|
147
|
+
Intent notificationIntent = getPackageManager().getLaunchIntentForPackage(getApplicationContext().getPackageName());
|
|
148
|
+
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
149
|
+
return PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private PendingIntent notificationSettingsIntent()
|
|
153
|
+
{
|
|
154
|
+
int sdkInt = Build.VERSION.SDK_INT;
|
|
155
|
+
if ( sdkInt < Build.VERSION_CODES.LOLLIPOP )
|
|
156
|
+
{
|
|
157
|
+
return openAppIntent();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Intent intent = new Intent();
|
|
161
|
+
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
|
162
|
+
|
|
163
|
+
//for Android 5-7
|
|
164
|
+
if ( sdkInt < Build.VERSION_CODES.O)
|
|
165
|
+
{
|
|
166
|
+
intent.putExtra("app_package", getPackageName());
|
|
167
|
+
intent.putExtra("app_uid", getApplicationInfo().uid);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// for Android 8 and above
|
|
171
|
+
if ( sdkInt >= Build.VERSION_CODES.O)
|
|
172
|
+
{
|
|
173
|
+
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private PendingIntent batteryIntent()
|
|
180
|
+
{
|
|
181
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
|
182
|
+
{
|
|
183
|
+
return openAppIntent();
|
|
184
|
+
}
|
|
185
|
+
Intent intent = new Intent();
|
|
186
|
+
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
|
187
|
+
return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private PendingIntent locationAuthIntent()
|
|
191
|
+
{
|
|
192
|
+
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
193
|
+
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
|
194
|
+
intent.setData(uri);
|
|
195
|
+
return PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private boolean isFirstDay()
|
|
199
|
+
{
|
|
200
|
+
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
201
|
+
long firstRunTime = sharedPreferences.getLong(FIRST_RUN_TIME, 0);
|
|
202
|
+
if ( firstRunTime == 0 )
|
|
203
|
+
{
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
long currentTime = System.currentTimeMillis();
|
|
207
|
+
long oneDayMs = TimeUnit.DAYS.toMillis(1);
|
|
208
|
+
return firstRunTime + oneDayMs > currentTime;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private void markFirstRunTime()
|
|
212
|
+
{
|
|
213
|
+
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
214
|
+
long firstRunTime = sharedPreferences.getLong(FIRST_RUN_TIME, 0);
|
|
215
|
+
if ( 0 != firstRunTime )
|
|
216
|
+
{
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
221
|
+
long currentTime = System.currentTimeMillis();
|
|
222
|
+
editor.putLong(FIRST_RUN_TIME, currentTime);
|
|
223
|
+
editor.apply();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package com.glympse.enroute.hybrid.android;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
|
|
5
|
+
import com.google.android.gms.common.api.ApiException;
|
|
6
|
+
import com.google.android.gms.location.LocationRequest;
|
|
7
|
+
import com.google.android.gms.location.LocationServices;
|
|
8
|
+
import com.google.android.gms.location.LocationSettingsRequest;
|
|
9
|
+
import com.google.android.gms.location.LocationSettingsResponse;
|
|
10
|
+
import com.google.android.gms.location.LocationSettingsStates;
|
|
11
|
+
import com.google.android.gms.tasks.OnCompleteListener;
|
|
12
|
+
import com.google.android.gms.tasks.Task;
|
|
13
|
+
|
|
14
|
+
import org.apache.cordova.CallbackContext;
|
|
15
|
+
import org.apache.cordova.PluginResult;
|
|
16
|
+
import org.apache.cordova.PluginResult.Status;
|
|
17
|
+
|
|
18
|
+
public class LocationAccuracyChecker{
|
|
19
|
+
|
|
20
|
+
public static void requestLocationAccuracy(final Context context, final CallbackContext callbackContext) {
|
|
21
|
+
LocationRequest locationRequest = new LocationRequest();
|
|
22
|
+
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
|
23
|
+
|
|
24
|
+
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
|
|
25
|
+
.addLocationRequest(locationRequest);
|
|
26
|
+
Task<LocationSettingsResponse> result =
|
|
27
|
+
LocationServices.getSettingsClient(context).checkLocationSettings(builder.build());
|
|
28
|
+
|
|
29
|
+
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
|
|
30
|
+
@Override
|
|
31
|
+
public void onComplete(Task<LocationSettingsResponse> task) {
|
|
32
|
+
try {
|
|
33
|
+
LocationSettingsResponse response = task.getResult(ApiException.class);
|
|
34
|
+
LocationSettingsStates states = response.getLocationSettingsStates();
|
|
35
|
+
if ( states.isNetworkLocationUsable() && states.isGpsUsable() && states.isBleUsable() ) {
|
|
36
|
+
PluginResult pluginResult = new PluginResult(Status.OK, "High accuracy available");
|
|
37
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
38
|
+
} else {
|
|
39
|
+
PluginResult pluginResult = new PluginResult(Status.ERROR, "High accuracy not available");
|
|
40
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
41
|
+
}
|
|
42
|
+
} catch (ApiException exception) {
|
|
43
|
+
PluginResult pluginResult = new PluginResult(Status.ERROR, "Status code: " + exception.getStatusCode());
|
|
44
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
package com.glympse.enroute.hybrid.android;
|
|
2
|
+
|
|
3
|
+
import android.app.job.JobInfo;
|
|
4
|
+
import android.app.job.JobScheduler;
|
|
5
|
+
import android.app.Notification;
|
|
6
|
+
import android.app.NotificationChannel;
|
|
7
|
+
import android.app.NotificationManager;
|
|
8
|
+
import android.app.PendingIntent;
|
|
9
|
+
import android.content.ComponentName;
|
|
10
|
+
import android.content.Context;
|
|
11
|
+
import android.content.Intent;
|
|
12
|
+
import android.os.Build;
|
|
13
|
+
import android.support.v4.app.NotificationCompat;
|
|
14
|
+
import android.support.v4.app.NotificationManagerCompat;
|
|
15
|
+
|
|
16
|
+
import com.glympse.android.core.GPrimitive;
|
|
17
|
+
import com.glympse.android.api.R;
|
|
18
|
+
import com.glympse.android.hal.GlympseService;
|
|
19
|
+
import com.glympse.android.toolbox.listener.GListener;
|
|
20
|
+
import com.glympse.android.toolbox.listener.GSource;
|
|
21
|
+
import com.glympse.enroute.android.api.*;
|
|
22
|
+
|
|
23
|
+
import com.glympse.enroute.hybrid.android.HealthCheckJobService;
|
|
24
|
+
|
|
25
|
+
public class ManagerWrapper implements GListener
|
|
26
|
+
{
|
|
27
|
+
private static String CHANNEL_ID = "glympse_enroute_channel";
|
|
28
|
+
private static int REQUEST_CODE_PICKUP_NOTIFICATION = 0;
|
|
29
|
+
private int _nextNotificationId = (int)(System.currentTimeMillis() / 1000L) & 0x3FFFFFFF;
|
|
30
|
+
|
|
31
|
+
private GEnRouteManager _manager;
|
|
32
|
+
private static ManagerWrapper _instance;
|
|
33
|
+
private Context _context;
|
|
34
|
+
private boolean _stopped = false;
|
|
35
|
+
|
|
36
|
+
// Turning this off for now since I think we want to make this configurable
|
|
37
|
+
private boolean _healthCheckNotifEnabled = false;
|
|
38
|
+
|
|
39
|
+
public static ManagerWrapper instance()
|
|
40
|
+
{
|
|
41
|
+
if ( null == _instance )
|
|
42
|
+
{
|
|
43
|
+
_instance = new ManagerWrapper();
|
|
44
|
+
}
|
|
45
|
+
return _instance;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public void create(Context context)
|
|
49
|
+
{
|
|
50
|
+
_context = context;
|
|
51
|
+
_manager = EnRouteFactory.createEnRouteManager(_context);
|
|
52
|
+
_manager.addListener(this);
|
|
53
|
+
|
|
54
|
+
// We will provide our own arrival notifications
|
|
55
|
+
GlympseService.enableXoaNotifications(false);
|
|
56
|
+
createNotificationChannel();
|
|
57
|
+
scheduleHealthCheck(_context);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public GEnRouteManager manager()
|
|
61
|
+
{
|
|
62
|
+
if ( _stopped )
|
|
63
|
+
{
|
|
64
|
+
create(_context);
|
|
65
|
+
_stopped = false;
|
|
66
|
+
}
|
|
67
|
+
return _manager;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public boolean isInitialized()
|
|
71
|
+
{
|
|
72
|
+
return !(_context == null);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public void loginWithCredentials(String username, String password)
|
|
76
|
+
{
|
|
77
|
+
_manager.loginWithCredentials(username, password);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public void logout()
|
|
81
|
+
{
|
|
82
|
+
logout(EnRouteConstants.LOGOUT_REASON_USER_ACTION);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public void logout(int reason)
|
|
86
|
+
{
|
|
87
|
+
_manager.logout(reason);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* GListener section
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
public void eventsOccurred(GSource source, int listener, int events, Object param1, Object param2)
|
|
95
|
+
{
|
|
96
|
+
if ( EE.LISTENER_ENROUTE_MANAGER == listener )
|
|
97
|
+
{
|
|
98
|
+
if ( 0 != ( EE.ENROUTE_MANAGER_STARTED & events ) )
|
|
99
|
+
{
|
|
100
|
+
started();
|
|
101
|
+
}
|
|
102
|
+
if ( 0 != ( EE.ENROUTE_MANAGER_STOPPED & events ) )
|
|
103
|
+
{
|
|
104
|
+
stopped();
|
|
105
|
+
}
|
|
106
|
+
if ( 0 != ( EE.ENROUTE_MANAGER_SHOW_NOTIFICATION & events ) )
|
|
107
|
+
{
|
|
108
|
+
showNotification((GPrimitive)param1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public void showNotification(GPrimitive config)
|
|
114
|
+
{
|
|
115
|
+
String message = config.getString("message");
|
|
116
|
+
if ( null == message )
|
|
117
|
+
{
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
int notificationId = _nextNotificationId++;
|
|
122
|
+
|
|
123
|
+
NotificationCompat.Builder builder = new NotificationCompat.Builder(_context, CHANNEL_ID)
|
|
124
|
+
.setSmallIcon(R.drawable.notification_00)
|
|
125
|
+
.setContentTitle("Glympse EnRoute")
|
|
126
|
+
.setContentText(message)
|
|
127
|
+
.setAutoCancel(true)
|
|
128
|
+
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
|
|
129
|
+
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
|
130
|
+
|
|
131
|
+
// Create a useful intent based on the id received
|
|
132
|
+
String pickupId = config.getString("pickup_id");
|
|
133
|
+
if ( null != pickupId )
|
|
134
|
+
{
|
|
135
|
+
Intent intent = new Intent(_context, NotificationService.class);
|
|
136
|
+
intent.setPackage(_context.getPackageName());
|
|
137
|
+
intent.setAction("{\"GLYMPSE_ACTION\":\"pickup_notification\",\"nid\":" + notificationId + "}");
|
|
138
|
+
intent.putExtra("PICKUP_ID", pickupId);
|
|
139
|
+
|
|
140
|
+
PendingIntent pendingIntent = createPendingServiceIntent(_context, intent, REQUEST_CODE_PICKUP_NOTIFICATION);
|
|
141
|
+
builder.setContentIntent(pendingIntent);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
NotificationManagerCompat.from(_context).notify(notificationId, builder.build());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public void started()
|
|
148
|
+
{
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public void stopped()
|
|
153
|
+
{
|
|
154
|
+
_stopped = true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public void loggedOut(int reason)
|
|
158
|
+
{
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
protected void scheduleHealthCheck(Context context)
|
|
163
|
+
{
|
|
164
|
+
if ( !_healthCheckNotifEnabled )
|
|
165
|
+
{
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if ( Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP )
|
|
170
|
+
{
|
|
171
|
+
ComponentName serviceComponent = new ComponentName(context, HealthCheckJobService.class);
|
|
172
|
+
JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
|
|
173
|
+
builder.setMinimumLatency(1 * 1000); // wait at least
|
|
174
|
+
builder.setOverrideDeadline(3 * 1000); // maximum delay
|
|
175
|
+
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
|
176
|
+
jobScheduler.schedule(builder.build());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private void createNotificationChannel()
|
|
181
|
+
{
|
|
182
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
183
|
+
{
|
|
184
|
+
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Glympse EnRoute", NotificationManager.IMPORTANCE_DEFAULT);
|
|
185
|
+
channel.setDescription("Glympse EnRoute status notifications");
|
|
186
|
+
NotificationManager notificationManager = _context.getSystemService(NotificationManager.class);
|
|
187
|
+
notificationManager.createNotificationChannel(channel);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private static PendingIntent createPendingServiceIntent(Context context, Intent intent, final int requestCode)
|
|
192
|
+
{
|
|
193
|
+
final int flags = PendingIntent.FLAG_CANCEL_CURRENT;
|
|
194
|
+
final PendingIntent pendingIntent = PendingIntent.getService(context, requestCode, intent, flags);
|
|
195
|
+
if ( Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2 )
|
|
196
|
+
{
|
|
197
|
+
// Cancel the pending intent and return an identical one to work around a bug in Kitkat.
|
|
198
|
+
// See https://code.google.com/p/android/issues/detail?id=61850
|
|
199
|
+
pendingIntent.cancel();
|
|
200
|
+
return PendingIntent.getService(context, requestCode, intent, flags);
|
|
201
|
+
}
|
|
202
|
+
return pendingIntent;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
package com.glympse.enroute.hybrid.android;
|
|
2
|
+
|
|
3
|
+
import android.app.Service;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.os.Bundle;
|
|
6
|
+
import android.os.IBinder;
|
|
7
|
+
import android.support.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
import com.glympse.android.core.GPrimitive;
|
|
10
|
+
import com.glympse.android.lib.json.JsonSerializer;
|
|
11
|
+
|
|
12
|
+
public class NotificationService extends Service
|
|
13
|
+
{
|
|
14
|
+
public static final String PICKUP_NOTIFICATION_ACTION = "com.glympse.android.PICKUP_NOTIFICATION";
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
@Override
|
|
18
|
+
public IBinder onBind(Intent intent)
|
|
19
|
+
{
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@SuppressWarnings("deprecation")
|
|
24
|
+
@Override public void onStart(Intent intent, int nStartId)
|
|
25
|
+
{
|
|
26
|
+
try
|
|
27
|
+
{
|
|
28
|
+
super.onStart(intent, nStartId);
|
|
29
|
+
|
|
30
|
+
// If we have an intent, then go process it.
|
|
31
|
+
if (null != intent)
|
|
32
|
+
{
|
|
33
|
+
processIntent(intent);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (Throwable e)
|
|
37
|
+
{
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private void processIntent(Intent intent) {
|
|
42
|
+
// Get the action and see if it is something we recognize.
|
|
43
|
+
String strAction = intent.getAction();
|
|
44
|
+
if (null == strAction || !strAction.startsWith("{\"GLYMPSE_ACTION"))
|
|
45
|
+
{
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Parse action string.
|
|
50
|
+
GPrimitive action = JsonSerializer.toPrimitive(strAction);
|
|
51
|
+
if (null == action)
|
|
52
|
+
{
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
String type = action.getString("GLYMPSE_ACTION");
|
|
57
|
+
int notificationId = (int)action.getLong("nid");
|
|
58
|
+
|
|
59
|
+
// Bail if we don't have a type.
|
|
60
|
+
if (null == type)
|
|
61
|
+
{
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (type.equalsIgnoreCase("pickup_notification"))
|
|
66
|
+
{
|
|
67
|
+
Bundle bundle = intent.getExtras();
|
|
68
|
+
if ( bundle == null )
|
|
69
|
+
{
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Notify host app if it is listening
|
|
74
|
+
String pickupId = bundle.getString("PICKUP_ID");
|
|
75
|
+
Intent pickupIntent = new Intent(PICKUP_NOTIFICATION_ACTION);
|
|
76
|
+
pickupIntent.setPackage(this.getPackageName());
|
|
77
|
+
pickupIntent.putExtra("PICKUP_ID", pickupId);
|
|
78
|
+
sendBroadcast(pickupIntent);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
package com.glympse.enroute.hybrid.android;
|
|
2
|
+
|
|
3
|
+
import com.glympse.android.api.GDataRow;
|
|
4
|
+
import com.glympse.android.api.GUser;
|
|
5
|
+
import com.glympse.android.core.GList;
|
|
6
|
+
import com.glympse.android.core.GPrimitive;
|
|
7
|
+
import com.glympse.android.hal.GlympseService;
|
|
8
|
+
import com.glympse.android.hal.NotificationListener;
|
|
9
|
+
import com.glympse.android.lib.GCP;
|
|
10
|
+
import com.glympse.android.lib.GUserMessage;
|
|
11
|
+
import com.glympse.android.lib.LibFactory;
|
|
12
|
+
import com.glympse.android.lib.json.JsonSerializer;
|
|
13
|
+
import com.glympse.android.toolbox.listener.GListener;
|
|
14
|
+
import com.glympse.android.toolbox.listener.GSource;
|
|
15
|
+
import com.glympse.enroute.android.api.EE;
|
|
16
|
+
import com.glympse.enroute.android.api.EnRouteConstants;
|
|
17
|
+
import com.glympse.enroute.android.api.GEnRouteManager;
|
|
18
|
+
import com.glympse.enroute.android.lib.GEnRouteManagerPrivate;
|
|
19
|
+
|
|
20
|
+
import android.content.BroadcastReceiver;
|
|
21
|
+
import android.content.Context;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
import android.util.Log;
|
|
24
|
+
|
|
25
|
+
public class PushReceiver extends BroadcastReceiver implements GListener
|
|
26
|
+
{
|
|
27
|
+
private String _stashedPayload;
|
|
28
|
+
@Override public void onReceive(Context context, Intent intent)
|
|
29
|
+
{
|
|
30
|
+
Log.d("AndroidPushDebug", "PushReceiver onReceive");
|
|
31
|
+
String action = intent.getAction();
|
|
32
|
+
if ( GlympseService.INTENT_STARTED.equals(action) )
|
|
33
|
+
{
|
|
34
|
+
Log.d("AndroidPushDebug", "PushReceiver action == STARTED");
|
|
35
|
+
startManager(context);
|
|
36
|
+
}
|
|
37
|
+
else if ( NotificationListener.INTENT_REFRESH.equals(action) )
|
|
38
|
+
{
|
|
39
|
+
Log.d("AndroidPushDebug", "PushReceiver action == REFRESH");
|
|
40
|
+
long flags = intent.getLongExtra(NotificationListener.INTENT_EXTRA_FLAGS, 0);
|
|
41
|
+
if ( 0 != ( GCP.ACCOUNT_HISTORY & flags ) )
|
|
42
|
+
{
|
|
43
|
+
Log.d("AndroidPushDebug", "PushReceiver AccountHistory flags");
|
|
44
|
+
startManager(context);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if ( NotificationListener.INTENT_DATA.equals(action) )
|
|
48
|
+
{
|
|
49
|
+
Log.d("AndroidPushDebug", "PushReceiver action == DATA");
|
|
50
|
+
_stashedPayload = intent.getStringExtra(NotificationListener.INTENT_EXTRA_PAYLOAD);
|
|
51
|
+
Log.d("AndroidPushDebug", "Stashed payload: " + _stashedPayload);
|
|
52
|
+
|
|
53
|
+
startManager(context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private void startManager(Context context)
|
|
58
|
+
{
|
|
59
|
+
Log.d("AndroidPushDebug", "PushReceiver startManager");
|
|
60
|
+
|
|
61
|
+
if ( !ManagerWrapper.instance().isInitialized() )
|
|
62
|
+
{
|
|
63
|
+
Log.d("AndroidPushDebug", "PushReceiver doesn't have context, must recreate");
|
|
64
|
+
ManagerWrapper.instance().create(context);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if ( !ManagerWrapper.instance().manager().isStarted() && !ManagerWrapper.instance().manager().isLoginNeeded() )
|
|
68
|
+
{
|
|
69
|
+
Log.d("AndroidPushDebug", "PushReceiver manager NOT started");
|
|
70
|
+
ManagerWrapper.instance().manager().addListener(this);
|
|
71
|
+
Log.d("AndroidPushDebug", "PushReceiver starting Manager");
|
|
72
|
+
ManagerWrapper.instance().manager().setAuthenticationMode(EnRouteConstants.AUTH_MODE_CREDENTIALS);
|
|
73
|
+
ManagerWrapper.instance().manager().start();
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override public void eventsOccurred(GSource source, int listener, int events, Object param1, Object param2)
|
|
79
|
+
{
|
|
80
|
+
if ( 0 != ( EE.ENROUTE_MANAGER_SYNCED & events ) )
|
|
81
|
+
{
|
|
82
|
+
if ( null != _stashedPayload )
|
|
83
|
+
{
|
|
84
|
+
GEnRouteManagerPrivate privateManager = (GEnRouteManagerPrivate)ManagerWrapper.instance().manager();
|
|
85
|
+
privateManager.handleRemoteNotification(_stashedPayload);
|
|
86
|
+
_stashedPayload = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|