2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-02 15:15:09 +00:00

Add NonNull annotations to Plugin and PluginFactory

This commit is contained in:
Albert Vaca Cintora
2023-05-26 22:19:21 +02:00
parent b065d5c1d1
commit 6b450d558e
26 changed files with 201 additions and 176 deletions

View File

@@ -40,12 +40,12 @@ public class BatteryPlugin extends Plugin {
private DeviceBatteryInfo remoteBatteryInfo; private DeviceBatteryInfo remoteBatteryInfo;
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_battery); return context.getResources().getString(R.string.pref_plugin_battery);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_battery_desc); return context.getResources().getString(R.string.pref_plugin_battery_desc);
} }
@@ -110,7 +110,7 @@ public class BatteryPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.getBoolean("request")) { if (np.getBoolean("request")) {
device.sendPacket(batteryInfo); device.sendPacket(batteryInfo);
@@ -139,12 +139,12 @@ public class BatteryPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_BATTERY_REQUEST, PACKET_TYPE_BATTERY}; return new String[]{PACKET_TYPE_BATTERY_REQUEST, PACKET_TYPE_BATTERY};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_BATTERY_REQUEST, PACKET_TYPE_BATTERY}; return new String[]{PACKET_TYPE_BATTERY_REQUEST, PACKET_TYPE_BATTERY};
} }

View File

@@ -17,6 +17,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.KeyEvent; import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Device;
@@ -42,12 +43,12 @@ public class BigscreenPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getString(R.string.pref_plugin_bigscreen); return context.getString(R.string.pref_plugin_bigscreen);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.pref_plugin_bigscreen_desc); return context.getString(R.string.pref_plugin_bigscreen_desc);
} }
@@ -79,19 +80,19 @@ public class BigscreenPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { return new String[]{PACKET_TYPE_BIGSCREEN_STT}; } public @NonNull String[] getSupportedPacketTypes() { return new String[]{PACKET_TYPE_BIGSCREEN_STT}; }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST, PACKET_TYPE_BIGSCREEN_STT}; return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST, PACKET_TYPE_BIGSCREEN_STT};
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.pref_plugin_bigscreen); return context.getString(R.string.pref_plugin_bigscreen);
} }
public String[] getOptionalPermissions() { public @NonNull String[] getOptionalPermissions() {
return new String[]{Manifest.permission.RECORD_AUDIO}; return new String[]{Manifest.permission.RECORD_AUDIO};
} }

View File

@@ -18,6 +18,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
@@ -54,17 +55,17 @@ public class ClipboardPlugin extends Plugin {
private final static String PACKET_TYPE_CLIPBOARD_CONNECT = "kdeconnect.clipboard.connect"; private final static String PACKET_TYPE_CLIPBOARD_CONNECT = "kdeconnect.clipboard.connect";
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_clipboard); return context.getResources().getString(R.string.pref_plugin_clipboard);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_clipboard_desc); return context.getResources().getString(R.string.pref_plugin_clipboard_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
String content = np.getString("content"); String content = np.getString("content");
switch (np.getType()) { switch (np.getType()) {
case (PACKET_TYPE_CLIPBOARD): case (PACKET_TYPE_CLIPBOARD):
@@ -114,17 +115,17 @@ public class ClipboardPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_CLIPBOARD, PACKET_TYPE_CLIPBOARD_CONNECT}; return new String[]{PACKET_TYPE_CLIPBOARD, PACKET_TYPE_CLIPBOARD_CONNECT};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_CLIPBOARD, PACKET_TYPE_CLIPBOARD_CONNECT}; return new String[]{PACKET_TYPE_CLIPBOARD, PACKET_TYPE_CLIPBOARD_CONNECT};
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.send_clipboard); return context.getString(R.string.send_clipboard);
} }

View File

@@ -16,6 +16,7 @@ import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import org.json.JSONException; import org.json.JSONException;
@@ -70,12 +71,12 @@ public class ConnectivityReportPlugin extends Plugin {
private final HashMap<Integer, SubscriptionState> states = new HashMap<>(); private final HashMap<Integer, SubscriptionState> states = new HashMap<>();
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_connectivity_report); return context.getResources().getString(R.string.pref_plugin_connectivity_report);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_connectivity_report_desc); return context.getResources().getString(R.string.pref_plugin_connectivity_report_desc);
} }
@@ -228,7 +229,7 @@ public class ConnectivityReportPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST.equals(np.getType())) { if (PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST.equals(np.getType())) {
Log.i("ConnectivityReport", "Requested"); Log.i("ConnectivityReport", "Requested");
serializeSignalStrengths(); serializeSignalStrengths();
@@ -239,17 +240,17 @@ public class ConnectivityReportPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST}; return new String[]{PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_CONNECTIVITY_REPORT}; return new String[]{PACKET_TYPE_CONNECTIVITY_REPORT};
} }
@Override @Override
public String[] getRequiredPermissions() { public @NonNull String[] getRequiredPermissions() {
return new String[]{ return new String[]{
Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_PHONE_STATE,
}; };

View File

@@ -12,6 +12,8 @@ package org.kde.kdeconnect.Plugins.ContactsPlugin;
import android.Manifest; import android.Manifest;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import org.kde.kdeconnect.Helpers.ContactsHelper; import org.kde.kdeconnect.Helpers.ContactsHelper;
import org.kde.kdeconnect.Helpers.ContactsHelper.ContactNotFoundException; import org.kde.kdeconnect.Helpers.ContactsHelper.ContactNotFoundException;
import org.kde.kdeconnect.Helpers.ContactsHelper.VCardBuilder; import org.kde.kdeconnect.Helpers.ContactsHelper.VCardBuilder;
@@ -66,17 +68,17 @@ public class ContactsPlugin extends Plugin {
private static final String PACKET_TYPE_CONTACTS_RESPONSE_VCARDS = "kdeconnect.contacts.response_vcards"; private static final String PACKET_TYPE_CONTACTS_RESPONSE_VCARDS = "kdeconnect.contacts.response_vcards";
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_contacts); return context.getResources().getString(R.string.pref_plugin_contacts);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_contacts_desc); return context.getResources().getString(R.string.pref_plugin_contacts_desc);
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS, PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS,
PACKET_TYPE_CONTACTS_REQUEST_VCARDS_BY_UIDS PACKET_TYPE_CONTACTS_REQUEST_VCARDS_BY_UIDS
@@ -84,7 +86,7 @@ public class ContactsPlugin extends Plugin {
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS, PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS,
PACKET_TYPE_CONTACTS_RESPONSE_VCARDS PACKET_TYPE_CONTACTS_RESPONSE_VCARDS
@@ -102,7 +104,7 @@ public class ContactsPlugin extends Plugin {
} }
@Override @Override
public String[] getRequiredPermissions() { public @NonNull String[] getRequiredPermissions() {
return new String[]{Manifest.permission.READ_CONTACTS}; return new String[]{Manifest.permission.READ_CONTACTS};
// One day maybe we will also support WRITE_CONTACTS, but not yet // One day maybe we will also support WRITE_CONTACTS, but not yet
} }
@@ -214,7 +216,7 @@ public class ContactsPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
switch (np.getType()) { switch (np.getType()) {
case PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS: case PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS:
return this.handleRequestAllUIDsTimestamps(np); return this.handleRequestAllUIDsTimestamps(np);

View File

@@ -20,6 +20,7 @@ import android.preference.PreferenceManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@@ -47,7 +48,7 @@ public class FindMyPhonePlugin extends Plugin {
private PowerManager powerManager; private PowerManager powerManager;
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
switch (DeviceHelper.getDeviceType(context)) { switch (DeviceHelper.getDeviceType(context)) {
case Tv: case Tv:
return context.getString(R.string.findmyphone_title_tv); return context.getString(R.string.findmyphone_title_tv);
@@ -60,7 +61,7 @@ public class FindMyPhonePlugin extends Plugin {
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.findmyphone_description); return context.getString(R.string.findmyphone_description);
} }
@@ -106,7 +107,7 @@ public class FindMyPhonePlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || LifecycleHelper.isInForeground()) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || LifecycleHelper.isInForeground()) {
Intent intent = new Intent(context, FindMyPhoneActivity.class); Intent intent = new Intent(context, FindMyPhoneActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -194,12 +195,12 @@ public class FindMyPhonePlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_FINDMYPHONE_REQUEST}; return new String[]{PACKET_TYPE_FINDMYPHONE_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }

View File

@@ -9,6 +9,8 @@ package org.kde.kdeconnect.Plugins.FindRemoteDevicePlugin;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhonePlugin; import org.kde.kdeconnect.Plugins.FindMyPhonePlugin.FindMyPhonePlugin;
@@ -20,22 +22,22 @@ import org.kde.kdeconnect_tp.R;
public class FindRemoteDevicePlugin extends Plugin { public class FindRemoteDevicePlugin extends Plugin {
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_findremotedevice); return context.getResources().getString(R.string.pref_plugin_findremotedevice);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_findremotedevice_desc); return context.getResources().getString(R.string.pref_plugin_findremotedevice_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
return true; return true;
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.ring); return context.getString(R.string.ring);
} }
@@ -57,12 +59,12 @@ public class FindRemoteDevicePlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{FindMyPhonePlugin.PACKET_TYPE_FINDMYPHONE_REQUEST}; return new String[]{FindMyPhonePlugin.PACKET_TYPE_FINDMYPHONE_REQUEST};
} }
} }

View File

@@ -11,6 +11,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
@@ -29,7 +30,7 @@ public class MousePadPlugin extends Plugin {
private boolean keyboardEnabled = true; private boolean keyboardEnabled = true;
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
keyboardEnabled = np.getBoolean("state", true); keyboardEnabled = np.getBoolean("state", true);
@@ -37,12 +38,12 @@ public class MousePadPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getString(R.string.pref_plugin_mousepad); return context.getString(R.string.pref_plugin_mousepad);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.pref_plugin_mousepad_desc); return context.getString(R.string.pref_plugin_mousepad_desc);
} }
@@ -74,17 +75,17 @@ public class MousePadPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE}; return new String[]{PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST}; return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST};
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.open_mousepad); return context.getString(R.string.open_mousepad);
} }

View File

@@ -10,9 +10,11 @@ import android.os.Build;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import org.apache.commons.lang3.ArrayUtils;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin; import org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin;
@@ -37,7 +39,7 @@ public class MouseReceiverPlugin extends Plugin {
} }
@Override @Override
public DialogFragment getPermissionExplanationDialog() { public @NonNull DialogFragment getPermissionExplanationDialog() {
return new StartActivityAlertDialogFragment.Builder() return new StartActivityAlertDialogFragment.Builder()
.setTitle(R.string.mouse_receiver_plugin_description) .setTitle(R.string.mouse_receiver_plugin_description)
.setMessage(R.string.mouse_receiver_no_permissions) .setMessage(R.string.mouse_receiver_no_permissions)
@@ -50,7 +52,7 @@ public class MouseReceiverPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (!np.getType().equals(PACKET_TYPE_MOUSEPAD_REQUEST)) { if (!np.getType().equals(PACKET_TYPE_MOUSEPAD_REQUEST)) {
Log.e("MouseReceiverPlugin", "Invalid packet type for MouseReceiverPlugin: " + np.getType()); Log.e("MouseReceiverPlugin", "Invalid packet type for MouseReceiverPlugin: " + np.getType());
return false; return false;
@@ -126,22 +128,22 @@ public class MouseReceiverPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getString(R.string.mouse_receiver_plugin_name); return context.getString(R.string.mouse_receiver_plugin_name);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.mouse_receiver_plugin_description); return context.getString(R.string.mouse_receiver_plugin_description);
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST}; return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[0]; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
} }

View File

@@ -13,6 +13,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
@@ -239,12 +240,12 @@ public class MprisPlugin extends Plugin {
private final ConcurrentHashMap<String, Callback> playerListUpdated = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, Callback> playerListUpdated = new ConcurrentHashMap<>();
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_mpris); return context.getResources().getString(R.string.pref_plugin_mpris);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_mpris_desc); return context.getResources().getString(R.string.pref_plugin_mpris_desc);
} }
@@ -305,7 +306,7 @@ public class MprisPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.getBoolean("transferringAlbumArt", false)) { if (np.getBoolean("transferringAlbumArt", false)) {
AlbumArtCache.payloadToDiskCache(np.getString("albumArtUrl"), np.getPayload()); AlbumArtCache.payloadToDiskCache(np.getString("albumArtUrl"), np.getPayload());
return true; return true;
@@ -405,12 +406,12 @@ public class MprisPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MPRIS}; return new String[]{PACKET_TYPE_MPRIS};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MPRIS_REQUEST}; return new String[]{PACKET_TYPE_MPRIS_REQUEST};
} }
@@ -493,7 +494,7 @@ public class MprisPlugin extends Plugin {
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.open_mpris_controls); return context.getString(R.string.open_mpris_controls);
} }

View File

@@ -15,6 +15,7 @@ import android.os.Looper;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@@ -86,17 +87,17 @@ public class MprisReceiverPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_mprisreceiver); return context.getResources().getString(R.string.pref_plugin_mprisreceiver);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_mprisreceiver_desc); return context.getResources().getString(R.string.pref_plugin_mprisreceiver_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.getBoolean("requestPlayerList")) { if (np.getBoolean("requestPlayerList")) {
sendPlayerList(); sendPlayerList();
@@ -158,12 +159,12 @@ public class MprisReceiverPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MPRIS_REQUEST}; return new String[]{PACKET_TYPE_MPRIS_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MPRIS}; return new String[]{PACKET_TYPE_MPRIS};
} }
@@ -233,7 +234,7 @@ public class MprisReceiverPlugin extends Plugin {
} }
@Override @Override
public DialogFragment getPermissionExplanationDialog() { public @NonNull DialogFragment getPermissionExplanationDialog() {
return new StartActivityAlertDialogFragment.Builder() return new StartActivityAlertDialogFragment.Builder()
.setTitle(R.string.pref_plugin_mpris) .setTitle(R.string.pref_plugin_mpris)
.setMessage(R.string.no_permission_mprisreceiver) .setMessage(R.string.no_permission_mprisreceiver)

View File

@@ -82,12 +82,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
private KeyguardManager keyguardManager; private KeyguardManager keyguardManager;
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_notifications); return context.getResources().getString(R.string.pref_plugin_notifications);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_notifications_desc); return context.getResources().getString(R.string.pref_plugin_notifications_desc);
} }
@@ -555,7 +555,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
} }
@Override @Override
public DialogFragment getPermissionExplanationDialog() { public @NonNull DialogFragment getPermissionExplanationDialog() {
return new StartActivityAlertDialogFragment.Builder() return new StartActivityAlertDialogFragment.Builder()
.setTitle(R.string.pref_plugin_notifications) .setTitle(R.string.pref_plugin_notifications)
.setMessage(R.string.no_permissions) .setMessage(R.string.no_permissions)
@@ -568,12 +568,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST, PACKET_TYPE_NOTIFICATION_REPLY, PACKET_TYPE_NOTIFICATION_ACTION}; return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST, PACKET_TYPE_NOTIFICATION_REPLY, PACKET_TYPE_NOTIFICATION_ACTION};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_NOTIFICATION}; return new String[]{PACKET_TYPE_NOTIFICATION};
} }

View File

@@ -11,6 +11,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.kde.kdeconnect.Helpers.FilesHelper; import org.kde.kdeconnect.Helpers.FilesHelper;
@@ -26,17 +27,17 @@ public class PhotoPlugin extends Plugin {
private final static String PACKET_TYPE_PHOTO_REQUEST = "kdeconnect.photo.request"; private final static String PACKET_TYPE_PHOTO_REQUEST = "kdeconnect.photo.request";
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.take_picture); return context.getResources().getString(R.string.take_picture);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.plugin_photo_desc); return context.getResources().getString(R.string.plugin_photo_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
Intent intent = new Intent(context, PhotoActivity.class); Intent intent = new Intent(context, PhotoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("deviceId", device.getDeviceId()); intent.putExtra("deviceId", device.getDeviceId());
@@ -62,12 +63,12 @@ public class PhotoPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_PHOTO_REQUEST}; return new String[]{PACKET_TYPE_PHOTO_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_PHOTO}; return new String[]{PACKET_TYPE_PHOTO};
} }

View File

@@ -14,6 +14,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@@ -30,17 +31,17 @@ public class PingPlugin extends Plugin {
private final static String PACKET_TYPE_PING = "kdeconnect.ping"; private final static String PACKET_TYPE_PING = "kdeconnect.ping";
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_ping); return context.getResources().getString(R.string.pref_plugin_ping);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_ping_desc); return context.getResources().getString(R.string.pref_plugin_ping_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (!np.getType().equals(PACKET_TYPE_PING)) { if (!np.getType().equals(PACKET_TYPE_PING)) {
Log.e("PingPlugin", "Ping plugin should not receive packets other than pings!"); Log.e("PingPlugin", "Ping plugin should not receive packets other than pings!");
@@ -86,7 +87,7 @@ public class PingPlugin extends Plugin {
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.send_ping); return context.getString(R.string.send_ping);
} }
@@ -108,12 +109,12 @@ public class PingPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_PING}; return new String[]{PACKET_TYPE_PING};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_PING}; return new String[]{PACKET_TYPE_PING};
} }

View File

@@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.NotNull;
import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.UserInterface.AlertDialogFragment; import org.kde.kdeconnect.UserInterface.AlertDialogFragment;
@@ -44,7 +45,7 @@ public abstract class Plugin {
} }
} }
public String getSharedPreferencesName() { public @NotNull String getSharedPreferencesName() {
if (device == null) { if (device == null) {
throw new RuntimeException("You have to call setContext() before you can call getSharedPreferencesName()"); throw new RuntimeException("You have to call setContext() before you can call getSharedPreferencesName()");
} }
@@ -55,8 +56,7 @@ public abstract class Plugin {
return this.getPluginKey() + "_preferences"; return this.getPluginKey() + "_preferences";
} }
@Nullable public @Nullable SharedPreferences getPreferences() {
public SharedPreferences getPreferences() {
return this.preferences; return this.preferences;
} }
@@ -64,7 +64,7 @@ public abstract class Plugin {
* To receive the network packet from the unpaired device, override * To receive the network packet from the unpaired device, override
* listensToUnpairedDevices to return true and this method. * listensToUnpairedDevices to return true and this method.
*/ */
public boolean onUnpairedDevicePacketReceived(NetworkPacket np) { public boolean onUnpairedDevicePacketReceived(@NonNull NetworkPacket np) {
return false; return false;
} }
@@ -80,11 +80,11 @@ public abstract class Plugin {
* Return the internal plugin name, that will be used as a * Return the internal plugin name, that will be used as a
* unique key to distinguish it. Use the class name as key. * unique key to distinguish it. Use the class name as key.
*/ */
public String getPluginKey() { public final @NonNull String getPluginKey() {
return getPluginKey(this.getClass()); return getPluginKey(this.getClass());
} }
public static String getPluginKey(Class<? extends Plugin> p) { public static @NonNull String getPluginKey(Class<? extends Plugin> p) {
return p.getSimpleName(); return p.getSimpleName();
} }
@@ -92,19 +92,19 @@ public abstract class Plugin {
* Return the human-readable plugin name. This function can * Return the human-readable plugin name. This function can
* access this.context to provide translated text. * access this.context to provide translated text.
*/ */
public abstract String getDisplayName(); public abstract @NonNull String getDisplayName();
/** /**
* Return the human-readable description of this plugin. This * Return the human-readable description of this plugin. This
* function can access this.context to provide translated text. * function can access this.context to provide translated text.
*/ */
public abstract String getDescription(); public abstract @NonNull String getDescription();
/** /**
* Return the action name displayed in the main activity, that * Return the action name displayed in the main activity, that
* will call startMainActivity when clicked * will call startMainActivity when clicked
*/ */
public String getActionName() { public @NonNull String getActionName() {
return getDisplayName(); return getDisplayName();
} }
@@ -112,7 +112,7 @@ public abstract class Plugin {
* Return an icon associated to this plugin. This function can * Return an icon associated to this plugin. This function can
* access this.context to load the image from resources. * access this.context to load the image from resources.
*/ */
public Drawable getIcon() { public @Nullable Drawable getIcon() {
return null; return null;
} }
@@ -148,7 +148,7 @@ public abstract class Plugin {
* *
* @return The PluginSettingsFragment used to display this plugins settings * @return The PluginSettingsFragment used to display this plugins settings
*/ */
public PluginSettingsFragment getSettingsFragment(Activity activity) { public @Nullable PluginSettingsFragment getSettingsFragment(Activity activity) {
throw new RuntimeException("Plugin doesn't reimplement getSettingsFragment: " + getPluginKey()); throw new RuntimeException("Plugin doesn't reimplement getSettingsFragment: " + getPluginKey());
} }
@@ -216,25 +216,25 @@ public abstract class Plugin {
* when we have done something in response to the packet or false * when we have done something in response to the packet or false
* otherwise, even though that value is unused as of now. * otherwise, even though that value is unused as of now.
*/ */
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
return false; return false;
} }
/** /**
* Should return the list of NetworkPacket types that this plugin can handle * Should return the list of NetworkPacket types that this plugin can handle
*/ */
public abstract String[] getSupportedPacketTypes(); public abstract @NonNull String[] getSupportedPacketTypes();
/** /**
* Should return the list of NetworkPacket types that this plugin can send * Should return the list of NetworkPacket types that this plugin can send
*/ */
public abstract String[] getOutgoingPacketTypes(); public abstract @NonNull String[] getOutgoingPacketTypes();
/** /**
* Should return the list of permissions from Manifest.permission.* that, if not present, * Should return the list of permissions from Manifest.permission.* that, if not present,
* mean the plugin can't be loaded. * mean the plugin can't be loaded.
*/ */
protected String[] getRequiredPermissions() { protected @NonNull String[] getRequiredPermissions() {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
@@ -242,7 +242,7 @@ public abstract class Plugin {
* Should return the list of permissions from Manifest.permission.* that enable additional * Should return the list of permissions from Manifest.permission.* that enable additional
* functionality in the plugin (without preventing the plugin to load). * functionality in the plugin (without preventing the plugin to load).
*/ */
protected String[] getOptionalPermissions() { protected @NonNull String[] getOptionalPermissions() {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
@@ -261,12 +261,12 @@ public abstract class Plugin {
} }
//Permission from Manifest.permission.* //Permission from Manifest.permission.*
protected boolean isPermissionGranted(String permission) { protected boolean isPermissionGranted(@NonNull String permission) {
int result = ContextCompat.checkSelfPermission(context, permission); int result = ContextCompat.checkSelfPermission(context, permission);
return (result == PackageManager.PERMISSION_GRANTED); return (result == PackageManager.PERMISSION_GRANTED);
} }
private boolean arePermissionsGranted(String[] permissions) { private boolean arePermissionsGranted(@NonNull String[] permissions) {
for (String permission : permissions) { for (String permission : permissions) {
if (!isPermissionGranted(permission)) { if (!isPermissionGranted(permission)) {
return false; return false;
@@ -275,7 +275,7 @@ public abstract class Plugin {
return true; return true;
} }
private PermissionsAlertDialogFragment requestPermissionDialog(final String[] permissions, @StringRes int reason) { private @NonNull PermissionsAlertDialogFragment requestPermissionDialog(@NonNull final String[] permissions, @StringRes int reason) {
return new PermissionsAlertDialogFragment.Builder() return new PermissionsAlertDialogFragment.Builder()
.setTitle(getDisplayName()) .setTitle(getDisplayName())
.setMessage(reason) .setMessage(reason)
@@ -291,11 +291,11 @@ public abstract class Plugin {
* the problem (and how to fix it, if possible) to the user. * the problem (and how to fix it, if possible) to the user.
*/ */
public DialogFragment getPermissionExplanationDialog() { public @NonNull DialogFragment getPermissionExplanationDialog() {
return requestPermissionDialog(getRequiredPermissions(), getPermissionExplanation()); return requestPermissionDialog(getRequiredPermissions(), getPermissionExplanation());
} }
public AlertDialogFragment getOptionalPermissionExplanationDialog() { public @NonNull AlertDialogFragment getOptionalPermissionExplanationDialog() {
return requestPermissionDialog(getOptionalPermissions(), getOptionalPermissionExplanation()); return requestPermissionDialog(getOptionalPermissions(), getOptionalPermissionExplanation());
} }

View File

@@ -6,13 +6,15 @@
package org.kde.kdeconnect.Plugins; package org.kde.kdeconnect.Plugins;
import static org.apache.commons.collections4.SetUtils.emptyIfNull;
import static org.apache.commons.collections4.SetUtils.unmodifiableSet; import static org.apache.commons.collections4.SetUtils.unmodifiableSet;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.atteo.classindex.ClassIndex; import org.atteo.classindex.ClassIndex;
import org.atteo.classindex.IndexAnnotated; import org.atteo.classindex.IndexAnnotated;
import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Device;
@@ -27,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class PluginFactory { public class PluginFactory {
public static void sortPluginList(List<String> plugins) { public static void sortPluginList(@NonNull List<String> plugins) {
plugins.sort(Comparator.comparing(o -> pluginInfo.get(o).displayName)); plugins.sort(Comparator.comparing(o -> pluginInfo.get(o).displayName));
} }
@@ -36,10 +38,10 @@ public class PluginFactory {
public static class PluginInfo { public static class PluginInfo {
PluginInfo(String displayName, String description, Drawable icon, PluginInfo(@NonNull String displayName, @NonNull String description, @Nullable Drawable icon,
boolean enabledByDefault, boolean hasSettings, boolean supportsDeviceSpecificSettings, boolean enabledByDefault, boolean hasSettings, boolean supportsDeviceSpecificSettings,
boolean listenToUnpaired, String[] supportedPacketTypes, String[] outgoingPacketTypes, boolean listenToUnpaired, @NonNull String[] supportedPacketTypes, @NonNull String[] outgoingPacketTypes,
Class<? extends Plugin> instantiableClass) { @NonNull Class<? extends Plugin> instantiableClass) {
this.displayName = displayName; this.displayName = displayName;
this.description = description; this.description = description;
this.icon = icon; this.icon = icon;
@@ -47,20 +49,20 @@ public class PluginFactory {
this.hasSettings = hasSettings; this.hasSettings = hasSettings;
this.supportsDeviceSpecificSettings = supportsDeviceSpecificSettings; this.supportsDeviceSpecificSettings = supportsDeviceSpecificSettings;
this.listenToUnpaired = listenToUnpaired; this.listenToUnpaired = listenToUnpaired;
this.supportedPacketTypes = emptyIfNull(unmodifiableSet(supportedPacketTypes)); this.supportedPacketTypes = unmodifiableSet(supportedPacketTypes);
this.outgoingPacketTypes = emptyIfNull(unmodifiableSet(outgoingPacketTypes)); this.outgoingPacketTypes = unmodifiableSet(outgoingPacketTypes);
this.instantiableClass = instantiableClass; this.instantiableClass = instantiableClass;
} }
public String getDisplayName() { public @NonNull String getDisplayName() {
return displayName; return displayName;
} }
public String getDescription() { public @NonNull String getDescription() {
return description; return description;
} }
public Drawable getIcon() { public @Nullable Drawable getIcon() {
return icon; return icon;
} }
@@ -90,15 +92,15 @@ public class PluginFactory {
return instantiableClass; return instantiableClass;
} }
private final String displayName; private final @NonNull String displayName;
private final String description; private final @NonNull String description;
private final Drawable icon; private final @Nullable Drawable icon;
private final boolean enabledByDefault; private final boolean enabledByDefault;
private final boolean hasSettings; private final boolean hasSettings;
private final boolean supportsDeviceSpecificSettings; private final boolean supportsDeviceSpecificSettings;
private final boolean listenToUnpaired; private final boolean listenToUnpaired;
private final Set<String> supportedPacketTypes; private final @NonNull Set<String> supportedPacketTypes;
private final Set<String> outgoingPacketTypes; private final @NonNull Set<String> outgoingPacketTypes;
private final Class<? extends Plugin> instantiableClass; private final Class<? extends Plugin> instantiableClass;
} }
@@ -126,11 +128,11 @@ public class PluginFactory {
Log.i("PluginFactory","Loaded "+pluginInfo.size()+" plugins"); Log.i("PluginFactory","Loaded "+pluginInfo.size()+" plugins");
} }
public static Set<String> getAvailablePlugins() { public static @NonNull Set<String> getAvailablePlugins() {
return pluginInfo.keySet(); return pluginInfo.keySet();
} }
public static Plugin instantiatePluginForDevice(Context context, String pluginKey, Device device) { public static @Nullable Plugin instantiatePluginForDevice(Context context, String pluginKey, Device device) {
PluginInfo info = pluginInfo.get(pluginKey); PluginInfo info = pluginInfo.get(pluginKey);
try { try {
Plugin plugin = info.getInstantiableClass().newInstance(); Plugin plugin = info.getInstantiableClass().newInstance();
@@ -142,7 +144,7 @@ public class PluginFactory {
} }
} }
public static Set<String> getIncomingCapabilities() { public static @NonNull Set<String> getIncomingCapabilities() {
HashSet<String> capabilities = new HashSet<>(); HashSet<String> capabilities = new HashSet<>();
for (PluginInfo plugin : pluginInfo.values()) { for (PluginInfo plugin : pluginInfo.values()) {
capabilities.addAll(plugin.getSupportedPacketTypes()); capabilities.addAll(plugin.getSupportedPacketTypes());
@@ -150,7 +152,7 @@ public class PluginFactory {
return capabilities; return capabilities;
} }
public static Set<String> getOutgoingCapabilities() { public static @NonNull Set<String> getOutgoingCapabilities() {
HashSet<String> capabilities = new HashSet<>(); HashSet<String> capabilities = new HashSet<>();
for (PluginInfo plugin : pluginInfo.values()) { for (PluginInfo plugin : pluginInfo.values()) {
capabilities.addAll(plugin.getOutgoingPacketTypes()); capabilities.addAll(plugin.getOutgoingPacketTypes());
@@ -158,7 +160,7 @@ public class PluginFactory {
return capabilities; return capabilities;
} }
public static Set<String> pluginsForCapabilities(Set<String> incoming, Set<String> outgoing) { public static @NonNull Set<String> pluginsForCapabilities(Set<String> incoming, Set<String> outgoing) {
HashSet<String> plugins = new HashSet<>(); HashSet<String> plugins = new HashSet<>();
for (Map.Entry<String, PluginInfo> entry : pluginInfo.entrySet()) { for (Map.Entry<String, PluginInfo> entry : pluginInfo.entrySet()) {
String pluginId = entry.getKey(); String pluginId = entry.getKey();

View File

@@ -15,6 +15,7 @@ import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.KeyEvent; import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@@ -35,7 +36,7 @@ public class PresenterPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getString(R.string.pref_plugin_presenter); return context.getString(R.string.pref_plugin_presenter);
} }
@@ -45,7 +46,7 @@ public class PresenterPlugin extends Plugin {
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.pref_plugin_presenter_desc); return context.getString(R.string.pref_plugin_presenter_desc);
} }
@@ -72,15 +73,15 @@ public class PresenterPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { return ArrayUtils.EMPTY_STRING_ARRAY; } public @NonNull String[] getSupportedPacketTypes() { return ArrayUtils.EMPTY_STRING_ARRAY; }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST, PACKET_TYPE_PRESENTER}; return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST, PACKET_TYPE_PRESENTER};
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.pref_plugin_presenter); return context.getString(R.string.pref_plugin_presenter);
} }

View File

@@ -14,6 +14,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@@ -33,12 +34,12 @@ public class ReceiveNotificationsPlugin extends Plugin {
private final static String PACKET_TYPE_NOTIFICATION_REQUEST = "kdeconnect.notification.request"; private final static String PACKET_TYPE_NOTIFICATION_REQUEST = "kdeconnect.notification.request";
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_receive_notifications); return context.getResources().getString(R.string.pref_plugin_receive_notifications);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_receive_notifications_desc); return context.getResources().getString(R.string.pref_plugin_receive_notifications_desc);
} }
@@ -113,12 +114,12 @@ public class ReceiveNotificationsPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_NOTIFICATION}; return new String[]{PACKET_TYPE_NOTIFICATION};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST}; return new String[]{PACKET_TYPE_NOTIFICATION_REQUEST};
} }
} }

View File

@@ -21,6 +21,7 @@ import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
@@ -143,12 +144,12 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getString(R.string.pref_plugin_remotekeyboard); return context.getString(R.string.pref_plugin_remotekeyboard);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getString(R.string.pref_plugin_remotekeyboard_desc); return context.getString(R.string.pref_plugin_remotekeyboard_desc);
} }
@@ -173,12 +174,12 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST}; return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_ECHO, PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE}; return new String[]{PACKET_TYPE_MOUSEPAD_ECHO, PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE};
} }
@@ -361,7 +362,7 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (!np.getType().equals(PACKET_TYPE_MOUSEPAD_REQUEST)) { if (!np.getType().equals(PACKET_TYPE_MOUSEPAD_REQUEST)) {
Log.e("RemoteKeyboardPlugin", "Invalid packet type for RemoteKeyboardPlugin: "+np.getType()); Log.e("RemoteKeyboardPlugin", "Invalid packet type for RemoteKeyboardPlugin: "+np.getType());
@@ -423,7 +424,7 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On
} }
@Override @Override
public DialogFragment getPermissionExplanationDialog() { public @NonNull DialogFragment getPermissionExplanationDialog() {
return new StartActivityAlertDialogFragment.Builder() return new StartActivityAlertDialogFragment.Builder()
.setTitle(R.string.pref_plugin_remotekeyboard) .setTitle(R.string.pref_plugin_remotekeyboard)
.setMessage(R.string.no_permissions_remotekeyboard) .setMessage(R.string.no_permissions_remotekeyboard)

View File

@@ -15,6 +15,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -67,12 +68,12 @@ public class RunCommandPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_runcommand); return context.getResources().getString(R.string.pref_plugin_runcommand);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_runcommand_desc); return context.getResources().getString(R.string.pref_plugin_runcommand_desc);
} }
@@ -89,7 +90,7 @@ public class RunCommandPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.has("commandList")) { if (np.has("commandList")) {
commandList.clear(); commandList.clear();
@@ -150,12 +151,12 @@ public class RunCommandPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_RUNCOMMAND}; return new String[]{PACKET_TYPE_RUNCOMMAND};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_RUNCOMMAND_REQUEST}; return new String[]{PACKET_TYPE_RUNCOMMAND_REQUEST};
} }
@@ -184,7 +185,7 @@ public class RunCommandPlugin extends Plugin {
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.pref_plugin_runcommand); return context.getString(R.string.pref_plugin_runcommand);
} }

View File

@@ -30,6 +30,7 @@ import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager; import android.telephony.SmsManager;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import com.klinker.android.logger.Log; import com.klinker.android.logger.Log;
@@ -374,17 +375,17 @@ public class SMSPlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telepathy); return context.getResources().getString(R.string.pref_plugin_telepathy);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_telepathy_desc); return context.getResources().getString(R.string.pref_plugin_telepathy_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
long subID; long subID;
switch (np.getType()) { switch (np.getType()) {
@@ -559,7 +560,7 @@ public class SMSPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_SMS_REQUEST, PACKET_TYPE_SMS_REQUEST,
TelephonyPlugin.PACKET_TYPE_TELEPHONY_REQUEST, TelephonyPlugin.PACKET_TYPE_TELEPHONY_REQUEST,
@@ -570,7 +571,7 @@ public class SMSPlugin extends Plugin {
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_SMS_MESSAGE, PACKET_TYPE_SMS_MESSAGE,
PACKET_TYPE_SMS_ATTACHMENT_FILE PACKET_TYPE_SMS_ATTACHMENT_FILE
@@ -578,7 +579,7 @@ public class SMSPlugin extends Plugin {
} }
@Override @Override
public String[] getRequiredPermissions() { public @NonNull String[] getRequiredPermissions() {
return new String[]{ return new String[]{
Manifest.permission.SEND_SMS, Manifest.permission.SEND_SMS,
Manifest.permission.READ_SMS, Manifest.permission.READ_SMS,

View File

@@ -49,12 +49,12 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
private static final SimpleSftpServer server = new SimpleSftpServer(); private static final SimpleSftpServer server = new SimpleSftpServer();
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_sftp); return context.getResources().getString(R.string.pref_plugin_sftp);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_sftp_desc); return context.getResources().getString(R.string.pref_plugin_sftp_desc);
} }
@@ -73,7 +73,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
} }
@Override @Override
public AlertDialogFragment getPermissionExplanationDialog() { public @NonNull AlertDialogFragment getPermissionExplanationDialog() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return new StartActivityAlertDialogFragment.Builder() return new StartActivityAlertDialogFragment.Builder()
.setTitle(getDisplayName()) .setTitle(getDisplayName())
@@ -106,7 +106,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.getBoolean("startBrowsing")) { if (np.getBoolean("startBrowsing")) {
if (!server.isInitialized()) { if (!server.isInitialized()) {
try { try {
@@ -219,12 +219,12 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_SFTP_REQUEST}; return new String[]{PACKET_TYPE_SFTP_REQUEST};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_SFTP}; return new String[]{PACKET_TYPE_SFTP};
} }

View File

@@ -79,7 +79,7 @@ public class SharePlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_sharereceiver); return context.getResources().getString(R.string.pref_plugin_sharereceiver);
} }
@@ -89,7 +89,7 @@ public class SharePlugin extends Plugin {
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_sharereceiver_desc); return context.getResources().getString(R.string.pref_plugin_sharereceiver_desc);
} }
@@ -99,7 +99,7 @@ public class SharePlugin extends Plugin {
} }
@Override @Override
public String getActionName() { public @NonNull String getActionName() {
return context.getString(R.string.send_files); return context.getString(R.string.send_files);
} }
@@ -117,7 +117,7 @@ public class SharePlugin extends Plugin {
@Override @Override
@WorkerThread @WorkerThread
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
try { try {
if (np.getType().equals(PACKET_TYPE_SHARE_REQUEST_UPDATE)) { if (np.getType().equals(PACKET_TYPE_SHARE_REQUEST_UPDATE)) {
if (receiveFileJob != null && receiveFileJob.isRunning()) { if (receiveFileJob != null && receiveFileJob.isRunning()) {
@@ -279,17 +279,17 @@ public class SharePlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_SHARE_REQUEST, PACKET_TYPE_SHARE_REQUEST_UPDATE}; return new String[]{PACKET_TYPE_SHARE_REQUEST, PACKET_TYPE_SHARE_REQUEST_UPDATE};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_SHARE_REQUEST}; return new String[]{PACKET_TYPE_SHARE_REQUEST};
} }
@Override @Override
public String[] getOptionalPermissions() { public @NonNull String[] getOptionalPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} else { } else {

View File

@@ -9,6 +9,8 @@ package org.kde.kdeconnect.Plugins.SystemVolumePlugin;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@@ -40,17 +42,17 @@ public class SystemVolumePlugin extends Plugin {
} }
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_systemvolume); return context.getResources().getString(R.string.pref_plugin_systemvolume);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_systemvolume_desc); return context.getResources().getString(R.string.pref_plugin_systemvolume_desc);
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
if (np.has("sinkList")) { if (np.has("sinkList")) {
sinks.clear(); sinks.clear();
@@ -128,12 +130,12 @@ public class SystemVolumePlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_SYSTEMVOLUME}; return new String[]{PACKET_TYPE_SYSTEMVOLUME};
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_SYSTEMVOLUME_REQUEST}; return new String[]{PACKET_TYPE_SYSTEMVOLUME_REQUEST};
} }

View File

@@ -22,6 +22,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@@ -122,12 +123,12 @@ public class TelephonyPlugin extends Plugin {
}; };
@Override @Override
public String getDisplayName() { public @NonNull String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telephony); return context.getResources().getString(R.string.pref_plugin_telephony);
} }
@Override @Override
public String getDescription() { public @NonNull String getDescription() {
return context.getResources().getString(R.string.pref_plugin_telephony_desc); return context.getResources().getString(R.string.pref_plugin_telephony_desc);
} }
@@ -263,7 +264,7 @@ public class TelephonyPlugin extends Plugin {
} }
@Override @Override
public boolean onPacketReceived(NetworkPacket np) { public boolean onPacketReceived(@NonNull NetworkPacket np) {
switch (np.getType()) { switch (np.getType()) {
case PACKET_TYPE_TELEPHONY_REQUEST: case PACKET_TYPE_TELEPHONY_REQUEST:
@@ -291,7 +292,7 @@ public class TelephonyPlugin extends Plugin {
} }
@Override @Override
public String[] getSupportedPacketTypes() { public @NonNull String[] getSupportedPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_TELEPHONY_REQUEST, PACKET_TYPE_TELEPHONY_REQUEST,
PACKET_TYPE_TELEPHONY_REQUEST_MUTE, PACKET_TYPE_TELEPHONY_REQUEST_MUTE,
@@ -299,14 +300,14 @@ public class TelephonyPlugin extends Plugin {
} }
@Override @Override
public String[] getOutgoingPacketTypes() { public @NonNull String[] getOutgoingPacketTypes() {
return new String[]{ return new String[]{
PACKET_TYPE_TELEPHONY PACKET_TYPE_TELEPHONY
}; };
} }
@Override @Override
public String[] getRequiredPermissions() { public @NonNull String[] getRequiredPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return new String[]{ return new String[]{
Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_PHONE_STATE,
@@ -318,7 +319,7 @@ public class TelephonyPlugin extends Plugin {
} }
@Override @Override
public String[] getOptionalPermissions() { public @NonNull String[] getOptionalPermissions() {
return new String[]{ return new String[]{
Manifest.permission.READ_CONTACTS, Manifest.permission.READ_CONTACTS,
}; };

View File

@@ -297,13 +297,13 @@ class DeviceFragment : Fragment() {
device.pluginsWithoutPermissions, device.pluginsWithoutPermissions,
R.string.plugins_need_permission R.string.plugins_need_permission
) { p: Plugin -> ) { p: Plugin ->
p.permissionExplanationDialog?.show(childFragmentManager, null) p.permissionExplanationDialog.show(childFragmentManager, null)
} }
createPermissionsList( createPermissionsList(
device.pluginsWithoutOptionalPermissions, device.pluginsWithoutOptionalPermissions,
R.string.plugins_need_optional_permission R.string.plugins_need_optional_permission
) { p: Plugin -> ) { p: Plugin ->
p.optionalPermissionExplanationDialog?.show(childFragmentManager, null) p.optionalPermissionExplanationDialog.show(childFragmentManager, null)
} }
requireDeviceBinding().permissionsList.adapter = requireDeviceBinding().permissionsList.adapter =