1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-25 00:57:33 +01:00

introduce GBApplication.isRunningPieOrLater() and fix indent of last commit

This commit is contained in:
Andreas Shimokawa 2020-02-22 10:12:33 +01:00
parent 01ab7bcb54
commit 1b416e18b9
2 changed files with 23 additions and 20 deletions

View File

@ -344,6 +344,10 @@ public class GBApplication extends Application {
return VERSION.SDK_INT >= Build.VERSION_CODES.O; return VERSION.SDK_INT >= Build.VERSION_CODES.O;
} }
public static boolean isRunningPieOrLater() {
return VERSION.SDK_INT >= Build.VERSION_CODES.P;
}
private static boolean isPrioritySender(int prioritySenders, String number) { private static boolean isPrioritySender(int prioritySenders, String number) {
if (prioritySenders == Policy.PRIORITY_SENDERS_ANY) { if (prioritySenders == Policy.PRIORITY_SENDERS_ANY) {
return true; return true;

View File

@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.receivers; package nodomain.freeyourgadget.gadgetbridge.service.receivers;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -24,6 +23,8 @@ import android.os.Build;
import android.telecom.TelecomManager; import android.telecom.TelecomManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import androidx.annotation.RequiresApi;
import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.ITelephony;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -43,24 +44,24 @@ public class GBCallControlReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
GBDeviceEventCallControl.Event callCmd = GBDeviceEventCallControl.Event.values()[intent.getIntExtra("event", 0)]; GBDeviceEventCallControl.Event callCmd = GBDeviceEventCallControl.Event.values()[intent.getIntExtra("event", 0)];
if (Build.VERSION.SDK_INT >= 28){ if (GBApplication.isRunningPieOrLater()) {
handleCallCmdTelecomManager(callCmd); handleCallCmdTelecomManager(callCmd);
}else { } else {
switch (callCmd) { switch (callCmd) {
case END: case END:
case REJECT: case REJECT:
case START: case START:
try { try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class clazz = Class.forName(telephonyManager.getClass().getName()); Class clazz = Class.forName(telephonyManager.getClass().getName());
Method method = clazz.getDeclaredMethod("getITelephony"); Method method = clazz.getDeclaredMethod("getITelephony");
method.setAccessible(true); method.setAccessible(true);
ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager); ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
if (callCmd == GBDeviceEventCallControl.Event.END || callCmd == GBDeviceEventCallControl.Event.REJECT) { if (callCmd == GBDeviceEventCallControl.Event.END || callCmd == GBDeviceEventCallControl.Event.REJECT) {
telephonyService.endCall(); telephonyService.endCall();
} else { } else {
telephonyService.answerRingingCall(); telephonyService.answerRingingCall();
} }
} catch (Exception e) { } catch (Exception e) {
LOG.warn("could not start or hangup call"); LOG.warn("could not start or hangup call");
} }
@ -70,22 +71,20 @@ public class GBCallControlReceiver extends BroadcastReceiver {
} }
} }
@TargetApi(28) @RequiresApi(api = Build.VERSION_CODES.P)
public void handleCallCmdTelecomManager(GBDeviceEventCallControl.Event callCmd){ public void handleCallCmdTelecomManager(GBDeviceEventCallControl.Event callCmd) {
try { try {
TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
if (callCmd == GBDeviceEventCallControl.Event.END || callCmd == GBDeviceEventCallControl.Event.REJECT) { if (callCmd == GBDeviceEventCallControl.Event.END || callCmd == GBDeviceEventCallControl.Event.REJECT) {
tm.endCall(); tm.endCall();
} } else if (callCmd == GBDeviceEventCallControl.Event.START || callCmd == GBDeviceEventCallControl.Event.ACCEPT) {
else if (callCmd == GBDeviceEventCallControl.Event.START || callCmd == GBDeviceEventCallControl.Event.ACCEPT) {
tm.acceptRingingCall(); tm.acceptRingingCall();
} }
}catch (SecurityException e){ } catch (SecurityException e) {
LOG.warn("no permission to start or hangup call"); LOG.warn("no permission to start or hangup call");
} } catch (Exception e) {
catch (Exception e) {
LOG.warn("could not start or hangup call"); LOG.warn("could not start or hangup call");
} }
} }