12
12
import android .content .pm .PackageManager ;
13
13
import android .content .pm .ResolveInfo ;
14
14
import android .util .Log ;
15
+
15
16
import androidx .annotation .NonNull ;
16
17
import androidx .annotation .Nullable ;
18
+
17
19
import com .parse .boltsinternal .Continuation ;
18
20
import com .parse .boltsinternal .Task ;
21
+
19
22
import java .io .File ;
20
23
import java .io .FileOutputStream ;
21
24
import java .io .IOException ;
26
29
import java .util .List ;
27
30
import java .util .Set ;
28
31
import java .util .concurrent .Callable ;
32
+
29
33
import okhttp3 .OkHttpClient ;
30
34
31
35
/**
@@ -75,7 +79,7 @@ private Parse() {
75
79
* }
76
80
* }
77
81
* </pre>
78
- *
82
+ * <p>
79
83
* See <a
80
84
* href="https://github.com/parse-community/Parse-SDK-Android/issues/279">https://github.com/parse-community/Parse-SDK-Android/issues/279</a>
81
85
* for a discussion on performance of local datastore, and if it is right for your project.
@@ -85,8 +89,8 @@ private Parse() {
85
89
public static void enableLocalDatastore (Context context ) {
86
90
if (isInitialized ()) {
87
91
throw new IllegalStateException (
88
- "`Parse#enableLocalDatastore(Context)` must be invoked "
89
- + "before `Parse#initialize(Context)`" );
92
+ "`Parse#enableLocalDatastore(Context)` must be invoked "
93
+ + "before `Parse#initialize(Context)`" );
90
94
}
91
95
isLocalDatastoreEnabled = true ;
92
96
}
@@ -113,7 +117,7 @@ public static boolean isLocalDatastoreEnabled() {
113
117
114
118
/**
115
119
* @return {@code True} if {@link Configuration.Builder#allowCustomObjectId()} has been called,
116
- * otherwise {@code false}.
120
+ * otherwise {@code false}.
117
121
*/
118
122
public static boolean isAllowCustomObjectId () {
119
123
return allowCustomObjectId ;
@@ -145,6 +149,9 @@ static void initialize(Configuration configuration, ParsePlugins parsePlugins) {
145
149
PLog .w (TAG , "Parse is already initialized" );
146
150
return ;
147
151
}
152
+ // Perform old dir migration on initialize.
153
+ new ParseCacheDirMigrationUtils (configuration .context ).runMigrations ();
154
+
148
155
// NOTE (richardross): We will need this here, as ParsePlugins uses the return value of
149
156
// isLocalDataStoreEnabled() to perform additional behavior.
150
157
isLocalDatastoreEnabled = configuration .localDataStoreEnabled ;
@@ -176,32 +183,32 @@ static void initialize(Configuration configuration, ParsePlugins parsePlugins) {
176
183
checkCacheApplicationId ();
177
184
final Context context = configuration .context ;
178
185
Task .callInBackground (
179
- (Callable <Void >)
180
- () -> {
181
- getEventuallyQueue (context );
182
- return null ;
183
- });
186
+ (Callable <Void >)
187
+ () -> {
188
+ getEventuallyQueue (context );
189
+ return null ;
190
+ });
184
191
185
192
ParseFieldOperations .registerDefaultDecoders ();
186
193
187
194
if (!allParsePushIntentReceiversInternal ()) {
188
195
throw new SecurityException (
189
- "To prevent external tampering to your app's notifications, "
190
- + "all receivers registered to handle the following actions must have "
191
- + "their exported attributes set to false: com.parse.push.intent.RECEIVE, "
192
- + "com.parse.push.intent.OPEN, com.parse.push.intent.DELETE" );
196
+ "To prevent external tampering to your app's notifications, "
197
+ + "all receivers registered to handle the following actions must have "
198
+ + "their exported attributes set to false: com.parse.push.intent.RECEIVE, "
199
+ + "com.parse.push.intent.OPEN, com.parse.push.intent.DELETE" );
193
200
}
194
201
195
202
ParseUser .getCurrentUserAsync ()
196
- .makeVoid ()
197
- .continueWith (
198
- (Continuation <Void , Void >)
199
- task -> {
200
- // Prime config in the background
201
- ParseConfig .getCurrentConfig ();
202
- return null ;
203
- },
204
- Task .BACKGROUND_EXECUTOR );
203
+ .makeVoid ()
204
+ .continueWith (
205
+ (Continuation <Void , Void >)
206
+ task -> {
207
+ // Prime config in the background
208
+ ParseConfig .getCurrentConfig ();
209
+ return null ;
210
+ },
211
+ Task .BACKGROUND_EXECUTOR );
205
212
206
213
dispatchOnParseInitialized ();
207
214
@@ -213,8 +220,11 @@ static void initialize(Configuration configuration, ParsePlugins parsePlugins) {
213
220
214
221
// region Server URL
215
222
216
- /** Returns the current server URL. */
217
- public static @ Nullable String getServer () {
223
+ /**
224
+ * Returns the current server URL.
225
+ */
226
+ public static @ Nullable
227
+ String getServer () {
218
228
URL server = ParseRESTCommand .server ;
219
229
return server == null ? null : server .toString ();
220
230
}
@@ -248,7 +258,8 @@ public static void setServer(@NonNull String server) {
248
258
* @param server The server URL to validate.
249
259
* @return The validated server URL.
250
260
*/
251
- private static @ Nullable String validateServerUrl (@ Nullable String server ) {
261
+ private static @ Nullable
262
+ String validateServerUrl (@ Nullable String server ) {
252
263
253
264
// Add an extra trailing slash so that Parse REST commands include
254
265
// the path as part of the server URL (i.e. http://api.myhost.com/parse)
@@ -285,7 +296,9 @@ public static void destroy() {
285
296
allowCustomObjectId = false ;
286
297
}
287
298
288
- /** @return {@code True} if {@link #initialize} has been called, otherwise {@code false}. */
299
+ /**
300
+ * @return {@code True} if {@link #initialize} has been called, otherwise {@code false}.
301
+ */
289
302
static boolean isInitialized () {
290
303
return ParsePlugins .get () != null ;
291
304
}
@@ -308,10 +321,10 @@ public static Context getApplicationContext() {
308
321
*/
309
322
private static boolean allParsePushIntentReceiversInternal () {
310
323
List <ResolveInfo > intentReceivers =
311
- ManifestInfo .getIntentReceivers (
312
- ParsePushBroadcastReceiver .ACTION_PUSH_RECEIVE ,
313
- ParsePushBroadcastReceiver .ACTION_PUSH_DELETE ,
314
- ParsePushBroadcastReceiver .ACTION_PUSH_OPEN );
324
+ ManifestInfo .getIntentReceivers (
325
+ ParsePushBroadcastReceiver .ACTION_PUSH_RECEIVE ,
326
+ ParsePushBroadcastReceiver .ACTION_PUSH_DELETE ,
327
+ ParsePushBroadcastReceiver .ACTION_PUSH_OPEN );
315
328
316
329
for (ResolveInfo resolveInfo : intentReceivers ) {
317
330
if (resolveInfo .activityInfo .exported ) {
@@ -414,15 +427,15 @@ private static ParseEventuallyQueue getEventuallyQueue(Context context) {
414
427
synchronized (MUTEX ) {
415
428
boolean isLocalDatastoreEnabled = Parse .isLocalDatastoreEnabled ();
416
429
if (eventuallyQueue == null
417
- || (isLocalDatastoreEnabled && eventuallyQueue instanceof ParseCommandCache )
418
- || (!isLocalDatastoreEnabled
419
- && eventuallyQueue instanceof ParsePinningEventuallyQueue )) {
430
+ || (isLocalDatastoreEnabled && eventuallyQueue instanceof ParseCommandCache )
431
+ || (!isLocalDatastoreEnabled
432
+ && eventuallyQueue instanceof ParsePinningEventuallyQueue )) {
420
433
checkContext ();
421
434
ParseHttpClient httpClient = ParsePlugins .get ().restClient ();
422
435
eventuallyQueue =
423
- isLocalDatastoreEnabled
424
- ? new ParsePinningEventuallyQueue (context , httpClient )
425
- : new ParseCommandCache (context , httpClient );
436
+ isLocalDatastoreEnabled
437
+ ? new ParsePinningEventuallyQueue (context , httpClient )
438
+ : new ParseCommandCache (context , httpClient );
426
439
427
440
// We still need to clear out the old command cache even if we're using Pinning in
428
441
// case
@@ -436,33 +449,35 @@ private static ParseEventuallyQueue getEventuallyQueue(Context context) {
436
449
}
437
450
}
438
451
439
- /** Used by Parse LiveQuery */
452
+ /**
453
+ * Used by Parse LiveQuery
454
+ */
440
455
public static void checkInit () {
441
456
if (ParsePlugins .get () == null ) {
442
457
throw new RuntimeException (
443
- "You must call Parse.initialize(Context)" + " before using the Parse library." );
458
+ "You must call Parse.initialize(Context)" + " before using the Parse library." );
444
459
}
445
460
446
461
if (ParsePlugins .get ().applicationId () == null ) {
447
462
throw new RuntimeException (
448
- "applicationId is null. "
449
- + "You must call Parse.initialize(Context)"
450
- + " before using the Parse library." );
463
+ "applicationId is null. "
464
+ + "You must call Parse.initialize(Context)"
465
+ + " before using the Parse library." );
451
466
}
452
467
}
453
468
454
469
static void checkContext () {
455
470
if (ParsePlugins .get ().applicationContext () == null ) {
456
471
throw new RuntimeException (
457
- "applicationContext is null. "
458
- + "You must call Parse.initialize(Context)"
459
- + " before using the Parse library." );
472
+ "applicationContext is null. "
473
+ + "You must call Parse.initialize(Context)"
474
+ + " before using the Parse library." );
460
475
}
461
476
}
462
477
463
478
static boolean hasPermission (String permission ) {
464
479
return (getApplicationContext ().checkCallingOrSelfPermission (permission )
465
- == PackageManager .PERMISSION_GRANTED );
480
+ == PackageManager .PERMISSION_GRANTED );
466
481
}
467
482
468
483
// endregion
@@ -472,10 +487,10 @@ static boolean hasPermission(String permission) {
472
487
static void requirePermission (String permission ) {
473
488
if (!hasPermission (permission )) {
474
489
throw new IllegalStateException (
475
- "To use this functionality, add this to your AndroidManifest.xml:\n "
476
- + "<uses-permission android:name=\" "
477
- + permission
478
- + "\" />" );
490
+ "To use this functionality, add this to your AndroidManifest.xml:\n "
491
+ + "<uses-permission android:name=\" "
492
+ + permission
493
+ + "\" />" );
479
494
}
480
495
}
481
496
@@ -489,7 +504,7 @@ static void requirePermission(String permission) {
489
504
static void registerParseCallbacks (ParseCallbacks listener ) {
490
505
if (isInitialized ()) {
491
506
throw new IllegalStateException (
492
- "You must register callbacks before Parse.initialize(Context)" );
507
+ "You must register callbacks before Parse.initialize(Context)" );
493
508
}
494
509
495
510
synchronized (MUTEX_CALLBACKS ) {
@@ -537,7 +552,9 @@ private static ParseCallbacks[] collectParseCallbacks() {
537
552
return callbacks ;
538
553
}
539
554
540
- /** Returns the level of logging that will be displayed. */
555
+ /**
556
+ * Returns the level of logging that will be displayed.
557
+ */
541
558
public static int getLogLevel () {
542
559
return PLog .getLogLevel ();
543
560
}
@@ -569,7 +586,9 @@ interface ParseCallbacks {
569
586
void onParseInitialized ();
570
587
}
571
588
572
- /** Represents an opaque configuration for the {@code Parse} SDK configuration. */
589
+ /**
590
+ * Represents an opaque configuration for the {@code Parse} SDK configuration.
591
+ */
573
592
public static final class Configuration {
574
593
final Context context ;
575
594
final String applicationId ;
@@ -591,7 +610,9 @@ private Configuration(Builder builder) {
591
610
this .maxRetries = builder .maxRetries ;
592
611
}
593
612
594
- /** Allows for simple constructing of a {@code Configuration} object. */
613
+ /**
614
+ * Allows for simple constructing of a {@code Configuration} object.
615
+ */
595
616
public static final class Builder {
596
617
private final Context context ;
597
618
private String applicationId ;
0 commit comments