AI 144245: Fix merge conflict for megering in the CDMA changes in to master from donutburger.

Automated import of CL 144245
This commit is contained in:
Wink Saville
2009-04-02 11:00:54 -07:00
committed by The Android Open Source Project
parent 3afdd56470
commit 04e71b3db8
189 changed files with 24484 additions and 8162 deletions

View File

@@ -19,8 +19,14 @@ package android.telephony;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.RILConstants;
/**
* Abstract class that represents the location of the device. Currently the only
@@ -56,7 +62,17 @@ public abstract class CellLocation {
* @hide
*/
public static CellLocation newFromBundle(Bundle bundle) {
return new GsmCellLocation(bundle);
// TODO: My need to be use: Settings.Secure.getInt(mContext, Settings.Secure.CURRENT_ACTIVE_PHONE, 0))
// instead of SystemProperties???
// NOTE here TelephonyManager.getDefault().getPhoneType() cannot be used since at startup
// ITelephony have not been created
if (RILConstants.CDMA_PHONE ==
SystemProperties.getInt(Settings.Secure.CURRENT_ACTIVE_PHONE, 0)) {
return new CdmaCellLocation(bundle);
} else {
return new GsmCellLocation(bundle);
}
}
/**
@@ -66,8 +82,20 @@ public abstract class CellLocation {
/**
* Return a new CellLocation object representing an unknown location.
*
*/
public static CellLocation getEmpty() {
return new GsmCellLocation();
// TODO: My need to be use: Settings.Secure.getInt(mContext, Settings.Secure.CURRENT_ACTIVE_PHONE, 0))
// instead of SystemProperties???
// NOTE here TelephonyManager.getDefault().getPhoneType() cannot be used since at startup
// ITelephony have not been created
if (RILConstants.CDMA_PHONE ==
SystemProperties.getInt(Settings.Secure.CURRENT_ACTIVE_PHONE, 0)) {
return new CdmaCellLocation();
} else {
return new GsmCellLocation();
}
}
}

View File

@@ -25,7 +25,7 @@ import java.util.Locale;
/**
* Watches a {@link TextView} and if a phone number is entered will format it using
* {@link PhoneNumberUtils#formatNumber(Editable, int)}. The formatting is based on
* {@link PhoneNumberUtils#formatNumber(Editable, int)}. The formatting is based on
* the current system locale when this object is created and future locale changes
* may not take effect on this instance.
*/
@@ -35,7 +35,7 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
static private Locale sCachedLocale;
private boolean mFormatting;
private boolean mDeletingHyphen;
private int mHyphenStart;
private int mHyphenStart;
private boolean mDeletingBackward;
public PhoneNumberFormattingTextWatcher() {
@@ -60,7 +60,7 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
text.delete(mHyphenStart, mHyphenStart + 1);
}
}
PhoneNumberUtils.formatNumber(text, sFormatType);
mFormatting = false;
@@ -73,8 +73,8 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
// Make sure user is deleting one char, without a selection
final int selStart = Selection.getSelectionStart(s);
final int selEnd = Selection.getSelectionEnd(s);
if (s.length() > 1 // Can delete another character
&& count == 1 // Deleting only one character
if (s.length() > 1 // Can delete another character
&& count == 1 // Deleting only one character
&& after == 0 // Deleting
&& s.charAt(start) == '-' // a hyphen
&& selStart == selEnd) { // no selection
@@ -89,7 +89,7 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
} else {
mDeletingHyphen = false;
}
}
}
}
public void onTextChanged(CharSequence s, int start, int before, int count) {

View File

@@ -11,18 +11,18 @@ import com.android.internal.telephony.IPhoneStateListener;
/**
* A listener class for monitoring changes in specific telephony states
* on the device, including service state, signal strength, message
* on the device, including service state, signal strength, message
* waiting indicator (voicemail), and others.
* <p>
* Override the methods for the state that you wish to receive updates for, and
* Override the methods for the state that you wish to receive updates for, and
* pass your PhoneStateListener object, along with bitwise-or of the LISTEN_
* flags to {@link TelephonyManager#listen TelephonyManager.listen()}.
* <p>
* Note that access to some telephony information is
* permission-protected. Your application won't receive updates for protected
* information unless it has the appropriate permissions declared in
* permission-protected. Your application won't receive updates for protected
* information unless it has the appropriate permissions declared in
* its manifest file. Where permissions apply, they are noted in the
* appropriate LISTEN_ flags.
* appropriate LISTEN_ flags.
*/
public class PhoneStateListener {
@@ -67,17 +67,17 @@ public class PhoneStateListener {
public static final int LISTEN_CALL_FORWARDING_INDICATOR = 0x00000008;
/**
* Listen for changes to the device's cell location. Note that
* Listen for changes to the device's cell location. Note that
* this will result in frequent callbacks to the listener.
* {@more}
* Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION
* ACCESS_COARSE_LOCATION}
* <p>
* If you need regular location updates but want more control over
* the update interval or location precision, you can set up a listener
* through the {@link android.location.LocationManager location manager}
* instead.
*
* If you need regular location updates but want more control over
* the update interval or location precision, you can set up a listener
* through the {@link android.location.LocationManager location manager}
* instead.
*
* @see #onCellLocationChanged
*/
public static final int LISTEN_CELL_LOCATION = 0x00000010;
@@ -100,7 +100,7 @@ public class PhoneStateListener {
* Listen for changes to the direction of data traffic on the data
* connection (cellular).
*
* Example: The status bar uses this to display the appropriate
* Example: The status bar uses this to display the appropriate
* data-traffic icon.
*
* @see #onDataActivity
@@ -111,7 +111,7 @@ public class PhoneStateListener {
}
/**
* Callback invoked when device service state changes.
* Callback invoked when device service state changes.
*
* @see ServiceState#STATE_EMERGENCY_ONLY
* @see ServiceState#STATE_IN_SERVICE
@@ -135,28 +135,28 @@ public class PhoneStateListener {
}
/**
* Callback invoked when the message-waiting indicator changes.
* Callback invoked when the message-waiting indicator changes.
*/
public void onMessageWaitingIndicatorChanged(boolean mwi) {
// default implementation empty
}
/**
* Callback invoked when the call-forwarding indicator changes.
* Callback invoked when the call-forwarding indicator changes.
*/
public void onCallForwardingIndicatorChanged(boolean cfi) {
// default implementation empty
}
/**
* Callback invoked when device cell location changes.
* Callback invoked when device cell location changes.
*/
public void onCellLocationChanged(CellLocation location) {
// default implementation empty
}
/**
* Callback invoked when device call state changes.
* Callback invoked when device call state changes.
*
* @see TelephonyManager#CALL_STATE_IDLE
* @see TelephonyManager#CALL_STATE_RINGING
@@ -167,7 +167,7 @@ public class PhoneStateListener {
}
/**
* Callback invoked when connection state changes.
* Callback invoked when connection state changes.
*
* @see TelephonyManager#DATA_DISCONNECTED
* @see TelephonyManager#DATA_CONNECTING
@@ -179,7 +179,7 @@ public class PhoneStateListener {
}
/**
* Callback invoked when data activity state changes.
* Callback invoked when data activity state changes.
*
* @see TelephonyManager#DATA_ACTIVITY_NONE
* @see TelephonyManager#DATA_ACTIVITY_IN

View File

@@ -2,16 +2,16 @@
**
** Copyright 2007, 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
** 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
** 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
** 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.
*/

View File

@@ -19,7 +19,7 @@ package android.telephony;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import com.android.internal.telephony.Phone;
import android.util.Log;
/**
* Contains phone state and service related information.
@@ -35,6 +35,8 @@ import com.android.internal.telephony.Phone;
*/
public class ServiceState implements Parcelable {
static final String LOG_TAG = "PHONE";
/**
* Normal operation condition, the phone is registered
* with an operator either in home network or in roaming.
@@ -59,13 +61,61 @@ public class ServiceState implements Parcelable {
*/
public static final int STATE_POWER_OFF = 3;
/**
* Available radio technologies for GSM, UMTS and CDMA.
*/
/** @hide */
public static final int RADIO_TECHNOLOGY_UNKNOWN = 0;
/** @hide */
public static final int RADIO_TECHNOLOGY_GPRS = 1;
/** @hide */
public static final int RADIO_TECHNOLOGY_EDGE = 2;
/** @hide */
public static final int RADIO_TECHNOLOGY_UMTS = 3;
/** @hide */
public static final int RADIO_TECHNOLOGY_IS95A = 4;
/** @hide */
public static final int RADIO_TECHNOLOGY_IS95B = 5;
/** @hide */
public static final int RADIO_TECHNOLOGY_1xRTT = 6;
/** @hide */
public static final int RADIO_TECHNOLOGY_EVDO_0 = 7;
/** @hide */
public static final int RADIO_TECHNOLOGY_EVDO_A = 8;
/**
* Available registration states for GSM, UMTS and CDMA.
*/
/** @hide */
public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING = 0;
/** @hide */
public static final int REGISTRATION_STATE_HOME_NETWORK = 1;
/** @hide */
public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_SEARCHING = 2;
/** @hide */
public static final int REGISTRATION_STATE_REGISTRATION_DENIED = 3;
/** @hide */
public static final int REGISTRATION_STATE_UNKNOWN = 4;
/** @hide */
public static final int REGISTRATION_STATE_ROAMING = 5;
/** @hide */
public static final int REGISTRATION_STATE_ROAMING_AFFILIATE = 6;
private int mState = STATE_OUT_OF_SERVICE;
private boolean mRoaming;
private int mExtendedCdmaRoaming;
private String mOperatorAlphaLong;
private String mOperatorAlphaShort;
private String mOperatorNumeric;
private boolean mIsManualNetworkSelection;
//***** CDMA
private int mRadioTechnology;
private boolean mCssIndicator;
private int mNetworkId;
private int mSystemId;
/**
* Create a new ServiceState from a intent notifier Bundle
*
@@ -105,6 +155,11 @@ public class ServiceState implements Parcelable {
mOperatorAlphaShort = s.mOperatorAlphaShort;
mOperatorNumeric = s.mOperatorNumeric;
mIsManualNetworkSelection = s.mIsManualNetworkSelection;
mRadioTechnology = s.mRadioTechnology;
mCssIndicator = s.mCssIndicator;
mNetworkId = s.mNetworkId;
mSystemId = s.mSystemId;
mExtendedCdmaRoaming = s.mExtendedCdmaRoaming;
}
/**
@@ -117,6 +172,11 @@ public class ServiceState implements Parcelable {
mOperatorAlphaShort = in.readString();
mOperatorNumeric = in.readString();
mIsManualNetworkSelection = in.readInt() != 0;
mRadioTechnology = in.readInt();
mCssIndicator = (in.readInt() != 0);
mNetworkId = in.readInt();
mSystemId = in.readInt();
mExtendedCdmaRoaming = in.readInt();
}
public void writeToParcel(Parcel out, int flags) {
@@ -126,6 +186,11 @@ public class ServiceState implements Parcelable {
out.writeString(mOperatorAlphaShort);
out.writeString(mOperatorNumeric);
out.writeInt(mIsManualNetworkSelection ? 1 : 0);
out.writeInt(mRadioTechnology);
out.writeInt(mCssIndicator ? 1 : 0);
out.writeInt(mNetworkId);
out.writeInt(mSystemId);
out.writeInt(mExtendedCdmaRoaming);
}
public int describeContents() {
@@ -166,6 +231,11 @@ public class ServiceState implements Parcelable {
return mRoaming;
}
/** @hide */
public int getExtendedCdmaRoaming(){
return this.mExtendedCdmaRoaming;
}
/**
* Get current registered operator name in long alphanumeric format
*
@@ -213,18 +283,19 @@ public class ServiceState implements Parcelable {
@Override
public int hashCode() {
return (mState * 0x1234)
return ((mState * 0x1234)
+ (mRoaming ? 1 : 0)
+ (mIsManualNetworkSelection ? 1 : 0)
+ ((null == mOperatorAlphaLong) ? 0 : mOperatorAlphaLong.hashCode())
+ ((null == mOperatorAlphaShort) ? 0 : mOperatorAlphaShort.hashCode())
+ ((null == mOperatorNumeric) ? 0 : mOperatorNumeric.hashCode());
+ ((null == mOperatorNumeric) ? 0 : mOperatorNumeric.hashCode())
+ (mExtendedCdmaRoaming));
}
@Override
public boolean equals (Object o) {
ServiceState s;
try {
s = (ServiceState) o;
} catch (ClassCastException ex) {
@@ -235,21 +306,66 @@ public class ServiceState implements Parcelable {
return false;
}
return mState == s.mState
return (mState == s.mState
&& mRoaming == s.mRoaming
&& mIsManualNetworkSelection == s.mIsManualNetworkSelection
&& equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong)
&& equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort)
&& equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric);
&& equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric)
&& equalsHandlesNulls(mRadioTechnology, s.mRadioTechnology)
&& equalsHandlesNulls(mCssIndicator, s.mCssIndicator)
&& equalsHandlesNulls(mNetworkId, s.mNetworkId)
&& equalsHandlesNulls(mSystemId, s.mSystemId)
&& equalsHandlesNulls(mExtendedCdmaRoaming, s.mExtendedCdmaRoaming));
}
@Override
public String toString() {
return mState + " " + (mRoaming ? "roaming" : "home")
String radioTechnology = new String("Error in radioTechnology");
switch(this.mRadioTechnology) {
case 0:
radioTechnology = "Unknown";
break;
case 1:
radioTechnology = "GPRS";
break;
case 2:
radioTechnology = "EDGE";
break;
case 3:
radioTechnology = "UMTS";
break;
case 4:
radioTechnology = "IS95A";
break;
case 5:
radioTechnology = "IS95B";
break;
case 6:
radioTechnology = "1xRTT";
break;
case 7:
radioTechnology = "EvDo rev. 0";
break;
case 8:
radioTechnology = "EvDo rev. A";
break;
default:
Log.w(LOG_TAG, "mRadioTechnology variable out of range.");
break;
}
return (mState + " " + (mRoaming ? "roaming" : "home")
+ " " + mOperatorAlphaLong
+ " " + mOperatorAlphaShort
+ " " + mOperatorNumeric
+ " " + (mIsManualNetworkSelection ? "(manual)" : "");
+ " " + (mIsManualNetworkSelection ? "(manual)" : "")
+ " " + radioTechnology
+ " " + (mCssIndicator ? "CSS supported" : "CSS not supported")
+ "NetworkId: " + mNetworkId
+ "SystemId: " + mSystemId
+ "ExtendedCdmaRoaming: " + mExtendedCdmaRoaming);
}
public void setStateOutOfService() {
@@ -259,6 +375,11 @@ public class ServiceState implements Parcelable {
mOperatorAlphaShort = null;
mOperatorNumeric = null;
mIsManualNetworkSelection = false;
mRadioTechnology = 0;
mCssIndicator = false;
mNetworkId = -1;
mSystemId = -1;
mExtendedCdmaRoaming = -1;
}
public void setStateOff() {
@@ -268,6 +389,11 @@ public class ServiceState implements Parcelable {
mOperatorAlphaShort = null;
mOperatorNumeric = null;
mIsManualNetworkSelection = false;
mRadioTechnology = 0;
mCssIndicator = false;
mNetworkId = -1;
mSystemId = -1;
mExtendedCdmaRoaming = -1;
}
public void setState(int state) {
@@ -278,6 +404,11 @@ public class ServiceState implements Parcelable {
mRoaming = roaming;
}
/** @hide */
public void setExtendedCdmaRoaming (int roaming) {
this.mExtendedCdmaRoaming = roaming;
}
public void setOperatorName(String longName, String shortName, String numeric) {
mOperatorAlphaLong = longName;
mOperatorAlphaShort = shortName;
@@ -287,7 +418,7 @@ public class ServiceState implements Parcelable {
public void setIsManualSelection(boolean isManual) {
mIsManualNetworkSelection = isManual;
}
/**
* Test whether two objects hold the same data values or both are null
*
@@ -312,6 +443,11 @@ public class ServiceState implements Parcelable {
mOperatorAlphaShort = m.getString("operator-alpha-short");
mOperatorNumeric = m.getString("operator-numeric");
mIsManualNetworkSelection = m.getBoolean("manual");
mRadioTechnology = m.getInt("radioTechnology");
mCssIndicator = m.getBoolean("cssIndicator");
mNetworkId = m.getInt("networkId");
mSystemId = m.getInt("systemId");
mExtendedCdmaRoaming = m.getInt("extendedCdmaRoaming");
}
/**
@@ -327,5 +463,47 @@ public class ServiceState implements Parcelable {
m.putString("operator-alpha-short", mOperatorAlphaShort);
m.putString("operator-numeric", mOperatorNumeric);
m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection));
m.putInt("radioTechnology", mRadioTechnology);
m.putBoolean("cssIndicator", mCssIndicator);
m.putInt("networkId", mNetworkId);
m.putInt("systemId", mSystemId);
m.putInt("extendedCdmaRoaming", mExtendedCdmaRoaming);
}
//***** CDMA
/** @hide */
public void setRadioTechnology(int state) {
this.mRadioTechnology = state;
}
/** @hide */
public void setCssIndicator(int css) {
this.mCssIndicator = (css != 0);
}
/** @hide */
public void setSystemAndNetworkId(int systemId, int networkId) {
this.mSystemId = systemId;
this.mNetworkId = networkId;
}
/** @hide */
public int getRadioTechnology() {
return this.mRadioTechnology;
}
/** @hide */
public int getCssIndicator() {
return this.mCssIndicator ? 1 : 0;
}
/** @hide */
public int getNetworkId() {
return this.mNetworkId;
}
/** @hide */
public int getSystemId() {
return this.mSystemId;
}
}

View File

@@ -0,0 +1,441 @@
/*
* 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.telephony;
import android.app.PendingIntent;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.TextUtils;
import com.android.internal.telephony.EncodeException;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.ISms;
import com.android.internal.telephony.IccConstants;
import com.android.internal.telephony.SmsRawData;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static android.telephony.SmsMessage.ENCODING_7BIT;
import static android.telephony.SmsMessage.ENCODING_8BIT;
import static android.telephony.SmsMessage.ENCODING_16BIT;
import static android.telephony.SmsMessage.ENCODING_UNKNOWN;
import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES;
import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER;
import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS;
import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER;
/**
* Manages SMS operations such as sending data, text, and pdu SMS messages.
* Get this object by calling the static method SmsManager.getDefault().
* @hide
*/
public final class SmsManager {
private static SmsManager sInstance;
/**
* Send a text based SMS.
*
* @param destinationAddress the address to send the message to
* @param scAddress is the service center address or null to use
* the current default SMSC
* @param text the body of the message to send
* @param sentIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is sucessfully sent, or failed.
* The result code will be <code>Activity.RESULT_OK<code> for success,
* or one of these errors:
* <code>RESULT_ERROR_GENERIC_FAILURE</code>
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or text are empty
*/
public void sendTextMessage(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(
scAddress, destinationAddress, text, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
}
/**
* Divide a text message into several messages, none bigger than
* the maximum SMS message size.
*
* @param text the original message. Must not be null.
* @return an <code>ArrayList</code> of strings that, in order,
* comprise the original message
*/
public ArrayList<String> divideMessage(String text) {
int size = text.length();
int[] params = SmsMessage.calculateLength(text, false);
/* SmsMessage.calculateLength returns an int[4] with:
* int[0] being the number of SMS's required,
* int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int messageCount = params[0];
int encodingType = params[3];
ArrayList<String> result = new ArrayList<String>(messageCount);
int start = 0;
int limit;
if (messageCount > 1) {
limit = (encodingType == ENCODING_7BIT)?
MAX_USER_DATA_SEPTETS_WITH_HEADER: MAX_USER_DATA_BYTES_WITH_HEADER;
} else {
limit = (encodingType == ENCODING_7BIT)?
MAX_USER_DATA_SEPTETS: MAX_USER_DATA_BYTES;
}
try {
while (start < size) {
int end = GsmAlphabet.findLimitIndex(text, start, limit, encodingType);
result.add(text.substring(start, end));
start = end;
}
}
catch (EncodeException e) {
// ignore it.
}
return result;
}
/**
* Send a multi-part text based SMS. The callee should have already
* divided the message into correctly sized parts by calling
* <code>divideMessage</code>.
*
* @param destinationAddress the address to send the message to
* @param scAddress is the service center address or null to use
* the current default SMSC
* @param parts an <code>ArrayList</code> of strings that, in order,
* comprise the original message
* @param sentIntents if not null, an <code>ArrayList</code> of
* <code>PendingIntent</code>s (one for each message part) that is
* broadcast when the corresponding message part has been sent.
* The result code will be <code>Activity.RESULT_OK<code> for success,
* or one of these errors:
* <code>RESULT_ERROR_GENERIC_FAILURE</code>
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applicaitons,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntents if not null, an <code>ArrayList</code> of
* <code>PendingIntent</code>s (one for each message part) that is
* broadcast when the corresponding message part has been delivered
* to the recipient. The raw pdu of the status report is in the
* extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
*/
public void sendMultipartTextMessage(
String destinationAddress, String scAddress, ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (parts == null || parts.size() < 1) {
throw new IllegalArgumentException("Invalid message body");
}
if (parts.size() > 1) {
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.sendMultipartText(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
} catch (RemoteException ex) {
// ignore it
}
} else {
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
if (sentIntents != null && sentIntents.size() > 0) {
sentIntent = sentIntents.get(0);
}
if (deliveryIntents != null && deliveryIntents.size() > 0) {
deliveryIntent = deliveryIntents.get(0);
}
sendTextMessage(destinationAddress, scAddress, parts.get(0),
sentIntent, deliveryIntent);
}
}
/**
* Send a data based SMS to a specific application port.
*
* @param destinationAddress the address to send the message to
* @param scAddress is the service center address or null to use
* the current default SMSC
* @param destinationPort the port to deliver the message to
* @param data the body of the message to send
* @param sentIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is sucessfully sent, or failed.
* The result code will be <code>Activity.RESULT_OK<code> for success,
* or one of these errors:
* <code>RESULT_ERROR_GENERIC_FAILURE</code>
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applicaitons,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
*/
public void sendDataMessage(
String destinationAddress, String scAddress, short destinationPort,
byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (data == null || data.length == 0) {
throw new IllegalArgumentException("Invalid message data");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(
scAddress, destinationAddress,
destinationPort, data, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
}
/**
* Send a raw SMS PDU.
*
* @param smsc the SMSC to send the message through, or NULL for the
* default SMSC
* @param pdu the raw PDU to send
* @param sentIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is successfully sent, or failed.
* The result code will be <code>Activity.RESULT_OK<code> for success,
* or one of these errors:
* <code>RESULT_ERROR_GENERIC_FAILURE</code>
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @hide
*/
private void sendRawPdu(byte[] smsc, byte[] pdu, PendingIntent sentIntent,
PendingIntent deliveryIntent) {
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.sendRawPdu(smsc, pdu, sentIntent, deliveryIntent);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Get the default instance of the SmsManager
*
* @return the default instance of the SmsManager
*/
public static SmsManager getDefault() {
if (sInstance == null) {
sInstance = new SmsManager();
}
return sInstance;
}
private SmsManager() {
//nothing
}
/**
* Copy a raw SMS PDU to the ICC.
*
* @param smsc the SMSC for this message, or NULL for the default SMSC
* @param pdu the raw PDU to store
* @param status message status (STATUS_ON_ICC_READ, STATUS_ON_ICC_UNREAD,
* STATUS_ON_ICC_SENT, STATUS_ON_ICC_UNSENT)
* @return true for success
*
* {@hide}
*/
public boolean copyMessageToIcc(byte[] smsc, byte[] pdu, int status) {
boolean success = false;
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
success = iccISms.copyMessageToIccEf(status, pdu, smsc);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Delete the specified message from the ICC.
*
* @param messageIndex is the record index of the message on ICC
* @return true for success
*
* {@hide}
*/
public boolean
deleteMessageFromIcc(int messageIndex) {
boolean success = false;
byte[] pdu = new byte[IccConstants.SMS_RECORD_LENGTH-1];
Arrays.fill(pdu, (byte)0xff);
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
success = iccISms.updateMessageOnIccEf(messageIndex, STATUS_ON_ICC_FREE, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Update the specified message on the ICC.
*
* @param messageIndex record index of message to update
* @param newStatus new message status (STATUS_ON_ICC_READ,
* STATUS_ON_ICC_UNREAD, STATUS_ON_ICC_SENT,
* STATUS_ON_ICC_UNSENT, STATUS_ON_ICC_FREE)
* @param pdu the raw PDU to store
* @return true for success
*
* {@hide}
*/
public boolean updateMessageOnIcc(int messageIndex, int newStatus, byte[] pdu) {
boolean success = false;
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
success = iccISms.updateMessageOnIccEf(messageIndex, newStatus, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
}
/**
* Retrieves all messages currently stored on ICC.
*
* @return <code>ArrayList</code> of <code>SmsMessage</code> objects
*
* {@hide}
*/
public ArrayList<SmsMessage> getAllMessagesFromIcc() {
List<SmsRawData> records = null;
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
records = iccISms.getAllMessagesFromIccEf();
}
} catch (RemoteException ex) {
// ignore it
}
return createMessageListFromRawRecords(records);
}
/**
* Create a list of <code>SmsMessage</code>s from a list of RawSmsData
* records returned by <code>getAllMessagesFromIcc()</code>
*
* @param records SMS EF records, returned by
* <code>getAllMessagesFromIcc</code>
* @return <code>ArrayList</code> of <code>SmsMessage</code> objects.
*/
private ArrayList<SmsMessage> createMessageListFromRawRecords(List records) {
ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
if (records != null) {
int count = records.size();
for (int i = 0; i < count; i++) {
SmsRawData data = (SmsRawData)records.get(i);
// List contains all records, including "free" records (null)
if (data != null) {
SmsMessage sms = SmsMessage.createFromEfRecord(i+1, data.getBytes());
messages.add(sms);
}
}
}
return messages;
}
// see SmsMessage.getStatusOnIcc
/** Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_FREE = 0;
/** Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_READ = 1;
/** Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_UNREAD = 3;
/** Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_SENT = 5;
/** Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). */
static public final int STATUS_ON_ICC_UNSENT = 7;
// SMS send failure result codes
/** Generic failure cause */
static public final int RESULT_ERROR_GENERIC_FAILURE = 1;
/** Failed because radio was explicitly turned off */
static public final int RESULT_ERROR_RADIO_OFF = 2;
/** Failed because no pdu provided */
static public final int RESULT_ERROR_NULL_PDU = 3;
/** Failed because service is currently unavailable */
static public final int RESULT_ERROR_NO_SERVICE = 4;
}

View File

@@ -0,0 +1,628 @@
/*
* 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.telephony;
import android.os.Parcel;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.EncodeException;
import com.android.internal.telephony.SmsMessageBase;
import com.android.internal.telephony.SmsMessageBase.SubmitPduBase;
import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
/**
* A Short Message Service message.
* @hide
*/
public class SmsMessage {
private static final boolean LOCAL_DEBUG = true;
private static final String LOG_TAG = "SMS";
/**
* SMS Class enumeration.
* See TS 23.038.
*
*/
public enum MessageClass{
UNKNOWN, CLASS_0, CLASS_1, CLASS_2, CLASS_3;
}
/** Unknown encoding scheme (see TS 23.038) */
public static final int ENCODING_UNKNOWN = 0;
/** 7-bit encoding scheme (see TS 23.038) */
public static final int ENCODING_7BIT = 1;
/** 8-bit encoding scheme (see TS 23.038) */
public static final int ENCODING_8BIT = 2;
/** 16-bit encoding scheme (see TS 23.038) */
public static final int ENCODING_16BIT = 3;
/** The maximum number of payload bytes per message */
public static final int MAX_USER_DATA_BYTES = 140;
/**
* The maximum number of payload bytes per message if a user data header
* is present. This assumes the header only contains the
* CONCATENATED_8_BIT_REFERENCE element.
*
* @hide pending API Council approval to extend the public API
*/
public static final int MAX_USER_DATA_BYTES_WITH_HEADER = 134;
/** The maximum number of payload septets per message */
public static final int MAX_USER_DATA_SEPTETS = 160;
/**
* The maximum number of payload septets per message if a user data header
* is present. This assumes the header only contains the
* CONCATENATED_8_BIT_REFERENCE element.
*/
public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153;
/** Contains actual SmsMessage. Only public for debugging and for framework layer.
* {@hide}
*/
public SmsMessageBase mWrappedSmsMessage;
public static class SubmitPdu extends SubmitPduBase {
//Constructor
public SubmitPdu() {
}
/* {@hide} */
protected SubmitPdu(SubmitPduBase spb) {
this.encodedMessage = spb.encodedMessage;
this.encodedScAddress = spb.encodedScAddress;
}
}
// Constructor
public SmsMessage() {
this(getSmsFacility());
}
private SmsMessage(SmsMessageBase smb) {
mWrappedSmsMessage = smb;
}
/**
* Create an SmsMessage from a raw PDU.
*/
public static SmsMessage createFromPdu(byte[] pdu) {
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu);
}
return new SmsMessage(wrappedMessage);
}
/**
* TS 27.005 3.4.1 lines[0] and lines[1] are the two lines read from the
* +CMT unsolicited response (PDU mode, of course)
* +CMT: [&lt;alpha>],<length><CR><LF><pdu>
*
* Only public for debugging and for RIL
*
* {@hide}
*/
public static SmsMessage newFromCMT(String[] lines){
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMT(lines);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines);
}
return new SmsMessage(wrappedMessage);
}
/** @hide */
protected static SmsMessage newFromCMTI(String line) {
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCMTI(line);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMTI(line);
}
return new SmsMessage(wrappedMessage);
}
/** @hide */
public static SmsMessage newFromCDS(String line) {
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromCDS(line);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCDS(line);
}
return new SmsMessage(wrappedMessage);
}
/** @hide */
public static SmsMessage newFromParcel(Parcel p) {
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromParcel(p);
}
return new SmsMessage(wrappedMessage);
}
/**
* Create an SmsMessage from an SMS EF record.
*
* @param index Index of SMS record. This should be index in ArrayList
* returned by SmsManager.getAllMessagesFromSim + 1.
* @param data Record data.
* @return An SmsMessage representing the record.
*
* @hide
*/
public static SmsMessage createFromEfRecord(int index, byte[] data) {
SmsMessageBase wrappedMessage;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromEfRecord(
index, data);
} else {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromEfRecord(
index, data);
}
return new SmsMessage(wrappedMessage);
}
/**
* Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
* length in bytes (not hex chars) less the SMSC header
*/
public static int getTPLayerLengthForPDU(String pdu) {
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
return com.android.internal.telephony.cdma.SmsMessage.getTPLayerLengthForPDU(pdu);
} else {
return com.android.internal.telephony.gsm.SmsMessage.getTPLayerLengthForPDU(pdu);
}
}
/**
* Calculates the number of SMS's required to encode the message body and
* the number of characters remaining until the next message, given the
* current encoding.
*
* @param messageBody the message to encode
* @param use7bitOnly if true, characters that are not part of the GSM
* alphabet are counted as a single space char. If false, a
* messageBody containing non-GSM alphabet characters is calculated
* for 16-bit encoding.
* @return an int[4] with int[0] being the number of SMS's required, int[1]
* the number of code units used, and int[2] is the number of code
* units remaining until the next message. int[3] is the encoding
* type that should be used for the message.
*/
public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) {
int ret[] = new int[4];
try {
// Try GSM alphabet
int septets = GsmAlphabet.countGsmSeptets(messageBody, !use7bitOnly);
ret[1] = septets;
if (septets > MAX_USER_DATA_SEPTETS) {
ret[0] = (septets / MAX_USER_DATA_SEPTETS_WITH_HEADER) + 1;
ret[2] = MAX_USER_DATA_SEPTETS_WITH_HEADER
- (septets % MAX_USER_DATA_SEPTETS_WITH_HEADER);
} else {
ret[0] = 1;
ret[2] = MAX_USER_DATA_SEPTETS - septets;
}
ret[3] = ENCODING_7BIT;
} catch (EncodeException ex) {
// fall back to UCS-2
int octets = messageBody.length() * 2;
ret[1] = messageBody.length();
if (octets > MAX_USER_DATA_BYTES) {
// 6 is the size of the user data header
ret[0] = (octets / MAX_USER_DATA_BYTES_WITH_HEADER) + 1;
ret[2] = (MAX_USER_DATA_BYTES_WITH_HEADER
- (octets % MAX_USER_DATA_BYTES_WITH_HEADER))/2;
} else {
ret[0] = 1;
ret[2] = (MAX_USER_DATA_BYTES - octets)/2;
}
ret[3] = ENCODING_16BIT;
}
return ret;
}
/**
* Calculates the number of SMS's required to encode the message body and
* the number of characters remaining until the next message, given the
* current encoding.
*
* @param messageBody the message to encode
* @param use7bitOnly if true, characters that are not part of the GSM
* alphabet are counted as a single space char. If false, a
* messageBody containing non-GSM alphabet characters is calculated
* for 16-bit encoding.
* @return an int[4] with int[0] being the number of SMS's required, int[1]
* the number of code units used, and int[2] is the number of code
* units remaining until the next message. int[3] is the encoding
* type that should be used for the message.
*/
public static int[] calculateLength(String messageBody, boolean use7bitOnly) {
return calculateLength((CharSequence)messageBody, use7bitOnly);
}
/**
* Get an SMS-SUBMIT PDU for a destination address and a message
*
* @param scAddress Service Centre address. Null means use default.
* @return a <code>SubmitPdu</code> containing the encoded SC
* address, if applicable, and the encoded message.
* Returns null on encode error.
* @hide
*/
public static SubmitPdu getSubmitPdu(String scAddress,
String destinationAddress, String message,
boolean statusReportRequested, byte[] header) {
SubmitPduBase spb;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, message, statusReportRequested, header);
} else {
spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, message, statusReportRequested, header);
}
return new SubmitPdu(spb);
}
/**
* Get an SMS-SUBMIT PDU for a destination address and a message
*
* @param scAddress Service Centre address. Null means use default.
* @return a <code>SubmitPdu</code> containing the encoded SC
* address, if applicable, and the encoded message.
* Returns null on encode error.
*/
public static SubmitPdu getSubmitPdu(String scAddress,
String destinationAddress, String message, boolean statusReportRequested) {
SubmitPduBase spb;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, message, statusReportRequested);
} else {
spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, message, statusReportRequested);
}
return new SubmitPdu(spb);
}
/**
* Get an SMS-SUBMIT PDU for a data message to a destination address &amp; port
*
* @param scAddress Service Centre address. null == use default
* @param destinationAddress the address of the destination for the message
* @param destinationPort the port to deliver the message to at the
* destination
* @param data the dat for the message
* @return a <code>SubmitPdu</code> containing the encoded SC
* address, if applicable, and the encoded message.
* Returns null on encode error.
*/
public static SubmitPdu getSubmitPdu(String scAddress,
String destinationAddress, short destinationPort, byte[] data,
boolean statusReportRequested) {
SubmitPduBase spb;
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, destinationPort, data, statusReportRequested);
} else {
spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
destinationAddress, destinationPort, data, statusReportRequested);
}
return new SubmitPdu(spb);
}
/**
* Returns the address of the SMS service center that relayed this message
* or null if there is none.
*/
public String getServiceCenterAddress() {
return mWrappedSmsMessage.getServiceCenterAddress();
}
/**
* Returns the originating address (sender) of this SMS message in String
* form or null if unavailable
*/
public String getOriginatingAddress() {
return mWrappedSmsMessage.getOriginatingAddress();
}
/**
* Returns the originating address, or email from address if this message
* was from an email gateway. Returns null if originating address
* unavailable.
*/
public String getDisplayOriginatingAddress() {
return mWrappedSmsMessage.getDisplayOriginatingAddress();
}
/**
* Returns the message body as a String, if it exists and is text based.
* @return message body is there is one, otherwise null
*/
public String getMessageBody() {
return mWrappedSmsMessage.getMessageBody();
}
/**
* Returns the class of this message.
*/
public MessageClass getMessageClass() {
return mWrappedSmsMessage.getMessageClass();
}
/**
* Returns the message body, or email message body if this message was from
* an email gateway. Returns null if message body unavailable.
*/
public String getDisplayMessageBody() {
return mWrappedSmsMessage.getDisplayMessageBody();
}
/**
* Unofficial convention of a subject line enclosed in parens empty string
* if not present
*/
public String getPseudoSubject() {
return mWrappedSmsMessage.getPseudoSubject();
}
/**
* Returns the service centre timestamp in currentTimeMillis() format
*/
public long getTimestampMillis() {
return mWrappedSmsMessage.getTimestampMillis();
}
/**
* Returns true if message is an email.
*
* @return true if this message came through an email gateway and email
* sender / subject / parsed body are available
*/
public boolean isEmail() {
return mWrappedSmsMessage.isEmail();
}
/**
* @return if isEmail() is true, body of the email sent through the gateway.
* null otherwise
*/
public String getEmailBody() {
return mWrappedSmsMessage.getEmailBody();
}
/**
* @return if isEmail() is true, email from address of email sent through
* the gateway. null otherwise
*/
public String getEmailFrom() {
return mWrappedSmsMessage.getEmailFrom();
}
/**
* Get protocol identifier.
*/
public int getProtocolIdentifier() {
return mWrappedSmsMessage.getProtocolIdentifier();
}
/**
* See TS 23.040 9.2.3.9 returns true if this is a "replace short message"
* SMS
*/
public boolean isReplace() {
return mWrappedSmsMessage.isReplace();
}
/**
* Returns true for CPHS MWI toggle message.
*
* @return true if this is a CPHS MWI toggle message See CPHS 4.2 section
* B.4.2
*/
public boolean isCphsMwiMessage() {
return mWrappedSmsMessage.isCphsMwiMessage();
}
/**
* returns true if this message is a CPHS voicemail / message waiting
* indicator (MWI) clear message
*/
public boolean isMWIClearMessage() {
return mWrappedSmsMessage.isMWIClearMessage();
}
/**
* returns true if this message is a CPHS voicemail / message waiting
* indicator (MWI) set message
*/
public boolean isMWISetMessage() {
return mWrappedSmsMessage.isMWISetMessage();
}
/**
* returns true if this message is a "Message Waiting Indication Group:
* Discard Message" notification and should not be stored.
*/
public boolean isMwiDontStore() {
return mWrappedSmsMessage.isMwiDontStore();
}
/**
* returns the user data section minus the user data header if one was
* present.
*/
public byte[] getUserData() {
return mWrappedSmsMessage.getUserData();
}
/* Not part of the SDK interface and only needed by specific classes:
protected SmsHeader getUserDataHeader()
*/
/**
* Returns the raw PDU for the message.
*
* @return the raw PDU for the message.
*/
public byte[] getPdu() {
return mWrappedSmsMessage.getPdu();
}
/**
* Returns the status of the message on the SIM (read, unread, sent, unsent).
*
* @return the status of the message on the SIM. These are:
* SmsManager.STATUS_ON_SIM_FREE
* SmsManager.STATUS_ON_SIM_READ
* SmsManager.STATUS_ON_SIM_UNREAD
* SmsManager.STATUS_ON_SIM_SEND
* SmsManager.STATUS_ON_SIM_UNSENT
* @deprecated Use getStatusOnIcc instead.
*/
@Deprecated public int getStatusOnSim() {
return mWrappedSmsMessage.getStatusOnIcc();
}
/**
* Returns the status of the message on the ICC (read, unread, sent, unsent).
*
* @return the status of the message on the ICC. These are:
* SmsManager.STATUS_ON_ICC_FREE
* SmsManager.STATUS_ON_ICC_READ
* SmsManager.STATUS_ON_ICC_UNREAD
* SmsManager.STATUS_ON_ICC_SEND
* SmsManager.STATUS_ON_ICC_UNSENT
*/
public int getStatusOnIcc() {
return mWrappedSmsMessage.getStatusOnIcc();
}
/**
* Returns the record index of the message on the SIM (1-based index).
* @return the record index of the message on the SIM, or -1 if this
* SmsMessage was not created from a SIM SMS EF record.
* @deprecated Use getIndexOnIcc instead.
*/
@Deprecated public int getIndexOnSim() {
return mWrappedSmsMessage.getIndexOnIcc();
}
/**
* Returns the record index of the message on the ICC (1-based index).
* @return the record index of the message on the ICC, or -1 if this
* SmsMessage was not created from a ICC SMS EF record.
*/
public int getIndexOnIcc() {
return mWrappedSmsMessage.getIndexOnIcc();
}
/**
* GSM:
* For an SMS-STATUS-REPORT message, this returns the status field from
* the status report. This field indicates the status of a previously
* submitted SMS, if requested. See TS 23.040, 9.2.3.15 TP-Status for a
* description of values.
* CDMA:
* For not interfering with status codes from GSM, the value is
* shifted to the bits 31-16.
* The value is composed of an error class (bits 25-24) and a status code (bits 23-16).
* Possible codes are described in C.S0015-B, v2.0, 4.5.21.
*
* @return 0 indicates the previously sent message was received.
* See TS 23.040, 9.9.2.3.15 and C.S0015-B, v2.0, 4.5.21
* for a description of other possible values.
*/
public int getStatus() {
return mWrappedSmsMessage.getStatus();
}
/**
* Return true iff the message is a SMS-STATUS-REPORT message.
*/
public boolean isStatusReportMessage() {
return mWrappedSmsMessage.isStatusReportMessage();
}
/**
* Returns true iff the <code>TP-Reply-Path</code> bit is set in
* this message.
*/
public boolean isReplyPathPresent() {
return mWrappedSmsMessage.isReplyPathPresent();
}
/** This method returns the reference to a specific
* SmsMessage object, which is used for accessing its static methods.
* @return Specific SmsMessage.
*/
private static final SmsMessageBase getSmsFacility(){
int activePhone = TelephonyManager.getDefault().getPhoneType();
if (PHONE_TYPE_CDMA == activePhone) {
return new com.android.internal.telephony.cdma.SmsMessage();
} else {
return new com.android.internal.telephony.gsm.SmsMessage();
}
}
}

View File

@@ -28,25 +28,31 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.telephony.CellLocation;
import com.android.internal.telephony.IPhoneSubInfo;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.ITelephonyRegistry;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.TelephonyProperties;
/**
* Provides access to information about the telephony services on
* the device. Applications can use the methods in this class to
* determine telephony services and states, as well as to access some
* types of subscriber information. Applications can also register
* a listener to receive notification of telephony state changes.
* types of subscriber information. Applications can also register
* a listener to receive notification of telephony state changes.
* <p>
* You do not instantiate this class directly; instead, you retrieve
* a reference to an instance through
* a reference to an instance through
* {@link android.content.Context#getSystemService
* Context.getSystemService(Context.TELEPHONY_SERVICE)}.
* <p>
* Note that acess to some telephony information is
* permission-protected. Your application cannot access the protected
* information unless it has the appropriate permissions declared in
* its manifest file. Where permissions apply, they are noted in the
* the methods through which you access the protected information.
* permission-protected. Your application cannot access the protected
* information unless it has the appropriate permissions declared in
* its manifest file. Where permissions apply, they are noted in the
* the methods through which you access the protected information.
*/
public class TelephonyManager {
private static final String TAG = "TelephonyManager";
@@ -166,10 +172,10 @@ public class TelephonyManager {
//
/**
* Returns the software version number for the device, for example,
* Returns the software version number for the device, for example,
* the IMEI/SV for GSM phones.
*
* <p>Requires Permission:
* <p>Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getDeviceSoftwareVersion() {
@@ -181,10 +187,10 @@ public class TelephonyManager {
}
/**
* Returns the unique device ID, for example,the IMEI for GSM
* Returns the unique device ID, for example, the IMEI for GSM and the MEID for CDMA
* phones.
*
* <p>Requires Permission:
* <p>Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getDeviceId() {
@@ -214,7 +220,7 @@ public class TelephonyManager {
* Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
*
* <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
* <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
* CONTROL_LOCATION_UPDATES}
*
* @hide
@@ -270,23 +276,37 @@ public class TelephonyManager {
public static final int PHONE_TYPE_GSM = 1;
/**
* Returns a constant indicating the device phone type.
*
* CDMA phone
* @hide
*/
public static final int PHONE_TYPE_CDMA = 2;
/**
* Returns a constant indicating the device phone type.
*
* @see #PHONE_TYPE_NONE
* @see #PHONE_TYPE_GSM
* @see #PHONE_TYPE_CDMA
*/
public int getPhoneType() {
// in the future, we should really check this
return PHONE_TYPE_GSM;
try{
if(getITelephony().getActivePhoneType() == RILConstants.CDMA_PHONE) {
return PHONE_TYPE_CDMA;
} else {
return PHONE_TYPE_GSM;
}
}catch(RemoteException ex){
return PHONE_TYPE_NONE;
}
}
//
//
//
// Current Network
//
//
/**
/**
* Returns the alphabetic name of current registered operator.
* <p>
* Availability: Only when user is registered to a network
@@ -295,7 +315,7 @@ public class TelephonyManager {
return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
}
/**
/**
* Returns the numeric name (MCC+MNC) of current registered operator.
* <p>
* Availability: Only when user is registered to a network
@@ -304,7 +324,7 @@ public class TelephonyManager {
return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
}
/**
/**
* Returns true if the device is considered roaming on the current
* network, for GSM purposes.
* <p>
@@ -314,7 +334,7 @@ public class TelephonyManager {
return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
}
/**
/**
* Returns the ISO country code equivilent of the current registered
* operator's MCC (Mobile Country Code).
* <p>
@@ -332,9 +352,20 @@ public class TelephonyManager {
public static final int NETWORK_TYPE_EDGE = 2;
/** Current network is UMTS */
public static final int NETWORK_TYPE_UMTS = 3;
/** Current network is CDMA: Either IS95A or IS95B*/
/** @hide */
public static final int NETWORK_TYPE_CDMA = 4;
/** Current network is EVDO revision 0 or revision A*/
/** @hide */
public static final int NETWORK_TYPE_EVDO_0 = 5;
/** @hide */
public static final int NETWORK_TYPE_EVDO_A = 6;
/** Current network is 1xRTT*/
/** @hide */
public static final int NETWORK_TYPE_1xRTT = 7;
/**
* Returns a constant indicating the radio technology (network type)
* Returns a constant indicating the radio technology (network type)
* currently in use on the device.
* @return the network type
*
@@ -342,6 +373,10 @@ public class TelephonyManager {
* @see #NETWORK_TYPE_GPRS
* @see #NETWORK_TYPE_EDGE
* @see #NETWORK_TYPE_UMTS
* @see #NETWORK_TYPE_CDMA
* @see #NETWORK_TYPE_EVDO_0
* @see #NETWORK_TYPE_EVDO_A
* @see #NETWORK_TYPE_1xRTT
*/
public int getNetworkType() {
String prop = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE);
@@ -354,6 +389,18 @@ public class TelephonyManager {
else if ("UMTS".equals(prop)) {
return NETWORK_TYPE_UMTS;
}
else if ("CDMA".equals(prop)) {
return NETWORK_TYPE_CDMA;
}
else if ("CDMA - EvDo rev. 0".equals(prop)) {
return NETWORK_TYPE_EVDO_0;
}
else if ("CDMA - EvDo rev. A".equals(prop)) {
return NETWORK_TYPE_EVDO_A;
}
else if ("CDMA - 1xRTT".equals(prop)) {
return NETWORK_TYPE_1xRTT;
}
else {
return NETWORK_TYPE_UNKNOWN;
}
@@ -374,6 +421,14 @@ public class TelephonyManager {
return "EDGE";
case NETWORK_TYPE_UMTS:
return "UMTS";
case NETWORK_TYPE_CDMA:
return "CDMA";
case NETWORK_TYPE_EVDO_0:
return "CDMA - EvDo rev. 0";
case NETWORK_TYPE_EVDO_A:
return "CDMA - EvDo rev. A";
case NETWORK_TYPE_1xRTT:
return "CDMA - 1xRTT";
default:
return "UNKNOWN";
}
@@ -387,7 +442,7 @@ public class TelephonyManager {
/** SIM card state: Unknown. Signifies that the SIM is in transition
* between states. For example, when the user inputs the SIM pin
* under PIN_REQUIRED state, a query for sim status returns
* under PIN_REQUIRED state, a query for sim status returns
* this state before turning to SIM_STATE_READY. */
public static final int SIM_STATE_UNKNOWN = 0;
/** SIM card state: no SIM card is available in the device */
@@ -400,11 +455,11 @@ public class TelephonyManager {
public static final int SIM_STATE_NETWORK_LOCKED = 4;
/** SIM card state: Ready */
public static final int SIM_STATE_READY = 5;
/**
* Returns a constant indicating the state of the
/**
* Returns a constant indicating the state of the
* device SIM card.
*
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_ABSENT
* @see #SIM_STATE_PIN_REQUIRED
@@ -434,7 +489,7 @@ public class TelephonyManager {
}
}
/**
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM. 5 or 6 decimal digits.
* <p>
@@ -443,36 +498,36 @@ public class TelephonyManager {
* @see #getSimState
*/
public String getSimOperator() {
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_NUMERIC);
return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
}
/**
* Returns the Service Provider Name (SPN).
/**
* Returns the Service Provider Name (SPN).
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
*/
public String getSimOperatorName() {
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_ALPHA);
return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA);
}
/**
/**
* Returns the ISO country code equivalent for the SIM provider's country code.
*/
public String getSimCountryIso() {
return SystemProperties.get(TelephonyProperties.PROPERTY_SIM_OPERATOR_ISO_COUNTRY);
return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY);
}
/**
* Returns the serial number of the SIM, if applicable.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getSimSerialNumber() {
try {
return getSubscriberInfo().getSimSerialNumber();
return getSubscriberInfo().getIccSerialNumber();
} catch (RemoteException ex) {
}
return null;
@@ -487,7 +542,7 @@ public class TelephonyManager {
/**
* Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getSubscriberId() {
@@ -499,10 +554,10 @@ public class TelephonyManager {
}
/**
* Returns the phone number string for line 1, for example, the MSISDN
* Returns the phone number string for line 1, for example, the MSISDN
* for a GSM phone.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getLine1Number() {
@@ -514,9 +569,9 @@ public class TelephonyManager {
}
/**
* Returns the alphabetic identifier associated with the line 1 number.
* Returns the alphabetic identifier associated with the line 1 number.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* @hide
* nobody seems to call this.
@@ -532,7 +587,7 @@ public class TelephonyManager {
/**
* Returns the voice mail number.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getVoiceMailNumber() {
@@ -547,7 +602,7 @@ public class TelephonyManager {
* Retrieves the alphabetic identifier associated with the voice
* mail number.
* <p>
* Requires Permission:
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
*/
public String getVoiceMailAlphaTag() {
@@ -567,10 +622,10 @@ public class TelephonyManager {
/** Device call state: No activity. */
public static final int CALL_STATE_IDLE = 0;
/** Device call state: Ringing. A new call arrived and is
* ringing or waiting. In the latter case, another call is
* ringing or waiting. In the latter case, another call is
* already active. */
public static final int CALL_STATE_RINGING = 1;
/** Device call state: Off-hook. At least one call exists
/** Device call state: Off-hook. At least one call exists
* that is dialing, active, or on hold, and no calls are ringing
* or waiting. */
public static final int CALL_STATE_OFFHOOK = 2;
@@ -621,13 +676,13 @@ public class TelephonyManager {
public static final int DATA_CONNECTING = 1;
/** Data connection state: Connected. IP traffic should be available. */
public static final int DATA_CONNECTED = 2;
/** Data connection state: Suspended. The connection is up, but IP
* traffic is temporarily unavailable. For example, in a 2G network,
/** Data connection state: Suspended. The connection is up, but IP
* traffic is temporarily unavailable. For example, in a 2G network,
* data activity may be suspended when a voice call arrives. */
public static final int DATA_SUSPENDED = 3;
/**
* Returns a constant indicating the current data connection state
* Returns a constant indicating the current data connection state
* (cellular).
*
* @see #DATA_DISCONNECTED
@@ -655,26 +710,26 @@ public class TelephonyManager {
//
/**
* Registers a listener object to receive notification of changes
* in specified telephony states.
* Registers a listener object to receive notification of changes
* in specified telephony states.
* <p>
* To register a listener, pass a {@link PhoneStateListener}
* and specify at least one telephony state of interest in
* the events argument.
*
* and specify at least one telephony state of interest in
* the events argument.
*
* At registration, and when a specified telephony state
* changes, the telephony manager invokes the appropriate
* callback method on the listener object and passes the
* changes, the telephony manager invokes the appropriate
* callback method on the listener object and passes the
* current (udpated) values.
* <p>
* To unregister a listener, pass the listener object and set the
* events argument to
* events argument to
* {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
*
*
* @param listener The {@link PhoneStateListener} object to register
* (or unregister)
* @param events The telephony state(s) of interest to the listener,
* as a bitwise-OR combination of {@link PhoneStateListener}
* as a bitwise-OR combination of {@link PhoneStateListener}
* LISTEN_ flags.
*/
public void listen(PhoneStateListener listener, int events) {

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2006 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.telephony.cdma;
import android.os.Bundle;
import android.telephony.CellLocation;
/**
* Represents the cell location on a GSM phone.
* @hide
*/
public class CdmaCellLocation extends CellLocation {
private int mBaseStationId = -1;
private int mBaseStationLatitude = -1;
private int mBaseStationLongitude = -1;
/**
* Empty constructor. Initializes the LAC and CID to -1.
*/
public CdmaCellLocation() {
this.mBaseStationId = -1;
this.mBaseStationLatitude = -1;
this.mBaseStationLongitude = -1;
}
/**
* Initialize the object from a bundle.
*/
public CdmaCellLocation(Bundle bundleWithValues) {
this.mBaseStationId = bundleWithValues.getInt("baseStationId");
this.mBaseStationLatitude = bundleWithValues.getInt("baseStationLatitude");
this.mBaseStationLongitude = bundleWithValues.getInt("baseStationLongitude");
}
/**
* @return cdma base station identification number, -1 if unknown
*/
public int getBaseStationId() {
return this.mBaseStationId;
}
/**
* @return cdma base station latitude, -1 if unknown
*/
public int getBaseStationLatitude() {
return this.mBaseStationLatitude;
}
/**
* @return cdma base station longitude, -1 if unknown
*/
public int getBaseStationLongitude() {
return this.mBaseStationLongitude;
}
/**
* Invalidate this object. The cell location data is set to -1.
*/
public void setStateInvalid() {
this.mBaseStationId = -1;
this.mBaseStationLatitude = -1;
this.mBaseStationLongitude = -1;
}
/**
* Set the cell location data.
*/
public void setCellLocationData(int baseStationId, int baseStationLatitude,
int baseStationLongitude) {
// The following values have to be written in the correct sequence
this.mBaseStationId = baseStationId;
this.mBaseStationLatitude = baseStationLatitude; //values[2];
this.mBaseStationLongitude = baseStationLongitude; //values[3];
}
@Override
public int hashCode() {
return this.mBaseStationId ^ this.mBaseStationLatitude ^ this.mBaseStationLongitude;
}
@Override
public boolean equals(Object o) {
CdmaCellLocation s;
try {
s = (CdmaCellLocation)o;
} catch (ClassCastException ex) {
return false;
}
if (o == null) {
return false;
}
return (equalsHandlesNulls(this.mBaseStationId, s.mBaseStationId) &&
equalsHandlesNulls(this.mBaseStationLatitude, s.mBaseStationLatitude) &&
equalsHandlesNulls(this.mBaseStationLongitude, s.mBaseStationLongitude)
);
}
@Override
public String toString() {
return "[" + this.mBaseStationId + ","
+ this.mBaseStationLatitude + ","
+ this.mBaseStationLongitude + "]";
}
/**
* Test whether two objects hold the same data values or both are null
*
* @param a first obj
* @param b second obj
* @return true if two objects equal or both are null
*/
private static boolean equalsHandlesNulls(Object a, Object b) {
return (a == null) ? (b == null) : a.equals (b);
}
/**
* Fill the cell location data into the intent notifier Bundle based on service state
*
* @param bundleToFill intent notifier Bundle
*/
public void fillInNotifierBundle(Bundle bundleToFill) {
bundleToFill.putInt("baseStationId", this.mBaseStationId);
bundleToFill.putInt("baseStationLatitude", this.mBaseStationLatitude);
bundleToFill.putInt("baseStationLongitude", this.mBaseStationLongitude);
}
}

View File

@@ -0,0 +1,5 @@
<HTML>
<BODY>
Provides APIs for utilizing CDMA-specific telephony features.
</BODY>
</HTML>

View File

@@ -17,14 +17,12 @@
package android.telephony.gsm;
import android.os.Bundle;
import com.android.internal.telephony.Phone;
import android.telephony.CellLocation;
/**
* Represents the cell location on a GSM phone.
*/
public class GsmCellLocation extends CellLocation
{
public class GsmCellLocation extends CellLocation {
private int mLac;
private int mCid;
@@ -82,7 +80,7 @@ public class GsmCellLocation extends CellLocation
@Override
public boolean equals(Object o) {
GsmCellLocation s;
try {
s = (GsmCellLocation)o;
} catch (ClassCastException ex) {
@@ -100,7 +98,7 @@ public class GsmCellLocation extends CellLocation
public String toString() {
return "["+ mLac + "," + mCid + "]";
}
/**
* Test whether two objects hold the same data values or both are null
*

View File

@@ -17,28 +17,35 @@
package android.telephony.gsm;
import android.app.PendingIntent;
import android.os.RemoteException;
import android.os.IServiceManager;
import android.os.ServiceManager;
import android.os.ServiceManagerNative;
import android.text.TextUtils;
import com.android.internal.telephony.gsm.EncodeException;
import com.android.internal.telephony.gsm.GsmAlphabet;
import com.android.internal.telephony.gsm.ISms;
import com.android.internal.telephony.gsm.SimConstants;
import com.android.internal.telephony.gsm.SmsRawData;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Manages SMS operations such as sending data, text, and pdu SMS messages.
* Get this object by calling the static method SmsManager.getDefault().
* @deprecated Replaced by android.telephony.SmsManager that supports both GSM and CDMA.
*/
public final class SmsManager {
@Deprecated public final class SmsManager {
private static SmsManager sInstance;
private android.telephony.SmsManager mSmsMgrProxy;
/** Get the default instance of the SmsManager
*
* @return the default instance of the SmsManager
* @deprecated Use android.telephony.SmsManager.
*/
@Deprecated
public static final SmsManager getDefault() {
if (sInstance == null) {
sInstance = new SmsManager();
}
return sInstance;
}
private SmsManager() {
mSmsMgrProxy = android.telephony.SmsManager.getDefault();
}
/**
* Send a text based SMS.
@@ -55,28 +62,21 @@ public final class SmsManager {
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applicaitons,
* is NULL the caller will be checked against all unknown applications,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or text are empty
* @deprecated Use android.telephony.SmsManager.
*/
public void sendTextMessage(
@Deprecated
public final void sendTextMessage(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(
scAddress, destinationAddress, text, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
mSmsMgrProxy.sendTextMessage(destinationAddress, scAddress, text,
sentIntent, deliveryIntent);
}
/**
@@ -86,55 +86,24 @@ public final class SmsManager {
* @param text the original message. Must not be null.
* @return an <code>ArrayList</code> of strings that, in order,
* comprise the original message
* @deprecated Use android.telephony.SmsManager.
*/
public ArrayList<String> divideMessage(String text) {
int size = text.length();
int[] params = SmsMessage.calculateLength(text, false);
/* SmsMessage.calculateLength returns an int[4] with:
* int[0] being the number of SMS's required,
* int[1] the number of code units used,
* int[2] is the number of code units remaining until the next message.
* int[3] is the encoding type that should be used for the message.
*/
int messageCount = params[0];
int encodingType = params[3];
ArrayList<String> result = new ArrayList<String>(messageCount);
int start = 0;
int limit;
if (messageCount > 1) {
limit = (encodingType == SmsMessage.ENCODING_7BIT) ?
SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER :
SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER;
} else {
limit = (encodingType == SmsMessage.ENCODING_7BIT) ?
SmsMessage.MAX_USER_DATA_SEPTETS : SmsMessage.MAX_USER_DATA_BYTES;
}
try {
while (start < size) {
int end = GsmAlphabet.findLimitIndex(text, start, limit, encodingType);
result.add(text.substring(start, end));
start = end;
}
} catch (EncodeException e) {
// ignore it.
}
return result;
@Deprecated
public final ArrayList<String> divideMessage(String text) {
return mSmsMgrProxy.divideMessage(text);
}
/**
* Send a multi-part text based SMS. The callee should have already
* divided the message into correctly sized parts by calling
* <code>divideMessage</code>.
*
*
* @param destinationAddress the address to send the message to
* @param scAddress is the service center address or null to use
* the current default SMSC
* @param parts an <code>ArrayList</code> of strings that, in order,
* comprise the original message
* @param sentIntents if not null, an <code>ArrayList</code> of
* @param sentIntents if not null, an <code>ArrayList</code> of
* <code>PendingIntent</code>s (one for each message part) that is
* broadcast when the corresponding message part has been sent.
* The result code will be <code>Activity.RESULT_OK<code> for success,
@@ -145,44 +114,21 @@ public final class SmsManager {
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applicaitons,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntents if not null, an <code>ArrayList</code> of
* @param deliveryIntents if not null, an <code>ArrayList</code> of
* <code>PendingIntent</code>s (one for each message part) that is
* broadcast when the corresponding message part has been delivered
* to the recipient. The raw pdu of the status report is in the
* extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
* @deprecated Use android.telephony.SmsManager.
*/
public void sendMultipartTextMessage(
@Deprecated
public final void sendMultipartTextMessage(
String destinationAddress, String scAddress, ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (parts == null || parts.size() < 1) {
throw new IllegalArgumentException("Invalid message body");
}
if (parts.size() > 1) {
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
simISms.sendMultipartText(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
} catch (RemoteException ex) {
// ignore it
}
} else {
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
if (sentIntents != null && sentIntents.size() > 0) {
sentIntent = sentIntents.get(0);
}
if (deliveryIntents != null && deliveryIntents.size() > 0) {
deliveryIntent = deliveryIntents.get(0);
}
sendTextMessage(destinationAddress, scAddress, parts.get(0),
sentIntent, deliveryIntent);
}
mSmsMgrProxy.sendMultipartTextMessage(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
/**
@@ -208,70 +154,14 @@ public final class SmsManager {
* raw pdu of the status report is in the extended data ("pdu").
*
* @throws IllegalArgumentException if destinationAddress or data are empty
* @deprecated Use android.telephony.SmsManager.
*/
public void sendDataMessage(
@Deprecated
public final void sendDataMessage(
String destinationAddress, String scAddress, short destinationPort,
byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (data == null || data.length == 0) {
throw new IllegalArgumentException("Invalid message data");
}
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress,
destinationPort, data, (deliveryIntent != null));
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
}
/**
* Send a raw SMS PDU.
*
* @param smsc the SMSC to send the message through, or NULL for the
* default SMSC
* @param pdu the raw PDU to send
* @param sentIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is sucessfully sent, or failed.
* The result code will be <code>Activity.RESULT_OK<code> for success,
* or one of these errors:
* <code>RESULT_ERROR_GENERIC_FAILURE</code>
* <code>RESULT_ERROR_RADIO_OFF</code>
* <code>RESULT_ERROR_NULL_PDU</code>.
* The per-application based SMS control checks sentIntent. If sentIntent
* is NULL the caller will be checked against all unknown applicaitons,
* which cause smaller number of SMS to be sent in checking period.
* @param deliveryIntent if not NULL this <code>PendingIntent</code> is
* broadcast when the message is delivered to the recipient. The
* raw pdu of the status report is in the extended data ("pdu").
*
*/
private void sendRawPdu(byte[] smsc, byte[] pdu, PendingIntent sentIntent,
PendingIntent deliveryIntent) {
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
simISms.sendRawPdu(smsc, pdu, sentIntent, deliveryIntent);
}
} catch (RemoteException ex) {
// ignore it
}
}
/**
* Get the default instance of the SmsManager
*
* @return the default instance of the SmsManager
*/
public static SmsManager getDefault() {
if (sInstance == null) {
sInstance = new SmsManager();
}
return sInstance;
}
private SmsManager() {
// nothing to see here
mSmsMgrProxy.sendDataMessage(destinationAddress, scAddress, destinationPort,
data, sentIntent, deliveryIntent);
}
/**
@@ -282,22 +172,12 @@ public final class SmsManager {
* @param status message status (STATUS_ON_SIM_READ, STATUS_ON_SIM_UNREAD,
* STATUS_ON_SIM_SENT, STATUS_ON_SIM_UNSENT)
* @return true for success
*
* @deprecated Use android.telephony.SmsManager.
* {@hide}
*/
public boolean copyMessageToSim(byte[] smsc, byte[] pdu, int status) {
boolean success = false;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.copyMessageToSimEf(status, pdu, smsc);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
@Deprecated
public final boolean copyMessageToSim(byte[] smsc, byte[] pdu, int status) {
return mSmsMgrProxy.copyMessageToIcc(smsc, pdu, status);
}
/**
@@ -305,26 +185,12 @@ public final class SmsManager {
*
* @param messageIndex is the record index of the message on SIM
* @return true for success
*
* @deprecated Use android.telephony.SmsManager.
* {@hide}
*/
public boolean
deleteMessageFromSim(int messageIndex) {
boolean success = false;
byte[] pdu = new byte[SimConstants.SMS_RECORD_LENGTH-1];
Arrays.fill(pdu, (byte)0xff);
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.updateMessageOnSimEf(messageIndex,
STATUS_ON_SIM_FREE, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
@Deprecated
public final boolean deleteMessageFromSim(int messageIndex) {
return mSmsMgrProxy.deleteMessageFromIcc(messageIndex);
}
/**
@@ -336,97 +202,59 @@ public final class SmsManager {
* STATUS_ON_SIM_UNSENT, STATUS_ON_SIM_FREE)
* @param pdu the raw PDU to store
* @return true for success
*
* @deprecated Use android.telephony.SmsManager.
* {@hide}
*/
public boolean updateMessageOnSim(int messageIndex, int newStatus,
byte[] pdu) {
boolean success = false;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
success = simISms.updateMessageOnSimEf(messageIndex, newStatus, pdu);
}
} catch (RemoteException ex) {
// ignore it
}
return success;
@Deprecated
public final boolean updateMessageOnSim(int messageIndex, int newStatus, byte[] pdu) {
return mSmsMgrProxy.updateMessageOnIcc(messageIndex, newStatus, pdu);
}
/**
* Retrieves all messages currently stored on SIM.
*
* @return <code>ArrayList</code> of <code>SmsMessage</code> objects
*
* @deprecated Use android.telephony.SmsManager.
* {@hide}
*/
public ArrayList<SmsMessage> getAllMessagesFromSim() {
List<SmsRawData> records = null;
try {
ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (simISms != null) {
records = simISms.getAllMessagesFromSimEf();
}
} catch (RemoteException ex) {
// ignore it
}
return createMessageListFromRawRecords(records);
}
/**
* Create a list of <code>SmsMessage</code>s from a list of RawSmsData
* records returned by <code>getAllMessagesFromSim()</code>
*
* @param records SMS EF records, returned by
* <code>getAllMessagesFromSim</code>
* @return <code>ArrayList</code> of <code>SmsMessage</code> objects.
*/
private ArrayList<SmsMessage> createMessageListFromRawRecords(List records) {
ArrayList<SmsMessage> messages = new ArrayList<SmsMessage>();
if (records != null) {
int count = records.size();
for (int i = 0; i < count; i++) {
SmsRawData data = (SmsRawData)records.get(i);
// List contains all records, including "free" records (null)
if (data != null) {
SmsMessage sms =
SmsMessage.createFromEfRecord(i+1, data.getBytes());
messages.add(sms);
}
}
}
return messages;
@Deprecated
public final ArrayList<android.telephony.SmsMessage> getAllMessagesFromSim() {
return mSmsMgrProxy.getAllMessagesFromIcc();
}
/** Free space (TS 51.011 10.5.3). */
static public final int STATUS_ON_SIM_FREE = 0;
/** Free space (TS 51.011 10.5.3).
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int STATUS_ON_SIM_FREE = 0;
/** Received and read (TS 51.011 10.5.3). */
static public final int STATUS_ON_SIM_READ = 1;
/** Received and read (TS 51.011 10.5.3).
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int STATUS_ON_SIM_READ = 1;
/** Received and unread (TS 51.011 10.5.3). */
static public final int STATUS_ON_SIM_UNREAD = 3;
/** Received and unread (TS 51.011 10.5.3).
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int STATUS_ON_SIM_UNREAD = 3;
/** Stored and sent (TS 51.011 10.5.3). */
static public final int STATUS_ON_SIM_SENT = 5;
/** Stored and sent (TS 51.011 10.5.3).
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int STATUS_ON_SIM_SENT = 5;
/** Stored and unsent (TS 51.011 10.5.3). */
static public final int STATUS_ON_SIM_UNSENT = 7;
/** Stored and unsent (TS 51.011 10.5.3).
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int STATUS_ON_SIM_UNSENT = 7;
/** Generic failure cause
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int RESULT_ERROR_GENERIC_FAILURE = 1;
// SMS send failure result codes
/** Failed because radio was explicitly turned off
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int RESULT_ERROR_RADIO_OFF = 2;
/** Failed because no pdu provided
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int RESULT_ERROR_NULL_PDU = 3;
/** Failed because service is currently unavailable
* @deprecated Use android.telephony.SmsManager. */
@Deprecated static public final int RESULT_ERROR_NO_SERVICE = 4;
/** Generic failure cause */
static public final int RESULT_ERROR_GENERIC_FAILURE = 1;
/** Failed because radio was explicitly turned off */
static public final int RESULT_ERROR_RADIO_OFF = 2;
/** Failed because no pdu provided */
static public final int RESULT_ERROR_NULL_PDU = 3;
/** Failed because service is currently unavailable */
static public final int RESULT_ERROR_NO_SERVICE = 4;
}

File diff suppressed because it is too large Load Diff