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

Commit 807fe0a1 authored by Ihab Awad's avatar Ihab Awad Committed by Santos Cordon
Browse files

Implement multi-SIM capabilities (1/6) [DO NOT MERGE]

- Split PhoneAccount into PhoneAccount & PhoneAccountMetadata
- Move PhoneAccount methods from TelephonyManager to TelecommManager

Bug:16292368
Change-Id: Ib440368d6bd0572b63c942360450fde5c27d84b9
(cherry picked from commit 936b3552b4a3569be9904c826b95b632886fb45d)
parent 8fbd0dc3
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -28110,18 +28110,27 @@ package android.telecomm {
    method protected abstract void updateCall(android.telecomm.InCallCall);
  }
  public final class PhoneAccount implements android.os.Parcelable {
    ctor public PhoneAccount(android.content.ComponentName, java.lang.String, android.net.Uri, java.lang.String, java.lang.String, boolean, boolean);
  public class PhoneAccount implements android.os.Parcelable {
    ctor public PhoneAccount(android.content.ComponentName, java.lang.String, android.net.Uri, int);
    method public int describeContents();
    method public int getCapabilities();
    method public android.content.ComponentName getComponentName();
    method public android.net.Uri getHandle();
    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
    method public android.graphics.drawable.Drawable getIcon(android.content.Context, int);
    method public java.lang.String getId();
    method public java.lang.String getLabel(android.content.Context);
    method public java.lang.String getShortDescription(android.content.Context);
    method public boolean isEnabled();
    method public boolean isSystemDefault();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int CAPABILITY_CALL_PROVIDER = 2; // 0x2
    field public static final int CAPABILITY_SIM_CALL_MANAGER = 1; // 0x1
    field public static final int CAPABILITY_SIM_SUBSCRIPTION = 4; // 0x4
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public class PhoneAccountMetadata implements android.os.Parcelable {
    ctor public PhoneAccountMetadata(android.telecomm.PhoneAccount, int, java.lang.String, java.lang.String);
    method public int describeContents();
    method public android.telecomm.PhoneAccount getAccount();
    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
    method public java.lang.String getLabel();
    method public java.lang.String getShortDescription();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
@@ -28662,7 +28671,6 @@ package android.telephony {
  }
  public class TelephonyManager {
    method public java.util.List<android.telecomm.PhoneAccount> getAccounts();
    method public java.util.List<android.telephony.CellInfo> getAllCellInfo();
    method public int getCallState();
    method public android.telephony.CellLocation getCellLocation();
@@ -28711,7 +28719,6 @@ package android.telephony {
    field public static final int DATA_CONNECTING = 1; // 0x1
    field public static final int DATA_DISCONNECTED = 0; // 0x0
    field public static final int DATA_SUSPENDED = 3; // 0x3
    field public static final java.lang.String EXTRA_ACCOUNT = "account";
    field public static final java.lang.String EXTRA_INCOMING_NUMBER = "incoming_number";
    field public static final java.lang.String EXTRA_STATE = "state";
    field public static final java.lang.String EXTRA_STATE_IDLE;
+1 −3
Original line number Diff line number Diff line
@@ -558,9 +558,7 @@ class ContextImpl extends Context {

        registerService(TELECOMM_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    IBinder b = ServiceManager.getService(TELECOMM_SERVICE);
                    return new TelecommManager(ctx.getOuterContext(),
                            ITelecommService.Stub.asInterface(b));
                    return new TelecommManager(ctx.getOuterContext());
                }});

        registerService(PHONE_SERVICE, new ServiceFetcher() {
+54 −113
Original line number Diff line number Diff line
@@ -17,52 +17,64 @@
package android.telecomm;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Rlog;
import android.util.DisplayMetrics;
import android.util.Log;

import java.util.MissingResourceException;
import java.util.Objects;

/**
 * Represents a distinct account, line of service or call placement method that
 * the system can use to place phone calls.
 */
public final class PhoneAccount implements Parcelable {
public class PhoneAccount implements Parcelable {

    private static final int NO_DENSITY = -1;

    private static final String LOG_TAG = "Account";
    /**
     * Flag indicating that this {@code PhoneAccount} can act as a call manager for traditional
     * SIM-based telephony calls. The {@link ConnectionService} associated with this phone-account
     * will be allowed to manage SIM-based phone calls including using its own proprietary
     * phone-call implementation (like VoIP calling) to make calls instead of the telephony stack.
     * When a user opts to place a call using the SIM-based telephony stack, the connection-service
     * associated with this phone-account will be attempted first if the user has explicitly
     * selected it to be used as the default call-manager.
     * <p>
     * See {@link #getCapabilities}
     */
    public static final int CAPABILITY_SIM_CALL_MANAGER = 0x1;

    private final ComponentName mComponentName;
    private final String mId;
    private final Uri mHandle;
    private final String mLabel;
    private final String mShortDescription;
    private final boolean mIsEnabled;
    private final boolean mIsSystemDefault;
    /**
     * Flag indicating that this {@code PhoneAccount} can make phone calls in place of traditional
     * SIM-based telephony calls. This account will be treated as a distinct method for placing
     * calls alongside the traditional SIM-based telephony stack. This flag is distinct from
     * {@link #CAPABILITY_SIM_CALL_MANAGER} in that it is not allowed to manage calls from or use
     * the built-in telephony stack to place its calls.
     * <p>
     * See {@link #getCapabilities}
     */
    public static final int CAPABILITY_CALL_PROVIDER = 0x2;

    /**
     * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM subscription.
     * <p>
     * Only the android framework can set this capability on a phone-account.
     */
    public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;

    private ComponentName mComponentName;
    private String mId;
    private Uri mHandle;
    private int mCapabilities;

    public PhoneAccount(
            ComponentName componentName,
            String id,
            Uri handle,
            String label,
            String shortDescription,
            boolean isEnabled,
            boolean isSystemDefault) {
            int capabilities) {
        mComponentName = componentName;
        mId = id;
        mHandle = handle;
        mLabel = label;
        mShortDescription = shortDescription;
        mIsSystemDefault = isSystemDefault;
        mIsEnabled = isEnabled;
        mCapabilities = capabilities;
    }

    /**
@@ -87,8 +99,8 @@ public final class PhoneAccount implements Parcelable {

    /**
     * The handle (e.g., a phone number) associated with this {@code PhoneAccount}. This represents
     * the destination from which outgoing calls using this {@code PhoneAccount} will appear to come
     * from, if applicable, and the destination to which incoming calls using this
     * the destination from which outgoing calls using this {@code PhoneAccount} will appear to
     * come, if applicable, and the destination to which incoming calls using this
     * {@code PhoneAccount} may be addressed.
     *
     * @return A handle expressed as a {@code Uri}, for example, a phone number.
@@ -98,76 +110,23 @@ public final class PhoneAccount implements Parcelable {
    }

    /**
     * A short string label describing this {@code PhoneAccount}.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * TODO(ihab): If don't need context, remove param
     * The capabilities of this {@code PhoneAccount}.
     *
     * @return A label for this {@code PhoneAccount}.
     * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
     */
    public String getLabel(Context context) {
        return mLabel;
    public int getCapabilities() {
        return mCapabilities;
    }

    /**
     * A short paragraph describing this {@code PhoneAccount}.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * TODO(ihab): If don't need context, remove param
     *
     * @return A description for this {@code PhoneAccount}.
     */
    public String getShortDescription(Context context) {
        return mShortDescription;
    @Override
    public int hashCode() {
        return Objects.hashCode(mComponentName) + Objects.hashCode(mId) +
                Objects.hashCode(mHandle) + mCapabilities;
    }

    // TODO(ihab): Representation of the icons
    //
    // Refactor to pass a Bitmap (scale it at runtime), but if they don't pass one, fall
    // back to the android:icon attr in the manifest (<service /> first, <application /> second)

    /**
     * An icon to represent this {@code PhoneAccount} in a user interface.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * @return An icon for this {@code PhoneAccount}.
     */
    public Drawable getIcon(Context context) {
        return null;  // TODO(ihab): See above
    }

    /**
     * An icon to represent this {@code PhoneAccount} in a user interface.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     * @param density A display density from {@link DisplayMetrics}.
     *
     * @return An icon for this {@code PhoneAccount}.
     */
    public Drawable getIcon(Context context, int density) {
        return null;  // TODO(ihab): See above
    }

    /**
     * Whether this {@code PhoneAccount} is enabled for use.
     *
     * @return {@code true} if this {@code PhoneAccount} is enabled.
     */
    public boolean isEnabled() {
        return mIsEnabled;
    }

    /**
     * Whether this {@code PhoneAccount} is the system default.
     *
     * @return {@code true} if this {@code PhoneAccount} is the system default.
     */
    public boolean isSystemDefault() {
        return mIsSystemDefault;
    }
    // Parcelable implementation.
    //

    @Override
    public int describeContents() {
@@ -179,18 +138,16 @@ public final class PhoneAccount implements Parcelable {
        out.writeParcelable(mComponentName, flags);
        out.writeString(mId);
        out.writeString(mHandle != null ? mHandle.toString() : "");
        out.writeString(mLabel);
        out.writeString(mShortDescription);
        out.writeInt(mIsEnabled ? 1 : 0);
        out.writeInt(mIsSystemDefault ? 1 : 0);
        out.writeInt(mCapabilities);
    }

    public static final Creator<PhoneAccount> CREATOR
            = new Creator<PhoneAccount>() {
    public static final Creator<PhoneAccount> CREATOR = new Creator<PhoneAccount>() {
        @Override
        public PhoneAccount createFromParcel(Parcel in) {
            return new PhoneAccount(in);
        }

        @Override
        public PhoneAccount[] newArray(int size) {
            return new PhoneAccount[size];
        }
@@ -201,22 +158,6 @@ public final class PhoneAccount implements Parcelable {
        mId = in.readString();
        String uriString = in.readString();
        mHandle = uriString.length() > 0 ? Uri.parse(uriString) : null;
        mLabel = in.readString();
        mShortDescription = in.readString();
        mIsEnabled = in.readInt() == 1;
        mIsSystemDefault = in.readInt() == 1;
    }

    @Override
    public boolean equals(Object other) {
        return
                other instanceof PhoneAccount &&
                Objects.equals(mComponentName, ((PhoneAccount) other).mComponentName) &&
                Objects.equals(mId, ((PhoneAccount) other).mId);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(mComponentName) + Objects.hashCode(mId);
        mCapabilities = in.readInt();
    }
}
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telecomm;

/**
 * {@hide}
  */
parcelable PhoneAccountMetadata;
+140 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telecomm;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.MissingResourceException;

/**
 * Provides user interface description information for a {@code PhoneAccount}.
 */
public class PhoneAccountMetadata implements Parcelable {
    private PhoneAccount mAccount;
    private int mIconResId;
    private String mLabel;
    private String mShortDescription;

    public PhoneAccountMetadata(
            PhoneAccount account,
            int iconResId,
            String label,
            String shortDescription) {
        mAccount = account;
        mIconResId = iconResId;
        mLabel = label;
        mShortDescription = shortDescription;
    }

    /**
     * The {@code PhoneAccount} to which this metadata pertains.
     *
     * @return A {@code PhoneAccount}.
     */
    public PhoneAccount getAccount() {
        return mAccount;
    }

    /**
     * A short string label describing a {@code PhoneAccount}.
     *
     * @return A label for this {@code PhoneAccount}.
     */
    public String getLabel() {
        return mLabel;
    }

    /**
     * A short paragraph describing a {@code PhoneAccount}.
     *
     * @return A description for this {@code PhoneAccount}.
     */
    public String getShortDescription() {
        return mShortDescription;
    }

    /**
     * An icon to represent this {@code PhoneAccount} in a user interface.
     *
     * @return An icon for this {@code PhoneAccount}.
     */
    public Drawable getIcon(Context context) {
        return getIcon(context, mIconResId);
    }

    private Drawable getIcon(Context context, int resId) {
        Context packageContext;
        try {
            packageContext = context.createPackageContext(
                    mAccount.getComponentName().getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(this, "Cannot find package %s", mAccount.getComponentName().getPackageName());
            return null;
        }
        try {
            return packageContext.getResources().getDrawable(resId);
        } catch (MissingResourceException e) {
            Log.e(this, e, "Cannot find icon %d in package %s",
                    resId, mAccount.getComponentName().getPackageName());
            return null;
        }
    }

    //
    // Parcelable implementation
    //

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mAccount, 0);
        out.writeInt(mIconResId);
        out.writeString(mLabel);
        out.writeString(mShortDescription);
    }

    public static final Creator<PhoneAccountMetadata> CREATOR
            = new Creator<PhoneAccountMetadata>() {
        @Override
        public PhoneAccountMetadata createFromParcel(Parcel in) {
            return new PhoneAccountMetadata(in);
        }

        @Override
        public PhoneAccountMetadata[] newArray(int size) {
            return new PhoneAccountMetadata[size];
        }
    };

    private PhoneAccountMetadata(Parcel in) {
        mAccount = in.readParcelable(getClass().getClassLoader());
        mIconResId = in.readInt();
        mLabel = in.readString();
        mShortDescription = in.readString();
    }
}
Loading