2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +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) {
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault();
boolean enabled = settings.getBoolean(pluginKey, enabledByDefault);
return enabled;
return settings.getBoolean(pluginKey, enabledByDefault);
}
public void reloadPluginsFromSettings() {

View File

@ -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().

View File

@ -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");

View File

@ -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 {

View File

@ -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};
}
}

View File

@ -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};
}

View File

@ -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