diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java index 38768c3a..714db0cb 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java @@ -1,152 +1,157 @@ /* * Copyright 2014 Samoilenko Yuri * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package org.kde.kdeconnect.Plugins.SftpPlugin; import android.Manifest; +import android.os.Build; import android.os.Environment; import org.kde.kdeconnect.Helpers.StorageHelper; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect_tp.R; import java.io.File; import java.util.ArrayList; import java.util.List; public class SftpPlugin extends Plugin { private final static String PACKET_TYPE_SFTP = "kdeconnect.sftp"; private final static String PACKET_TYPE_SFTP_REQUEST = "kdeconnect.sftp.request"; private static final SimpleSftpServer server = new SimpleSftpServer(); @Override public String getDisplayName() { return context.getResources().getString(R.string.pref_plugin_sftp); } @Override public String getDescription() { return context.getResources().getString(R.string.pref_plugin_sftp_desc); } @Override public boolean onCreate() { permissionExplanation = R.string.sftp_permission_explanation; try { server.init(context, device); return true; } catch (Exception e) { e.printStackTrace(); return false; } } @Override public void onDestroy() { server.stop(); } @Override public boolean onPacketReceived(NetworkPacket np) { if (np.getBoolean("startBrowsing")) { if (server.start()) { NetworkPacket np2 = new NetworkPacket(PACKET_TYPE_SFTP); np2.set("ip", server.getLocalIpAddress()); np2.set("port", server.getPort()); np2.set("user", SimpleSftpServer.USER); np2.set("password", server.getPassword()); //Kept for compatibility, in case "multiPaths" is not possible or the other end does not support it np2.set("path", Environment.getExternalStorageDirectory().getAbsolutePath()); List storageList = StorageHelper.getStorageList(); ArrayList paths = new ArrayList<>(); ArrayList pathNames = new ArrayList<>(); for (StorageHelper.StorageInfo storage : storageList) { paths.add(storage.path); StringBuilder res = new StringBuilder(); if (storageList.size() > 1) { if (!storage.removable) { res.append(context.getString(R.string.sftp_internal_storage)); } else if (storage.number > 1) { res.append(context.getString(R.string.sftp_sdcard_num, storage.number)); } else { res.append(context.getString(R.string.sftp_sdcard)); } } else { res.append(context.getString(R.string.sftp_all_files)); } String pathName = res.toString(); if (storage.readonly) { res.append(" "); res.append(context.getString(R.string.sftp_readonly)); } pathNames.add(res.toString()); //Shortcut for users that only want to browse camera pictures String dcim = storage.path + "/DCIM/Camera"; if (new File(dcim).exists()) { paths.add(dcim); if (storageList.size() > 1) { pathNames.add(context.getString(R.string.sftp_camera) + "(" + pathName + ")"); } else { pathNames.add(context.getString(R.string.sftp_camera)); } } } if (paths.size() > 0) { np2.set("multiPaths", paths); np2.set("pathNames", pathNames); } device.sendPacket(np2); return true; } } return false; } @Override public String[] getRequiredPermissions() { - return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}; + } else { + return new String[0]; + } } @Override public String[] getSupportedPacketTypes() { return new String[]{PACKET_TYPE_SFTP_REQUEST}; } @Override public String[] getOutgoingPacketTypes() { return new String[]{PACKET_TYPE_SFTP}; } }