1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-10 07:07:57 +02: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;
}
public static boolean isRunningPieOrLater() {
return VERSION.SDK_INT >= Build.VERSION_CODES.P;
}
private static boolean isPrioritySender(int prioritySenders, String number) {
if (prioritySenders == Policy.PRIORITY_SENDERS_ANY) {
return true;

View File

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