File indexing completed on 2024-12-22 04:41:40
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Erik Duisters <e.duisters1@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.Plugins.SftpPlugin; 0008 0009 import android.content.Context; 0010 0011 import org.apache.sshd.common.Session; 0012 import org.apache.sshd.common.file.FileSystemFactory; 0013 import org.apache.sshd.common.file.FileSystemView; 0014 0015 import java.util.HashMap; 0016 import java.util.List; 0017 import java.util.Map; 0018 0019 class AndroidFileSystemFactory implements FileSystemFactory { 0020 final private Context context; 0021 final Map<String, String> roots; 0022 0023 AndroidFileSystemFactory(Context context) { 0024 this.context = context; 0025 this.roots = new HashMap<>(); 0026 } 0027 0028 void initRoots(List<SftpPlugin.StorageInfo> storageInfoList) { 0029 for (SftpPlugin.StorageInfo curStorageInfo : storageInfoList) { 0030 if (curStorageInfo.isFileUri()) { 0031 if (curStorageInfo.uri.getPath() != null){ 0032 roots.put(curStorageInfo.displayName, curStorageInfo.uri.getPath()); 0033 } 0034 } else if (curStorageInfo.isContentUri()){ 0035 roots.put(curStorageInfo.displayName, curStorageInfo.uri.toString()); 0036 } 0037 } 0038 } 0039 0040 @Override 0041 public FileSystemView createFileSystemView(final Session username) { 0042 return new AndroidSafFileSystemView(roots, username.getUsername(), context); 0043 } 0044 }