2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-01 14:45:08 +00:00

Compare commits

...

1 Commits

Author SHA1 Message Date
Albert Vaca Cintora
36636406b0 Require Android 6 (API 32) 2024-05-12 16:25:11 +02:00
14 changed files with 38 additions and 129 deletions

View File

@@ -43,7 +43,7 @@ android {
namespace = "org.kde.kdeconnect_tp" namespace = "org.kde.kdeconnect_tp"
compileSdk = 34 compileSdk = 34
defaultConfig { defaultConfig {
minSdk = 21 minSdk = 23
targetSdk = 33 targetSdk = 33
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
} }

View File

@@ -414,7 +414,7 @@ public class LanLinkProvider extends BaseLinkProvider {
DatagramSocket socket; DatagramSocket socket;
try { try {
socket = new DatagramSocket(); socket = new DatagramSocket();
if (network != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { if (network != null) {
try { try {
network.bindSocket(socket); network.bindSocket(socket);
} catch (IOException e) { } catch (IOException e) {

View File

@@ -222,9 +222,6 @@ object SMSHelper {
* @param context android.content.Context running the request. * @param context android.content.Context running the request.
*/ */
private fun getSubscriptionIdSupport(uri: Uri, context: Context): Boolean { private fun getSubscriptionIdSupport(uri: Uri, context: Context): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
return false
}
// Some (Xiaomi) devices running >= Android Lollipop (SDK 22+) don't support // Some (Xiaomi) devices running >= Android Lollipop (SDK 22+) don't support
// `Telephony.Sms.SUBSCRIPTION_ID`, so additional check is needed. // `Telephony.Sms.SUBSCRIPTION_ID`, so additional check is needed.
// It may be possible to use "sim_id" instead of "sub_id" on these devices // It may be possible to use "sim_id" instead of "sub_id" on these devices
@@ -1109,7 +1106,6 @@ object SMSHelper {
* These columns are for determining what SIM card the message belongs to, and therefore * These columns are for determining what SIM card the message belongs to, and therefore
* are only defined on Android versions with multi-sim capabilities * are only defined on Android versions with multi-sim capabilities
*/ */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
val multiSIMColumns = arrayOf(Telephony.Sms.SUBSCRIPTION_ID) val multiSIMColumns = arrayOf(Telephony.Sms.SUBSCRIPTION_ID)
} }
} }

View File

@@ -35,16 +35,10 @@ public class RsaHelper {
String keyAlgorithm; String keyAlgorithm;
try { try {
KeyPairGenerator keyGen; KeyPairGenerator keyGen;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { keyAlgorithm = KeyProperties.KEY_ALGORITHM_EC;
keyAlgorithm = KeyProperties.KEY_ALGORITHM_EC; keyGen = KeyPairGenerator.getInstance(keyAlgorithm);
keyGen = KeyPairGenerator.getInstance(keyAlgorithm); ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1"); keyGen.initialize(spec);
keyGen.initialize(spec);
} else {
keyAlgorithm = "RSA";
keyGen = KeyPairGenerator.getInstance(keyAlgorithm);
keyGen.initialize(2048);
}
keyPair = keyGen.generateKeyPair(); keyPair = keyGen.generateKeyPair();
} catch (Exception e) { } catch (Exception e) {
Log.e("KDE/initializeRsaKeys", "Exception", e); Log.e("KDE/initializeRsaKeys", "Exception", e);

View File

@@ -37,7 +37,6 @@ public class TelephonyHelper {
* Get all subscriptionIDs of the device * Get all subscriptionIDs of the device
* As far as I can tell, this is essentially a way of identifying particular SIM cards * As far as I can tell, this is essentially a way of identifying particular SIM cards
*/ */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public static List<Integer> getActiveSubscriptionIDs( public static List<Integer> getActiveSubscriptionIDs(
@NonNull Context context) @NonNull Context context)
throws SecurityException { throws SecurityException {
@@ -73,7 +72,6 @@ public class TelephonyHelper {
* This lets you identify additions/removals of SIM cards. * This lets you identify additions/removals of SIM cards.
* Make sure to call `cancelActiveSubscriptionIDsListener` with the return value of this once you're done. * Make sure to call `cancelActiveSubscriptionIDsListener` with the return value of this once you're done.
*/ */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public static OnSubscriptionsChangedListener listenActiveSubscriptionIDs( public static OnSubscriptionsChangedListener listenActiveSubscriptionIDs(
@NonNull Context context, SubscriptionCallback onAdd, SubscriptionCallback onRemove) { @NonNull Context context, SubscriptionCallback onAdd, SubscriptionCallback onRemove) {
SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class); SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class);
@@ -117,7 +115,6 @@ public class TelephonyHelper {
/** /**
* Cancels a listener created by `listenActiveSubscriptionIDs` * Cancels a listener created by `listenActiveSubscriptionIDs`
*/ */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public static void cancelActiveSubscriptionIDsListener(@NonNull Context context, @NonNull OnSubscriptionsChangedListener listener) { public static void cancelActiveSubscriptionIDsListener(@NonNull Context context, @NonNull OnSubscriptionsChangedListener listener) {
SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class); SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class);
if (sm == null) { if (sm == null) {
@@ -139,44 +136,26 @@ public class TelephonyHelper {
public static @NonNull List<LocalPhoneNumber> getAllPhoneNumbers( public static @NonNull List<LocalPhoneNumber> getAllPhoneNumbers(
@NonNull Context context) @NonNull Context context)
throws SecurityException { throws SecurityException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { // Potentially multi-sim
// Single-sim case SubscriptionManager subscriptionManager = ContextCompat.getSystemService(context,
// From https://stackoverflow.com/a/25131061/3723163 SubscriptionManager.class);
// Android added support for multi-sim devices in Lollypop v5.1 (api 22) if (subscriptionManager == null) {
// See: https://developer.android.com/about/versions/android-5.1.html#multisim // I don't know why or when this happens...
// There were vendor-specific implmentations before then, but those are very difficult to support Log.w(LOGGING_TAG, "Could not get SubscriptionManager");
// S/O Reference: https://stackoverflow.com/a/28571835/3723163 return Collections.emptyList();
TelephonyManager telephonyManager = ContextCompat.getSystemService(context,
TelephonyManager.class);
if (telephonyManager == null) {
// I don't know why or when this happens...
Log.w(LOGGING_TAG, "Could not get TelephonyManager");
return Collections.emptyList();
}
LocalPhoneNumber phoneNumber = getPhoneNumber(telephonyManager);
return Collections.singletonList(phoneNumber);
} else {
// Potentially multi-sim case
SubscriptionManager subscriptionManager = ContextCompat.getSystemService(context,
SubscriptionManager.class);
if (subscriptionManager == null) {
// I don't know why or when this happens...
Log.w(LOGGING_TAG, "Could not get SubscriptionManager");
return Collections.emptyList();
}
List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfos == null) {
// This happens when there is no SIM card inserted
Log.w(LOGGING_TAG, "Could not get SubscriptionInfos");
return Collections.emptyList();
}
List<LocalPhoneNumber> phoneNumbers = new ArrayList<>(subscriptionInfos.size());
for (SubscriptionInfo info : subscriptionInfos) {
LocalPhoneNumber thisPhoneNumber = new LocalPhoneNumber(info.getNumber(), info.getSubscriptionId());
phoneNumbers.add(thisPhoneNumber);
}
return phoneNumbers.stream().filter(localPhoneNumber -> localPhoneNumber.number != null).collect(Collectors.toList());
} }
List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfos == null) {
// This happens when there is no SIM card inserted
Log.w(LOGGING_TAG, "Could not get SubscriptionInfos");
return Collections.emptyList();
}
List<LocalPhoneNumber> phoneNumbers = new ArrayList<>(subscriptionInfos.size());
for (SubscriptionInfo info : subscriptionInfos) {
LocalPhoneNumber thisPhoneNumber = new LocalPhoneNumber(info.getNumber(), info.getSubscriptionId());
phoneNumbers.add(thisPhoneNumber);
}
return phoneNumbers.stream().filter(localPhoneNumber -> localPhoneNumber.number != null).collect(Collectors.toList());
} }
/** /**
@@ -245,14 +224,7 @@ public class TelephonyHelper {
Uri telephonyCarriersUri = Telephony.Carriers.CONTENT_URI; Uri telephonyCarriersUri = Telephony.Carriers.CONTENT_URI;
Uri telephonyCarriersPreferredApnUri; Uri telephonyCarriersPreferredApnUri = Uri.withAppendedPath(telephonyCarriersUri, "/preferapn/subId/" + subscriptionId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
telephonyCarriersPreferredApnUri = Uri.withAppendedPath(telephonyCarriersUri, "/preferapn/subId/" + subscriptionId);
} else {
// Ignore subID for devices before that existed
telephonyCarriersPreferredApnUri = Uri.withAppendedPath(telephonyCarriersUri, "/preferapn/");
}
try (Cursor cursor = context.getContentResolver().query( try (Cursor cursor = context.getContentResolver().query(
telephonyCarriersPreferredApnUri, telephonyCarriersPreferredApnUri,

View File

@@ -11,33 +11,6 @@ import android.telephony.CellInfo;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
public class ASUUtils { public class ASUUtils {
/**
* Implementation of SignalStrength.toLevel usable from API Level 7+
*/
public static int signalStrengthToLevel(SignalStrength signalStrength) {
int level;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
level = signalStrength.getLevel();
} else {
// Should work on all supported versions, uses copied functions from modern SDKs
// Needs testing
int gsmLevel = signalStrength.getGsmSignalStrength();
if (gsmLevel >= 0 && gsmLevel <= 31) {
// Convert getGsmSignalStrength range (0..31) to getLevel range (0..4)
gsmLevel = gsmLevel * 4 / 31;
} else {
gsmLevel = 0;
}
int cdmaLevel = getCdmaLevel(signalStrength.getCdmaDbm(), signalStrength.getCdmaEcio());
int evdoLevel = getEvdoLevel(signalStrength.getEvdoDbm(), signalStrength.getEvdoSnr());
level = Math.max(gsmLevel, Math.max(cdmaLevel, evdoLevel));
}
return level;
}
/** /**
* Get cdma as level 0..4 * Get cdma as level 0..4

View File

@@ -136,7 +136,7 @@ public class ConnectivityReportPlugin extends Plugin {
return new PhoneStateListener() { return new PhoneStateListener() {
@Override @Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) { public void onSignalStrengthsChanged(SignalStrength signalStrength) {
int level = ASUUtils.signalStrengthToLevel(signalStrength); int level = signalStrength.getLevel();
SubscriptionState state = states.get(subID); SubscriptionState state = states.get(subID);
if (state != null) { if (state != null) {

View File

@@ -58,7 +58,6 @@ public class SendKeystrokesToHostActivity extends AppCompatActivity {
} }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1) // needed for this.getReferrer()
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();

View File

@@ -15,7 +15,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
class MprisReceiverCallback extends MediaController.Callback { class MprisReceiverCallback extends MediaController.Callback {
private static final String TAG = "MprisReceiver"; private static final String TAG = "MprisReceiver";

View File

@@ -38,7 +38,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@PluginFactory.LoadablePlugin @PluginFactory.LoadablePlugin
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public class MprisReceiverPlugin extends Plugin { public class MprisReceiverPlugin extends Plugin {
private final static String PACKET_TYPE_MPRIS = "kdeconnect.mpris"; private final static String PACKET_TYPE_MPRIS = "kdeconnect.mpris";
private final static String PACKET_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request"; private final static String PACKET_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request";

View File

@@ -303,10 +303,8 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
try { try {
Context foreignContext = context.createPackageContext(statusBarNotification.getPackageName(), 0); Context foreignContext = context.createPackageContext(statusBarNotification.getPackageName(), 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notification.getLargeIcon() != null) { if (notification.getLargeIcon() != null) {
return iconToBitmap(foreignContext, notification.getLargeIcon()); return iconToBitmap(foreignContext, notification.getLargeIcon());
} else if (notification.largeIcon != null) {
return notification.largeIcon;
} }
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
@@ -398,7 +396,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return res; return res;
} }
@RequiresApi(Build.VERSION_CODES.M)
private Bitmap iconToBitmap(Context foreignContext, Icon icon) { private Bitmap iconToBitmap(Context foreignContext, Icon icon) {
if (icon == null) return null; if (icon == null) return null;

View File

@@ -57,11 +57,9 @@ public class RunCommandUrlActivity extends AppCompatActivity {
plugin.runCommand(uri.getPathSegments().get(1)); plugin.runCommand(uri.getPathSegments().get(1));
RunCommandUrlActivity.this.finish(); RunCommandUrlActivity.this.finish();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { Vibrator vibrator = getSystemService(Vibrator.class);
Vibrator vibrator = getSystemService(Vibrator.class); if(vibrator != null && vibrator.hasVibrator()) {
if(vibrator != null && vibrator.hasVibrator()) { vibrator.vibrate(100);
vibrator.vibrate(100);
}
} }
} catch (Exception e) { } catch (Exception e) {
Log.e("RuncommandPlugin", "Exception", e); Log.e("RuncommandPlugin", "Exception", e);

View File

@@ -176,12 +176,7 @@ public class SmsMmsUtils {
if (transaction.checkMMS(message)) { if (transaction.checkMMS(message)) {
Log.v("", "Sending new MMS"); Log.v("", "Sending new MMS");
//transaction.sendNewMessage(message, Transaction.NO_THREAD_ID); //transaction.sendNewMessage(message, Transaction.NO_THREAD_ID);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { sendMmsMessageNative(context, message, settings);
sendMmsMessageNative(context, message, settings);
} else {
// Cross fingers and hope Klinker's library works for this case
transaction.sendNewMessage(message, Transaction.NO_THREAD_ID);
}
} else { } else {
Log.v(SENDING_MESSAGE, "Sending new SMS"); Log.v(SENDING_MESSAGE, "Sending new SMS");
transaction.sendNewMessage(message, Transaction.NO_THREAD_ID); transaction.sendNewMessage(message, Transaction.NO_THREAD_ID);
@@ -200,7 +195,6 @@ public class SmsMmsUtils {
* @param message * @param message
* @param klinkerSettings * @param klinkerSettings
*/ */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
protected static void sendMmsMessageNative(Context context, Message message, Settings klinkerSettings) { protected static void sendMmsMessageNative(Context context, Message message, Settings klinkerSettings) {
ArrayList<MMSPart> data = new ArrayList<>(); ArrayList<MMSPart> data = new ArrayList<>();

View File

@@ -221,11 +221,7 @@ public class TelephonyPlugin extends Plugin {
private void unmuteRinger() { private void unmuteRinger() {
if (isMuted) { if (isMuted) {
AudioManager am = ContextCompat.getSystemService(context, AudioManager.class); AudioManager am = ContextCompat.getSystemService(context, AudioManager.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_UNMUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_RING, false);
}
isMuted = false; isMuted = false;
} }
} }
@@ -233,11 +229,7 @@ public class TelephonyPlugin extends Plugin {
private void muteRinger() { private void muteRinger() {
if (!isMuted) { if (!isMuted) {
AudioManager am = ContextCompat.getSystemService(context, AudioManager.class); AudioManager am = ContextCompat.getSystemService(context, AudioManager.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
am.setStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
} else {
am.setStreamMute(AudioManager.STREAM_RING, true);
}
isMuted = true; isMuted = true;
} }
} }
@@ -310,14 +302,10 @@ public class TelephonyPlugin extends Plugin {
@Override @Override
public @NonNull String[] getRequiredPermissions() { public @NonNull String[] getRequiredPermissions() {
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, Manifest.permission.READ_CALL_LOG,
Manifest.permission.READ_CALL_LOG, };
};
} else {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
} }
@Override @Override