Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android auto support #5880

Closed
wants to merge 11 commits into from
Closed

Android auto support #5880

wants to merge 11 commits into from

Conversation

snaggen
Copy link

@snaggen snaggen commented Nov 21, 2016

This pull request adds Android Auto support. I have implemented it according to the guidelines https://developer.android.com/training/auto/messaging/index.html
I have tested it using the Android Auto emulator and used it for two month in a car.

I didn't read the bit about the BitHub reward until i had done all my commits, but they are intended to be freebies.

Fixes #5619
//FREEBIE

First time contributor checklist

Contributor checklist

  • Volkswagen Passat 2016 with Android Auto using a Nexus 5X
  • Android Auto Emulator using a Nexus 5X
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax
  • I have made the choice whether I want the BitHub reward or not by omitting or adding the word FREEBIE in the commit message of my first commit

Description

This adds android auto support accordign to
https://developer.android.com/training/auto/messaging/index.html#messaging
However, since android auto is not officially supported in my country,
the functionality is limited. Which means that I have not been able
to fully test everything yet.
What work is:
* Message notification is shown.
* When you click on it, the message is read.
I didn't notice any difference from before, but the
developer documentation explicitly states that
it should be set.
https://developer.android.com/training/auto/messaging/index.html#messaging
import java.util.List;

/**
* Get the response text from the Wearable Device and sends an message as a reply
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you copied this from the wearable receiver? Can you update the comment?


public static final String TAG = AndroidAutoHeardReceiver.class.getSimpleName();
public static final String HEARD_ACTION = "org.thoughtcrime.securesms.notifications.ANDROID_AUTO_HEARD";
public static final String THREAD_IDS_EXTRA = "car_heard_thread_ids";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align please

import java.util.List;

/**
* Get the response text from the Wearable Device and sends an message as a reply
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment please

final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
final long threadId = intent.getLongExtra(THREAD_ID_EXTRA, -1);
final CharSequence responseText = getMessageText(intent);
final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align please

return remoteInput.getCharSequence(VOICE_REPLY_KEY);
}
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two space indents


private CharSequence getMessageText(Intent intent) {
Bundle remoteInput =
RemoteInput.getResultsFromIntent(intent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one line

@@ -233,6 +233,8 @@ private static void sendSingleThreadNotification(@NonNull Context context,
notificationState.getMarkAsReadIntent(context),
notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getWearableReplyIntent(context, notifications.get(0).getRecipients()));
builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getAndroidAutoHeardIntent(context, notifications.get(0).getRecipients()), notifications.get(0).getTimestamp());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align please

return;

RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY)
.setLabel("Reply").build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localize?

RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY)
.setLabel("Reply").build();

NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't abbreviate variable names

.addMessage(mContentText.toString())
.setLatestTimestamp(timestamp)
.setReadPendingIntent(androidAutoHeardIntent)
.setReplyAction(androidAutoReplyIntent, remoteInput);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align please

@snaggen
Copy link
Author

snaggen commented Nov 22, 2016

Thanks for the feedback! Since this was my first android, the lazy coder in me based it of the Ware code and forgot the comments :) However, I have fixed that, and the rest of your feedback.

Copy link
Contributor

@FeuRenard FeuRenard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I request two indentation changes.


public static final String TAG = AndroidAutoHeardReceiver.class.getSimpleName();
public static final String HEARD_ACTION = "org.thoughtcrime.securesms.notifications.ANDROID_AUTO_HEARD";
public static final String THREAD_IDS_EXTRA = "car_heard_thread_ids";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are three unnecessary white spaces in front of each equal sign.

@@ -107,6 +107,9 @@
<meta-data android:name="org.thoughtcrime.securesms.mms.TextSecureGlideModule"
android:value="GlideModule" />

<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android:resource and android:name should start in the same column.

@snaggen
Copy link
Author

snaggen commented Nov 22, 2016

I have fixed the indentation changes.

@@ -455,6 +458,19 @@
</intent-filter>
</receiver>

<receiver android:name=".notifications.AndroidAutoHeardReceiver">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these need to be exported? (default true if you have an intent filter defined iirc)

wouldn't that allow any app on the device to send a signal message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested to set export=false for the ReplyReciever and that seems to work. So I have pushed a fix for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this one is still exported though?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't change that since is basically doing the same thing as the MarkReadReceiver that is explicitly set to exported=true. So setting AndroidAutoHeardReciever doesn't really change anything in regards to what external apps can do. But I can change and test this if you like it not to be exported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a rule, no broadcast receivers should ever be exported unless they absolutely have to be

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now tested this, and it worked fine. I have pushed a fix.

@@ -233,6 +233,8 @@ private static void sendSingleThreadNotification(@NonNull Context context,
notificationState.getMarkAsReadIntent(context),
notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getWearableReplyIntent(context, notifications.get(0).getRecipients()));
builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipients()),
notificationState.getAndroidAutoHeardIntent(context, notifications.get(0).getRecipients()), notifications.get(0).getTimestamp());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please align this. notificationState needs to be below notificationState on the line above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed a fix for this.

moxie0 pushed a commit that referenced this pull request Nov 28, 2016
This adds android auto support accordign to
https://developer.android.com/training/auto/messaging/index.html#messaging
However, since android auto is not officially supported in my country,
the functionality is limited. Which means that I have not been able
to fully test everything yet.

What work is:
* Message notification is shown.
* When you click on it, the message is read.

Closes #5880
@moxie0
Copy link
Contributor

moxie0 commented Nov 28, 2016

in 3.24.0

@moxie0 moxie0 closed this Nov 28, 2016
@riyapenn
Copy link

riyapenn commented Dec 13, 2016

One user is stating that with "SMS enabled, the notifications are doubling up. One from the Android system for SMS and the second from Signal." I suspect the SMS is being intercepted by the default messenger first. https://gist.github.com/fdc3e86e7ca5947959cef4235438c646

@snaggen
Copy link
Author

snaggen commented Dec 14, 2016

I have seen this too. But I fail to see how this is a bug in Signal, since that is the application selected to handle SMS.... which it does. I think this is a bug in either Android Auto, Android or Google Messanger, since they clearly sends out a SMS notification when they should not.
Also, the documentation for the messaging doesn't mention any special treatment of SMS.
https://developer.android.com/training/auto/messaging/index.html

And... if Signal doesn't send the android auto notification, the possibility of replying to messages from within Signal, and marking the Signal conversation as read/heard will not be available. In short, the application handling the SMS, must send the notification to be able to mark messages as read within the application and reply within the conversation.

@snaggen
Copy link
Author

snaggen commented Dec 14, 2016

Have asked about this on the android auto forum
https://productforums.google.com/forum/#!topic/android-auto/PJYVAA11OI0;context-place=forum/android-auto

@snaggen
Copy link
Author

snaggen commented Dec 15, 2016

One person from the Android Auto Team replied, and confirmed that Android Auto overrides the users preferences regarding SMS handling. To work around the issue with duplicate SMS notifications he proposed the following:

If you switch off the SMS permission for Android Auto, you will only get the notifications from Signal which will handle the read and replies for SMS messages as you mentioned.

@rubin110
Copy link

Is there some documentation on how this integration is supposed to work? Can we access Signal through the Android Auto app, or is this just to simply pass notifications and interact with Signal through there? Thanks!

@snaggen
Copy link
Author

snaggen commented Dec 19, 2016 via email

@rubin110
Copy link

@snaggen: Thank you for the response. I ended up using it today while driving a friend to the airport. I think this is a great feature and will hopefully keep some people from texting and driving (and if it does theni it's worth it). Thank you for implementing this.

I searched around but couldn't find a good answer, is there any way to include Signal in the list of messaging apps Android Auto supports when you give it a voice commend to send a message to someone? Currently for me it only verbally lists Hangouts and SMS.

@snaggen
Copy link
Author

snaggen commented Dec 19, 2016

@rubin110 I have not seen any Android Auto Api to define voice commands and things like that... what I currently have implemented seems to be what the api allows. But if you find out something about this that I have been missing, just let me know.

@rubin110
Copy link

@sneggen: I went searching again and you're correct, it doesn't seem like Google has exposed an API to do this yet.

The behavior I'm talking about is when you issue the voice command "Send a message to Dana." The Android then verbal responds asking which messaging app to use and then lists them out, which for me is currently Hangouts and SMS.

BLeQuerrec pushed a commit to SilenceIM/Silence that referenced this pull request Feb 9, 2017
This adds android auto support accordign to
https://developer.android.com/training/auto/messaging/index.html#messaging
However, since android auto is not officially supported in my country,
the functionality is limited. Which means that I have not been able
to fully test everything yet.

What work is:
* Message notification is shown.
* When you click on it, the message is read.

Closes signalapp/Signal-Android#5880

Upstream commit: signalapp/Signal-Android@9148b7d
@FeuRenard
Copy link
Contributor

btw: #5619 should be closed (but it's locked, so I can't inform you there 😉 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add Android Auto Messaging support
5 participants