mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Begun to bring back 2.3 compatibility
Removed use of SharedPreferences.getStringSet
This commit is contained in:
@@ -6,9 +6,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -17,8 +15,10 @@ import org.kde.connect.LinkProviders.BaseLinkProvider;
|
||||
import org.kde.connect.LinkProviders.BroadcastTcpLinkProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BackgroundService extends Service {
|
||||
@@ -28,11 +28,12 @@ public class BackgroundService extends Service {
|
||||
private HashMap<String, Device> devices = new HashMap<String, Device>();
|
||||
|
||||
private void loadRememberedDevicesFromSettings() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
Set<String> trustedDevices = preferences.getStringSet("trusted", new HashSet<String>());
|
||||
SharedPreferences preferences = getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
|
||||
Set<String> trustedDevices = preferences.getAll().keySet();
|
||||
for(String deviceId : trustedDevices) {
|
||||
Log.e("loadRememberedDevicesFromSettings",deviceId);
|
||||
devices.put(deviceId,new Device(getBaseContext(), deviceId));
|
||||
if (preferences.getBoolean(deviceId, false)) {
|
||||
devices.put(deviceId,new Device(getBaseContext(), deviceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -31,13 +31,13 @@ public class Device implements BaseComputerLink.PackageReceiver {
|
||||
|
||||
//Remembered trusted device, we need to wait for a incoming devicelink to communicate
|
||||
Device(Context context, String deviceId) {
|
||||
settings = context.getSharedPreferences(deviceId,Context.MODE_PRIVATE);
|
||||
settings = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE);
|
||||
|
||||
//Log.e("Device","Constructor A");
|
||||
|
||||
this.context = context;
|
||||
this.deviceId = deviceId;
|
||||
this.name = settings.getString("deviceName",null);
|
||||
this.name = settings.getString("deviceName", null);
|
||||
this.trusted = true;
|
||||
|
||||
reloadPluginsFromSettings();
|
||||
@@ -45,7 +45,7 @@ public class Device implements BaseComputerLink.PackageReceiver {
|
||||
|
||||
//Device known via an incoming connection sent to us via a devicelink, we know everything but we don't trust it yet
|
||||
Device(Context context, String deviceId, String name, BaseComputerLink dl) {
|
||||
settings = context.getSharedPreferences(deviceId,Context.MODE_PRIVATE);
|
||||
settings = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE);
|
||||
|
||||
//Log.e("Device","Constructor B");
|
||||
|
||||
@@ -86,23 +86,14 @@ public class Device implements BaseComputerLink.PackageReceiver {
|
||||
public void setTrusted(boolean b) {
|
||||
trusted = b;
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> trustedDevices = preferences.getStringSet("trusted", new HashSet<String>());
|
||||
SharedPreferences preferences = context.getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
|
||||
|
||||
boolean wasTrusted = trustedDevices.contains(deviceId);
|
||||
|
||||
if (trusted != wasTrusted) {
|
||||
if (trusted) {
|
||||
//Log.e("trust",deviceId);
|
||||
trustedDevices.add(deviceId);
|
||||
} else {
|
||||
//Log.e("untrust",deviceId);
|
||||
trustedDevices.remove(deviceId);
|
||||
}
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putStringSet("trusted",trustedDevices);
|
||||
editor.commit();
|
||||
boolean wasTrusted = preferences.getBoolean(deviceId, false);
|
||||
|
||||
if (trusted && !wasTrusted) {
|
||||
preferences.edit().putBoolean(deviceId, true).commit();
|
||||
} else if(!trusted && wasTrusted) {
|
||||
preferences.edit().remove(deviceId).commit();
|
||||
}
|
||||
|
||||
reloadPluginsFromSettings();
|
||||
@@ -122,7 +113,6 @@ public class Device implements BaseComputerLink.PackageReceiver {
|
||||
|
||||
Log.e("Device","addLink "+link.getLinkProvider().getName()+" -> "+getName() + " active links: "+ links.size());
|
||||
|
||||
|
||||
Collections.sort(links, new Comparator<BaseComputerLink>() {
|
||||
@Override
|
||||
public int compare(BaseComputerLink o, BaseComputerLink o2) {
|
||||
|
Reference in New Issue
Block a user