mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 13:17:43 +00:00
Use Kotlin's Charsets class.
This commit is contained in:
parent
fcae39846e
commit
1a2a01d3ff
@ -20,14 +20,12 @@
|
||||
|
||||
package org.kde.kdeconnect.Backends.BluetoothBackend;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothServerSocket;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.kde.kdeconnect.Backends.BaseLink;
|
||||
@ -40,10 +38,9 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.UUID;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
import kotlin.text.Charsets;
|
||||
|
||||
public class BluetoothLink extends BaseLink {
|
||||
private final ConnectionMultiplexer connection;
|
||||
@ -59,7 +56,7 @@ public class BluetoothLink extends BaseLink {
|
||||
public void run() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
Reader reader = new InputStreamReader(input, "UTF-8");
|
||||
Reader reader = new InputStreamReader(input, Charsets.UTF_8);
|
||||
char[] buf = new char[512];
|
||||
while (continueAccepting) {
|
||||
while (sb.indexOf("\n") == -1 && continueAccepting) {
|
||||
@ -146,7 +143,7 @@ public class BluetoothLink extends BaseLink {
|
||||
}
|
||||
|
||||
private void sendMessage(NetworkPacket np) throws JSONException, IOException {
|
||||
byte[] message = np.serialize().getBytes(Charset.forName("UTF-8"));
|
||||
byte[] message = np.serialize().getBytes(Charsets.UTF_8);
|
||||
Log.i("BluetoothLink", "Beginning to send message");
|
||||
output.write(message);
|
||||
Log.i("BluetoothLink", "Finished sending message");
|
||||
|
@ -48,6 +48,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import kotlin.text.Charsets;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public class BluetoothLinkProvider extends BaseLinkProvider {
|
||||
|
||||
@ -199,7 +201,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
|
||||
InputStream inputStream = connection.getDefaultInputStream();
|
||||
|
||||
NetworkPacket np = NetworkPacket.createIdentityPacket(context);
|
||||
byte[] message = np.serialize().getBytes("UTF-8");
|
||||
byte[] message = np.serialize().getBytes(Charsets.UTF_8);
|
||||
outputStream.write(message);
|
||||
outputStream.flush();
|
||||
|
||||
@ -207,7 +209,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
|
||||
|
||||
// Listen for the response
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Reader reader = new InputStreamReader(inputStream, "UTF-8");
|
||||
Reader reader = new InputStreamReader(inputStream, Charsets.UTF_8);
|
||||
int charsRead;
|
||||
char[] buf = new char[512];
|
||||
while (sb.lastIndexOf("\n") == -1 && (charsRead = reader.read(buf)) != -1) {
|
||||
|
@ -23,12 +23,13 @@ package org.kde.kdeconnect.Backends.LanBackend;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.kde.kdeconnect.Backends.BaseLink;
|
||||
import org.kde.kdeconnect.Backends.BasePairingHandler;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||
import org.kde.kdeconnect.Helpers.StringsHelper;
|
||||
import org.kde.kdeconnect.NetworkPacket;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -45,7 +46,7 @@ import java.nio.channels.NotYetConnectedException;
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
import kotlin.text.Charsets;
|
||||
|
||||
public class LanLink extends BaseLink {
|
||||
|
||||
@ -92,7 +93,7 @@ public class LanLink extends BaseLink {
|
||||
//Create a thread to take care of incoming data for the new socket
|
||||
new Thread(() -> {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), Charsets.UTF_8));
|
||||
while (true) {
|
||||
String packet;
|
||||
try {
|
||||
@ -167,7 +168,7 @@ public class LanLink extends BaseLink {
|
||||
//Send body of the network package
|
||||
try {
|
||||
OutputStream writer = socket.getOutputStream();
|
||||
writer.write(np.serialize().getBytes(StringsHelper.UTF8));
|
||||
writer.write(np.serialize().getBytes(Charsets.UTF_8));
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
disconnect(); //main socket is broken, disconnect
|
||||
|
@ -32,7 +32,6 @@ import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||
import org.kde.kdeconnect.Helpers.StringsHelper;
|
||||
import org.kde.kdeconnect.Helpers.TrustedNetworkHelper;
|
||||
import org.kde.kdeconnect.NetworkPacket;
|
||||
import org.kde.kdeconnect.UserInterface.CustomDevicesActivity;
|
||||
@ -57,6 +56,8 @@ import java.util.TimerTask;
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import kotlin.text.Charsets;
|
||||
|
||||
/**
|
||||
* This BaseLinkProvider creates {@link LanLink}s to other devices on the same
|
||||
* WiFi network. The first packet sent over a socket must be an
|
||||
@ -122,7 +123,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
||||
|
||||
try {
|
||||
|
||||
String message = new String(packet.getData(), StringsHelper.UTF8);
|
||||
String message = new String(packet.getData(), Charsets.UTF_8);
|
||||
final NetworkPacket identityPacket = NetworkPacket.unserialize(message);
|
||||
final String deviceId = identityPacket.getString("deviceId");
|
||||
if (!identityPacket.getType().equals(NetworkPacket.PACKET_TYPE_IDENTITY)) {
|
||||
@ -388,7 +389,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
||||
socket = new DatagramSocket();
|
||||
socket.setReuseAddress(true);
|
||||
socket.setBroadcast(true);
|
||||
bytes = identity.serialize().getBytes(StringsHelper.UTF8);
|
||||
bytes = identity.serialize().getBytes(Charsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
Log.e("KDE/LanLinkProvider", "Failed to create DatagramSocket", e);
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import kotlin.text.Charsets;
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
public class SMSHelper {
|
||||
|
||||
@ -799,7 +801,7 @@ public class SMSHelper {
|
||||
try (InputStream is = context.getContentResolver().openInputStream(partURI)) {
|
||||
if (is != null) {
|
||||
// The stream is buffered internally, so buffering it separately is unnecessary.
|
||||
body = IOUtils.toString(is, StringsHelper.UTF8);
|
||||
body = IOUtils.toString(is, Charsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SMSHelper.MessageAccessException(partURI, e);
|
||||
|
@ -1,8 +0,0 @@
|
||||
package org.kde.kdeconnect.Helpers;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class StringsHelper {
|
||||
|
||||
public static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user