2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-05 16:45:08 +00:00
Files
kdeconnect-android/src/org/kde/kdeconnect/Plugins/SftpPlugin/AndroidFileSystemView.java

102 lines
3.2 KiB
Java
Raw Normal View History

Use Storage Access Framework on SDK >= 21 (Lollipop and above) Summary: Use Storage Access Framework on Android running SDK >= 21 so writing to sdcard will work again |{F6546802}|{F6546803}|{F6546804}| |API 21+|API 19-|Edit| Test Plan: Install patch on Android phone with Build.Version < 19 (Kitkat) - Without a sdcard: Verify that dolphin displays an "All Files" entry that is empty - With a sdcard and with "Add camera folder shortcut" turned off: Verify that dolphin displays the configured display name of the sdcard - With a sdcard and with "Add camera folder shortcut" turned on: Verify that dolphin displays the configured display name of the sdcard and also lists a "Camera pictures" shortcut - With a sdcard: Verify that when changing the display name or the "Add camera folder shortcut" preference dolphin displays the updated items (after pressing F5) - With a sdcard: Verify that files can be read and written to/from the sdcard Install patch on Android phone with Build.Version < 19 (Kitkat) - Repeat the above tests except for the read/write test: Verify that files can be read from the sdcard Install patch on Android phone with Build.Version > 21 (Lollipop) - Without any configured storage locations: Verify dolphin displays an "All Files" entry that is empty - With configured storage locations: Verify dolphin displays the display names of the configured storage locations and that entering a location displays the correct directory entries - Make one or several changes to the configured storage locations: Verify dolphin displays the display names of the configured storage locations (after pressing F5) and that entering a location displays the correct directory entries Reviewers: #kde_connect, albertvaka, sredman Reviewed By: #kde_connect, albertvaka, sredman Subscribers: albertvaka, sredman, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D18212
2019-03-08 13:44:54 +01:00
/*
2020-08-17 16:17:20 +02:00
* SPDX-FileCopyrightText: 2018 Erik Duisters <e.duisters1@gmail.com>
Use Storage Access Framework on SDK >= 21 (Lollipop and above) Summary: Use Storage Access Framework on Android running SDK >= 21 so writing to sdcard will work again |{F6546802}|{F6546803}|{F6546804}| |API 21+|API 19-|Edit| Test Plan: Install patch on Android phone with Build.Version < 19 (Kitkat) - Without a sdcard: Verify that dolphin displays an "All Files" entry that is empty - With a sdcard and with "Add camera folder shortcut" turned off: Verify that dolphin displays the configured display name of the sdcard - With a sdcard and with "Add camera folder shortcut" turned on: Verify that dolphin displays the configured display name of the sdcard and also lists a "Camera pictures" shortcut - With a sdcard: Verify that when changing the display name or the "Add camera folder shortcut" preference dolphin displays the updated items (after pressing F5) - With a sdcard: Verify that files can be read and written to/from the sdcard Install patch on Android phone with Build.Version < 19 (Kitkat) - Repeat the above tests except for the read/write test: Verify that files can be read from the sdcard Install patch on Android phone with Build.Version > 21 (Lollipop) - Without any configured storage locations: Verify dolphin displays an "All Files" entry that is empty - With configured storage locations: Verify dolphin displays the display names of the configured storage locations and that entering a location displays the correct directory entries - Make one or several changes to the configured storage locations: Verify dolphin displays the display names of the configured storage locations (after pressing F5) and that entering a location displays the correct directory entries Reviewers: #kde_connect, albertvaka, sredman Reviewed By: #kde_connect, albertvaka, sredman Subscribers: albertvaka, sredman, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D18212
2019-03-08 13:44:54 +01:00
*
2020-08-17 16:17:20 +02:00
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
Use Storage Access Framework on SDK >= 21 (Lollipop and above) Summary: Use Storage Access Framework on Android running SDK >= 21 so writing to sdcard will work again |{F6546802}|{F6546803}|{F6546804}| |API 21+|API 19-|Edit| Test Plan: Install patch on Android phone with Build.Version < 19 (Kitkat) - Without a sdcard: Verify that dolphin displays an "All Files" entry that is empty - With a sdcard and with "Add camera folder shortcut" turned off: Verify that dolphin displays the configured display name of the sdcard - With a sdcard and with "Add camera folder shortcut" turned on: Verify that dolphin displays the configured display name of the sdcard and also lists a "Camera pictures" shortcut - With a sdcard: Verify that when changing the display name or the "Add camera folder shortcut" preference dolphin displays the updated items (after pressing F5) - With a sdcard: Verify that files can be read and written to/from the sdcard Install patch on Android phone with Build.Version < 19 (Kitkat) - Repeat the above tests except for the read/write test: Verify that files can be read from the sdcard Install patch on Android phone with Build.Version > 21 (Lollipop) - Without any configured storage locations: Verify dolphin displays an "All Files" entry that is empty - With configured storage locations: Verify dolphin displays the display names of the configured storage locations and that entering a location displays the correct directory entries - Make one or several changes to the configured storage locations: Verify dolphin displays the display names of the configured storage locations (after pressing F5) and that entering a location displays the correct directory entries Reviewers: #kde_connect, albertvaka, sredman Reviewed By: #kde_connect, albertvaka, sredman Subscribers: albertvaka, sredman, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D18212
2019-03-08 13:44:54 +01:00
*/
package org.kde.kdeconnect.Plugins.SftpPlugin;
import android.content.Context;
import org.apache.sshd.common.file.FileSystemView;
import org.apache.sshd.common.file.SshFile;
import org.apache.sshd.common.file.nativefs.NativeFileSystemView;
import org.apache.sshd.common.file.nativefs.NativeSshFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
class AndroidFileSystemView extends NativeFileSystemView {
final private String userName;
final private Context context;
private final Map<String, String> roots;
private final RootFile rootFile;
AndroidFileSystemView(Map<String, String> roots, String currentRoot, final String userName, Context context) {
super(userName, roots, currentRoot, File.separatorChar, true);
this.roots = roots;
this.userName = userName;
this.context = context;
this.rootFile = new RootFile( createFileList(), userName, true);
}
private List<SshFile> createFileList() {
List<SshFile> list = new ArrayList<>();
for (Map.Entry<String, String> entry : roots.entrySet()) {
String displayName = entry.getKey();
String path = entry.getValue();
list.add(createNativeSshFile(displayName, new File(path), userName));
}
return list;
}
@Override
public SshFile getFile(String file) {
return getFile("/", file);
}
@Override
public SshFile getFile(SshFile baseDir, String file) {
return getFile(baseDir.getAbsolutePath(), file);
}
@Override
protected SshFile getFile(String dir, String file) {
if (!dir.endsWith("/")) {
dir = dir + "/";
}
if (!file.startsWith("/")) {
file = dir + file;
}
String filename = NativeSshFile.getPhysicalName("/", "/", file, false);
if (filename.equals("/")) {
return rootFile;
}
for (String root : roots.keySet()) {
if (filename.indexOf(root) == 1) {
String nameWithoutRoot = filename.substring(root.length() + 1);
String path = roots.get(root);
if (nameWithoutRoot.isEmpty()) {
return createNativeSshFile(filename, new File(path), userName);
} else {
return createNativeSshFile(filename, new File(path, nameWithoutRoot), userName);
}
}
}
//It's a file under / but not one covered by any Tree
return new RootFile(new ArrayList<>(0), userName, false);
}
// NativeFileSystemView.getFile(), NativeSshFile.getParentFile() and NativeSshFile.listSshFiles() call
// createNativeSshFile to create new NativeSshFiles so override that instead of getFile() to always create an AndroidSshFile
@Override
public AndroidSshFile createNativeSshFile(String name, File file, String username) {
return new AndroidSshFile(this, name, file, username, context);
}
@Override
public FileSystemView getNormalizedView() {
return this;
}
}