mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 14:45:08 +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 android.os.Build;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class HumanDeviceNames {
|
public class DeviceHelper {
|
||||||
|
|
||||||
//from https://github.com/meetup/android-device-names
|
//from https://github.com/meetup/android-device-names
|
||||||
//Converted to java using:
|
//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.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||||
import org.kde.kdeconnect.UserInterface.MainSettingsActivity;
|
import org.kde.kdeconnect.UserInterface.MainSettingsActivity;
|
||||||
import org.kde.kdeconnect_tp.R;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
@@ -28,6 +26,7 @@ public class NetworkPackage {
|
|||||||
|
|
||||||
public final static int ProtocolVersion = 5;
|
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_IDENTITY = "kdeconnect.identity";
|
||||||
public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair";
|
public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair";
|
||||||
public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted";
|
public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted";
|
||||||
@@ -222,15 +221,19 @@ public class NetworkPackage {
|
|||||||
np.mBody.put("deviceName",
|
np.mBody.put("deviceName",
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).getString(
|
PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||||
MainSettingsActivity.KEY_DEVICE_NAME_PREFERENCE,
|
MainSettingsActivity.KEY_DEVICE_NAME_PREFERENCE,
|
||||||
HumanDeviceNames.getDeviceName()));
|
DeviceHelper.getDeviceName()));
|
||||||
np.mBody.put("protocolVersion", NetworkPackage.ProtocolVersion);
|
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;
|
return np;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public NetworkPackage createPublicKeyPackage(Context context) {
|
static public NetworkPackage createPublicKeyPackage(Context context) {
|
||||||
|
|
||||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PAIR);
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PAIR);
|
||||||
|
@@ -13,7 +13,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.kde.kdeconnect.HumanDeviceNames;
|
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
public class MainSettingsActivity extends PreferenceActivity{
|
public class MainSettingsActivity extends PreferenceActivity{
|
||||||
@@ -79,7 +79,7 @@ public class MainSettingsActivity extends PreferenceActivity{
|
|||||||
Log.i("MainSettingsActivity", "New device name: " + deviceName);
|
Log.i("MainSettingsActivity", "New device name: " + deviceName);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
|
||||||
KEY_DEVICE_NAME_PREFERENCE,
|
KEY_DEVICE_NAME_PREFERENCE,
|
||||||
HumanDeviceNames.getDeviceName()).commit();
|
DeviceHelper.getDeviceName()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user