2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Inline more variables

Reviewers: #kde_connect, mtijink

Reviewed By: #kde_connect, mtijink

Subscribers: #kde_connect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D10945
This commit is contained in:
Nicolas Fella
2018-03-03 15:51:35 +01:00
parent 49021b87af
commit 0a08cd43cb
7 changed files with 27 additions and 37 deletions

View File

@@ -795,8 +795,7 @@ public class Device implements BaseLink.PackageReceiver {
public boolean isPluginEnabled(String pluginKey) { public boolean isPluginEnabled(String pluginKey) {
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault(); boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault();
boolean enabled = settings.getBoolean(pluginKey, enabledByDefault); return settings.getBoolean(pluginKey, enabledByDefault);
return enabled;
} }
public void reloadPluginsFromSettings() { public void reloadPluginsFromSettings() {

View File

@@ -477,8 +477,7 @@ public class DeviceHelper {
public static boolean isTablet() { public static boolean isTablet() {
Configuration config = Resources.getSystem().getConfiguration(); Configuration config = Resources.getSystem().getConfiguration();
//This assumes that the values for the screen sizes are consecutive, so XXLARGE > XLARGE > LARGE //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 ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
return isLarge;
} }
//It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName(). //It returns getAndroidDeviceName() if no user-defined name has been set with setDeviceName().

View File

@@ -54,7 +54,7 @@ public class RsaHelper {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048); keyGen.initialize(2048);
keyPair = keyGen.genKeyPair(); keyPair = keyGen.genKeyPair();
} catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.e("KDE/initializeRsaKeys", "Exception"); Log.e("KDE/initializeRsaKeys", "Exception");
return; return;
@@ -64,43 +64,41 @@ public class RsaHelper {
byte[] privateKey = keyPair.getPrivate().getEncoded(); byte[] privateKey = keyPair.getPrivate().getEncoded();
SharedPreferences.Editor edit = settings.edit(); SharedPreferences.Editor edit = settings.edit();
edit.putString("publicKey", Base64.encodeToString(publicKey, 0).trim()+"\n"); edit.putString("publicKey", Base64.encodeToString(publicKey, 0).trim() + "\n");
edit.putString("privateKey",Base64.encodeToString(privateKey, 0)); edit.putString("privateKey", Base64.encodeToString(privateKey, 0));
edit.apply(); edit.apply();
} }
} }
public static PublicKey getPublicKey (Context context) throws Exception{ public static PublicKey getPublicKey(Context context) throws Exception {
try { try {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); 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 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;
} catch (Exception e) { } catch (Exception e) {
throw 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 { try {
SharedPreferences globalSettings = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences globalSettings = PreferenceManager.getDefaultSharedPreferences(context);
byte[] privateKeyBytes = Base64.decode(globalSettings.getString("privateKey", ""), 0); byte[] privateKeyBytes = Base64.decode(globalSettings.getString("privateKey", ""), 0);
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes)); return KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyBytes));
return privateKey;
} catch (Exception e) { } catch (Exception e) {
throw 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"); JSONArray chunks = np.getJSONArray("data");

View File

@@ -161,8 +161,7 @@ public class NetworkPackage {
jo.put("payloadTransferInfo", mPayloadTransferInfo); jo.put("payloadTransferInfo", mPayloadTransferInfo);
} }
//QJSon does not escape slashes, but Java JSONObject does. Converting to QJson format. //QJSon does not escape slashes, but Java JSONObject does. Converting to QJson format.
String json = jo.toString().replace("\\/","/")+"\n"; return jo.toString().replace("\\/", "/") + "\n";
return json;
} }
static public NetworkPackage unserialize(String s) throws JSONException { static public NetworkPackage unserialize(String s) throws JSONException {

View File

@@ -111,14 +111,12 @@ public class BatteryPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
String[] packetTypes = {PACKAGE_TYPE_BATTERY_REQUEST}; return new String[]{PACKAGE_TYPE_BATTERY_REQUEST};
return packetTypes;
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
String[] packetTypes = {PACKAGE_TYPE_BATTERY}; return new String[]{PACKAGE_TYPE_BATTERY};
return packetTypes;
} }
} }

View File

@@ -75,14 +75,12 @@ public class ClipboardPlugin extends Plugin {
@Override @Override
public String[] getSupportedPackageTypes() { public String[] getSupportedPackageTypes() {
String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD}; return new String[]{PACKAGE_TYPE_CLIPBOARD};
return packetTypes;
} }
@Override @Override
public String[] getOutgoingPackageTypes() { public String[] getOutgoingPackageTypes() {
String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD}; return new String[]{PACKAGE_TYPE_CLIPBOARD};
return packetTypes;
} }

View File

@@ -133,8 +133,7 @@ public class SftpPlugin extends Plugin {
@Override @Override
public String[] getRequiredPermissions() { public String[] getRequiredPermissions() {
String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE}; return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
return perms;
} }
@Override @Override