Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8047e589 authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

Merge "Updates Self-managed CS test app to play ringtone and support silence." am: 113e5814

am: 49550723

Change-Id: Id2a10ac4dae83e4e8cd11f17f95f0f65f8f78eac
parents 2eadc413 49550723
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package com.android.server.telecom.testapps;

import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.telecom.ConnectionRequest;
@@ -100,6 +104,7 @@ public class SelfManagedCallingActivity extends Activity {
                        | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;

        getWindow().addFlags(flags);
        configureNotificationChannel();
        setContentView(R.layout.self_managed_sample_main);
        mCheckIfPermittedBeforeCalling = (CheckBox) findViewById(
                R.id.checkIfPermittedBeforeCalling);
@@ -196,4 +201,20 @@ public class SelfManagedCallingActivity extends Activity {
        }
        tm.addNewIncomingCall(getSelectedPhoneAccountHandle(), extras);
    }

    private void configureNotificationChannel() {
        NotificationChannel channel = new NotificationChannel(
                SelfManagedConnection.INCOMING_CALL_CHANNEL_ID, "Incoming Calls",
                NotificationManager.IMPORTANCE_MAX);
        channel.setShowBadge(false);
        Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        channel.setSound(ringtoneUri, new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .build());
        channel.enableLights(true);

        NotificationManager mgr = getSystemService(NotificationManager.class);
        mgr.createNotificationChannel(channel);
    }
}
 No newline at end of file
+20 −3
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.telecom.Call;
import android.telecom.CallAudioState;
@@ -43,7 +46,7 @@ public class SelfManagedConnection extends Connection {
        public void onConnectionStateChanged(SelfManagedConnection connection) {}
        public void onConnectionRemoved(SelfManagedConnection connection) {}
    }

    public static final String INCOMING_CALL_CHANNEL_ID = "INCOMING_CALL_CHANNEL_ID";
    public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
            "com.android.server.telecom.testapps.extra.PHONE_ACCOUNT_HANDLE";
    public static final String CALL_NOTIFICATION = "com.android.server.telecom.testapps.CALL";
@@ -58,6 +61,7 @@ public class SelfManagedConnection extends Connection {
    private boolean mIsIncomingCallUiShowing;
    private Listener mListener;
    private boolean mIsHandover;
    private Notification.Builder mNotificationBuilder;

    SelfManagedConnection(SelfManagedCallList callList, Context context, boolean isIncoming) {
        mCallList = callList;
@@ -93,7 +97,8 @@ public class SelfManagedConnection extends Connection {
        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 1, intent, 0);

        // Build the notification as an ongoing high priority item.
        final Notification.Builder builder = new Notification.Builder(mContext);
        final Notification.Builder builder = new Notification.Builder(mContext,
                INCOMING_CALL_CHANNEL_ID);
        builder.setOngoing(true);
        builder.setPriority(Notification.PRIORITY_HIGH);

@@ -131,9 +136,12 @@ public class SelfManagedConnection extends Connection {
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .build());

        Notification notification = builder.build();
        notification.flags |= Notification.FLAG_INSISTENT;
        NotificationManager notificationManager = mContext.getSystemService(
                NotificationManager.class);
        notificationManager.notify(CALL_NOTIFICATION, mCallId, builder.build());
        mNotificationBuilder = builder;
        notificationManager.notify(CALL_NOTIFICATION, mCallId, notification);
    }

    @Override
@@ -172,6 +180,15 @@ public class SelfManagedConnection extends Connection {
        setConnectionDisconnected(DisconnectCause.LOCAL);
    }

    @Override
    public void onSilence() {
        // Re-post our notification without a ringtone.
        mNotificationBuilder.setOnlyAlertOnce(true);
        NotificationManager notificationManager = mContext.getSystemService(
                NotificationManager.class);
        notificationManager.notify(CALL_NOTIFICATION, mCallId, mNotificationBuilder.build());
    }

    public void setConnectionActive() {
        mMediaPlayer.start();
        setActive();