mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Added deviceType to the identity packages
This will tell if we are a phone, tablet, laptop or desktop
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package org.kde.kdeconnect;
|
||||
package org.kde.kdeconnect.Helpers;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HumanDeviceNames {
|
||||
public class DeviceHelper {
|
||||
|
||||
//from https://github.com/meetup/android-device-names
|
||||
//Converted to java using:
|
||||
@@ -167,4 +169,11 @@ public class HumanDeviceNames {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@@ -10,13 +10,11 @@ import android.util.Log;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||
import org.kde.kdeconnect.UserInterface.MainSettingsActivity;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
@@ -28,6 +26,7 @@ public class NetworkPackage {
|
||||
|
||||
public final static int ProtocolVersion = 5;
|
||||
|
||||
//TODO: Move these to their respective plugins
|
||||
public final static String PACKAGE_TYPE_IDENTITY = "kdeconnect.identity";
|
||||
public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair";
|
||||
public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted";
|
||||
@@ -222,15 +221,19 @@ public class NetworkPackage {
|
||||
np.mBody.put("deviceName",
|
||||
PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||
MainSettingsActivity.KEY_DEVICE_NAME_PREFERENCE,
|
||||
HumanDeviceNames.getDeviceName()));
|
||||
DeviceHelper.getDeviceName()));
|
||||
np.mBody.put("protocolVersion", NetworkPackage.ProtocolVersion);
|
||||
} catch (JSONException e) {
|
||||
np.mBody.put("deviceType", DeviceHelper.isTablet()? "tablet" : "phone");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("NetworkPacakge","Exception on createIdentityPackage");
|
||||
}
|
||||
|
||||
return np;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static public NetworkPackage createPublicKeyPackage(Context context) {
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PAIR);
|
||||
|
@@ -13,7 +13,7 @@ import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.kde.kdeconnect.HumanDeviceNames;
|
||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
|
||||
public class MainSettingsActivity extends PreferenceActivity{
|
||||
@@ -79,7 +79,7 @@ public class MainSettingsActivity extends PreferenceActivity{
|
||||
Log.i("MainSettingsActivity", "New device name: " + deviceName);
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
|
||||
KEY_DEVICE_NAME_PREFERENCE,
|
||||
HumanDeviceNames.getDeviceName()).commit();
|
||||
DeviceHelper.getDeviceName()).commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user