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

Commit 87161a76 authored by Ihab Awad's avatar Ihab Awad Committed by Android (Google) Code Review
Browse files

Merge "Add methods to TelephonyManager for Subscription management (1/3)"

parents 441aea77 c35ad025
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -27737,8 +27737,17 @@ package android.telecomm {
  }
  public class Subscription implements android.os.Parcelable {
    ctor public Subscription();
    ctor public Subscription(android.content.ComponentName, java.lang.String, android.net.Uri, int, int, int, boolean, boolean);
    method public int describeContents();
    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 android.os.Parcelable.Creator CREATOR;
  }
@@ -28202,6 +28211,7 @@ package android.telephony {
    method public java.lang.String getSimSerialNumber();
    method public int getSimState();
    method public java.lang.String getSubscriberId();
    method public java.util.List<android.telecomm.Subscription> getSubscriptions();
    method public java.lang.String getVoiceMailAlphaTag();
    method public java.lang.String getVoiceMailNumber();
    method public boolean hasIccCard();
@@ -28226,6 +28236,7 @@ package android.telephony {
    field public static final java.lang.String EXTRA_STATE_IDLE;
    field public static final java.lang.String EXTRA_STATE_OFFHOOK;
    field public static final java.lang.String EXTRA_STATE_RINGING;
    field public static final java.lang.String EXTRA_SUBSCRIPTION = "subscription";
    field public static final int NETWORK_TYPE_1xRTT = 7; // 0x7
    field public static final int NETWORK_TYPE_CDMA = 4; // 0x4
    field public static final int NETWORK_TYPE_EDGE = 2; // 0x2
+0 −6
Original line number Diff line number Diff line
@@ -20,15 +20,9 @@ import android.net.Uri;
import android.os.Bundle;
import android.telephony.DisconnectCause;

import android.os.SystemClock;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * A {@link android.app.Service} that provides telephone connections to
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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 Subscription;
+199 −6
Original line number Diff line number Diff line
@@ -16,25 +16,169 @@

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;

/**
 * Represents a distinct subscription, line of service or call placement method that
 * a {@link ConnectionService} can use to place phone calls.
 * the system can use to place phone calls.
 */
public class Subscription implements Parcelable {

    public Subscription() {}
    private static final int NO_DENSITY = -1;

    private static final String LOG_TAG = "Subscription";

    private final ComponentName mComponentName;
    private final String mId;
    private final Uri mHandle;
    private final int mLabelResId;
    private final int mShortDescriptionResId;
    private final int mIconResId;
    private final boolean mIsEnabled;
    private final boolean mIsSystemDefault;

    public Subscription(
            ComponentName componentName,
            String id,
            Uri handle,
            int labelResId,
            int shortDescriptionResId,
            int iconResId,
            boolean isEnabled,
            boolean isSystemDefault) {
        mComponentName = componentName;
        mId = id;
        mHandle = handle;
        mLabelResId = labelResId;
        mShortDescriptionResId = shortDescriptionResId;
        mIconResId = iconResId;
        mIsSystemDefault = isSystemDefault;
        mIsEnabled = isEnabled;
    }

    /**
     * The {@code ComponentName} of the {@link android.telecomm.ConnectionService} which is
     * responsible for making phone calls using this {@code Subscription}.
     *
     * @return A suitable {@code ComponentName}.
     */
    public ComponentName getComponentName() {
        return mComponentName;
    }

    /**
     * A unique identifier for this {@code Subscription}, generated by and meaningful to the
     * {@link android.telecomm.ConnectionService} that created it.
     *
     * @return A unique identifier for this {@code Subscription}.
     */
    public String getId() {
        return mId;
    }

    /**
     * The handle (e.g., a phone number) associated with this {@code Subscription}. This represents
     * the destination from which outgoing calls using this {@code Subscription} will appear to come
     * from, if applicable, and the destination to which incoming calls using this
     * {@code Subscription} may be addressed.
     *
     * @return A handle expressed as a {@code Uri}, for example, a phone number.
     */
    public Uri getHandle() {
        return mHandle;
    }

    /**
     * A short string label describing this {@code Subscription}.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * @return A label for this {@code Subscription}.
     */
    public String getLabel(Context context) {
        return getString(context, mLabelResId);
    }

    /**
     * A short paragraph describing this {@code Subscription}.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * @return A description for this {@code Subscription}.
     */
    public String getShortDescription(Context context) {
        return getString(context, mShortDescriptionResId);
    }

    /**
     * An icon to represent this {@code Subscription} in a user interface.
     *
     * @param context The invoking {@code Context}, used for retrieving resources.
     *
     * @return An icon for this {@code Subscription}.
     */
    public Drawable getIcon(Context context) {
        return getIcon(context, mIconResId, NO_DENSITY);
    }

    /**
     * An icon to represent this {@code Subscription} 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 Subscription}.
     */
    public Drawable getIcon(Context context, int density) {
        return getIcon(context, mIconResId, density);
    }

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

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

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {}
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mComponentName, flags);
        out.writeString(mId);
        out.writeString(mHandle != null ? mHandle.toString() : "");
        out.writeInt(mLabelResId);
        out.writeInt(mShortDescriptionResId);
        out.writeInt(mIconResId);
        out.writeInt(mIsEnabled ? 1 : 0);
        out.writeInt(mIsSystemDefault ? 1 : 0);
    }

    public static final Parcelable.Creator<Subscription> CREATOR
            = new Parcelable.Creator<Subscription>() {
    public static final Creator<Subscription> CREATOR
            = new Creator<Subscription>() {
        public Subscription createFromParcel(Parcel in) {
            return new Subscription(in);
        }
@@ -44,5 +188,54 @@ public class Subscription implements Parcelable {
        }
    };

    private Subscription(Parcel in) {}
    private Subscription(Parcel in) {
        mComponentName = in.readParcelable(getClass().getClassLoader());
        mId = in.readString();
        String uriString = in.readString();
        mHandle = uriString.length() > 0 ? Uri.parse(uriString) : null;
        mLabelResId = in.readInt();
        mShortDescriptionResId = in.readInt();
        mIconResId = in.readInt();
        mIsEnabled = in.readInt() == 1;
        mIsSystemDefault = in.readInt() == 1;
    }

    private String getString(Context context, int resId) {
        Context packageContext;
        try {
            packageContext = context.createPackageContext(mComponentName.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            if (Rlog.isLoggable(LOG_TAG, Log.WARN)) {
                Rlog.w(LOG_TAG, "Cannot find package " + mComponentName.getPackageName());
            }
            return null;
        }
        String result = packageContext.getString(resId);
        if (result == null && Rlog.isLoggable(LOG_TAG, Log.WARN)) {
            Rlog.w(LOG_TAG, "Cannot find string " + resId + " in package " +
                    mComponentName.getPackageName());
        }
        return result;
    }

    private Drawable getIcon(Context context, int resId, int density) {
        Context packageContext;
        try {
            packageContext = context.createPackageContext(mComponentName.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            if (Rlog.isLoggable(LOG_TAG, Log.WARN)) {
                Rlog.w(LOG_TAG, "Cannot find package " + mComponentName.getPackageName());
            }
            return null;
        }
        try {
            return density == NO_DENSITY ?
                    packageContext.getResources().getDrawable(resId) :
                    packageContext.getResources().getDrawableForDensity(resId, density);
        } catch (MissingResourceException e) {
            Rlog.e(LOG_TAG, "Cannot find icon " + resId + " in package " +
                    mComponentName.getPackageName() + ": " + e.toString());
            return null;
        }
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telecomm;

import android.telecomm.Subscription;
import android.content.ComponentName;

/**
@@ -45,4 +46,19 @@ interface ITelecommService {
     * Returns the component name of the phone application installed on the system partition.
     */
    ComponentName getSystemPhoneApplication();

    /**
     * Gets a list of Subscriptions.
     */
    List<Subscription> getSubscriptions();

    /**
     * Sets the enabled state of a given Subscription.
     */
    void setEnabled(in Subscription subscription, boolean enabled);

    /**
     * Sets a given Subscription as the system default.
     */
    void setSystemDefault(in Subscription subscription);
}
Loading