forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOCFile.java
More file actions
1178 lines (1002 loc) · 34.1 KB
/
OCFile.java
File metadata and controls
1178 lines (1002 loc) · 34.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2023 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2022 Álvaro Brey Vilas <alvaro@alvarobrey.com>
* SPDX-FileCopyrightText: 2020 Tobias Kaminsky <tobias@kaminsky.me>
* SPDX-FileCopyrightText: 2018 Andy Scherzinger <info@andy-scherzinger.de>
* SPDX-FileCopyrightText: 2018 Mario Danic <mario@lovelyhq.com>
* SPDX-FileCopyrightText: 2016 ownCloud Inc.
* SPDX-FileCopyrightText: 2012-2016 David A. Velasco <dvelasco@solidgear.es>
* SPDX-FileCopyrightText: 2012 Bartosz Przybylski <bart.p.pl@gmail.com>
* SPDX-License-Identifier: GPL-2.0-only AND (AGPL-3.0-or-later OR GPL-2.0-only)
*/
package com.owncloud.android.datamodel;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.nextcloud.utils.BuildHelper;
import com.nextcloud.utils.extensions.StringExtensionsKt;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.model.FileLockType;
import com.owncloud.android.lib.resources.files.model.GeoLocation;
import com.owncloud.android.lib.resources.files.model.ImageDimension;
import com.owncloud.android.lib.resources.files.model.ServerFileInterface;
import com.owncloud.android.lib.resources.shares.ShareeUser;
import com.owncloud.android.lib.resources.tags.Tag;
import com.owncloud.android.utils.MimeType;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.daveKoeller.AlphanumComparator;
public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
public final static String PERMISSION_CAN_RESHARE = "R";
public final static String PERMISSION_SHARED = "S";
public final static String PERMISSION_MOUNTED = "M";
public final static String PERMISSION_CAN_CREATE_FILE_INSIDE_FOLDER = "C";
public final static String PERMISSION_CAN_CREATE_FOLDER_INSIDE_FOLDER = "K";
public final static String PERMISSION_CAN_READ = "G";
public final static String PERMISSION_CAN_WRITE = "W";
public final static String PERMISSION_CAN_DELETE_OR_LEAVE_SHARE = "D";
public final static String PERMISSION_CAN_RENAME = "N";
public final static String PERMISSION_CAN_MOVE = "V";
public final static String PERMISSION_CAN_CREATE_FILE_AND_FOLDER = PERMISSION_CAN_CREATE_FILE_INSIDE_FOLDER + PERMISSION_CAN_CREATE_FOLDER_INSIDE_FOLDER;
private final static int MAX_FILE_SIZE_FOR_IMMEDIATE_PREVIEW_BYTES = 1024000;
public static final String PATH_SEPARATOR = "/";
public static final String ROOT_PATH = PATH_SEPARATOR;
private static final String TAG = OCFile.class.getSimpleName();
private long fileId; // android internal ID of the file
private long parentId;
private long fileLength;
private long creationTimestamp; // UNIX timestamp of the time the file was created
private long modificationTimestamp; // UNIX timestamp of the file modification time
private long uploadTimestamp;
/**
* UNIX timestamp of the modification time, corresponding to the value returned by the server in the last
* synchronization of THE CONTENTS of this file.
*/
private long modificationTimestampAtLastSyncForData;
private long firstShareTimestamp; // UNIX timestamp of the first share time
private String remotePath;
private String decryptedRemotePath;
private String localPath;
private String mimeType;
private boolean needsUpdatingWhileSaving;
private long lastSyncDateForProperties;
private long lastSyncDateForData;
private boolean previewAvailable;
private String livePhoto;
public OCFile livePhotoVideo;
private String etag;
private String etagOnServer;
private boolean sharedViaLink;
private String permissions;
private long localId; // unique fileId for the file within the instance
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
private boolean updateThumbnailNeeded;
private boolean downloading;
private String etagInConflict; // Only saves file etag in the server, when there is a conflict
private boolean sharedWithSharee;
private boolean favorite;
private boolean hidden;
private boolean encrypted;
private WebdavEntry.MountType mountType;
private int unreadCommentsCount;
private String ownerId;
private String ownerDisplayName;
String note;
private List<ShareeUser> sharees;
private String richWorkspace;
private boolean locked;
@Nullable
private FileLockType lockType;
@Nullable
private String lockOwnerId;
@Nullable
private String lockOwnerDisplayName;
@Nullable
private String lockOwnerEditor;
private long lockTimestamp;
private long lockTimeout;
@Nullable
private String lockToken;
@Nullable
private ImageDimension imageDimension;
private long e2eCounter = -1;
@Nullable
private GeoLocation geolocation;
private List<Tag> tags = new ArrayList<>();
private Long internalFolderSyncTimestamp = -1L;
private String internalFolderSyncResult = "";
// region Recommend files variables
private boolean recommendedFile = false;
private String reason = "";
// endregion
/**
* URI to the local path of the file contents, if stored in the device; cached after first call to
* {@link #getStorageUri()}
*/
private Uri localUri;
/**
* Exportable URI to the local path of the file contents, if stored in the device.
* <p>
* Cached after first call, until changed.
*/
private Uri exposedFileUri;
/**
* Create new {@link OCFile} with given path.
* <p>
* The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
*
* @param path The remote path of the file.
*/
public OCFile(String path) {
resetData();
needsUpdatingWhileSaving = false;
if (TextUtils.isEmpty(path) || !path.startsWith(PATH_SEPARATOR)) {
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
}
remotePath = path;
}
/**
* Reconstruct from parcel
*
* @param source The source parcel
*/
private OCFile(Parcel source) {
fileId = source.readLong();
parentId = source.readLong();
fileLength = source.readLong();
uploadTimestamp = source.readLong();
creationTimestamp = source.readLong();
modificationTimestamp = source.readLong();
modificationTimestampAtLastSyncForData = source.readLong();
remotePath = source.readString();
decryptedRemotePath = source.readString();
localPath = source.readString();
mimeType = source.readString();
needsUpdatingWhileSaving = source.readInt() == 0;
lastSyncDateForProperties = source.readLong();
lastSyncDateForData = source.readLong();
etag = source.readString();
etagOnServer = source.readString();
sharedViaLink = source.readInt() == 1;
permissions = source.readString();
localId = source.readLong();
remoteId = source.readString();
updateThumbnailNeeded = source.readInt() == 1;
downloading = source.readInt() == 1;
etagInConflict = source.readString();
sharedWithSharee = source.readInt() == 1;
favorite = source.readInt() == 1;
hidden = source.readInt() == 1;
encrypted = source.readInt() == 1;
ownerId = source.readString();
ownerDisplayName = source.readString();
mountType = (WebdavEntry.MountType) source.readSerializable();
richWorkspace = source.readString();
previewAvailable = source.readInt() == 1;
firstShareTimestamp = source.readLong();
locked = source.readInt() == 1;
lockType = FileLockType.fromValue(source.readInt());
lockOwnerId = source.readString();
lockOwnerDisplayName = source.readString();
lockOwnerEditor = source.readString();
lockTimestamp = source.readLong();
lockTimeout = source.readLong();
lockToken = source.readString();
livePhoto = source.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(fileId);
dest.writeLong(parentId);
dest.writeLong(fileLength);
dest.writeLong(uploadTimestamp);
dest.writeLong(creationTimestamp);
dest.writeLong(modificationTimestamp);
dest.writeLong(modificationTimestampAtLastSyncForData);
dest.writeString(remotePath);
dest.writeString(decryptedRemotePath);
dest.writeString(localPath);
dest.writeString(mimeType);
dest.writeInt(needsUpdatingWhileSaving ? 1 : 0);
dest.writeLong(lastSyncDateForProperties);
dest.writeLong(lastSyncDateForData);
dest.writeString(etag);
dest.writeString(etagOnServer);
dest.writeInt(sharedViaLink ? 1 : 0);
dest.writeString(permissions);
dest.writeLong(localId);
dest.writeString(remoteId);
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
dest.writeInt(downloading ? 1 : 0);
dest.writeString(etagInConflict);
dest.writeInt(sharedWithSharee ? 1 : 0);
dest.writeInt(favorite ? 1 : 0);
dest.writeInt(hidden ? 1 : 0);
dest.writeInt(encrypted ? 1 : 0);
dest.writeString(ownerId);
dest.writeString(ownerDisplayName);
dest.writeSerializable(mountType);
dest.writeString(richWorkspace);
dest.writeInt(previewAvailable ? 1 : 0);
dest.writeLong(firstShareTimestamp);
dest.writeInt(locked ? 1 : 0);
dest.writeInt(lockType != null ? lockType.getValue() : -1);
dest.writeString(lockOwnerId);
dest.writeString(lockOwnerDisplayName);
dest.writeString(lockOwnerEditor);
dest.writeLong(lockTimestamp);
dest.writeLong(lockTimeout);
dest.writeString(lockToken);
dest.writeString(livePhoto);
}
public String getLinkedFileIdForLivePhoto() {
return livePhoto;
}
public void setLivePhoto(String livePhoto) {
this.livePhoto = livePhoto;
}
public void setDecryptedRemotePath(String path) {
decryptedRemotePath = path;
}
/**
* Use decrypted remote path for every local file operation Use encrypted remote path for every dav related
* operation
*/
public String getDecryptedRemotePath() {
// Fallback
// TODO test without, on a new created folder
if (!isEncrypted() && decryptedRemotePath == null) {
decryptedRemotePath = remotePath;
}
if (isFolder()) {
if (decryptedRemotePath.endsWith(PATH_SEPARATOR)) {
return decryptedRemotePath;
} else {
return decryptedRemotePath + PATH_SEPARATOR;
}
} else {
if (decryptedRemotePath == null) {
// last fallback
return remotePath;
} else {
return decryptedRemotePath;
}
}
}
/**
* Returns the remote path of the file on Nextcloud
* (this might be an encrypted file path, if E2E is used)
* <p>
* Use decrypted remote path for every local file operation.
* Use remote path for every dav related operation
*
* @return The remote path to the file
*/
public String getRemotePath() {
if (isFolder()) {
if (remotePath.endsWith(PATH_SEPARATOR)) {
return remotePath;
} else {
return remotePath + PATH_SEPARATOR;
}
} else {
return remotePath;
}
}
/**
* Can be used to check, whether or not this file exists in the database already
*
* @return true, if the file exists in the database
*/
public boolean fileExists() {
return fileId != -1;
}
/**
* Use this to find out if this file is a folder.
*
* @return true if it is a folder
*/
public boolean isFolder() {
return MimeType.DIRECTORY.equals(mimeType) || MimeType.WEBDAV_FOLDER.equals(mimeType);
}
/**
* Sets mimetype to folder and returns this file
* Only for testing
*
* @return OCFile this file
*/
public OCFile setFolder() {
setMimeType(MimeType.DIRECTORY);
return this;
}
/**
* Use this to check if this file is available locally
*
* @return true if it is
*/
public boolean isDown() {
return !isFolder() && existsOnDevice();
}
/**
* Use this to check if this file or folder is available locally
*
* @return true if it is
*/
public boolean existsOnDevice() {
if (!TextUtils.isEmpty(localPath)) {
return new File(localPath).exists();
}
return false;
}
/**
* The path, where the file is stored locally
*
* @return The local path to the file
*/
public String getStoragePath() {
return localPath;
}
/**
* The URI to the file contents, if stored locally
*
* @return A URI to the local copy of the file, or NULL if not stored in the device
*/
public Uri getStorageUri() {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (localUri == null) {
Uri.Builder builder = new Uri.Builder();
builder.scheme(ContentResolver.SCHEME_FILE);
builder.path(localPath);
localUri = builder.build();
}
return localUri;
}
public Uri getExposedFileUri(Context context) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (exposedFileUri == null) {
try {
exposedFileUri = FileProvider.getUriForFile(
context,
context.getString(R.string.file_provider_authority),
new File(localPath));
} catch (IllegalArgumentException ex) {
Log_OC.d(TAG, "Given File is outside the paths supported by the provider");
}
}
return exposedFileUri;
}
/**
* Can be used to set the path where the file is stored
*
* @param storage_path to set
*/
public void setStoragePath(String storage_path) {
if (storage_path == null) {
localPath = null;
} else {
localPath = storage_path.replaceAll("//", "/");
if (isFolder() && !localPath.endsWith("/")) {
localPath = localPath + "/";
}
}
localUri = null;
exposedFileUri = null;
}
/**
* Returns the decrypted filename and "/" for the root directory
*
* @return The name of the file
*/
public String getFileName() {
return getDecryptedFileName();
}
/**
* Returns the decrypted filename and "/" for the root directory
*
* @return The name of the file
*/
public String getDecryptedFileName() {
File f = new File(getDecryptedRemotePath());
return f.getName().length() == 0 ? ROOT_PATH : f.getName();
}
/**
* Returns the encrypted filename and "/" for the root directory
*
* @return The name of the file
*/
public String getEncryptedFileName() {
File f = new File(remotePath);
return f.getName().length() == 0 ? ROOT_PATH : f.getName();
}
/**
* Sets the name of the file
* <p/>
* Does nothing if the new name is null, empty or includes "/" ; or if the file is the root
* directory
*/
public void setFileName(String name) {
Log_OC.d(TAG, "OCFile name changing from " + remotePath);
if (!TextUtils.isEmpty(name) && !name.contains(PATH_SEPARATOR) && !ROOT_PATH.equals(remotePath)) {
String parent = new File(this.getRemotePath()).getParent();
if (parent != null) {
parent = parent.endsWith(PATH_SEPARATOR) ? parent : parent + PATH_SEPARATOR;
remotePath = parent + name;
if (isFolder()) {
remotePath += PATH_SEPARATOR;
}
Log_OC.d(TAG, "OCFile name changed to " + remotePath);
}
}
}
/**
* Used internally. Reset all file properties
*/
private void resetData() {
fileId = -1;
remotePath = null;
decryptedRemotePath = null;
parentId = 0;
localPath = null;
mimeType = null;
fileLength = 0;
uploadTimestamp = 0;
creationTimestamp = 0;
modificationTimestamp = 0;
modificationTimestampAtLastSyncForData = 0;
lastSyncDateForProperties = 0;
lastSyncDateForData = 0;
needsUpdatingWhileSaving = false;
etag = null;
etagOnServer = null;
sharedViaLink = false;
permissions = null;
localId = -1;
remoteId = null;
updateThumbnailNeeded = false;
downloading = false;
etagInConflict = null;
sharedWithSharee = false;
favorite = false;
hidden = false;
encrypted = false;
mountType = WebdavEntry.MountType.INTERNAL;
richWorkspace = "";
firstShareTimestamp = 0;
locked = false;
lockType = null;
lockOwnerId = null;
lockOwnerDisplayName = null;
lockOwnerEditor = null;
lockTimestamp = 0;
lockTimeout = 0;
lockToken = null;
livePhoto = null;
imageDimension = null;
}
/**
* get remote path of parent file
*
* @return remote path
*/
public String getParentRemotePath() {
String parentPath = new File(this.getRemotePath()).getParent();
if (parentPath != null) {
return parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
} else {
return null;
}
}
@Override
public int describeContents() {
return super.hashCode();
}
@Override
public int compareTo(@NonNull OCFile another) {
if (isFolder() && another.isFolder()) {
return AlphanumComparator.compare(this, another);
} else if (isFolder()) {
return -1;
} else if (another.isFolder()) {
return 1;
}
return AlphanumComparator.compare(this, another);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OCFile ocFile = (OCFile) o;
return fileId == ocFile.fileId && parentId == ocFile.parentId;
}
@Override
public int hashCode() {
return Objects.hash(fileId,parentId);
}
@NonNull
@Override
public String toString() {
String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, " +
"parentId=%s, etag=%s, favourite=%s]";
return String.format(asString,
fileId,
getFileName(),
mimeType,
isDown(),
localPath,
remotePath,
parentId,
etag,
favorite);
}
public void setEtag(String etag) {
this.etag = etag != null ? etag : "";
}
public void setEtagOnServer(String etag) {
this.etagOnServer = etag != null ? etag : "";
}
public long getLocalModificationTimestamp() {
if (!TextUtils.isEmpty(localPath)) {
File f = new File(localPath);
return f.lastModified();
}
return 0;
}
/**
* @return 'True' if the file is hidden
*/
public boolean isHidden() {
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}
/**
* unique fileId for the file within the instance
*/
@SuppressFBWarnings("STT")
public long getLocalId() {
if (localId > 0) {
return localId;
} else if (remoteId != null && remoteId.length() > 8) {
return Long.parseLong(remoteId.substring(0, 8).replaceAll("^0*", ""));
} else {
return -1;
}
}
public boolean isInConflict() {
return !TextUtils.isEmpty(etagInConflict);
}
public boolean isSharedWithMe() {
return hasPermission(PERMISSION_SHARED);
}
public boolean canReshare() {
return hasPermission(PERMISSION_CAN_RESHARE);
}
public boolean canCreateFileAndFolder() {
return hasPermission(PERMISSION_CAN_CREATE_FILE_AND_FOLDER);
}
public boolean mounted() {
return hasPermission(PERMISSION_MOUNTED);
}
public boolean canRead() {
return hasPermission(PERMISSION_CAN_READ);
}
public boolean canCreateFileInsideFolder() {
return hasPermission(PERMISSION_CAN_CREATE_FILE_INSIDE_FOLDER);
}
public boolean canCreateFolderInsideFolder() {
return hasPermission(PERMISSION_CAN_CREATE_FOLDER_INSIDE_FOLDER);
}
/**
* Determines whether the current account has the ability to delete the file or leave the share.
*
* <p>
* - If the file is shared with the current account (i.e., the user is the recipient),
* the user cannot delete the file itself but can leave the shared file.
* <p>
* - If the file is belongs to the current user. User can delete the file.
*
* @return true if the user is allowed to either delete or leave the share; false otherwise.
*/
public boolean canDeleteOrLeaveShare() {
return hasPermission(PERMISSION_CAN_DELETE_OR_LEAVE_SHARE);
}
public boolean canRename() {
return hasPermission(PERMISSION_CAN_RENAME);
}
public boolean canWrite() {
return hasPermission(PERMISSION_CAN_WRITE);
}
public boolean canMove() {
return hasPermission(PERMISSION_CAN_MOVE);
}
private boolean hasPermission(String permission) {
String permissions = getPermissions();
return permissions != null && permissions.contains(permission);
}
public Integer getFileOverlayIconId(boolean isAutoUploadFolder) {
if (WebdavEntry.MountType.GROUP == mountType || mounted()) {
return R.drawable.ic_folder_overlay_account_group;
} else if (sharedViaLink && !encrypted) {
return R.drawable.ic_folder_overlay_link;
} else if (isSharedWithMe() || sharedWithSharee) {
return R.drawable.ic_folder_overlay_share;
} else if (encrypted) {
return R.drawable.ic_folder_overlay_key;
} else if (WebdavEntry.MountType.EXTERNAL == mountType) {
return R.drawable.ic_folder_overlay_external;
} else if (locked) {
return R.drawable.ic_folder_overlay_lock;
} else if (isAutoUploadFolder) {
return R.drawable.ic_folder_overlay_upload;
} else {
return null;
}
}
public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<>() {
@Override
public OCFile createFromParcel(Parcel source) {
return new OCFile(source);
}
@Override
public OCFile[] newArray(int size) {
return new OCFile[size];
}
};
/**
* Android's internal ID of the file
*/
public long getFileId() {
return this.fileId;
}
public long getParentId() {
return this.parentId;
}
public long getFileLength() {
return this.fileLength;
}
public boolean isFileEligibleForImmediatePreview() {
return fileLength <= MAX_FILE_SIZE_FOR_IMMEDIATE_PREVIEW_BYTES;
}
public long getCreationTimestamp() {
return this.creationTimestamp;
}
/**
* @return unix timestamp in milliseconds
*/
public long getModificationTimestamp() {
return this.modificationTimestamp;
}
public long getModificationTimestampAtLastSyncForData() {
return this.modificationTimestampAtLastSyncForData;
}
public String getMimeType() {
return this.mimeType;
}
public boolean isNeedsUpdatingWhileSaving() {
return this.needsUpdatingWhileSaving;
}
public long getLastSyncDateForProperties() {
return this.lastSyncDateForProperties;
}
public long getLastSyncDateForData() {
return this.lastSyncDateForData;
}
public boolean isPreviewAvailable() {
return this.previewAvailable;
}
public String getEtag() {
return this.etag;
}
public String getEtagOnServer() {
return this.etagOnServer;
}
public boolean isEtagChanged() {
return StringExtensionsKt.eTagChanged(getEtag(), getEtagOnServer());
}
public boolean isSharedViaLink() {
return this.sharedViaLink;
}
public boolean isShared() {
return isSharedViaLink() || isSharedWithSharee() || isSharedWithMe() || !sharees.isEmpty();
}
public String getPermissions() {
return this.permissions;
}
public String getRemoteId() {
return this.remoteId;
}
public boolean isUpdateThumbnailNeeded() {
return this.updateThumbnailNeeded;
}
public boolean isDownloading() {
return this.downloading;
}
public boolean isRootDirectory() {
return ROOT_PATH.equals(decryptedRemotePath);
}
public boolean isOfflineOperation() {
return getRemoteId() == null;
}
public String getEtagInConflict() {
return this.etagInConflict;
}
public boolean isSharedWithSharee() {
return this.sharedWithSharee;
}
public boolean isFavorite() {
return this.favorite;
}
public boolean shouldHide() {
return this.hidden;
}
public boolean isEncrypted() {
return this.encrypted;
}
public WebdavEntry.MountType getMountType() {
return this.mountType;
}
public int getUnreadCommentsCount() {
return this.unreadCommentsCount;
}
public String getOwnerId() {
return this.ownerId;
}
public String getOwnerDisplayName() {
return this.ownerDisplayName;
}
public String getNote() {
return this.note;
}
public List<ShareeUser> getSharees() {
return this.sharees;
}
public String getRichWorkspace() {
return this.richWorkspace;
}
public void setFileId(long fileId) {
this.fileId = fileId;
}
public void setLocalId(long localId) {
this.localId = localId;
}
public void setParentId(long parentId) {
this.parentId = parentId;
}
public void setFileLength(long fileLength) {
this.fileLength = fileLength;
}
public void setCreationTimestamp(long creationTimestamp) {
this.creationTimestamp = creationTimestamp;
}
public void setModificationTimestamp(long modificationTimestamp) {
this.modificationTimestamp = modificationTimestamp;
}
public void setModificationTimestampAtLastSyncForData(long modificationTimestampAtLastSyncForData) {
this.modificationTimestampAtLastSyncForData = modificationTimestampAtLastSyncForData;
}
public void setRemotePath(String remotePath) {
this.remotePath = remotePath;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public void setLastSyncDateForProperties(long lastSyncDateForProperties) {
this.lastSyncDateForProperties = lastSyncDateForProperties;
}
public void setLastSyncDateForData(long lastSyncDateForData) {
this.lastSyncDateForData = lastSyncDateForData;
}
public void setPreviewAvailable(boolean previewAvailable) {
this.previewAvailable = previewAvailable;
}
public void setSharedViaLink(boolean sharedViaLink) {
this.sharedViaLink = sharedViaLink;
}
public void setPermissions(String permissions) {
this.permissions = permissions;
}
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
public void setUpdateThumbnailNeeded(boolean updateThumbnailNeeded) {
this.updateThumbnailNeeded = updateThumbnailNeeded;
}
public void setDownloading(boolean downloading) {
this.downloading = downloading;
}
public void setEtagInConflict(String etagInConflict) {
this.etagInConflict = etagInConflict;
}
public void setSharedWithSharee(boolean sharedWithSharee) {
this.sharedWithSharee = sharedWithSharee;
}
public void setFavorite(boolean favorite) {
this.favorite = favorite;
}
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
public void setEncrypted(boolean encrypted) {
this.encrypted = encrypted;
}
public void setMountType(WebdavEntry.MountType mountType) {
this.mountType = mountType;
}
public void setUnreadCommentsCount(int unreadCommentsCount) {
this.unreadCommentsCount = unreadCommentsCount;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
public void setOwnerDisplayName(String ownerDisplayName) {
this.ownerDisplayName = ownerDisplayName;
}
public void setNote(String note) {
this.note = note;
}
public void setSharees(List<ShareeUser> sharees) {
this.sharees = sharees;
}
public void setRichWorkspace(String richWorkspace) {
this.richWorkspace = richWorkspace;
}
public long getFirstShareTimestamp() {
return firstShareTimestamp;
}