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

Commit dee56a8a authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Expand call/connection extras API.

Currently, connection extras are propagated up to Telecom as an
entire bundle.  This is not ideal, as any time a change is made to
the extras, the bundle needs to be fetched, changed, and then re-set on
the connection, where it is parceled to Telecom as a whole.

Using how extras on an Intent as inspiration, this CL adds separate
putExtras, putExtra, and removeExtra methods to allow manipulation of
the extras bundle without operating on it in its entirety.

This Cl also adds support for Calls modifying the extras bundle, with
changes propagated back down to ConnectionServices.

Bug: 27458894
Change-Id: I152340a3bca2dc03f170b06b172a6823410fb961
parent fbc98e1c
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -36008,9 +36008,11 @@ package android.telecom {
    method public void playDtmfTone(char);
    method public void postDialContinue(boolean);
    method public void pullExternalCall();
    method public final void putExtras(android.os.Bundle);
    method public void registerCallback(android.telecom.Call.Callback);
    method public void registerCallback(android.telecom.Call.Callback, android.os.Handler);
    method public void reject(boolean, java.lang.String);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public void sendCallEvent(java.lang.String, android.os.Bundle);
    method public void splitFromConference();
    method public void stopDtmfTone();
@@ -36151,6 +36153,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onConnectionAdded(android.telecom.Connection);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onMerge(android.telecom.Connection);
    method public void onMerge();
@@ -36159,14 +36162,16 @@ package android.telecom {
    method public void onStopDtmfTone();
    method public void onSwap();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeConnection(android.telecom.Connection);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public final void setActive();
    method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
    method public final void setConnectionCapabilities(int);
    method public final void setConnectionTime(long);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setOnHold();
    method public final void setStatusHints(android.telecom.StatusHints);
    method public final void setVideoProvider(android.telecom.Connection, android.telecom.Connection.VideoProvider);
@@ -36204,6 +36209,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onCallEvent(java.lang.String, android.os.Bundle);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onPlayDtmfTone(char);
    method public void onPostDialContinue(boolean);
@@ -36214,6 +36220,8 @@ package android.telecom {
    method public void onStateChanged(int);
    method public void onStopDtmfTone();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public void sendConnectionEvent(java.lang.String, android.os.Bundle);
    method public final void setActive();
    method public final void setAddress(android.net.Uri, int);
@@ -36224,7 +36232,7 @@ package android.telecom {
    method public final void setConnectionCapabilities(int);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setInitialized();
    method public final void setInitializing();
    method public final void setNextPostDialChar(char);
+10 −2
Original line number Diff line number Diff line
@@ -38571,9 +38571,11 @@ package android.telecom {
    method public void playDtmfTone(char);
    method public void postDialContinue(boolean);
    method public void pullExternalCall();
    method public final void putExtras(android.os.Bundle);
    method public void registerCallback(android.telecom.Call.Callback);
    method public void registerCallback(android.telecom.Call.Callback, android.os.Handler);
    method public void reject(boolean, java.lang.String);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public deprecated void removeListener(android.telecom.Call.Listener);
    method public void sendCallEvent(java.lang.String, android.os.Bundle);
    method public void splitFromConference();
@@ -38724,6 +38726,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onConnectionAdded(android.telecom.Connection);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onMerge(android.telecom.Connection);
    method public void onMerge();
@@ -38732,7 +38735,9 @@ package android.telecom {
    method public void onStopDtmfTone();
    method public void onSwap();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeConnection(android.telecom.Connection);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public final void setActive();
    method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
    method public final deprecated void setConnectTimeMillis(long);
@@ -38740,7 +38745,7 @@ package android.telecom {
    method public final void setConnectionTime(long);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setOnHold();
    method public final void setStatusHints(android.telecom.StatusHints);
    method public final void setVideoProvider(android.telecom.Connection, android.telecom.Connection.VideoProvider);
@@ -38780,6 +38785,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onCallEvent(java.lang.String, android.os.Bundle);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onPlayDtmfTone(char);
    method public void onPostDialContinue(boolean);
@@ -38790,6 +38796,8 @@ package android.telecom {
    method public void onStateChanged(int);
    method public void onStopDtmfTone();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public void sendConnectionEvent(java.lang.String, android.os.Bundle);
    method public final void setActive();
    method public final void setAddress(android.net.Uri, int);
@@ -38800,7 +38808,7 @@ package android.telecom {
    method public final void setConnectionCapabilities(int);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setInitialized();
    method public final void setInitializing();
    method public final void setNextPostDialChar(char);
+10 −2
Original line number Diff line number Diff line
@@ -36079,9 +36079,11 @@ package android.telecom {
    method public void playDtmfTone(char);
    method public void postDialContinue(boolean);
    method public void pullExternalCall();
    method public final void putExtras(android.os.Bundle);
    method public void registerCallback(android.telecom.Call.Callback);
    method public void registerCallback(android.telecom.Call.Callback, android.os.Handler);
    method public void reject(boolean, java.lang.String);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public void sendCallEvent(java.lang.String, android.os.Bundle);
    method public void splitFromConference();
    method public void stopDtmfTone();
@@ -36222,6 +36224,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onConnectionAdded(android.telecom.Connection);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onMerge(android.telecom.Connection);
    method public void onMerge();
@@ -36230,14 +36233,16 @@ package android.telecom {
    method public void onStopDtmfTone();
    method public void onSwap();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeConnection(android.telecom.Connection);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public final void setActive();
    method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
    method public final void setConnectionCapabilities(int);
    method public final void setConnectionTime(long);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setOnHold();
    method public final void setStatusHints(android.telecom.StatusHints);
    method public final void setVideoProvider(android.telecom.Connection, android.telecom.Connection.VideoProvider);
@@ -36275,6 +36280,7 @@ package android.telecom {
    method public void onCallAudioStateChanged(android.telecom.CallAudioState);
    method public void onCallEvent(java.lang.String, android.os.Bundle);
    method public void onDisconnect();
    method public void onExtrasChanged(android.os.Bundle);
    method public void onHold();
    method public void onPlayDtmfTone(char);
    method public void onPostDialContinue(boolean);
@@ -36285,6 +36291,8 @@ package android.telecom {
    method public void onStateChanged(int);
    method public void onStopDtmfTone();
    method public void onUnhold();
    method public final void putExtras(android.os.Bundle);
    method public final void removeExtras(java.util.List<java.lang.String>);
    method public void sendConnectionEvent(java.lang.String, android.os.Bundle);
    method public final void setActive();
    method public final void setAddress(android.net.Uri, int);
@@ -36295,7 +36303,7 @@ package android.telecom {
    method public final void setConnectionCapabilities(int);
    method public final void setDialing();
    method public final void setDisconnected(android.telecom.DisconnectCause);
    method public final void setExtras(android.os.Bundle);
    method public final deprecated void setExtras(android.os.Bundle);
    method public final void setInitialized();
    method public final void setInitializing();
    method public final void setNextPostDialChar(char);
+84 −0
Original line number Diff line number Diff line
@@ -813,6 +813,7 @@ public final class Call {
    private String mRemainingPostDialSequence;
    private VideoCallImpl mVideoCallImpl;
    private Details mDetails;
    private Bundle mExtras;

    /**
     * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
@@ -987,6 +988,89 @@ public final class Call {
        mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
    }

    /**
     * Adds some extras to this {@link Call}.  Existing keys are replaced and new ones are
     * added.
     * <p>
     * No assumptions should be made as to how an In-Call UI or service will handle these
     * extras.  Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
     *
     * @param extras The extras to add.
     */
    public final void putExtras(Bundle extras) {
        if (extras == null) {
            return;
        }

        if (mExtras == null) {
            mExtras = new Bundle();
        }
        mExtras.putAll(extras);
        mInCallAdapter.putExtras(mTelecomCallId, extras);
    }

    /**
     * Adds a boolean extra to this {@link Call}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, boolean value) {
        if (mExtras == null) {
            mExtras = new Bundle();
        }
        mExtras.putBoolean(key, value);
        mInCallAdapter.putExtra(mTelecomCallId, key, value);
    }

    /**
     * Adds an integer extra to this {@code Connection}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, int value) {
        if (mExtras == null) {
            mExtras = new Bundle();
        }
        mExtras.putInt(key, value);
        mInCallAdapter.putExtra(mTelecomCallId, key, value);
    }

    /**
     * Adds a string extra to this {@code Connection}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, String value) {
        if (mExtras == null) {
            mExtras = new Bundle();
        }
        mExtras.putString(key, value);
        mInCallAdapter.putExtra(mTelecomCallId, key, value);
    }

    /**
     * Removes extras from this {@code Connection}.
     *
     * @param keys The keys of the extras to remove.
     */
    public final void removeExtras(List<String> keys) {
        if (mExtras != null) {
            for (String key : keys) {
                mExtras.remove(key);
            }
            if (mExtras.size() == 0) {
                mExtras = null;
            }
        }
        mInCallAdapter.removeExtras(mTelecomCallId, keys);
    }

    /**
     * Obtains the parent of this {@code Call} in a conference, if any.
     *
+158 −6
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package android.telecom;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.telecom.Connection.VideoProvider;
import android.util.ArraySet;

import java.util.ArrayList;
import java.util.Collections;
@@ -54,7 +56,8 @@ public abstract class Conference extends Conferenceable {
        public void onVideoStateChanged(Conference c, int videoState) { }
        public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
        public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
        public void onExtrasChanged(Conference conference, Bundle extras) {}
        public void onExtrasChanged(Conference c, Bundle extras) {}
        public void onExtrasRemoved(Conference c, List<String> keys) {}
    }

    private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
@@ -75,6 +78,7 @@ public abstract class Conference extends Conferenceable {
    private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
    private StatusHints mStatusHints;
    private Bundle mExtras;
    private Set<String> mPreviousExtraKeys;

    private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
        @Override
@@ -640,23 +644,171 @@ public abstract class Conference extends Conferenceable {
    }

    /**
     * Set some extras that can be associated with this {@code Conference}. No assumptions should
     * be made as to how an In-Call UI or service will handle these extras.
     * Replaces all the extras associated with this {@code Conference}.
     * <p>
     * New or existing keys are replaced in the {@code Conference} extras.  Keys which are no longer
     * in the new extras, but were present the last time {@code setExtras} was called are removed.
     * <p>
     * No assumptions should be made as to how an In-Call UI or service will handle these extras.
     * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
     *
     * @param extras The extras associated with this {@code Connection}.
     * @param extras The extras associated with this {@code Conference}.
     * @deprecated Use {@link #putExtras(Bundle)} to add extras.  Use {@link #removeExtras(List)}
     * to remove extras.
     */
    public final void setExtras(@Nullable Bundle extras) {
        mExtras = extras;
        // Add/replace any new or changed extras values.
        putExtras(extras);

        // If we have used "setExtras" in the past, compare the key set from the last invocation to
        // the current one and remove any keys that went away.
        if (mPreviousExtraKeys != null) {
            List<String> toRemove = new ArrayList<String>();
            for (String oldKey : mPreviousExtraKeys) {
                if (!extras.containsKey(oldKey)) {
                    toRemove.add(oldKey);
                }
            }

            if (!toRemove.isEmpty()) {
                removeExtras(toRemove);
            }
        }

        // Track the keys the last time set called setExtras.  This way, the next time setExtras is
        // called we can see if the caller has removed any extras values.
        if (mPreviousExtraKeys == null) {
            mPreviousExtraKeys = new ArraySet<String>();
        }
        mPreviousExtraKeys.clear();
        mPreviousExtraKeys.addAll(extras.keySet());
    }

    /**
     * Adds some extras to this {@link Conference}.  Existing keys are replaced and new ones are
     * added.
     * <p>
     * No assumptions should be made as to how an In-Call UI or service will handle these extras.
     * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
     *
     * @param extras The extras to add.
     */
    public final void putExtras(@NonNull Bundle extras) {
        if (extras == null) {
            return;
        }

        if (mExtras == null) {
            mExtras = new Bundle();
        }
        mExtras.putAll(extras);

        for (Listener l : mListeners) {
            l.onExtrasChanged(this, extras);
        }
    }

    /**
     * @return The extras associated with this conference.
     * Adds a boolean extra to this {@link Conference}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, boolean value) {
        Bundle newExtras = new Bundle();
        newExtras.putBoolean(key, value);
        putExtras(newExtras);
    }

    /**
     * Adds an integer extra to this {@link Conference}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, int value) {
        Bundle newExtras = new Bundle();
        newExtras.putInt(key, value);
        putExtras(newExtras);
    }

    /**
     * Adds a string extra to this {@link Conference}.
     *
     * @param key The extra key.
     * @param value The value.
     * @hide
     */
    public final void putExtra(String key, String value) {
        Bundle newExtras = new Bundle();
        newExtras.putString(key, value);
        putExtras(newExtras);
    }

    /**
     * Removes an extra from this {@link Conference}.
     *
     * @param keys The key of the extra key to remove.
     */
    public final void removeExtras(List<String> keys) {
        if (keys == null || keys.isEmpty()) {
            return;
        }

        if (mExtras != null) {
            for (String key : keys) {
                mExtras.remove(key);
            }
            if (mExtras.size() == 0) {
                mExtras = null;
            }
        }

        for (Listener l : mListeners) {
            l.onExtrasRemoved(this, keys);
        }
    }

    /**
     * Returns the extras associated with this conference.
     * <p>
     * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
     * <p>
     * Telecom or an {@link InCallService} can also update the extras via
     * {@link android.telecom.Call#putExtras(Bundle)}, and
     * {@link Call#removeExtras(List)}.
     * <p>
     * The conference is notified of changes to the extras made by Telecom or an
     * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
     *
     * @return The extras associated with this connection.
     */
    public final Bundle getExtras() {
        return mExtras;
    }

    /**
     * Notifies this {@link Conference} of a change to the extras made outside the
     * {@link ConnectionService}.
     * <p>
     * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
     * {@link android.telecom.Call#putExtras(Bundle)}, and
     * {@link Call#removeExtras(List)}.
     *
     * @param extras The new extras bundle.
     */
    public void onExtrasChanged(Bundle extras) {}

    /**
     * Handles a change to extras received from Telecom.
     *
     * @param extras The new extras.
     * @hide
     */
    final void handleExtrasChanged(Bundle extras) {
        mExtras = extras;
        onExtrasChanged(mExtras);
    }
}
Loading