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

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

Allowing enable/disable of phone accounts. (1/3)

- added "hasCapabilities" method on PhoneAccount.
- added CAPABILITY_PLACE_EMERGENCY_CALLS.
- added isEnabled method builder constructor to initialize from an
existing PhoneAccount.

Bug: 17306514
Bug: 17408536

Change-Id: I57de508b4adcf207f3b29cab449bfc634db80153
parent 4823aece
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -28340,9 +28340,12 @@ package android.telecomm {
    method public java.lang.CharSequence getShortDescription();
    method public android.net.Uri getSubscriptionAddress();
    method public java.util.List<java.lang.String> getSupportedUriSchemes();
    method public boolean hasCapabilities(int);
    method public boolean isEnabled();
    method public boolean supportsUriScheme(java.lang.String);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int CAPABILITY_CONNECTION_MANAGER = 1; // 0x1
    field public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 16; // 0x10
    field public static final int CAPABILITY_SIM_SUBSCRIPTION = 4; // 0x4
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final java.lang.String SCHEME_SIP = "sip";
@@ -28352,6 +28355,7 @@ package android.telecomm {
  public static class PhoneAccount.Builder {
    ctor public PhoneAccount.Builder(android.telecomm.PhoneAccountHandle, java.lang.CharSequence);
    ctor public PhoneAccount.Builder(android.telecomm.PhoneAccount);
    method public android.telecomm.PhoneAccount build();
    method public android.telecomm.PhoneAccount.Builder setAddress(android.net.Uri);
    method public android.telecomm.PhoneAccount.Builder setCapabilities(int);
+92 −2
Original line number Diff line number Diff line
@@ -82,6 +82,25 @@ public class PhoneAccount implements Parcelable {
     */
    public static final int CAPABILITY_VIDEO_CALLING = 0x8;

    /**
     * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
     * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
     * <p>
     * See {@link #getCapabilities}
     */
    public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;

    /**
     * Flag indicating that this {@code PhoneAccount} is always enabled and cannot be disabled by
     * the user.
     * This capability is reserved for important {@code PhoneAccount}s such as the emergency calling
     * only {@code PhoneAccount}.
     * <p>
     * See {@link #getCapabilities}
     * @hide
     */
    public static final int CAPABILITY_ALWAYS_ENABLED = 0x20;

    /**
     * URI scheme for telephone number URIs.
     */
@@ -105,6 +124,7 @@ public class PhoneAccount implements Parcelable {
    private final CharSequence mLabel;
    private final CharSequence mShortDescription;
    private final List<String> mSupportedUriSchemes;
    private final boolean mIsEnabled;

    public static class Builder {
        private PhoneAccountHandle mAccountHandle;
@@ -115,12 +135,31 @@ public class PhoneAccount implements Parcelable {
        private CharSequence mLabel;
        private CharSequence mShortDescription;
        private List<String> mSupportedUriSchemes = new ArrayList<String>();
        private boolean mIsEnabled = false;

        public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
            this.mAccountHandle = accountHandle;
            this.mLabel = label;
        }

        /**
         * Creates an instance of the {@link PhoneAccount.Builder} from an existing
         * {@link PhoneAccount}.
         *
         * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
         */
        public Builder(PhoneAccount phoneAccount) {
            mAccountHandle = phoneAccount.getAccountHandle();
            mAddress = phoneAccount.getAddress();
            mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
            mCapabilities = phoneAccount.getCapabilities();
            mIconResId = phoneAccount.getIconResId();
            mLabel = phoneAccount.getLabel();
            mShortDescription = phoneAccount.getShortDescription();
            mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
            mIsEnabled = phoneAccount.isEnabled();
        }

        public Builder setAddress(Uri value) {
            this.mAddress = value;
            return this;
@@ -177,6 +216,24 @@ public class PhoneAccount implements Parcelable {
            return this;
        }

        /**
         * Specifies whether the {@link PhoneAccount} is enabled or not.  {@link PhoneAccount}s are
         * by default not enabled.
         *
         * @param value {@code True} if the {@link PhoneAccount} is enabled.
         * @return The Builder.
         * @hide
         */
        public Builder setEnabled(boolean value) {
            this.mIsEnabled = value;
            return this;
        }

        /**
         * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
         *
         * @return The {@link PhoneAccount}.
         */
        public PhoneAccount build() {
            // If no supported URI schemes were defined, assume "tel" is supported.
            if (mSupportedUriSchemes.isEmpty()) {
@@ -191,7 +248,8 @@ public class PhoneAccount implements Parcelable {
                    mIconResId,
                    mLabel,
                    mShortDescription,
                    mSupportedUriSchemes);
                    mSupportedUriSchemes,
                    mIsEnabled);
        }
    }

@@ -203,7 +261,8 @@ public class PhoneAccount implements Parcelable {
            int iconResId,
            CharSequence label,
            CharSequence shortDescription,
            List<String> supportedUriSchemes) {
            List<String> supportedUriSchemes,
            boolean enabled) {
        mAccountHandle = account;
        mAddress = address;
        mSubscriptionAddress = subscriptionAddress;
@@ -212,6 +271,7 @@ public class PhoneAccount implements Parcelable {
        mLabel = label;
        mShortDescription = shortDescription;
        mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
        mIsEnabled = enabled;
    }

    public static Builder builder(
@@ -220,6 +280,14 @@ public class PhoneAccount implements Parcelable {
        return new Builder(accountHandle, label);
    }

    /**
     * Returns a builder initialized with the current {@link PhoneAccount} instance.
     *
     * @return The builder.
     * @hide
     */
    public Builder toBuilder() { return new Builder(this); }

    /**
     * The unique identifier of this {@code PhoneAccount}.
     *
@@ -264,6 +332,17 @@ public class PhoneAccount implements Parcelable {
        return mCapabilities;
    }

    /**
     * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
     * bit mask.
     *
     * @param capability The capabilities to check.
     * @return {@code True} if the phone account has the capability.
     */
    public boolean hasCapabilities(int capability) {
        return (mCapabilities & capability) == capability;
    }

    /**
     * A short label describing a {@code PhoneAccount}.
     *
@@ -312,6 +391,15 @@ public class PhoneAccount implements Parcelable {
        return false;
    }

    /**
     * Determines whether this {@code PhoneAccount} is enabled.
     *
     * @return {@code True} if this {@code PhoneAccount} is enabled..
     */
    public boolean isEnabled() {
        return mIsEnabled;
    }

    /**
     * The icon resource ID for the icon of this {@code PhoneAccount}.
     *
@@ -367,6 +455,7 @@ public class PhoneAccount implements Parcelable {
        out.writeCharSequence(mLabel);
        out.writeCharSequence(mShortDescription);
        out.writeList(mSupportedUriSchemes);
        out.writeInt(mIsEnabled ? 1 : 0);
    }

    public static final Creator<PhoneAccount> CREATOR
@@ -396,5 +485,6 @@ public class PhoneAccount implements Parcelable {
        List<String> supportedUriSchemes = new ArrayList<>();
        in.readList(supportedUriSchemes, classLoader);
        mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
        mIsEnabled = in.readInt() == 1;
    }
}
+79 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.Log;
import com.android.internal.telecomm.ITelecommService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
@@ -347,8 +348,8 @@ public class TelecommManager {
    }

    /**
     * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
     * calls.
     * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive
     * phone calls.
     *
     * @see #EXTRA_PHONE_ACCOUNT_HANDLE
     * @return A list of {@code PhoneAccountHandle} objects.
@@ -356,10 +357,10 @@ public class TelecommManager {
    public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
        try {
            if (isServiceConnected()) {
                return getTelecommService().getOutgoingPhoneAccounts();
                return getTelecommService().getEnabledPhoneAccounts();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelecommService#getOutgoingPhoneAccounts", e);
            Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e);
        }
        return new ArrayList<>();
    }
@@ -425,8 +426,8 @@ public class TelecommManager {
    }

    /**
     * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
     * calls which support the specified URI scheme.
     * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and
     * receive phone calls which support the specified URI scheme.
     * <P>
     * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
     * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}).  Invoking with
@@ -475,6 +476,78 @@ public class TelecommManager {
        return null;
    }

    /**
     * Returns a count of enabled and disabled {@link PhoneAccount}s.
     *
     * @return The count of enabled and disabled {@link PhoneAccount}s.
     * @hide
     */
    @SystemApi
    public int getAllPhoneAccountsCount() {
        try {
            if (isServiceConnected()) {
                return getTelecommService().getAllPhoneAccountsCount();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountsCount", e);
        }
        return 0;
    }

    /**
     * Returns a list of all {@link PhoneAccount}s.
     *
     * @return All {@link PhoneAccount}s.
     * @hide
     */
    @SystemApi
    public List<PhoneAccount> getAllPhoneAccounts() {
        try {
            if (isServiceConnected()) {
                return getTelecommService().getAllPhoneAccounts();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccounts", e);
        }
        return Collections.EMPTY_LIST;
    }

    /**
     * Returns a list of all {@link PhoneAccountHandle}s.
     *
     * @return All {@link PhoneAccountHandle}s.
     * @hide
     */
    @SystemApi
    public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
        try {
            if (isServiceConnected()) {
                return getTelecommService().getAllPhoneAccountHandles();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountHandles", e);
        }
        return Collections.EMPTY_LIST;
    }

    /**
     * Enables or disables a {@link PhoneAccount}.
     *
     * @param account The {@link PhoneAccountHandle} to enable or disable.
     * @param isEnabled {@code True} if the phone account should be enabled.
     * @hide
     */
    @SystemApi
    public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
        try {
            if (isServiceConnected()) {
                getTelecommService().setPhoneAccountEnabled(account, isEnabled);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelecommService#setPhoneAccountEnabled", e);
        }
    }

    /**
     * Register a {@link PhoneAccount} for use by the system.
     *
+22 −2
Original line number Diff line number Diff line
@@ -50,9 +50,9 @@ interface ITelecommService {
    void setUserSelectedOutgoingPhoneAccount(in PhoneAccountHandle account);

    /**
     * @see TelecommServiceImpl#getOutgoingPhoneAccounts
     * @see TelecommServiceImpl#getEnabledPhoneAccounts
     */
    List<PhoneAccountHandle> getOutgoingPhoneAccounts();
    List<PhoneAccountHandle> getEnabledPhoneAccounts();

    /**
     * @see TelecommManager#getPhoneAccountsSupportingScheme
@@ -64,6 +64,21 @@ interface ITelecommService {
     */
    PhoneAccount getPhoneAccount(in PhoneAccountHandle account);

    /**
     * @see TelecommManager#getAllPhoneAccountsCount
     */
    int getAllPhoneAccountsCount();

    /**
     * @see TelecommManager#getAllPhoneAccounts
     */
    List<PhoneAccount> getAllPhoneAccounts();

    /**
     * @see TelecommManager#getAllPhoneAccountHandles
     */
    List<PhoneAccountHandle> getAllPhoneAccountHandles();

    /**
     * @see TelecommServiceImpl#getSimCallManager
     */
@@ -79,6 +94,11 @@ interface ITelecommService {
     */
    List<PhoneAccountHandle> getSimCallManagers();

    /**
     * @see TelecommServiceImpl#setPhoneAccountEnabled
     */
    void setPhoneAccountEnabled(in PhoneAccountHandle account, in boolean isEnabled);

    /**
     * @see TelecommServiceImpl#registerPhoneAccount
     */