diff options
Diffstat (limited to 'telecomm/java/android/telecom/Connection.java')
-rw-r--r-- | telecomm/java/android/telecom/Connection.java | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java index 96d5af8ddd6a..a9618076a653 100644 --- a/telecomm/java/android/telecom/Connection.java +++ b/telecomm/java/android/telecom/Connection.java @@ -45,6 +45,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.nio.channels.Channels; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -894,6 +895,8 @@ public abstract class Connection extends Conferenceable { private final OutputStreamWriter mPipeToInCall; private final ParcelFileDescriptor mFdFromInCall; private final ParcelFileDescriptor mFdToInCall; + + private final FileInputStream mFromInCallFileInputStream; private char[] mReadBuffer = new char[READ_BUFFER_SIZE]; /** @@ -902,8 +905,11 @@ public abstract class Connection extends Conferenceable { public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) { mFdFromInCall = fromInCall; mFdToInCall = toInCall; + mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor()); + + // Wrap the FileInputStream in a Channel so that it's interruptible. mPipeFromInCall = new InputStreamReader( - new FileInputStream(fromInCall.getFileDescriptor())); + Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream))); mPipeToInCall = new OutputStreamWriter( new FileOutputStream(toInCall.getFileDescriptor())); } @@ -951,7 +957,7 @@ public abstract class Connection extends Conferenceable { * not entered any new text yet. */ public String readImmediately() throws IOException { - if (mPipeFromInCall.ready()) { + if (mFromInCallFileInputStream.available() > 0) { return read(); } else { return null; @@ -2855,9 +2861,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. + * <p> + * The ringer may be silenced by any of the following methods: + * <ul> + * <li>{@link TelecomManager#silenceRinger()}</li> + * <li>The user presses the volume-down button while a call is ringing.</li> + * </ul> + * <p> + * 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() {} @@ -2934,7 +2952,29 @@ public abstract class Connection extends Conferenceable { * <p> * 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: + * <pre><code> + * 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); + * </code></pre> + * When it comes time to post a notification for your incoming call, ensure it uses your + * incoming call {@link android.app.NotificationChannel}. * <pre><code> * // Create an intent which triggers your fullscreen incoming call user interface. * Intent intent = new Intent(Intent.ACTION_MAIN, null); @@ -2960,11 +3000,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); * </code></pre> */ public void onShowIncomingCallUi() {} |