Merge "Add methods to TelephonyManager for Subscription management (1/3)"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
telecomm/java/android/telecomm/Subscription.aidl
Normal file
22
telecomm/java/android/telecomm/Subscription.aidl
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -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,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);
|
||||
}
|
||||
|
||||
@@ -19,15 +19,12 @@ package android.telephony;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.telephony.Rlog;
|
||||
import android.telecomm.Subscription;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.telecomm.ITelecommService;
|
||||
@@ -40,7 +37,6 @@ import com.android.internal.telephony.TelephonyProperties;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -301,6 +297,17 @@ public class TelephonyManager {
|
||||
*/
|
||||
public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
|
||||
|
||||
/**
|
||||
* The lookup key used with an {@link android.content.Intent#ACTION_CALL} or
|
||||
* {@link android.content.Intent#ACTION_DIAL} {@code Intent} for a {@link Subscription}
|
||||
* object indicating a preference when making a phone connection.
|
||||
*
|
||||
* <p class="note">
|
||||
* Retrieve with
|
||||
* {@link android.content.Intent#getParcelableExtra(String)}.
|
||||
*/
|
||||
public static final String EXTRA_SUBSCRIPTION = "subscription";
|
||||
|
||||
/**
|
||||
* Broadcast intent action indicating that a precise call state
|
||||
* (cellular) on the device has changed.
|
||||
@@ -3112,4 +3119,40 @@ public class TelephonyManager {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of Subscriptions that can be used to indicate a preference when making
|
||||
* a phone call.
|
||||
*
|
||||
* @see #EXTRA_SUBSCRIPTION
|
||||
* @return A list of {@code Subscription} objects.
|
||||
*/
|
||||
public List<Subscription> getSubscriptions() {
|
||||
try {
|
||||
return getTelecommService().getSubscriptions();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling ITelephony#getSubscriptions", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@SystemApi
|
||||
public void setEnabled(Subscription subscription, boolean enabled) {
|
||||
try {
|
||||
getTelecommService().setEnabled(subscription, enabled);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling ITelephony#setEnabled", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@SystemApi
|
||||
public void setSystemDefault(Subscription subscription) {
|
||||
try {
|
||||
getTelecommService().setSystemDefault(subscription);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling ITelephony#setSystemDefault", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user