1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Fix answering/rejecting calls on Android 9

This commit is contained in:
Andrzej Surowiec 2020-02-21 21:57:18 +01:00 committed by Andreas Shimokawa
parent 57d9d88986
commit 01ab7bcb54
4 changed files with 44 additions and 11 deletions

View File

@ -22,7 +22,7 @@ android {
defaultConfig {
applicationId "nodomain.freeyourgadget.gadgetbridge"
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 28
// Note: always bump BOTH versionCode and versionName!
versionName "0.42.0"

View File

@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

View File

@ -343,6 +343,8 @@ public class ControlCenterv2 extends AppCompatActivity
wantedPermissions.add(Manifest.permission.READ_CONTACTS);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_DENIED)
wantedPermissions.add(Manifest.permission.CALL_PHONE);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED)
wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_DENIED)
wantedPermissions.add(Manifest.permission.READ_CALL_LOG);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_DENIED)

View File

@ -16,9 +16,12 @@
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;
import android.os.Build;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import com.android.internal.telephony.ITelephony;
@ -28,20 +31,26 @@ import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
public class GBCallControlReceiver extends BroadcastReceiver {
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
private static final Logger LOG = LoggerFactory.getLogger(GBCallControlReceiver.class);
private Context mContext = GBApplication.getContext();
@Override
public void onReceive(Context context, Intent intent) {
GBDeviceEventCallControl.Event callCmd = GBDeviceEventCallControl.Event.values()[intent.getIntExtra("event", 0)];
switch (callCmd) {
case END:
case REJECT:
case START:
try {
if (Build.VERSION.SDK_INT >= 28){
handleCallCmdTelecomManager(callCmd);
}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");
@ -52,11 +61,32 @@ public class GBCallControlReceiver extends BroadcastReceiver {
} else {
telephonyService.answerRingingCall();
}
} catch (Exception e) {
LOG.warn("could not start or hangup call");
}
break;
default:
} catch (Exception e) {
LOG.warn("could not start or hangup call");
}
break;
default:
}
}
}
@TargetApi(28)
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) {
tm.acceptRingingCall();
}
}catch (SecurityException e){
LOG.warn("no permission to start or hangup call");
}
catch (Exception e) {
LOG.warn("could not start or hangup call");
}
}
}