1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 14:02:56 +01:00

Support for rejecting/ending calls via Pebble buttons

This commit is contained in:
Andreas Shimokawa 2015-03-07 17:44:39 +01:00
parent 85ccafc922
commit 6fa99082ab
6 changed files with 84 additions and 12 deletions

View File

@ -2,24 +2,23 @@ Gadgetbridge
============ ============
Gadgetbridge is a Android (4.4+) Application which will allow you to use your Gadgetbridge is a Android (4.4+) Application which will allow you to use your
Gadget (Smartwatches/Fitness Bands etc) without the vendors closed source Pebble without the vendors closed source application and without the need to
application and without the need to create an account and sync your data to the create an account and transmit any of your data to the vendors servers.
vendors servers.
Right now this is in very early testing stages and only supports the Pebble. We plan to add support for the Mi Band and maybe even more devices.
USE IT AT YOUR OWN RISK. It will problably not work. And if it works it will
annoy you more than it helps you ;)
Features: Features:
* Incoming calls notification and display (caller, phone number) * Incoming calls notification and display (caller, phone number)
* Outgoing call display
* Reject/Hangup Calls
* SMS notification (sender, body) * SMS notification (sender, body)
* K-9 Mail notification support (sender, subject, preview) * K-9 Mail notification support (sender, subject, preview)
* Support for generic notificaions (above filtered out) * Support for generic notificaions (above filtered out)
* Apollo Music Playback info (artist, album, track) * Apollo Music Playback info (artist, album, track)
* Music Control: Play/Pause, Next Track, Previous Track
How to use (Pebble): How to use:
1. Pair your Pebble though the Android Bluetooth Settings 1. Pair your Pebble though the Android Bluetooth Settings
2. Start Gadgetbridge, press "connect" 2. Start Gadgetbridge, press "connect"
@ -28,7 +27,6 @@ How to use (Pebble):
Known Issues: Known Issues:
* No reconnect, if connection is lost, you have to press "connect" again * No reconnect, if connection is lost, you have to press "connect" again
* Can't reject or hang up phone calls yet
* Notifications are not properly queued, if two arrive at about the same time, * Notifications are not properly queued, if two arrive at about the same time,
one of them might get lost (TODO: confirm) one of them might get lost (TODO: confirm)
* Android 4.4+ only, we can only change this by not handling generic * Android 4.4+ only, we can only change this by not handling generic

View File

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" /> <uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" />
@ -77,6 +78,11 @@
<action android:name="nodomain.freeyourgadget.gadgetbridge.musiccontrol" /> <action android:name="nodomain.freeyourgadget.gadgetbridge.musiccontrol" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".GBCallControlReceiver">
<intent-filter>
<action android:name="nodomain.freeyourgadget.gadgetbridge.callcontrol" />
</intent-filter>
</receiver>
<activity <activity
android:name=".DebugActivity" android:name=".DebugActivity"

View File

@ -0,0 +1,8 @@
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}

View File

@ -118,12 +118,15 @@ public class BluetoothCommunicationService extends Service {
switch (cmdBundle.commandClass) { switch (cmdBundle.commandClass) {
case MUSIC_CONTROL: case MUSIC_CONTROL:
Log.i(TAG, "Got command for MUSIC_CONTROL"); Log.i(TAG, "Got command for MUSIC_CONTROL");
Intent i = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL); Intent musicintent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
i.putExtra("command", cmdBundle.command.ordinal()); musicintent.putExtra("command", cmdBundle.command.ordinal());
sendBroadcast(i); sendBroadcast(musicintent);
break; break;
case CALL_CONTROL: case CALL_CONTROL:
Log.i(TAG, "Got command for CALL_CONTROL"); Log.i(TAG, "Got command for CALL_CONTROL");
Intent callintent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
callintent.putExtra("command", cmdBundle.command.ordinal());
sendBroadcast(callintent);
break; break;
default: default:
break; break;

View File

@ -0,0 +1,40 @@
package nodomain.freeyourgadget.gadgetbridge;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.internal.telephony.ITelephony;
import java.lang.reflect.Method;
public class GBCallControlReceiver extends BroadcastReceiver {
private final String TAG = this.getClass().getSimpleName();
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
@Override
public void onReceive(Context context, Intent intent) {
GBCommand command = GBCommand.values()[intent.getIntExtra("command", 0)];
int keyCode;
switch (command) {
case CALL_END:
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);
telephonyService.endCall();
} catch (Exception e) {
Log.w(TAG, "could not hangup call");
}
break;
default:
return;
}
}
}

View File

@ -1,10 +1,15 @@
package nodomain.freeyourgadget.gadgetbridge; package nodomain.freeyourgadget.gadgetbridge;
import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
public class PebbleProtocol { public class PebbleProtocol {
static private String TAG = "PebbleProtocol";
static final short ENDPOINT_FIRMWARE = 1; static final short ENDPOINT_FIRMWARE = 1;
static final short ENDPOINT_TIME = 11; static final short ENDPOINT_TIME = 11;
static final short ENDPOINT_FIRMWAREVERSION = 16; static final short ENDPOINT_FIRMWAREVERSION = 16;
@ -253,6 +258,18 @@ public class PebbleProtocol {
break; break;
} }
break; break;
case ENDPOINT_PHONECONTROL:
cmd.commandClass = GBCommandClass.CALL_CONTROL;
switch (pebbleCmd) {
case PHONECONTROL_HANGUP:
cmd.command = GBCommand.CALL_END;
break;
default:
Log.i(TAG, "Unknown PHONECONTROL command" + pebbleCmd);
cmd.command = GBCommand.UNDEFINEND;
break;
}
break;
default: default:
return null; return null;
} }