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"
compileSdk = 34
defaultConfig {
minSdk = 21
minSdk = 23
targetSdk = 33
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}

View File

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

View File

@@ -222,9 +222,6 @@ object SMSHelper {
* @param context android.content.Context running the request.
*/
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
// `Telephony.Sms.SUBSCRIPTION_ID`, so additional check is needed.
// 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
* are only defined on Android versions with multi-sim capabilities
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
val multiSIMColumns = arrayOf(Telephony.Sms.SUBSCRIPTION_ID)
}
}

View File

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

View File

@@ -37,7 +37,6 @@ public class TelephonyHelper {
* Get all subscriptionIDs of the device
* 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(
@NonNull Context context)
throws SecurityException {
@@ -73,7 +72,6 @@ public class TelephonyHelper {
* This lets you identify additions/removals of SIM cards.
* 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(
@NonNull Context context, SubscriptionCallback onAdd, SubscriptionCallback onRemove) {
SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class);
@@ -117,7 +115,6 @@ public class TelephonyHelper {
/**
* Cancels a listener created by `listenActiveSubscriptionIDs`
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public static void cancelActiveSubscriptionIDsListener(@NonNull Context context, @NonNull OnSubscriptionsChangedListener listener) {
SubscriptionManager sm = ContextCompat.getSystemService(context, SubscriptionManager.class);
if (sm == null) {
@@ -139,44 +136,26 @@ public class TelephonyHelper {
public static @NonNull List<LocalPhoneNumber> getAllPhoneNumbers(
@NonNull Context context)
throws SecurityException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
// Single-sim case
// From https://stackoverflow.com/a/25131061/3723163
// Android added support for multi-sim devices in Lollypop v5.1 (api 22)
// See: https://developer.android.com/about/versions/android-5.1.html#multisim
// There were vendor-specific implmentations before then, but those are very difficult to support
// S/O Reference: https://stackoverflow.com/a/28571835/3723163
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());
// Potentially multi-sim
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());
}
/**
@@ -245,14 +224,7 @@ public class TelephonyHelper {
Uri telephonyCarriersUri = Telephony.Carriers.CONTENT_URI;
Uri telephonyCarriersPreferredApnUri;
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/");
}
Uri telephonyCarriersPreferredApnUri = Uri.withAppendedPath(telephonyCarriersUri, "/preferapn/subId/" + subscriptionId);
try (Cursor cursor = context.getContentResolver().query(
telephonyCarriersPreferredApnUri,

View File

@@ -11,33 +11,6 @@ import android.telephony.CellInfo;
import android.telephony.SignalStrength;
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

View File

@@ -136,7 +136,7 @@ public class ConnectivityReportPlugin extends Plugin {
return new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
int level = ASUUtils.signalStrengthToLevel(signalStrength);
int level = signalStrength.getLevel();
SubscriptionState state = states.get(subID);
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
protected void onStart() {
super.onStart();

View File

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

View File

@@ -38,7 +38,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
@PluginFactory.LoadablePlugin
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public class MprisReceiverPlugin extends Plugin {
private final static String PACKET_TYPE_MPRIS = "kdeconnect.mpris";
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 {
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());
} else if (notification.largeIcon != null) {
return notification.largeIcon;
}
PackageManager pm = context.getPackageManager();
@@ -398,7 +396,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return res;
}
@RequiresApi(Build.VERSION_CODES.M)
private Bitmap iconToBitmap(Context foreignContext, Icon icon) {
if (icon == null) return null;

View File

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

View File

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

View File

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