From db3f4a2fec2ff9a40e723d5bf0a6c63e0ebf527f Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 1 Mar 2015 20:57:45 -0800 Subject: [PATCH] We now update the name of a device if it changed the next time we see it --- src/org/kde/kdeconnect/Device.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index 4c49af83..547301ca 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -56,7 +56,7 @@ public class Device implements BaseLink.PackageReceiver { private final Context context; private final String deviceId; - private final String name; + private String name; public PublicKey publicKey; private int notificationId; private int protocolVersion; @@ -93,7 +93,7 @@ public class Device implements BaseLink.PackageReceiver { this.context = context; this.deviceId = deviceId; - this.name = settings.getString("deviceName", "unknown device"); + this.name = settings.getString("deviceName", context.getString(R.string.unknown_device)); this.pairStatus = PairStatus.Paired; this.protocolVersion = NetworkPackage.ProtocolVersion; //We don't know it yet @@ -115,7 +115,7 @@ public class Device implements BaseLink.PackageReceiver { this.context = context; this.deviceId = np.getString("deviceId"); - this.name = np.getString("deviceName", "unidentified device"); + this.name = np.getString("deviceName", context.getString(R.string.unknown_device)); this.protocolVersion = np.getInt("protocolVersion"); this.pairStatus = PairStatus.NotPaired; this.publicKey = null; @@ -324,6 +324,16 @@ public class Device implements BaseLink.PackageReceiver { this.protocolVersion = identityPackage.getInt("protocolVersion"); + if (identityPackage.has("deviceName")) { + this.name = identityPackage.getString("deviceName", this.name); + SharedPreferences.Editor editor = settings.edit(); + editor.putString("deviceName", this.name); + String encodedPublicKey = Base64.encodeToString(publicKey.getEncoded(), 0); + editor.putString("publicKey", encodedPublicKey); + editor.apply(); + } + + links.add(link); try {