diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index 73b1b818..f5f27662 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -795,8 +795,7 @@ public class Device implements BaseLink.PackageReceiver { public boolean isPluginEnabled(String pluginKey) { boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault(); - boolean enabled = settings.getBoolean(pluginKey, enabledByDefault); - return enabled; + return settings.getBoolean(pluginKey, enabledByDefault); } public void reloadPluginsFromSettings() { diff --git a/src/org/kde/kdeconnect/Helpers/DeviceHelper.java b/src/org/kde/kdeconnect/Helpers/DeviceHelper.java index e04e5dba..374e7b75 100644 --- a/src/org/kde/kdeconnect/Helpers/DeviceHelper.java +++ b/src/org/kde/kdeconnect/Helpers/DeviceHelper.java @@ -477,8 +477,7 @@ public class DeviceHelper { public static boolean isTablet() { Configuration config = Resources.getSystem().getConfiguration(); //This assumes that the values for the screen sizes are consecutive, so XXLARGE > XLARGE > LARGE - boolean isLarge = ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); - return isLarge; + return ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); } //It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName(). diff --git a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java index a4f1ac1e..96ee2a95 100644 --- a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/RsaHelper.java @@ -54,7 +54,7 @@ public class RsaHelper { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2048); keyPair = keyGen.genKeyPair(); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); Log.e("KDE/initializeRsaKeys", "Exception"); return; @@ -64,43 +64,41 @@ public class RsaHelper { byte[] privateKey = keyPair.getPrivate().getEncoded(); SharedPreferences.Editor edit = settings.edit(); - edit.putString("publicKey", Base64.encodeToString(publicKey, 0).trim()+"\n"); - edit.putString("privateKey",Base64.encodeToString(privateKey, 0)); + edit.putString("publicKey", Base64.encodeToString(publicKey, 0).trim() + "\n"); + edit.putString("privateKey", Base64.encodeToString(privateKey, 0)); edit.apply(); } } - public static PublicKey getPublicKey (Context context) throws Exception{ + public static PublicKey getPublicKey(Context context) throws Exception { try { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); - PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); - return publicKey; - }catch (Exception e){ - throw e; - } - } - - public static PublicKey getPublicKey(Context context, String deviceId) throws Exception{ - try { - SharedPreferences settings = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE); - byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); - PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); - return publicKey; + + return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); } catch (Exception e) { throw e; } } - public static PrivateKey getPrivateKey(Context context) throws Exception{ + public static PublicKey getPublicKey(Context context, String deviceId) throws Exception { + try { + SharedPreferences settings = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE); + byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); + return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyBytes)); + } catch (Exception e) { + throw e; + } + } + + public static PrivateKey getPrivateKey(Context context) throws Exception { try { SharedPreferences globalSettings = PreferenceManager.getDefaultSharedPreferences(context); byte[] privateKeyBytes = Base64.decode(globalSettings.getString("privateKey", ""), 0); - PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes)); - return privateKey; + return KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes)); } catch (Exception e) { throw e; } @@ -138,7 +136,7 @@ public class RsaHelper { } - public static NetworkPackage decrypt(NetworkPackage np, PrivateKey privateKey) throws GeneralSecurityException, JSONException { + public static NetworkPackage decrypt(NetworkPackage np, PrivateKey privateKey) throws GeneralSecurityException, JSONException { JSONArray chunks = np.getJSONArray("data"); diff --git a/src/org/kde/kdeconnect/NetworkPackage.java b/src/org/kde/kdeconnect/NetworkPackage.java index f2975ac7..6b5a557b 100644 --- a/src/org/kde/kdeconnect/NetworkPackage.java +++ b/src/org/kde/kdeconnect/NetworkPackage.java @@ -161,8 +161,7 @@ public class NetworkPackage { jo.put("payloadTransferInfo", mPayloadTransferInfo); } //QJSon does not escape slashes, but Java JSONObject does. Converting to QJson format. - String json = jo.toString().replace("\\/","/")+"\n"; - return json; + return jo.toString().replace("\\/", "/") + "\n"; } static public NetworkPackage unserialize(String s) throws JSONException { diff --git a/src/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java b/src/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java index 9ea1f776..ee0f8fe3 100644 --- a/src/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java @@ -111,14 +111,12 @@ public class BatteryPlugin extends Plugin { @Override public String[] getSupportedPackageTypes() { - String[] packetTypes = {PACKAGE_TYPE_BATTERY_REQUEST}; - return packetTypes; + return new String[]{PACKAGE_TYPE_BATTERY_REQUEST}; } @Override public String[] getOutgoingPackageTypes() { - String[] packetTypes = {PACKAGE_TYPE_BATTERY}; - return packetTypes; + return new String[]{PACKAGE_TYPE_BATTERY}; } } diff --git a/src/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java b/src/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java index 97551e18..5bcb2abc 100644 --- a/src/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java @@ -75,14 +75,12 @@ public class ClipboardPlugin extends Plugin { @Override public String[] getSupportedPackageTypes() { - String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD}; - return packetTypes; + return new String[]{PACKAGE_TYPE_CLIPBOARD}; } @Override public String[] getOutgoingPackageTypes() { - String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD}; - return packetTypes; + return new String[]{PACKAGE_TYPE_CLIPBOARD}; } diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java index aaa3211f..0ec83789 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java @@ -133,8 +133,7 @@ public class SftpPlugin extends Plugin { @Override public String[] getRequiredPermissions() { - String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE}; - return perms; + return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}; } @Override