mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 13:17:43 +00:00
Remove pre-kitkat code paths in SFTP plugin
We no longer support KitKat. This simplifies the SFTP plugin quite a bit since it contained a diferent code path for pre-kitkat devices
This commit is contained in:
parent
5b73c2bac2
commit
9cbfed84de
@ -266,23 +266,13 @@
|
||||
<string name="filter_apps_info">Notifications will be synchronized for the selected apps.</string>
|
||||
<string name="show_notification_if_screen_off">Send notifications only if the screen is off</string>
|
||||
<string name="screen_off_notification_state" translatable="false">pref_notification_screen_off</string>
|
||||
<string name="sftp_sdcard_num">SD card %d</string>
|
||||
<string name="sftp_sdcard">SD card</string>
|
||||
<string name="sftp_readonly">(read only)</string>
|
||||
<string name="sftp_camera">Camera pictures</string>
|
||||
<string name="add_device_dialog_title">Add device</string>
|
||||
<string name="add_device_hint">Hostname or IP address</string>
|
||||
<string name="sftp_preference_detected_sdcards">Detected SD cards</string>
|
||||
<string name="sftp_preference_edit_sdcard_title">Edit SD card</string>
|
||||
<string name="sftp_preference_configured_storage_locations">Configured storage locations</string>
|
||||
<string name="sftp_preference_add_storage_location_title">Add storage location</string>
|
||||
<string name="sftp_preference_edit_storage_location">Edit storage location</string>
|
||||
<string name="sftp_preference_add_camera_shortcut">Add camera folder shortcut</string>
|
||||
<string name="sftp_preference_add_camera_shortcut_summary_on">Add a shortcut to the camera folder</string>
|
||||
<string name="sftp_preference_add_camera_shortcut_summary_off">Do not add a shortcut to the camera folder</string>
|
||||
<string name="sftp_preference_key_preference_category" translatable="false">key_sftp_preference_category</string>
|
||||
<string name="sftp_preference_key_add_storage" translatable="false">key_sftp_add_storage</string>
|
||||
<string name="sftp_preference_key_add_camera_shortcut" translatable="false">key_sftp_add_camera_shotcut</string>
|
||||
<string name="sftp_preference_key_storage_info" translatable="false">key_sftp_storage_info%d"</string>
|
||||
<string name="sftp_preference_key_storage_info_list" translatable="false">key_sftp_storage_info_list</string>
|
||||
<string name="sftp_storage_preference_storage_location">Storage location</string>
|
||||
@ -292,7 +282,6 @@
|
||||
<string name="sftp_storage_preference_display_name_already_used">This display name is already used</string>
|
||||
<string name="sftp_storage_preference_display_name_cannot_be_empty">Display name cannot be empty</string>
|
||||
<string name="sftp_action_mode_menu_delete">Delete</string>
|
||||
<string name="sftp_no_sdcard_detected">No SD card detected</string>
|
||||
<string name="sftp_no_storage_locations_configured">No storage locations configured</string>
|
||||
<string name="sftp_saf_permission_explanation">To access files remotely you have to configure storage locations</string>
|
||||
<string name="no_players_connected">No players found</string>
|
||||
|
@ -4,9 +4,8 @@
|
||||
tools:keep="@xml/sftpplugin_preferences">
|
||||
<PreferenceCategory
|
||||
android:key="@string/sftp_preference_key_preference_category"
|
||||
android:title="@string/sftp_preference_detected_sdcards"
|
||||
android:title="@string/sftp_preference_configured_storage_locations"
|
||||
android:persistent="false">
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<org.kde.kdeconnect.Plugins.SftpPlugin.StoragePreference
|
||||
@ -14,11 +13,4 @@
|
||||
android:icon="@drawable/ic_add"
|
||||
android:title="@string/sftp_preference_add_storage_location_title"
|
||||
android:persistent="false"/>
|
||||
|
||||
<androidx.preference.SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="@string/sftp_preference_key_add_camera_shortcut"
|
||||
android:summaryOff="@string/sftp_preference_add_camera_shortcut_summary_off"
|
||||
android:summaryOn="@string/sftp_preference_add_camera_shortcut_summary_on"
|
||||
android:title="@string/sftp_preference_add_camera_shortcut"/>
|
||||
</PreferenceScreen>
|
@ -40,17 +40,6 @@ class AndroidFileSystemFactory implements FileSystemFactory {
|
||||
|
||||
@Override
|
||||
public FileSystemView createFileSystemView(final Session username) {
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
||||
if (roots.size() == 0) {
|
||||
throw new RuntimeException("roots cannot be empty");
|
||||
}
|
||||
|
||||
String[] rootsAsString = new String[roots.size()];
|
||||
roots.keySet().toArray(rootsAsString);
|
||||
|
||||
return new AndroidFileSystemView(roots, rootsAsString[0], username.getUsername(), context);
|
||||
} else {
|
||||
return new AndroidSafFileSystemView(roots, username.getUsername(), context);
|
||||
}
|
||||
return new AndroidSafFileSystemView(roots, username.getUsername(), context);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
private final static String PACKET_TYPE_SFTP_REQUEST = "kdeconnect.sftp.request";
|
||||
|
||||
static int PREFERENCE_KEY_STORAGE_INFO_LIST = R.string.sftp_preference_key_storage_info_list;
|
||||
private static int PREFERENCE_KEY_ADD_CAMERA_SHORTCUT = R.string.sftp_preference_key_add_camera_shortcut;
|
||||
|
||||
private static final SimpleSftpServer server = new SimpleSftpServer();
|
||||
|
||||
@ -57,11 +56,6 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
public boolean onCreate() {
|
||||
try {
|
||||
server.init(context, device);
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
||||
return SftpSettingsFragment.getStorageInfoList(context, this).size() != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e("SFTP", "Exception in server.init()", e);
|
||||
@ -71,11 +65,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
|
||||
@Override
|
||||
public boolean checkOptionalPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return SftpSettingsFragment.getStorageInfoList(context, this).size() != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
return SftpSettingsFragment.getStorageInfoList(context, this).size() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -111,15 +101,8 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
getPathsAndNamesForStorageInfoList(paths, pathNames, storageInfoList);
|
||||
} else {
|
||||
NetworkPacket np2 = new NetworkPacket(PACKET_TYPE_SFTP);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
np2.set("errorMessage", context.getString(R.string.sftp_no_storage_locations_configured));
|
||||
} else {
|
||||
np2.set("errorMessage", context.getString(R.string.sftp_no_sdcard_detected));
|
||||
}
|
||||
|
||||
np2.set("errorMessage", context.getString(R.string.sftp_no_storage_locations_configured));
|
||||
device.sendPacket(np2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -158,14 +141,6 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
StorageInfo prevInfo = null;
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
|
||||
boolean addCameraShortcuts = false;
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
||||
if (preferences != null) {
|
||||
addCameraShortcuts = preferences.getBoolean(context.getString(PREFERENCE_KEY_ADD_CAMERA_SHORTCUT), true);
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageInfo curInfo : storageInfoList) {
|
||||
pathBuilder.setLength(0);
|
||||
pathBuilder.append("/");
|
||||
@ -188,17 +163,6 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
|
||||
paths.add(pathBuilder.toString());
|
||||
pathNames.add(curInfo.displayName);
|
||||
|
||||
if (addCameraShortcuts) {
|
||||
if (new File(curInfo.uri.getPath(), "/DCIM/Camera").exists()) {
|
||||
paths.add(pathBuilder.toString() + "/DCIM/Camera");
|
||||
if (storageInfoList.size() > 1) {
|
||||
pathNames.add(context.getString(R.string.sftp_camera) + "(" + curInfo.displayName + ")");
|
||||
} else {
|
||||
pathNames.add(context.getString(R.string.sftp_camera));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,14 +204,11 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
@Override
|
||||
public void copyGlobalToDeviceSpecificSettings(SharedPreferences globalSharedPreferences) {
|
||||
String KeyStorageInfoList = context.getString(PREFERENCE_KEY_STORAGE_INFO_LIST);
|
||||
String KeyAddCameraShortcut = context.getString(PREFERENCE_KEY_ADD_CAMERA_SHORTCUT);
|
||||
|
||||
if (this.preferences != null &&
|
||||
(!this.preferences.contains(KeyStorageInfoList) || !this.preferences.contains(KeyAddCameraShortcut))) {
|
||||
if (this.preferences != null && !this.preferences.contains(KeyStorageInfoList)) {
|
||||
this.preferences
|
||||
.edit()
|
||||
.putString(KeyStorageInfoList, globalSharedPreferences.getString(KeyStorageInfoList, "[]"))
|
||||
.putBoolean(KeyAddCameraShortcut, globalSharedPreferences.getBoolean(KeyAddCameraShortcut, true))
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
@ -257,7 +218,6 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
sharedPreferences
|
||||
.edit()
|
||||
.remove(context.getString(PREFERENCE_KEY_STORAGE_INFO_LIST))
|
||||
.remove(context.getString(PREFERENCE_KEY_ADD_CAMERA_SHORTCUT))
|
||||
.apply();
|
||||
}
|
||||
|
||||
@ -268,8 +228,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(context.getString(PREFERENCE_KEY_STORAGE_INFO_LIST)) ||
|
||||
key.equals(context.getString(PREFERENCE_KEY_ADD_CAMERA_SHORTCUT))) {
|
||||
if (key.equals(context.getString(PREFERENCE_KEY_STORAGE_INFO_LIST))) {
|
||||
//TODO: There used to be a way to request an un-mount (see desktop SftpPlugin's Mounter::onPackageReceived) but that is not handled anymore by the SftpPlugin on KDE.
|
||||
if (server.isStarted()) {
|
||||
server.stop();
|
||||
|
@ -47,8 +47,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
//TODO: Is it possible on API 19 to select a directory and then have write permission for everything beneath it
|
||||
//TODO: Is it necessary to check if uri permissions are still in place? If it is make the user aware of the fact (red text or something)
|
||||
public class SftpSettingsFragment
|
||||
extends PluginSettingsFragment
|
||||
implements StoragePreferenceDialogFragment.Callback,
|
||||
@ -100,34 +98,16 @@ public class SftpSettingsFragment
|
||||
int colorAccent = ta.getColor(0, 0);
|
||||
ta.recycle();
|
||||
|
||||
int sdkInt = Build.VERSION.SDK_INT;
|
||||
|
||||
storageInfoList = getStorageInfoList(requireContext(), plugin);
|
||||
|
||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
preferenceCategory = preferenceScreen
|
||||
.findPreference(getString(R.string.sftp_preference_key_preference_category));
|
||||
|
||||
if (sdkInt <= 19) {
|
||||
preferenceCategory.setTitle(R.string.sftp_preference_detected_sdcards);
|
||||
} else {
|
||||
preferenceCategory.setTitle(R.string.sftp_preference_configured_storage_locations);
|
||||
}
|
||||
|
||||
addStoragePreferences(preferenceCategory);
|
||||
|
||||
Preference addStoragePreference = preferenceScreen.findPreference(getString(R.string.sftp_preference_key_add_storage));
|
||||
addStoragePreference.getIcon().setColorFilter(colorAccent, PorterDuff.Mode.SRC_IN);
|
||||
|
||||
if (sdkInt <= 19) {
|
||||
addStoragePreference.setVisible(false);
|
||||
}
|
||||
|
||||
Preference addCameraShortcutPreference = preferenceScreen.findPreference(getString(R.string.sftp_preference_key_add_camera_shortcut));
|
||||
|
||||
if (sdkInt > 19) {
|
||||
addCameraShortcutPreference.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void addStoragePreferences(PreferenceCategory preferenceCategory) {
|
||||
@ -143,17 +123,11 @@ public class SftpSettingsFragment
|
||||
SftpPlugin.StorageInfo storageInfo = storageInfoList.get(i);
|
||||
StoragePreference preference = new StoragePreference(context);
|
||||
preference.setOnPreferenceChangeListener(this);
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
preference.setOnLongClickListener(this);
|
||||
}
|
||||
preference.setOnLongClickListener(this);
|
||||
preference.setKey(getString(R.string.sftp_preference_key_storage_info, i));
|
||||
preference.setIcon(android.R.color.transparent);
|
||||
preference.setDefaultValue(storageInfo);
|
||||
if (storageInfo.isFileUri()) {
|
||||
preference.setDialogTitle(R.string.sftp_preference_edit_sdcard_title);
|
||||
} else {
|
||||
preference.setDialogTitle(R.string.sftp_preference_edit_storage_location);
|
||||
}
|
||||
preference.setDialogTitle(R.string.sftp_preference_edit_storage_location);
|
||||
|
||||
preferenceCategory.addPreference(preference);
|
||||
}
|
||||
@ -266,53 +240,9 @@ public class SftpSettingsFragment
|
||||
Log.e("SFTPSettings", "Couldn't load storage info", e);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT <= 19) {
|
||||
addDetectedSDCardsToStorageInfoList(context, storageInfoList);
|
||||
}
|
||||
|
||||
return storageInfoList;
|
||||
}
|
||||
|
||||
private static void addDetectedSDCardsToStorageInfoList(@NonNull Context context, List<SftpPlugin.StorageInfo> storageInfoList) {
|
||||
List<StorageHelper.StorageInfo> storageHelperInfoList = StorageHelper.getStorageList();
|
||||
|
||||
for (StorageHelper.StorageInfo info : storageHelperInfoList) {
|
||||
// on at least API 17 emulator Environment.isExternalStorageRemovable returns false
|
||||
if (info.removable || info.path.startsWith(Environment.getExternalStorageDirectory().getPath())) {
|
||||
StringBuilder displayNameBuilder = new StringBuilder();
|
||||
StringBuilder displayNameReadOnlyBuilder = new StringBuilder();
|
||||
|
||||
Uri sdCardUri = Uri.fromFile(new File(info.path));
|
||||
|
||||
if (isAlreadyConfigured(storageInfoList, sdCardUri)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
|
||||
do {
|
||||
if (i == 1) {
|
||||
displayNameBuilder.append(context.getString(R.string.sftp_sdcard));
|
||||
} else {
|
||||
displayNameBuilder.setLength(0);
|
||||
displayNameBuilder.append(context.getString(R.string.sftp_sdcard_num, i));
|
||||
}
|
||||
|
||||
displayNameReadOnlyBuilder
|
||||
.append(displayNameBuilder)
|
||||
.append(" ")
|
||||
.append(context.getString(R.string.sftp_readonly));
|
||||
|
||||
i++;
|
||||
} while (!isDisplayNameUnique(storageInfoList, displayNameBuilder.toString(), displayNameReadOnlyBuilder.toString()));
|
||||
|
||||
String displayName = info.readonly ?
|
||||
displayNameReadOnlyBuilder.toString() : displayNameBuilder.toString();
|
||||
|
||||
storageInfoList.add(new SftpPlugin.StorageInfo(displayName, Uri.fromFile(new File(info.path))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDisplayNameUnique(List<SftpPlugin.StorageInfo> storageInfoList, String displayName, String displayNameReadOnly) {
|
||||
for (SftpPlugin.StorageInfo info : storageInfoList) {
|
||||
@ -470,14 +400,12 @@ public class SftpSettingsFragment
|
||||
if (preference.checkbox.isChecked()) {
|
||||
SftpPlugin.StorageInfo info = storageInfoList.remove(i);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
try {
|
||||
// This throws when trying to release a URI we don't have access to
|
||||
requireContext().getContentResolver().releasePersistableUriPermission(info.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
} catch (SecurityException e) {
|
||||
// Usually safe to ignore, but who knows?
|
||||
Log.e("SFTP Settings", "Exception", e);
|
||||
}
|
||||
try {
|
||||
// This throws when trying to release a URI we don't have access to
|
||||
requireContext().getContentResolver().releasePersistableUriPermission(info.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
} catch (SecurityException e) {
|
||||
// Usually safe to ignore, but who knows?
|
||||
Log.e("SFTP Settings", "Exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user