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

Commit d7acc5a4 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Call Screening / Caller ID API Changes"

parents c9f60fb4 9e76fd19
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -42662,6 +42662,7 @@ package android.telecom {
    method public static java.lang.String capabilitiesToString(int);
    method public android.telecom.PhoneAccountHandle getAccountHandle();
    method public int getCallCapabilities();
    method public int getCallDirection();
    method public android.telecom.CallIdentification getCallIdentification();
    method public int getCallProperties();
    method public java.lang.String getCallerDisplayName();
@@ -42698,6 +42699,9 @@ package android.telecom {
    field public static final int CAPABILITY_SUPPORT_DEFLECT = 16777216; // 0x1000000
    field public static final int CAPABILITY_SUPPORT_HOLD = 2; // 0x2
    field public static final int CAPABILITY_SWAP_CONFERENCE = 8; // 0x8
    field public static final int DIRECTION_INCOMING = 0; // 0x0
    field public static final int DIRECTION_OUTGOING = 1; // 0x1
    field public static final int DIRECTION_UNKNOWN = -1; // 0xffffffff
    field public static final int PROPERTY_CONFERENCE = 1; // 0x1
    field public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 4; // 0x4
    field public static final int PROPERTY_ENTERPRISE_CALL = 32; // 0x20
+50 −0
Original line number Diff line number Diff line
@@ -66,6 +66,56 @@ public final class RoleManager {

    private static final String LOG_TAG = RoleManager.class.getSimpleName();

    /**
     * The name of the proxy calling role.
     * <p>
     * A proxy calling app implements the {@link android.telecom.CallRedirectionService} API and
     * provides a means to re-write the phone number for an outgoing call to place the call through
     * a proxy calling service.
     * <p>
     * A single app may fill this role at any one time.
     * @hide
     */
    public static final String ROLE_PROXY_CALLING_APP = "android.app.role.PROXY_CALLING_APP";

    /**
     * The name of the call screening and caller id role.
     * <p>
     * A call screening and caller id app implements the
     * {@link android.telecom.CallScreeningService} API.
     * <p>
     * A single app may fill this role at any one time.
     * @hide
     */
    public static final String ROLE_CALL_SCREENING_APP = "android.app.role.CALL_SCREENING_APP";

    /**
     * The name of the call companion app role.
     * <p>
     * A call companion app provides no user interface for calls, but will be bound to by Telecom
     * when there are active calls on the device.  Companion apps for wearable devices are an
     * acceptable use-case.  A call companion app implements the
     * {@link android.telecom.InCallService} API.
     * <p>
     * Multiple apps app may fill this role at any one time.
     * @hide
     */
    public static final String ROLE_CALL_COMPANION_APP = "android.app.role.CALL_COMPANION_APP";

    /**
     * The name of the car mode dialer app role.
     * <p>
     * Similar to the {@link #ROLE_DIALER} role, this role determines which app is responsible for
     * showing the user interface for ongoing calls on the device.  This app filling this role is
     * only used when the device is in car mode (see
     * {@link android.app.UiModeManager#ACTION_ENTER_CAR_MODE} for more information).  An app
     * filling this role must implement the {@link android.telecom.InCallService} API.
     * <p>
     * A single app may fill this role at any one time.
     * @hide
     */
    public static final String ROLE_CAR_MODE_DIALER_APP = "android.app.role.CAR_MODE_DIALER_APP";

    /**
     * The name of the dialer role.
     */
+42 −4
Original line number Diff line number Diff line
@@ -239,6 +239,30 @@ public final class Call {
            "android.telecom.event.HANDOVER_FAILED";

    public static class Details {
        /** @hide */
        @Retention(RetentionPolicy.SOURCE)
        @IntDef(
                prefix = { "DIRECTION_" },
                value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
        public @interface CallDirection {}

        /**
         * Indicates that the call is neither and incoming nor an outgoing call.  This can be the
         * case for calls reported directly by a {@link ConnectionService} in special cases such as
         * call handovers.
         */
        public static final int DIRECTION_UNKNOWN = -1;

        /**
         * Indicates that the call is an incoming call.
         */
        public static final int DIRECTION_INCOMING = 0;

        /**
         * Indicates that the call is an outgoing call.
         */
        public static final int DIRECTION_OUTGOING = 1;


        /** Call can currently be put on hold or unheld. */
        public static final int CAPABILITY_HOLD = 0x00000001;
@@ -519,6 +543,7 @@ public final class Call {
        private final Bundle mIntentExtras;
        private final long mCreationTimeMillis;
        private final CallIdentification mCallIdentification;
        private final @CallDirection int mCallDirection;

        /**
         * Whether the supplied capabilities  supports the specified capability.
@@ -838,6 +863,14 @@ public final class Call {
            return mCallIdentification;
        }

        /**
         * Indicates whether the call is an incoming or outgoing call.
         * @return The call's direction.
         */
        public @CallDirection int getCallDirection() {
            return mCallDirection;
        }

        @Override
        public boolean equals(Object o) {
            if (o instanceof Details) {
@@ -859,7 +892,8 @@ public final class Call {
                        areBundlesEqual(mExtras, d.mExtras) &&
                        areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
                        Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
                        Objects.equals(mCallIdentification, d.mCallIdentification);
                        Objects.equals(mCallIdentification, d.mCallIdentification) &&
                        Objects.equals(mCallDirection, d.mCallDirection);
            }
            return false;
        }
@@ -881,7 +915,8 @@ public final class Call {
                            mExtras,
                            mIntentExtras,
                            mCreationTimeMillis,
                            mCallIdentification);
                            mCallIdentification,
                            mCallDirection);
        }

        /** {@hide} */
@@ -902,7 +937,8 @@ public final class Call {
                Bundle extras,
                Bundle intentExtras,
                long creationTimeMillis,
                CallIdentification callIdentification) {
                CallIdentification callIdentification,
                int callDirection) {
            mTelecomCallId = telecomCallId;
            mHandle = handle;
            mHandlePresentation = handlePresentation;
@@ -920,6 +956,7 @@ public final class Call {
            mIntentExtras = intentExtras;
            mCreationTimeMillis = creationTimeMillis;
            mCallIdentification = callIdentification;
            mCallDirection = callDirection;
        }

        /** {@hide} */
@@ -941,7 +978,8 @@ public final class Call {
                    parcelableCall.getExtras(),
                    parcelableCall.getIntentExtras(),
                    parcelableCall.getCreationTimeMillis(),
                    parcelableCall.getCallIdentification());
                    parcelableCall.getCallIdentification(),
                    parcelableCall.getCallDirection());
        }

        @Override
+20 −2
Original line number Diff line number Diff line
@@ -250,8 +250,8 @@ public final class CallIdentification implements Parcelable {
        mDetails = details;
        mPhoto = photo;
        mNuisanceConfidence = nuisanceConfidence;
        mCallScreeningAppName = callScreeningPackageName;
        mCallScreeningPackageName = callScreeningAppName;
        mCallScreeningAppName = callScreeningAppName;
        mCallScreeningPackageName = callScreeningPackageName;
    }

    private String mName;
@@ -430,4 +430,22 @@ public final class CallIdentification implements Parcelable {
        return Objects.hash(mName, mDescription, mDetails, mPhoto, mNuisanceConfidence,
                mCallScreeningAppName, mCallScreeningPackageName);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[CallId mName=");
        sb.append(Log.pii(mName));
        sb.append(", mDesc=");
        sb.append(mDescription);
        sb.append(", mDet=");
        sb.append(mDetails);
        sb.append(", conf=");
        sb.append(mNuisanceConfidence);
        sb.append(", appName=");
        sb.append(mCallScreeningAppName);
        sb.append(", pkgName=");
        sb.append(mCallScreeningPackageName);
        return sb.toString();
    }
}
+54 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.SdkConstant;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -33,8 +34,9 @@ import com.android.internal.telecom.ICallScreeningService;

/**
 * This service can be implemented by the default dialer (see
 * {@link TelecomManager#getDefaultDialerPackage()}) to allow or disallow incoming calls before
 * they are shown to a user.
 * {@link TelecomManager#getDefaultDialerPackage()}) or a third party app to allow or disallow
 * incoming calls before they are shown to a user.  This service can also provide
 * {@link CallIdentification} information for calls.
 * <p>
 * Below is an example manifest registration for a {@code CallScreeningService}.
 * <pre>
@@ -56,6 +58,34 @@ import com.android.internal.telecom.ICallScreeningService;
 *     information about a {@link Call.Details call} which will be shown to the user in the
 *     Dialer app.</li>
 * </ol>
 * <p>
 * <h2>Becoming the {@link CallScreeningService}</h2>
 * Telecom will bind to a single app chosen by the user which implements the
 * {@link CallScreeningService} API when there are new incoming and outgoing calls.
 * <p>
 * The code snippet below illustrates how your app can request that it fills the call screening
 * role.
 * <pre>
 * {@code
 * private static final int REQUEST_ID = 1;
 *
 * public void requestRole() {
 *     RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
 *     Intent intent = roleManager.createRequestRoleIntent("android.app.role.CALL_SCREENING_APP");
 *     startActivityForResult(intent, REQUEST_ID);
 * }
 *
 * &#64;Override
 * public void onActivityResult(int requestCode, int resultCode, Intent data) {
 *     if (requestCode == REQUEST_ID) {
 *         if (resultCode == android.app.Activity.RESULT_OK) {
 *             // Your app is now the call screening app
 *         } else {
 *             // Your app is not the call screening app
 *         }
 *     }
 * }
 * </pre>
 */
public abstract class CallScreeningService extends Service {
    /**
@@ -222,30 +252,46 @@ public abstract class CallScreeningService extends Service {
    }

    /**
     * Called when a new incoming call is added.
     * {@link CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse)}
     * should be called to allow or disallow the call.
     * Called when a new incoming or outgoing call is added which is not in the user's contact list.
     * <p>
     * A {@link CallScreeningService} must indicate whether an incoming call is allowed or not by
     * calling
     * {@link CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse)}.
     * Your app can tell if a call is an incoming call by checking to see if
     * {@link Call.Details#getCallDirection()} is {@link Call.Details#DIRECTION_INCOMING}.
     * <p>
     * For incoming or outgoing calls, the {@link CallScreeningService} can call
     * {@link #provideCallIdentification(Call.Details, CallIdentification)} in order to provide
     * {@link CallIdentification} for the call.
     * <p>
     * Note: The {@link Call.Details} instance provided to a call screening service will only have
     * the following properties set.  The rest of the {@link Call.Details} properties will be set to
     * their default value or {@code null}.
     * <ul>
     *     <li>{@link Call.Details#getState()}</li>
     *     <li>{@link Call.Details#getCallDirection()}</li>
     *     <li>{@link Call.Details#getConnectTimeMillis()}</li>
     *     <li>{@link Call.Details#getCreationTimeMillis()}</li>
     *     <li>{@link Call.Details#getHandle()}</li>
     *     <li>{@link Call.Details#getHandlePresentation()}</li>
     * </ul>
     * <p>
     * Only calls where the {@link Call.Details#getHandle() handle} {@link Uri#getScheme() scheme}
     * is {@link PhoneAccount#SCHEME_TEL} are passed for call
     * screening.  Further, only calls which are not in the user's contacts are passed for
     * screening.  For outgoing calls, no post-dial digits are passed.
     *
     * @param callDetails Information about a new incoming call, see {@link Call.Details}.
     * @param callDetails Information about a new call, see {@link Call.Details}.
     */
    public abstract void onScreenCall(@NonNull Call.Details callDetails);

    /**
     * Responds to the given call, either allowing it or disallowing it.
     * Responds to the given incoming call, either allowing it or disallowing it.
     * <p>
     * The {@link CallScreeningService} calls this method to inform the system whether the call
     * should be silently blocked or not.
     * <p>
     * Calls to this method are ignored unless the {@link Call.Details#getCallDirection()} is
     * {@link Call.Details#DIRECTION_INCOMING}.
     *
     * @param callDetails The call to allow.
     *                    <p>
Loading