Offset 6, 21 lines modifiedOffset 6, 20 lines modified
6 import·java.io.Serializable;6 import·java.io.Serializable;
7 import·java.nio.file.OpenOption;7 import·java.nio.file.OpenOption;
8 import·java.nio.file.FileVisitor;8 import·java.nio.file.FileVisitor;
9 import·android.webkit.MimeTypeMap;9 import·android.webkit.MimeTypeMap;
10 import·java.nio.file.NoSuchFileException;10 import·java.nio.file.NoSuchFileException;
11 import·java.nio.charset.StandardCharsets;11 import·java.nio.charset.StandardCharsets;
12 import·java.nio.file.Files;12 import·java.nio.file.Files;
13 import·android.os.ParcelFileDescriptor; 
14 import·java.nio.file.Path; 
15 import·java.util.Optional;13 import·java.util.Optional;
16 import·java.io.IOException;14 import·java.io.IOException;
 15 import·android.os.ParcelFileDescriptor;
 16 import·java.nio.file.Path;
17 import·android.provider.MediaStore;17 import·android.provider.MediaStore;
18 import·java.util.ArrayList;18 import·java.util.ArrayList;
19 import·android.os.storage.StorageVolume; 
20 import·android.os.storage.StorageManager;19 import·android.os.storage.StorageManager;
21 import·android.content.Context;20 import·android.content.Context;
22 import·android.provider.MediaStore$Files;21 import·android.provider.MediaStore$Files;
23 import·java.util.Objects;22 import·java.util.Objects;
24 import·android.net.Uri;23 import·android.net.Uri;
25 import·java.util.Comparator;24 import·java.util.Comparator;
26 import·java.util.Arrays;25 import·java.util.Arrays;
Offset 45, 15 lines modifiedOffset 44, 14 lines modified
  
45 public·class·FileUtils44 public·class·FileUtils
46 {45 {
47 ····private·static·final·String·CAMERA_RELATIVE_PATH;46 ····private·static·final·String·CAMERA_RELATIVE_PATH;
48 ····public·static·final·long·DEFAULT_DURATION_PENDING·=·604800000L;47 ····public·static·final·long·DEFAULT_DURATION_PENDING·=·604800000L;
49 ····public·static·final·long·DEFAULT_DURATION_TRASHED·=·2592000000L;48 ····public·static·final·long·DEFAULT_DURATION_TRASHED·=·2592000000L;
50 ····public·static·final·String[]·DEFAULT_FOLDER_NAMES;49 ····public·static·final·String[]·DEFAULT_FOLDER_NAMES;
51 ····private·static·final·int·MAX_READ_STRING_SIZE·=·4096; 
52 ····public·static·final·Pattern·PATTERN_DATA_OR_OBB_PATH;50 ····public·static·final·Pattern·PATTERN_DATA_OR_OBB_PATH;
53 ····private·static·final·Pattern·PATTERN_DCF_RELAXED;51 ····private·static·final·Pattern·PATTERN_DCF_RELAXED;
54 ····private·static·final·Pattern·PATTERN_DCF_STRICT;52 ····private·static·final·Pattern·PATTERN_DCF_STRICT;
55 ····public·static·final·Pattern·PATTERN_DOWNLOADS_DIRECTORY;53 ····public·static·final·Pattern·PATTERN_DOWNLOADS_DIRECTORY;
56 ····public·static·final·Pattern·PATTERN_DOWNLOADS_FILE;54 ····public·static·final·Pattern·PATTERN_DOWNLOADS_FILE;
57 ····public·static·final·Pattern·PATTERN_EXPIRES_FILE;55 ····public·static·final·Pattern·PATTERN_EXPIRES_FILE;
58 ····public·static·final·Pattern·PATTERN_OWNED_PATH;56 ····public·static·final·Pattern·PATTERN_OWNED_PATH;
Offset 243, 29 lines modifiedOffset 241, 27 lines modified
243 ········final·String·s3·=·".%s-%d-%s";241 ········final·String·s3·=·".%s-%d-%s";
244 ········final·long·n2·=·1000L;242 ········final·long·n2·=·1000L;
245 ········final·String·s4·=·"date_expires";243 ········final·String·s4·=·"date_expires";
246 ········final·int·n3·=·2;244 ········final·int·n3·=·2;
247 ········final·int·n4·=·1;245 ········final·int·n4·=·1;
248 ········if·(!b·&&·DatabaseUtils.getAsBoolean(contentValues,·"is_pending",·false))·{246 ········if·(!b·&&·DatabaseUtils.getAsBoolean(contentValues,·"is_pending",·false))·{
249 ············final·long·asLong·=·DatabaseUtils.getAsLong(contentValues,·s4,·(System.currentTimeMillis()·+·604800000L)·/·n2);247 ············final·long·asLong·=·DatabaseUtils.getAsLong(contentValues,·s4,·(System.currentTimeMillis()·+·604800000L)·/·n2);
250 ············final·Locale·us·=·Locale.US; 
251 ············final·Object[]·array·=·new·Object[n];248 ············final·Object[]·array·=·new·Object[n];
252 ············array[0]·=·"pending";249 ············array[0]·=·"pending";
253 ············array[n4]·=·asLong;250 ············array[n4]·=·asLong;
254 ············array[n3]·=·s2;251 ············array[n3]·=·s2;
255 ············s2·=·String.format(us,·s3,·array);252 ············s2·=·String.format(s3,·array);
256 ········}253 ········}
257 ········else·if·(DatabaseUtils.getAsBoolean(contentValues,·"is_trashed",·false))·{254 ········else·if·(DatabaseUtils.getAsBoolean(contentValues,·"is_trashed",·false))·{
258 ············final·long·asLong2·=·DatabaseUtils.getAsLong(contentValues,·s4,·(System.currentTimeMillis()·+·2592000000L)·/·n2);255 ············final·long·asLong2·=·DatabaseUtils.getAsLong(contentValues,·s4,·(System.currentTimeMillis()·+·2592000000L)·/·n2);
259 ············final·Locale·us2·=·Locale.US; 
260 ············final·Object[]·array2·=·new·Object[n];256 ············final·Object[]·array2·=·new·Object[n];
261 ············array2[0]·=·"trashed";257 ············array2[0]·=·"trashed";
262 ············array2[n4]·=·asLong2;258 ············array2[n4]·=·asLong2;
263 ············array2[n3]·=·s2;259 ············array2[n3]·=·s2;
264 ············s2·=·String.format(us2,·s3,·array2);260 ············s2·=·String.format(s3,·array2);
265 ········}261 ········}
266 ········final·String[]·array3·=·new·String[n3];262 ········final·String[]·array3·=·new·String[n3];
267 ········array3[0]·=·contentValues.getAsString("relative_path");263 ········array3[0]·=·contentValues.getAsString("relative_path");
268 ········array3[n4]·=·s2;264 ········array3[n4]·=·s2;
269 ········contentValues.put(s,·buildPath(file,·array3).getAbsolutePath());265 ········contentValues.put(s,·buildPath(file,·array3).getAbsolutePath());
270 ····}266 ····}
271 ····267 ····
Offset 555, 38 lines modifiedOffset 551, 19 lines modified
555 ····}551 ····}
556 ····552 ····
557 ····public·static·Uri·getContentUriForPath(final·String·s)·{553 ····public·static·Uri·getContentUriForPath(final·String·s)·{
558 ········Objects.requireNonNull(s);554 ········Objects.requireNonNull(s);
559 ········return·MediaStore$Files.getContentUri(extractVolumeName(s));555 ········return·MediaStore$Files.getContentUri(extractVolumeName(s));
560 ····}556 ····}
561 ····557 ····
562 ····public·static·File·getTopLevelNoMedia(File·parentFile)·{ 
563 ········File·file·=·null; 
564 ········while·(parentFile·!=·null)·{ 
565 ············final·File·file2·=·new·File(parentFile,·".nomedia"); 
566 ············if·(file2.exists())·{ 
567 ················file·=·file2; 
568 ············} 
569 ············parentFile·=·parentFile.getParentFile(); 
570 ········} 
571 ········return·file; 
572 ····} 
573 ···· 
574 ····public·static·String·getVolumeName(final·Context·context,·final·File·file)·{558 ····public·static·String·getVolumeName(final·Context·context,·final·File·file)·{
575 ········if·(!contains(Environment.getStorageDirectory(),·file))·{559 ········if·(contains(Environment.getStorageDirectory(),·file))·{
576 ············return·"internal";560 ············return·((StorageManager)context.getSystemService((Class)StorageManager.class)).getStorageVolume(file).getMediaStoreVolumeName();
577 ········}561 ········}
578 ········final·StorageVolume·storageVolume·=·((StorageManager)context.getSystemService((Class)StorageManager.class)).getStorageVolume(file);562 ········return·"internal";
579 ········if·(storageVolume·!=·null)·{ 
580 ············return·storageVolume.getMediaStoreVolumeName(); 
581 ········} 
582 ········final·StringBuilder·sb·=·new·StringBuilder(); 
583 ········sb.append("Can't·find·volume·for·"); 
584 ········sb.append(file.getPath()); 
585 ········throw·new·FileNotFoundException(sb.toString()); 
586 ····}563 ····}
587 ····564 ····
588 ····public·static·File·getVolumePath(final·Context·context,·String·s)·{565 ····public·static·File·getVolumePath(final·Context·context,·String·s)·{
589 ········final·int·hashCode·=·s.hashCode();566 ········final·int·hashCode·=·s.hashCode();
590 ········final·int·n·=·-1820761141;567 ········final·int·n·=·-1820761141;
591 ········final·boolean·b·=·true;568 ········final·boolean·b·=·true;
592 ········int·n2·=·0;569 ········int·n2·=·0;
Offset 609, 31 lines modifiedOffset 586, 15 lines modified
609 ········if·(n2·==·0·||·n2·==·(b·?·1·:·0))·{586 ········if·(n2·==·0·||·n2·==·(b·?·1·:·0))·{
610 ············final·StringBuilder·sb·=·new·StringBuilder();587 ············final·StringBuilder·sb·=·new·StringBuilder();
611 ············sb.append(s);588 ············sb.append(s);
612 ············sb.append(s2);589 ············sb.append(s2);
613 ············s·=·sb.toString();590 ············s·=·sb.toString();
614 ············throw·new·FileNotFoundException(s);591 ············throw·new·FileNotFoundException(s);
615 ········}592 ········}
616 ········final·Uri·contentUri·=·MediaStore$Files.getContentUri(s);593 ········final·File·directory·=·((StorageManager)context.getSystemService((Class)StorageManager.class)).getStorageVolume(MediaStore$Files.getContentUri(s)).getDirectory();
617 ········File·directory·=·null; 
618 ········final·Class<StorageManager>·clazz·=·StorageManager.class; 
619 ········try·{ 
620 ············final·Object·systemService·=·context.getSystemService((Class)clazz); 
621 ············try·{ 
622 ················final·StorageVolume·storageVolume·=·((StorageManager)systemService).getStorageVolume(contentUri); 
623 ················try·{ 
624 ····················directory·=·storageVolume.getDirectory(); 
625 ················} 
626 ················catch·(IllegalStateException·ex)·{ 
627 ····················Log.w("Ignoring·volume·not·found·exception",·(Throwable)ex); 
628 ················} 
629 ············} 
630 ············catch·(IllegalStateException·ex2)·{} 
631 ········} 
632 ········catch·(IllegalStateException·ex3)·{} 
633 ········if·(directory·!=·null)·{594 ········if·(directory·!=·null)·{
634 ············return·directory;595 ············return·directory;
635 ········}596 ········}
636 ········final·StringBuilder·sb2·=·new·StringBuilder();597 ········final·StringBuilder·sb2·=·new·StringBuilder();
637 ········sb2.append(s);598 ········sb2.append(s);
638 ········sb2.append(s2);599 ········sb2.append(s2);
639 ········s·=·sb2.toString();600 ········s·=·sb2.toString();
Offset 698, 50 lines modifiedOffset 659, 14 lines modified
698 ············if·(default_FOLDER_NAMES[i].equalsIgnoreCase(s))·{659 ············if·(default_FOLDER_NAMES[i].equalsIgnoreCase(s))·{
699 ················return·true;660 ················return·true;
700 ············}661 ············}
701 ········}662 ········}
702 ········return·false;663 ········return·false;
703 ····}664 ····}
704 ····665 ····
705 ····public·static·boolean·isDirectoryDirty(final·File·file)·{ 
706 ········final·File·file2·=·new·File(file,·".nomedia"); 
707 ········final·boolean·exists·=·file2.exists(); 
708 ········boolean·b·=·true; 
709 ········if·(exists)·{ 
710 ············try·{ 
711 ················final·Optional·string·=·readString(file2); 
712 ················try·{ 
713 ····················if·(!string.isPresent())·{ 
714 ························return·b; 
715 ····················} 
716 ····················final·String·value·=·string.get(); 
717 ····················try·{ 
718 ························final·String·s·=·(String)value; 
719 ························try·{ 
720 ····························if·(s.equals(file.getPath()))·{ 
721 ································b·=·false; 
722 ····························} 
723 ····························return·b; 
724 ························} 
725 ························catch·(IOException·ex)·{ 
726 ····························final·StringBuilder·sb·=·new·StringBuilder(); 
727 ····························sb.append("Failed·to·read·directory·dirty"); 
728 ····························sb.append(file); 
729 ····························Log.w("MediaProvider",·sb.toString()); 
730 ························} 
731 ····················} 
732 ····················catch·(IOException·ex2)·{} 
733 ················} 
734 ················catch·(IOException·ex3)·{} 
735 ············} 
736 ············catch·(IOException·ex4)·{} 
737 ········} 
738 ········return·b; 
739 ····} 
740 ···· 
741 ····public·static·boolean·isDirectoryHidden(final·File·file)·{666 ····public·static·boolean·isDirectoryHidden(final·File·file)·{
742 ········final·String·name·=·file.getName();667 ········final·String·name·=·file.getName();
743 ········final·boolean·startsWith·=·name.startsWith(".");668 ········final·boolean·startsWith·=·name.startsWith(".");
744 ········final·boolean·b·=·true;669 ········final·boolean·b·=·true;
745 ········if·(startsWith)·{670 ········if·(startsWith)·{
746 ············return·b;671 ············return·b;
747 ········}672 ········}
Offset 823, 45 lines modifiedOffset 748, 30 lines modified
823 ········}748 ········}
824 ········catch·(IOException·ex4)·{}749 ········catch·(IOException·ex4)·{}
825 ········catch·(ErrnoException·ex5)·{}750 ········catch·(ErrnoException·ex5)·{}
826 ····}751 ····}
827 ····752 ····
828 ····public·static·Optional·readString(final·File·file)·{753 ····public·static·Optional·readString(final·File·file)·{
829 ········try·{754 ········try·{
830 ············Label_0053:·{755 ············try·{
831 ················if·(file.length()·>·4096L)·{756 ················final·Path·path·=·file.toPath();
832 ····················break·Label_0053; 
833 ················} 
834 ················try·{757 ················try·{
835 ····················final·Path·path·=·file.toPath();758 ····················final·byte[]·allBytes·=·Files.readAllBytes(path);
836 ····················try·{759 ····················try·{
837 ························final·byte[]·allBytes·=·Files.readAllBytes(path);760 ························return·Optional.of(new·String(allBytes,·StandardCharsets.UTF_8));
838 ························try·{761 ····················}
839 ····························return·Optional.of(new·String(allBytes,·StandardCharsets.UTF_8));762 ····················catch·(NoSuchFileException·ex)·{
840 ····························final·String·s·=·"Ignored·reading·%s,·file·size·exceeds·%d";763 ························return·Optional.empty();
841 ····························final·Object[]·array·=·{·file,·4096·}; 
842 ····························final·String·s2·=·s; 
843 ····························try·{ 
844 ································final·String·format·=·String.format(s2,·array); 
845 ································try·{ 
846 ····································Logging.logPersistent(format); 
847 ····································return·Optional.empty(); 
848 ································} 
849 ································catch·(NoSuchFileException·ex)·{} 
850 ····························} 
851 ····························catch·(NoSuchFileException·ex2)·{} 
852 ························} 
853 ························catch·(NoSuchFileException·ex3)·{} 
854 ····················}764 ····················}
855 ····················catch·(NoSuchFileException·ex4)·{} 
856 ················}765 ················}
857 ················catch·(NoSuchFileException·ex5)·{}766 ················catch·(NoSuchFileException·ex2)·{}
858 ············}767 ············}
 768 ············catch·(NoSuchFileException·ex3)·{}
859 ········}769 ········}
860 ········catch·(NoSuchFileException·ex6)·{}770 ········catch·(NoSuchFileException·ex4)·{}
861 ····}771 ····}
862 ····772 ····
863 ····public·static·String·sanitizeDisplayName(final·String·s)·{773 ····public·static·String·sanitizeDisplayName(final·String·s)·{
864 ········return·sanitizeDisplayName(s,·false);774 ········return·sanitizeDisplayName(s,·false);
865 ····}775 ····}
866 ····776 ····
867 ····public·static·String·sanitizeDisplayName(final·String·s,·final·boolean·b)·{777 ····public·static·String·sanitizeDisplayName(final·String·s,·final·boolean·b)·{
Offset 905, 42 lines modifiedOffset 815, 14 lines modified
905 ········sb.append(String.join((CharSequence)s2,·(CharSequence[])split));815 ········sb.append(String.join((CharSequence)s2,·(CharSequence[])split));
906 ········sb.append(s2);816 ········sb.append(s2);
907 ········contentValues.put(s,·sb.toString());817 ········contentValues.put(s,·sb.toString());
908 ········final·String·s3·=·"_display_name";818 ········final·String·s3·=·"_display_name";
909 ········contentValues.put(s3,·sanitizeDisplayName(contentValues.getAsString(s3),·b));819 ········contentValues.put(s3,·sanitizeDisplayName(contentValues.getAsString(s3),·b));
910 ····}820 ····}
911 ····821 ····
912 ····public·static·void·setDirectoryDirty(final·File·file,·final·boolean·b)·{ 
913 ········final·File·file2·=·new·File(file,·".nomedia"); 
914 ········if·(file2.exists())·{ 
915 ············Label_0041:·{ 
916 ················if·(!b)·{ 
917 ····················break·Label_0041; 
918 ················} 
919 ················String·path·=·""; 
920 ················try·{ 
921 ····················while·(true)·{ 
922 ························writeString(file2,·Optional.of(path)); 
923 ························return; 
924 ························path·=·file.getPath(); 
925 ························continue; 
926 ····················} 
927 ················} 
928 ················catch·(IOException·ex)·{ 
929 ····················final·StringBuilder·sb·=·new·StringBuilder(); 
930 ····················sb.append("Failed·to·change·directory·dirty:·"); 
931 ····················sb.append(file); 
932 ····················sb.append(".·isDirty:·"); 
933 ····················sb.append(b); 
934 ····················Log.w("MediaProvider",·sb.toString()); 
935 ················} 
936 ············} 
937 ········} 
938 ····} 
939 ···· 
940 ····public·static·String[]·splitFileName(final·String·s,·String·s2)·{822 ····public·static·String[]·splitFileName(final·String·s,·String·s2)·{
941 ········final·int·lastIndex·=·s2.lastIndexOf(46);823 ········final·int·lastIndex·=·s2.lastIndexOf(46);
942 ········final·int·n·=·1;824 ········final·int·n·=·1;
943 ········String·extensionFromMimeType·=·null;825 ········String·extensionFromMimeType·=·null;
944 ········String·substring;826 ········String·substring;
945 ········String·substring2;827 ········String·substring2;
946 ········String·mimeTypeFromExtension;828 ········String·mimeTypeFromExtension;