From 06f0616f6dbc710c3cb81ff09008df5073b168c4 Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Mon, 18 Jun 2018 11:24:15 -0700 Subject: Make Connection#onSilence a public API. Connection#onSilence is generally applicable to apps implementing the self-managed ConnectionService API. Also updated the docs to make it more clear where that API is to be used and how the developer can silence the ringtone. Test: CTS test, manual test. Bug: 110348674 Change-Id: I1c1791c101827780949fd633c531ed83037e7b4e --- api/current.txt | 1 + telecomm/java/android/telecom/Connection.java | 49 +++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/api/current.txt b/api/current.txt index da5addc63c3c..6ebcb541155f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -39386,6 +39386,7 @@ package android.telecom { method public void onReject(java.lang.String); method public void onSeparate(); method public void onShowIncomingCallUi(); + method public void onSilence(); method public void onStartRtt(android.telecom.Connection.RttTextStream); method public void onStateChanged(int); method public void onStopDtmfTone(); diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java index ca444d4d78ed..25e67c8ee17b 100644 --- a/telecomm/java/android/telecom/Connection.java +++ b/telecomm/java/android/telecom/Connection.java @@ -2802,9 +2802,21 @@ public abstract class Connection extends Conferenceable { public void onReject(String replyMessage) {} /** - * Notifies the Connection of a request to silence the ringer. - * - * @hide + * Notifies this Connection of a request to silence the ringer. + *

+ * The ringer may be silenced by any of the following methods: + *

+ *

+ * Self-managed {@link ConnectionService} implementations should override this method in their + * {@link Connection} implementation and implement logic to silence their app's ringtone. If + * your app set the ringtone as part of the incoming call {@link Notification} (see + * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call + * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This + * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel} + * stops playing. */ public void onSilence() {} @@ -2881,7 +2893,29 @@ public abstract class Connection extends Conferenceable { *

* You should trigger the display of the incoming call user interface for your application by * showing a {@link Notification} with a full-screen {@link Intent} specified. - * For example: + * + * In your application code, you should create a {@link android.app.NotificationChannel} for + * incoming call notifications from your app: + *


+     * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
+     *          NotificationManager.IMPORTANCE_MAX);
+     * // other channel setup stuff goes here.
+     *
+     * // We'll use the default system ringtone for our incoming call notification channel.  You can
+     * // use your own audio resource here.
+     * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
+     * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
+     *          // Setting the AudioAttributes is important as it identifies the purpose of your
+     *          // notification sound.
+     *          .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
+     *          .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+     *      .build());
+     *
+     * NotificationManager mgr = getSystemService(NotificationManager.class);
+     * mgr.createNotificationChannel(channel);
+     * 
+ * When it comes time to post a notification for your incoming call, ensure it uses your + * incoming call {@link android.app.NotificationChannel}. *

      *     // Create an intent which triggers your fullscreen incoming call user interface.
      *     Intent intent = new Intent(Intent.ACTION_MAIN, null);
@@ -2907,11 +2941,14 @@ public abstract class Connection extends Conferenceable {
      *     builder.setContentTitle("Your notification title");
      *     builder.setContentText("Your notification content.");
      *
-     *     // Use builder.addAction(..) to add buttons to answer or reject the call.
+     *     // Set notification as insistent to cause your ringtone to loop.
+     *     Notification notification = builder.build();
+     *     notification.flags |= Notification.FLAG_INSISTENT;
      *
+     *     // Use builder.addAction(..) to add buttons to answer or reject the call.
      *     NotificationManager notificationManager = mContext.getSystemService(
      *         NotificationManager.class);
-     *     notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
+     *     notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
      * 
*/ public void onShowIncomingCallUi() {} -- cgit v1.2.3-59-g8ed1b