Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Helpers/StorageHelper.java
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 75 | if (def_path_available) { | |||
---|---|---|---|---|---|
76 | paths.add(def_path); | 76 | paths.add(def_path); | ||
77 | list.add(0, new StorageInfo(def_path, def_path_readonly, def_path_removable, def_path_removable ? cur_removable_number++ : -1)); | 77 | list.add(0, new StorageInfo(def_path, def_path_readonly, def_path_removable, def_path_removable ? cur_removable_number++ : -1)); | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | File storage = new File("/storage/"); | 80 | File storage = new File("/storage/"); | ||
81 | if (storage.exists() && storage.isDirectory()) { | 81 | if (storage.exists() && storage.isDirectory()) { | ||
82 | String mounts = null; | 82 | String mounts = null; | ||
83 | try { | 83 | try { | ||
84 | Scanner scanner = new Scanner( new File("/proc/mounts") ); | 84 | Scanner scanner = new Scanner(new File("/proc/mounts")); | ||
85 | mounts = scanner.useDelimiter("\\A").next(); | 85 | mounts = scanner.useDelimiter("\\A").next(); | ||
86 | scanner.close(); | 86 | scanner.close(); | ||
87 | //Log.e("Mounts",mounts); | 87 | //Log.e("Mounts",mounts); | ||
88 | } catch(Exception e) { | 88 | } catch (Exception e) { | ||
89 | e.printStackTrace(); | 89 | e.printStackTrace(); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | File dirs[] = storage.listFiles(); | 92 | File dirs[] = storage.listFiles(); | ||
93 | for (File dir : dirs) { | 93 | for (File dir : dirs) { | ||
94 | //Log.e("getStorageList", "path: "+dir.getAbsolutePath()); | 94 | //Log.e("getStorageList", "path: "+dir.getAbsolutePath()); | ||
95 | if (dir.isDirectory() && dir.canRead() && dir.canExecute()) { | 95 | if (dir.isDirectory() && dir.canRead() && dir.canExecute()) { | ||
96 | String path, path2; | 96 | String path, path2; | ||
97 | path2 = dir.getAbsolutePath(); | 97 | path2 = dir.getAbsolutePath(); | ||
98 | try { | 98 | try { | ||
99 | //Log.e(dir.getAbsolutePath(), dir.getCanonicalPath()); | 99 | //Log.e(dir.getAbsolutePath(), dir.getCanonicalPath()); | ||
100 | path = dir.getCanonicalPath(); | 100 | path = dir.getCanonicalPath(); | ||
101 | } catch(Exception e){ | 101 | } catch (Exception e) { | ||
102 | path = path2; | 102 | path = path2; | ||
103 | } | 103 | } | ||
104 | if (!path.startsWith("/storage/emulated") || dirs.length == 1) { | 104 | if (!path.startsWith("/storage/emulated") || dirs.length == 1) { | ||
105 | if (!paths.contains(path) && !paths.contains(path2)) { | 105 | if (!paths.contains(path) && !paths.contains(path2)) { | ||
106 | if (mounts == null || mounts.contains(path) || mounts.contains(path2)) { | 106 | if (mounts == null || mounts.contains(path) || mounts.contains(path2)) { | ||
107 | list.add(0, new StorageInfo(path, false, true, cur_removable_number++)); | 107 | list.add(0, new StorageInfo(path, false, true, cur_removable_number++)); | ||
108 | paths.add(path); | 108 | paths.add(path); | ||
109 | } | 109 | } | ||
110 | } | 110 | } | ||
111 | } | 111 | } | ||
112 | } | 112 | } | ||
113 | } | 113 | } | ||
114 | } else { | 114 | } else { | ||
115 | 115 | | |||
116 | //Legacy code for Android < 4.0 that still didn't have /storage | 116 | //Legacy code for Android < 4.0 that still didn't have /storage | ||
117 | 117 | | |||
118 | ArrayList<String> entries = new ArrayList<>(); | 118 | ArrayList<String> entries = new ArrayList<>(); | ||
119 | BufferedReader buf_reader = null; | 119 | BufferedReader buf_reader = null; | ||
120 | try { | 120 | try { | ||
121 | buf_reader = new BufferedReader(new FileReader("/proc/mounts")); | 121 | buf_reader = new BufferedReader(new FileReader("/proc/mounts")); | ||
122 | String entry; | 122 | String entry; | ||
123 | while((entry = buf_reader.readLine()) != null) { | 123 | while ((entry = buf_reader.readLine()) != null) { | ||
124 | //Log.e("getStorageList", entry); | 124 | //Log.e("getStorageList", entry); | ||
125 | if (entry.contains("vfat") || entry.contains("exfat") || entry.contains("ntfs") || entry.contains("/mnt")) { | 125 | if (entry.contains("vfat") || entry.contains("exfat") || entry.contains("ntfs") || entry.contains("/mnt")) { | ||
126 | if (entry.contains("/storage/sdcard")) entries.add(0, entry); | 126 | if (entry.contains("/storage/sdcard")) entries.add(0, entry); | ||
127 | else entries.add(entry); | 127 | else entries.add(entry); | ||
128 | } | 128 | } | ||
129 | } | 129 | } | ||
130 | } catch (Exception e) { | 130 | } catch (Exception e) { | ||
131 | e.printStackTrace(); | 131 | e.printStackTrace(); | ||
Show All 38 Lines |