Permalink
Browse files

Add phone status, still not early enough to avoid the audio focus tho…

…ugh :(
  • Loading branch information...
lmagder committed Dec 17, 2017
1 parent 5975877 commit ea20917328092917f1eaf34a1a2761c181c79a17
Showing with 241 additions and 4 deletions.
  1. +63 −0 hu/hu.proto
  2. +100 −1 hu/hu_aap.cpp
  3. +33 −0 hu/hu_aap.h
  4. +17 −2 mazda/callbacks.cpp
  5. +10 −0 ubuntu/callbacks.cpp
  6. +4 −0 ubuntu/callbacks.h
  7. +14 −1 ubuntu/outputs.cpp
View
@@ -399,6 +399,12 @@ message ChannelDescriptor
//nav==8
//mediaplayback == 9
//phonestatus = 10
message PhoneStatusService
{
}
optional PhoneStatusService phone_status_service = 10;
//mediabrowser=11
message VendorExtensionService
@@ -412,6 +418,10 @@ message ChannelDescriptor
//vendor extension==12
//genericnotification==13
message GenericNotificationService
{
}
optional GenericNotificationService generic_notification_service = 13;
}
message ServiceDiscoveryRequest
@@ -608,3 +618,56 @@ message AuthCompleteResponse
{
required STATUS status = 1;
}
message PhoneStatus
{
enum PHONE_STATE
{
PHONE_STATE_IN_CALL = 1;
PHONE_STATE_ON_HOLD = 2;
PHONE_STATE_HANGINGUP = 3;
PHONE_STATE_INCOMING = 4;
PHONE_STATE_UNKNOWN_5 = 5;
PHONE_STATE_UNKNOWN_6 = 6;
}
message Call
{
optional PHONE_STATE state = 1;
//in seconds
optional uint32 call_time = 2;
optional string phone_number = 3;
optional string caller_id = 4;
optional string phone_number_type = 5;
optional string thumbnail = 6;
}
repeated Call calls = 1;
optional uint32 signal_strength = 2;
}
message PhoneStatusInput
{
optional string caller_number = 1;
optional string caller_id = 2;
}
message GenericNotificationRequest
{
required string id = 1;
optional string text = 2;
optional string icon = 3;
}
message GenericNotificationResponse
{
required string id = 1;
required bool handled = 2;
}
message StartGenericNotifications
{
}
message StopGenericNotifications
{
}
View
@@ -530,7 +530,12 @@
callbacks.CustomizeInputChannel(AA_CH_MIC, *inner);
}
callbacks.CustomizeCarInfo(carInfo);
HU::ChannelDescriptor* notificationChannel = carInfo.add_channels();
notificationChannel->set_channel_id(AA_CH_NOT);
{
auto inner = notificationChannel->mutable_generic_notification_service();
//nothing to set here actually
}
std::string carBTAddress = callbacks.GetCarBluetoothAddress();
if (carBTAddress.size() > 0)
@@ -545,12 +550,21 @@
inner->add_supported_pairing_methods(HU::ChannelDescriptor_BluetoothService::BLUETOOTH_PARING_METHOD_HFP);
callbacks.CustomizeBluetoothService(AA_CH_BT, *inner);
}
HU::ChannelDescriptor* phoneStatusChannel = carInfo.add_channels();
phoneStatusChannel->set_channel_id(AA_CH_PSTAT);
{
auto inner = phoneStatusChannel->mutable_phone_status_service();
//nothing to set here actually
}
}
else
{
logw("No Bluetooth or finding BT address failed. Not exposing Bluetooth service");
}
callbacks.CustomizeCarInfo(carInfo);
return hu_aap_enc_send_message(0, chan, HU_PROTOCOL_MESSAGE::ServiceDiscoveryResponse, carInfo);
}
@@ -805,6 +819,65 @@
return hu_aap_enc_send_message(0, chan, HU_MEDIA_CHANNEL_MESSAGE::MediaAck, mediaAck);
}
int HUServer::hu_handle_PhoneStatus(int chan, byte * buf, int len) {
HU::PhoneStatus request;
if (!request.ParseFromArray(buf, len))
{
loge ("PhoneStatus Focus Request");
return -1;
}
else
{
logd ("PhoneStatus Focus Request");
}
callbacks.HandlePhoneStatus(*this, request);
return 0;
}
int HUServer::hu_handle_GenericNotificationResponse(int chan, byte * buf, int len) {
HU::GenericNotificationResponse request;
if (!request.ParseFromArray(buf, len))
{
loge ("GenericNotificationResponse Focus Request");
return -1;
}
else
{
logd ("GenericNotificationResponse Focus Request");
}
//callbacks.HandleGenericNotificationResponse(*this, request);
return 0;
}
int HUServer::hu_handle_StartGenericNotifications(int chan, byte * buf, int len) {
HU::StartGenericNotifications request;
if (!request.ParseFromArray(buf, len))
{
loge ("StartGenericNotifications Focus Request");
return -1;
}
else
{
logd ("StartGenericNotifications Focus Request");
}
//callbacks.ShowingGenericNotifications(*this, true);
return 0;
}
int HUServer::hu_handle_StopGenericNotifications(int chan, byte * buf, int len) {
HU::StopGenericNotifications request;
if (!request.ParseFromArray(buf, len))
{
loge ("StopGenericNotifications Focus Request");
return -1;
}
else
{
logd ("StopGenericNotifications Focus Request");
}
//callbacks.ShowingGenericNotifications(*this, false);
return 0;
}
int HUServer::iaap_msg_process (int chan, uint16_t msg_type, byte * buf, int len) {
@@ -891,6 +964,32 @@
{
logw("BLUETOOTH CHANNEL MESSAGE = chan %d - msg_type: %d", chan, msg_type);
}
else if (chan == AA_CH_PSTAT)
{
switch((HU_PHONE_STATUS_CHANNEL_MESSAGE)msg_type)
{
case HU_PHONE_STATUS_CHANNEL_MESSAGE::PhoneStatus:
return hu_handle_PhoneStatus(chan, buf, len);
default:
loge ("Unknown msg_type: %d", msg_type);
return (0);
}
}
else if (chan == AA_CH_NOT)
{
switch((HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE)msg_type)
{
case HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE::StartGenericNotifications:
return hu_handle_StartGenericNotifications(chan, buf, len);
case HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE::StopGenericNotifications:
return hu_handle_StopGenericNotifications(chan, buf, len);
case HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE::GenericNotificationResponse:
return hu_handle_GenericNotificationResponse(chan, buf, len);
default:
loge ("Unknown msg_type: %d", msg_type);
return (0);
}
}
else if (chan == AA_CH_AUD || chan == AA_CH_AU1 || chan == AA_CH_AU2 || chan == AA_CH_VID || chan == AA_CH_MIC)
{
switch((HU_MEDIA_CHANNEL_MESSAGE)msg_type)
View
@@ -15,6 +15,8 @@
#define AA_CH_AU2 6
#define AA_CH_MIC 7
#define AA_CH_BT 8
#define AA_CH_PSTAT 9
#define AA_CH_NOT 10
#define AA_CH_MAX 256
enum HU_STATE
@@ -40,6 +42,8 @@ inline const char * chan_get (int chan) {
case AA_CH_AU2: return ("AA_CH_AU2");
case AA_CH_MIC: return ("AA_CH_MIC");
case AA_CH_BT: return ("AA_CH_BT");
case AA_CH_PSTAT: return ("AA_CH_PSTAT");
case AA_CH_NOT: return ("AA_CH_NOT");
}
return ("<Invalid>");
}
@@ -161,6 +165,16 @@ class IHUConnectionThreadEventCallbacks
virtual void AudioFocusRequest(int chan, const HU::AudioFocusRequest& request) = 0;
virtual void VideoFocusRequest(int chan, const HU::VideoFocusRequest& request) = 0;
virtual void HandlePhoneStatus(IHUConnectionThreadInterface& stream, const HU::PhoneStatus& phoneStatus) {}
//Doesn't actually work yet
/*
//A lot times we probably don't care about this, except maybe to resend if there was a failure
virtual void HandleGenericNotificationResponse(IHUConnectionThreadInterface& stream, const HU::GenericNotificationResponse& response) {}
virtual void ShowingGenericNotifications(IHUConnectionThreadInterface& stream, bool bIsShowing) {}
*/
};
@@ -248,6 +262,10 @@ class HUServer : protected IHUConnectionThreadInterface
int hu_handle_MicRequest (int chan, byte * buf, int len);
int hu_handle_MediaDataWithTimestamp (int chan, byte * buf, int len);
int hu_handle_MediaData(int chan, byte * buf, int len);
int hu_handle_PhoneStatus(int chan, byte * buf, int len);
int hu_handle_GenericNotificationResponse(int chan, byte * buf, int len);
int hu_handle_StartGenericNotifications(int chan, byte * buf, int len);
int hu_handle_StopGenericNotifications(int chan, byte * buf, int len);
//Can be called from any thread
virtual int hu_queue_command(IHUAnyThreadInterface::HUThreadCommand&& command) override;
@@ -307,6 +325,21 @@ enum class HU_INPUT_CHANNEL_MESSAGE : uint16_t
BindingResponse = 0x8003,
};
enum class HU_PHONE_STATUS_CHANNEL_MESSAGE : uint16_t
{
PhoneStatus = 0x8001,
PhoneStatusInput = 0x8002,
};
//Not sure if these are right
enum class HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE : uint16_t
{
StartGenericNotifications = 0x8001,
StopGenericNotifications = 0x8002,
GenericNotificationRequest = 0x8003,
GenericNotificationResponse = 0x8004,
};
enum HU_INPUT_BUTTON
{
HUIB_MIC1 = 0x01,
View
@@ -615,10 +615,25 @@ BTHFClient::BTHFClient(MazdaEventCallbacks &callbacks, DBus::Connection &hmiBus)
void BTHFClient::CallStatus(const uint32_t& bthfstate, const uint32_t& call1status, const uint32_t& call2status, const ::DBus::Struct< std::vector< uint8_t > >& call1Number, const ::DBus::Struct< std::vector< uint8_t > >& call2Number)
{
logw("CallStatus: bthfstate %u call1status %u call2status %u call1Number (%zu bytes) call2Number (%zu bytes)", bthfstate, call1status, call2status, call1Number._1.size(), call2Number._1.size());
logd("CallStatus: bthfstate %u call1status %u call2status %u call1Number (%zu bytes) call2Number (%zu bytes)", bthfstate, call1status, call2status, call1Number._1.size(), call2Number._1.size());
//unfortunately this seems to come after the phone requests audio focus :(
CallStatusState cs1 = (CallStatusState)call1status;
CallStatusState cs2 = (CallStatusState)call2status;
callbacks.inCall = (cs1 != CallStatusState::Inactive || cs2 != CallStatusState::Inactive);
bool bInCall = (cs1 != CallStatusState::Inactive || cs2 != CallStatusState::Inactive);
callbacks.inCall = bInCall;
if (bInCall)
{
run_on_main_thread([this](){
//Check again since it could have changed since we queued it
if (callbacks.audioFocus != AudioManagerClient::FocusType::NONE && callbacks.inCall)
{
logw("We are in a call, giving up focus");
callbacks.releaseAudioFocus();
}
return false;
});
}
}
View
@@ -93,6 +93,16 @@ std::string DesktopEventCallbacks::GetCarBluetoothAddress()
return get_bluetooth_mac_address();
}
void DesktopEventCallbacks::HandlePhoneStatus(IHUConnectionThreadInterface& stream, const HU::PhoneStatus& phoneStatus) {
printf("HandlePhoneStatus: %s\n", phoneStatus.DebugString().c_str());
}
/*
void DesktopEventCallbacks::ShowingGenericNotifications(IHUConnectionThreadInterface& stream, bool bIsShowing) {
printf("ShowingGenericNotifications: %s\n", bIsShowing ? "true" : "false");
}
*/
void DesktopEventCallbacks::VideoFocusHappened(bool hasFocus, VIDEO_FOCUS_REQUESTOR videoFocusRequestor) {
run_on_main_thread([this, hasFocus, videoFocusRequestor](){
if ((bool)videoOutput != hasFocus) {
View
@@ -34,6 +34,10 @@ class DesktopEventCallbacks : public IHUConnectionThreadEventCallbacks {
virtual void AudioFocusRequest(int chan, const HU::AudioFocusRequest& request) override;
virtual void VideoFocusRequest(int chan, const HU::VideoFocusRequest& request) override;
virtual void HandlePhoneStatus(IHUConnectionThreadInterface& stream, const HU::PhoneStatus& phoneStatus) override;
//Doesn't actually work yet
//virtual void ShowingGenericNotifications(IHUConnectionThreadInterface& stream, bool bIsShowing) override;
virtual std::string GetCarBluetoothAddress() override;
void VideoFocusHappened(bool hasFocus, VIDEO_FOCUS_REQUESTOR videoFocusRequestor);
View
@@ -201,7 +201,7 @@ gboolean VideoOutput::sdl_poll_event() {
if (event.type == SDL_KEYUP) {
nightmodenow = !nightmodenow;
}
} else if (key->keysym.sym = SDLK_F2) {
} else if (key->keysym.sym == SDLK_F2) {
if (event.type == SDL_KEYUP) {
// Send a fake location in germany
HU::SensorEvent sensorEvent;
@@ -222,6 +222,19 @@ gboolean VideoOutput::sdl_poll_event() {
printf("Sending fake location.");
}
} else if (key->keysym.sym == SDLK_F3) {
if (event.type == SDL_KEYUP) {
HU::GenericNotificationRequest notificationReq;
notificationReq.set_id("test");
notificationReq.set_text("This is a test");
g_hu->hu_queue_command([notificationReq](IHUConnectionThreadInterface& s)
{
s.hu_aap_enc_send_message(0, AA_CH_NOT, HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE::GenericNotificationRequest, notificationReq);
});
printf("Sending notification.");
}
}
if (buttonInfo->has_scan_code()) {

0 comments on commit ea20917

Please sign in to comment.