Remove mms-common library

Put the Mms files back in the framework where they've been since 1.0.

Change-Id: I3c449468053ddd82d35c45a06d71957de660bf99
This commit is contained in:
Tom Taylor
2010-03-08 16:34:53 -08:00
parent 147113ee54
commit a87afd07c0
35 changed files with 378 additions and 2150 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms;
import java.util.ArrayList;
@@ -26,7 +26,6 @@ public class ContentType {
public static final String MMS_GENERIC = "application/vnd.wap.mms-generic";
public static final String MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";
public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
public static final String TEXT_PLAIN = "text/plain";
public static final String TEXT_HTML = "text/html";

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms;
/**
* Thrown when an invalid header value was set.

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms;
/**
* A generic exception that is thrown by the Mms client.

View File

@@ -0,0 +1,5 @@
<body>
{@hide}
</body>

View File

@@ -15,10 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* M-Acknowledge.ind PDU.

View File

@@ -0,0 +1,167 @@
/*
* Copyright (C) 2007 Esmertec AG.
* Copyright (C) 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
*
* 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 com.google.android.mms.pdu;
public class Base64 {
/**
* Used to get the number of Quadruples.
*/
static final int FOURBYTE = 4;
/**
* Byte used to pad output.
*/
static final byte PAD = (byte) '=';
/**
* The base length.
*/
static final int BASELENGTH = 255;
// Create arrays to hold the base64 characters
private static byte[] base64Alphabet = new byte[BASELENGTH];
// Populating the character arrays
static {
for (int i = 0; i < BASELENGTH; i++) {
base64Alphabet[i] = (byte) -1;
}
for (int i = 'Z'; i >= 'A'; i--) {
base64Alphabet[i] = (byte) (i - 'A');
}
for (int i = 'z'; i >= 'a'; i--) {
base64Alphabet[i] = (byte) (i - 'a' + 26);
}
for (int i = '9'; i >= '0'; i--) {
base64Alphabet[i] = (byte) (i - '0' + 52);
}
base64Alphabet['+'] = 62;
base64Alphabet['/'] = 63;
}
/**
* Decodes Base64 data into octects
*
* @param base64Data Byte array containing Base64 data
* @return Array containing decoded data.
*/
public static byte[] decodeBase64(byte[] base64Data) {
// RFC 2045 requires that we discard ALL non-Base64 characters
base64Data = discardNonBase64(base64Data);
// handle the edge case, so we don't have to worry about it later
if (base64Data.length == 0) {
return new byte[0];
}
int numberQuadruple = base64Data.length / FOURBYTE;
byte decodedData[] = null;
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0, marker0 = 0, marker1 = 0;
// Throw away anything not in base64Data
int encodedIndex = 0;
int dataIndex = 0;
{
// this sizes the output array properly - rlw
int lastData = base64Data.length;
// ignore the '=' padding
while (base64Data[lastData - 1] == PAD) {
if (--lastData == 0) {
return new byte[0];
}
}
decodedData = new byte[lastData - numberQuadruple];
}
for (int i = 0; i < numberQuadruple; i++) {
dataIndex = i * 4;
marker0 = base64Data[dataIndex + 2];
marker1 = base64Data[dataIndex + 3];
b1 = base64Alphabet[base64Data[dataIndex]];
b2 = base64Alphabet[base64Data[dataIndex + 1]];
if (marker0 != PAD && marker1 != PAD) {
//No PAD e.g 3cQl
b3 = base64Alphabet[marker0];
b4 = base64Alphabet[marker1];
decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex + 1] =
(byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex + 2] = (byte) (b3 << 6 | b4);
} else if (marker0 == PAD) {
//Two PAD e.g. 3c[Pad][Pad]
decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
} else if (marker1 == PAD) {
//One PAD e.g. 3cQ[Pad]
b3 = base64Alphabet[marker0];
decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex + 1] =
(byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
}
encodedIndex += 3;
}
return decodedData;
}
/**
* Check octect wheter it is a base64 encoding.
*
* @param octect to be checked byte
* @return ture if it is base64 encoding, false otherwise.
*/
private static boolean isBase64(byte octect) {
if (octect == PAD) {
return true;
} else if (base64Alphabet[octect] == -1) {
return false;
} else {
return true;
}
}
/**
* Discards any characters outside of the base64 alphabet, per
* the requirements on page 25 of RFC 2045 - "Any characters
* outside of the base64 alphabet are to be ignored in base64
* encoded data."
*
* @param data The base-64 encoded data to groom
* @return The data, less non-base64 characters (see RFC 2045).
*/
static byte[] discardNonBase64(byte[] data) {
byte groomedData[] = new byte[data.length];
int bytesCopied = 0;
for (int i = 0; i < data.length; i++) {
if (isBase64(data[i])) {
groomedData[bytesCopied++] = data[i];
}
}
byte packedData[] = new byte[bytesCopied];
System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
return packedData;
}
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms.pdu;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* M-Delivery.Ind Pdu.

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms.pdu;
import android.util.Config;
import android.util.Log;
@@ -269,7 +269,7 @@ public class EncodedStringValue implements Cloneable {
return new EncodedStringValue(value.mCharacterSet, value.mData);
}
public static EncodedStringValue[] encodeStrings(String[] array) {
int count = array.length;
if (count > 0) {

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
public class GenericPdu {
/**

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* Multimedia message PDU.

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* M-Notification.ind PDU.

View File

@@ -15,10 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* M-NofifyResp.ind PDU.

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import java.util.HashMap;
import java.util.Map;

View File

@@ -15,10 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.PduHeaders;
package com.google.android.mms.pdu;
import android.content.ContentResolver;
import android.content.Context;

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
public class PduContentTypes {
/**

View File

@@ -15,7 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon;
package com.google.android.mms.pdu;
import com.google.android.mms.InvalidHeaderValueException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -337,7 +339,7 @@ public class PduHeaders {
* with specified header field. Return 0 if
* the value is not set.
*/
public int getOctet(int field) {
protected int getOctet(int field) {
Integer octet = (Integer) mHeaderMap.get(field);
if (null == octet) {
return 0;
@@ -353,7 +355,7 @@ public class PduHeaders {
* @param field the field
* @throws InvalidHeaderValueException if the value is invalid.
*/
public void setOctet(int value, int field)
protected void setOctet(int value, int field)
throws InvalidHeaderValueException{
/**
* Check whether this field can be set for specific
@@ -497,7 +499,7 @@ public class PduHeaders {
* @return the TextString value of the pdu header
* with specified header field
*/
public byte[] getTextString(int field) {
protected byte[] getTextString(int field) {
return (byte[]) mHeaderMap.get(field);
}
@@ -510,7 +512,7 @@ public class PduHeaders {
* with specified header field
* @throws NullPointerException if the value is null.
*/
public void setTextString(byte[] value, int field) {
protected void setTextString(byte[] value, int field) {
/**
* Check whether this field can be set for specific
* header and check validity of the field.
@@ -546,7 +548,7 @@ public class PduHeaders {
* @return the EncodedStringValue value of the pdu header
* with specified header field
*/
public EncodedStringValue getEncodedStringValue(int field) {
protected EncodedStringValue getEncodedStringValue(int field) {
return (EncodedStringValue) mHeaderMap.get(field);
}
@@ -557,7 +559,7 @@ public class PduHeaders {
* @return the EncodeStringValue array of the pdu header
* with specified header field
*/
public EncodedStringValue[] getEncodedStringValues(int field) {
protected EncodedStringValue[] getEncodedStringValues(int field) {
ArrayList<EncodedStringValue> list =
(ArrayList<EncodedStringValue>) mHeaderMap.get(field);
if (null == list) {
@@ -576,7 +578,7 @@ public class PduHeaders {
* with specified header field
* @throws NullPointerException if the value is null.
*/
public void setEncodedStringValue(EncodedStringValue value, int field) {
protected void setEncodedStringValue(EncodedStringValue value, int field) {
/**
* Check whether this field can be set for specific
* header and check validity of the field.
@@ -613,7 +615,7 @@ public class PduHeaders {
* with specified header field
* @throws NullPointerException if the value is null.
*/
public void setEncodedStringValues(EncodedStringValue[] value, int field) {
protected void setEncodedStringValues(EncodedStringValue[] value, int field) {
/**
* Check whether this field can be set for specific
* header and check validity of the field.
@@ -646,7 +648,7 @@ public class PduHeaders {
* @param field the field
* @throws NullPointerException if the value is null.
*/
public void appendEncodedStringValue(EncodedStringValue value,
protected void appendEncodedStringValue(EncodedStringValue value,
int field) {
if (null == value) {
throw new NullPointerException();
@@ -678,7 +680,7 @@ public class PduHeaders {
* with specified header field. if return -1, the
* field is not existed in pdu header.
*/
public long getLongInteger(int field) {
protected long getLongInteger(int field) {
Long longInteger = (Long) mHeaderMap.get(field);
if (null == longInteger) {
return -1;
@@ -693,7 +695,7 @@ public class PduHeaders {
* @param value the value
* @param field the field
*/
public void setLongInteger(long value, int field) {
protected void setLongInteger(long value, int field) {
/**
* Check whether this field can be set for specific
* header and check validity of the field.

View File

@@ -15,17 +15,13 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.CharacterSets;
import com.android.mmscommon.ContentType;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.ContentType;
import com.google.android.mms.InvalidHeaderValueException;
import android.util.Config;
import android.util.Log;
import android.util.base64.Base64;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -161,11 +157,9 @@ public class PduParser {
}
String ctTypeStr = new String(contentType);
if (ctTypeStr.equals(ContentType.MULTIPART_MIXED)
|| ctTypeStr.equals(ContentType.MULTIPART_RELATED)
|| ctTypeStr.equals(ContentType.MULTIPART_ALTERNATIVE)) {
|| ctTypeStr.equals(ContentType.MULTIPART_RELATED)) {
// The MMS content type must be "application/vnd.wap.multipart.mixed"
// or "application/vnd.wap.multipart.related"
// or "application/vnd.wap.multipart.alternative"
return retrieveConf;
}
return null;
@@ -791,7 +785,7 @@ public class PduParser {
String encoding = new String(partDataEncoding);
if (encoding.equalsIgnoreCase(PduPart.P_BASE64)) {
// Decode "base64" into "binary".
partData = Base64.decode(partData, Base64.DEFAULT);
partData = Base64.decodeBase64(partData);
} else if (encoding.equalsIgnoreCase(PduPart.P_QUOTED_PRINTABLE)) {
// Decode "quoted-printable" into "binary".
partData = QuotedPrintable.decodeQuotedPrintable(partData);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import android.net.Uri;

View File

@@ -15,19 +15,14 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.mms.pdu.PduPersister;
import com.android.mmscommon.ContentType;
import com.android.mmscommon.CharacterSets;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.MmsException;
import com.android.mmscommon.PduHeaders;
import com.android.mmscommon.mms.util.PduCache;
import com.android.mmscommon.mms.util.PduCacheEntry;
import android.database.sqlite.SqliteWrapper;
import com.google.android.mms.ContentType;
import com.google.android.mms.InvalidHeaderValueException;
import com.google.android.mms.MmsException;
import com.google.android.mms.util.PduCache;
import com.google.android.mms.util.PduCacheEntry;
import com.google.android.mms.util.SqliteWrapper;
import android.content.ContentResolver;
import android.content.ContentUris;
@@ -36,13 +31,13 @@ import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
import com.android.mmscommon.telephony.TelephonyProvider;
import com.android.mmscommon.telephony.TelephonyProvider.Mms;
import com.android.mmscommon.telephony.TelephonyProvider.MmsSms;
import com.android.mmscommon.telephony.TelephonyProvider.Threads;
import com.android.mmscommon.telephony.TelephonyProvider.Mms.Addr;
import com.android.mmscommon.telephony.TelephonyProvider.Mms.Part;
import com.android.mmscommon.telephony.TelephonyProvider.MmsSms.PendingMessages;
import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.MmsSms;
import android.provider.Telephony.Threads;
import android.provider.Telephony.Mms.Addr;
import android.provider.Telephony.Mms.Part;
import android.provider.Telephony.MmsSms.PendingMessages;
import android.text.TextUtils;
import android.util.Config;
import android.util.Log;
@@ -60,6 +55,7 @@ import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import com.google.android.mms.pdu.EncodedStringValue;
/**
* This class is the high-level manager of PDU storage.
@@ -426,12 +422,8 @@ public class PduPersister {
// Store simple string values directly in the database instead of an
// external file. This makes the text searchable and retrieval slightly
// faster.
if (ContentType.TEXT_PLAIN.equals(type) || ContentType.APP_SMIL.equals(type)
|| ContentType.TEXT_HTML.equals(type)) {
if ("text/plain".equals(type) || "application/smil".equals(type)) {
String text = c.getString(PART_COLUMN_TEXT);
if (text == null) {
text = "";
}
byte [] blob = new EncodedStringValue(text).getTextString();
baos.write(blob, 0, blob.length);
} else {
@@ -743,11 +735,9 @@ public class PduPersister {
try {
byte[] data = part.getData();
if (ContentType.TEXT_PLAIN.equals(contentType)
|| ContentType.APP_SMIL.equals(contentType)
|| ContentType.TEXT_HTML.equals(contentType)) {
if ("text/plain".equals(contentType) || "application/smil".equals(contentType)) {
ContentValues cv = new ContentValues();
cv.put(TelephonyProvider.Mms.Part.TEXT, new EncodedStringValue(data).getString());
cv.put(Telephony.Mms.Part.TEXT, new EncodedStringValue(data).getString());
if (mContentResolver.update(uri, cv, null, null) != 1) {
throw new MmsException("unable to update " + uri.toString());
}
@@ -868,7 +858,7 @@ public class PduPersister {
} else {
values.put(Mms.SUBJECT, "");
}
long messageSize = sendReq.getMessageSize();
if (messageSize > 0) {
values.put(Mms.MESSAGE_SIZE, messageSize);
@@ -1145,10 +1135,6 @@ public class PduPersister {
}
}
// mark "read" and "seen"
values.put(Mms.READ, 0);
values.put(Mms.SEEN, 0);
Uri res = SqliteWrapper.insert(mContext, mContentResolver, uri, values);
if (res == null) {
throw new MmsException("persist() failed: return null.");

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import java.io.ByteArrayOutputStream;

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
public class ReadOrigInd extends GenericPdu {
/**

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
public class ReadRecInd extends GenericPdu {
/**

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
/**
* M-Retrive.conf Pdu.

View File

@@ -15,11 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
public class SendConf extends GenericPdu {
/**

View File

@@ -15,13 +15,11 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.pdu;
package com.google.android.mms.pdu;
import android.util.Log;
import com.android.mmscommon.EncodedStringValue;
import com.android.mmscommon.InvalidHeaderValueException;
import com.android.mmscommon.PduHeaders;
import com.google.android.mms.InvalidHeaderValueException;
public class SendReq extends MultimediaMessagePdu {
private static final String TAG = "SendReq";

View File

@@ -0,0 +1,5 @@
<body>
{@hide}
</body>

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.util;
package com.google.android.mms.util;
import android.util.Config;
import android.util.Log;

View File

@@ -15,12 +15,12 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.util;
package com.google.android.mms.util;
import android.content.ContentUris;
import android.content.UriMatcher;
import android.net.Uri;
import com.android.mmscommon.telephony.TelephonyProvider.Mms;
import android.provider.Telephony.Mms;
import android.util.Config;
import android.util.Log;

View File

@@ -15,9 +15,9 @@
* limitations under the License.
*/
package com.android.mmscommon.mms.util;
package com.google.android.mms.util;
import com.android.mmscommon.mms.pdu.GenericPdu;
import com.google.android.mms.pdu.GenericPdu;
public final class PduCacheEntry {
private final GenericPdu mPdu;

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2008 Esmertec AG.
* 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 com.google.android.mms.util;
import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
public final class SqliteWrapper {
private static final String TAG = "SqliteWrapper";
private static final String SQLITE_EXCEPTION_DETAIL_MESSAGE
= "unable to open database file";
private SqliteWrapper() {
// Forbidden being instantiated.
}
// FIXME: It looks like outInfo.lowMemory does not work well as we expected.
// after run command: adb shell fillup -p 100, outInfo.lowMemory is still false.
private static boolean isLowMemory(Context context) {
if (null == context) {
return false;
}
ActivityManager am = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(outInfo);
return outInfo.lowMemory;
}
// FIXME: need to optimize this method.
private static boolean isLowMemory(SQLiteException e) {
return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE);
}
public static void checkSQLiteException(Context context, SQLiteException e) {
if (isLowMemory(e)) {
Toast.makeText(context, com.android.internal.R.string.low_memory,
Toast.LENGTH_SHORT).show();
} else {
throw e;
}
}
public static Cursor query(Context context, ContentResolver resolver, Uri uri,
String[] projection, String selection, String[] selectionArgs, String sortOrder) {
try {
return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
} catch (SQLiteException e) {
Log.e(TAG, "Catch a SQLiteException when query: ", e);
checkSQLiteException(context, e);
return null;
}
}
public static boolean requery(Context context, Cursor cursor) {
try {
return cursor.requery();
} catch (SQLiteException e) {
Log.e(TAG, "Catch a SQLiteException when requery: ", e);
checkSQLiteException(context, e);
return false;
}
}
public static int update(Context context, ContentResolver resolver, Uri uri,
ContentValues values, String where, String[] selectionArgs) {
try {
return resolver.update(uri, values, where, selectionArgs);
} catch (SQLiteException e) {
Log.e(TAG, "Catch a SQLiteException when update: ", e);
checkSQLiteException(context, e);
return -1;
}
}
public static int delete(Context context, ContentResolver resolver, Uri uri,
String where, String[] selectionArgs) {
try {
return resolver.delete(uri, where, selectionArgs);
} catch (SQLiteException e) {
Log.e(TAG, "Catch a SQLiteException when delete: ", e);
checkSQLiteException(context, e);
return -1;
}
}
public static Uri insert(Context context, ContentResolver resolver,
Uri uri, ContentValues values) {
try {
return resolver.insert(uri, values);
} catch (SQLiteException e) {
Log.e(TAG, "Catch a SQLiteException when insert: ", e);
checkSQLiteException(context, e);
return null;
}
}
}

View File

@@ -0,0 +1,5 @@
<body>
{@hide}
</body>

View File

@@ -1,30 +0,0 @@
# Copyright (C) 2009 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.
LOCAL_PATH := $(call my-dir)
# Note: the source code is in java/, not src/, because this code is also part of
# the framework library, and build/core/pathmap.mk expects a java/ subdirectory.
include $(CLEAR_VARS)
LOCAL_MODULE := mms-common
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_STATIC_JAVA_LIBRARIES += android-common
include $(BUILD_STATIC_JAVA_LIBRARY)
# Include this library in the build server's output directory
$(call dist-for-goals, droid, $(LOCAL_BUILT_MODULE):mms-common.jar)
# Build the test package
include $(call all-makefiles-under,$(LOCAL_PATH))

View File

@@ -1,223 +0,0 @@
/*
* Copyright (C) 2007-2008 Esmertec AG.
* Copyright (C) 2007-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 com.android.mmscommon.mms;
import java.util.ArrayList;
public class ContentType {
public static final String MMS_MESSAGE = "application/vnd.wap.mms-message";
// The phony content type for generic PDUs (e.g. ReadOrig.ind,
// Notification.ind, Delivery.ind).
public static final String MMS_GENERIC = "application/vnd.wap.mms-generic";
public static final String MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";
public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
public static final String TEXT_PLAIN = "text/plain";
public static final String TEXT_HTML = "text/html";
public static final String TEXT_VCALENDAR = "text/x-vCalendar";
public static final String TEXT_VCARD = "text/x-vCard";
public static final String IMAGE_UNSPECIFIED = "image/*";
public static final String IMAGE_JPEG = "image/jpeg";
public static final String IMAGE_JPG = "image/jpg";
public static final String IMAGE_GIF = "image/gif";
public static final String IMAGE_WBMP = "image/vnd.wap.wbmp";
public static final String IMAGE_PNG = "image/png";
public static final String AUDIO_UNSPECIFIED = "audio/*";
public static final String AUDIO_AAC = "audio/aac";
public static final String AUDIO_AMR = "audio/amr";
public static final String AUDIO_IMELODY = "audio/imelody";
public static final String AUDIO_MID = "audio/mid";
public static final String AUDIO_MIDI = "audio/midi";
public static final String AUDIO_MP3 = "audio/mp3";
public static final String AUDIO_MPEG3 = "audio/mpeg3";
public static final String AUDIO_MPEG = "audio/mpeg";
public static final String AUDIO_MPG = "audio/mpg";
public static final String AUDIO_MP4 = "audio/mp4";
public static final String AUDIO_X_MID = "audio/x-mid";
public static final String AUDIO_X_MIDI = "audio/x-midi";
public static final String AUDIO_X_MP3 = "audio/x-mp3";
public static final String AUDIO_X_MPEG3 = "audio/x-mpeg3";
public static final String AUDIO_X_MPEG = "audio/x-mpeg";
public static final String AUDIO_X_MPG = "audio/x-mpg";
public static final String AUDIO_3GPP = "audio/3gpp";
public static final String AUDIO_OGG = "application/ogg";
public static final String VIDEO_UNSPECIFIED = "video/*";
public static final String VIDEO_3GPP = "video/3gpp";
public static final String VIDEO_3G2 = "video/3gpp2";
public static final String VIDEO_H263 = "video/h263";
public static final String VIDEO_MP4 = "video/mp4";
public static final String APP_SMIL = "application/smil";
public static final String APP_WAP_XHTML = "application/vnd.wap.xhtml+xml";
public static final String APP_XHTML = "application/xhtml+xml";
public static final String APP_DRM_CONTENT = "application/vnd.oma.drm.content";
public static final String APP_DRM_MESSAGE = "application/vnd.oma.drm.message";
private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
static {
sSupportedContentTypes.add(TEXT_PLAIN);
sSupportedContentTypes.add(TEXT_HTML);
sSupportedContentTypes.add(TEXT_VCALENDAR);
sSupportedContentTypes.add(TEXT_VCARD);
sSupportedContentTypes.add(IMAGE_JPEG);
sSupportedContentTypes.add(IMAGE_GIF);
sSupportedContentTypes.add(IMAGE_WBMP);
sSupportedContentTypes.add(IMAGE_PNG);
sSupportedContentTypes.add(IMAGE_JPG);
//supportedContentTypes.add(IMAGE_SVG); not yet supported.
sSupportedContentTypes.add(AUDIO_AAC);
sSupportedContentTypes.add(AUDIO_AMR);
sSupportedContentTypes.add(AUDIO_IMELODY);
sSupportedContentTypes.add(AUDIO_MID);
sSupportedContentTypes.add(AUDIO_MIDI);
sSupportedContentTypes.add(AUDIO_MP3);
sSupportedContentTypes.add(AUDIO_MPEG3);
sSupportedContentTypes.add(AUDIO_MPEG);
sSupportedContentTypes.add(AUDIO_MPG);
sSupportedContentTypes.add(AUDIO_X_MID);
sSupportedContentTypes.add(AUDIO_X_MIDI);
sSupportedContentTypes.add(AUDIO_X_MP3);
sSupportedContentTypes.add(AUDIO_X_MPEG3);
sSupportedContentTypes.add(AUDIO_X_MPEG);
sSupportedContentTypes.add(AUDIO_X_MPG);
sSupportedContentTypes.add(AUDIO_3GPP);
sSupportedContentTypes.add(AUDIO_OGG);
sSupportedContentTypes.add(VIDEO_3GPP);
sSupportedContentTypes.add(VIDEO_3G2);
sSupportedContentTypes.add(VIDEO_H263);
sSupportedContentTypes.add(VIDEO_MP4);
sSupportedContentTypes.add(APP_SMIL);
sSupportedContentTypes.add(APP_WAP_XHTML);
sSupportedContentTypes.add(APP_XHTML);
sSupportedContentTypes.add(APP_DRM_CONTENT);
sSupportedContentTypes.add(APP_DRM_MESSAGE);
// add supported image types
sSupportedImageTypes.add(IMAGE_JPEG);
sSupportedImageTypes.add(IMAGE_GIF);
sSupportedImageTypes.add(IMAGE_WBMP);
sSupportedImageTypes.add(IMAGE_PNG);
sSupportedImageTypes.add(IMAGE_JPG);
// add supported audio types
sSupportedAudioTypes.add(AUDIO_AAC);
sSupportedAudioTypes.add(AUDIO_AMR);
sSupportedAudioTypes.add(AUDIO_IMELODY);
sSupportedAudioTypes.add(AUDIO_MID);
sSupportedAudioTypes.add(AUDIO_MIDI);
sSupportedAudioTypes.add(AUDIO_MP3);
sSupportedAudioTypes.add(AUDIO_MPEG3);
sSupportedAudioTypes.add(AUDIO_MPEG);
sSupportedAudioTypes.add(AUDIO_MPG);
sSupportedAudioTypes.add(AUDIO_MP4);
sSupportedAudioTypes.add(AUDIO_X_MID);
sSupportedAudioTypes.add(AUDIO_X_MIDI);
sSupportedAudioTypes.add(AUDIO_X_MP3);
sSupportedAudioTypes.add(AUDIO_X_MPEG3);
sSupportedAudioTypes.add(AUDIO_X_MPEG);
sSupportedAudioTypes.add(AUDIO_X_MPG);
sSupportedAudioTypes.add(AUDIO_3GPP);
sSupportedAudioTypes.add(AUDIO_OGG);
// add supported video types
sSupportedVideoTypes.add(VIDEO_3GPP);
sSupportedVideoTypes.add(VIDEO_3G2);
sSupportedVideoTypes.add(VIDEO_H263);
sSupportedVideoTypes.add(VIDEO_MP4);
}
// This class should never be instantiated.
private ContentType() {
}
public static boolean isSupportedType(String contentType) {
return (null != contentType) && sSupportedContentTypes.contains(contentType);
}
public static boolean isSupportedImageType(String contentType) {
return isImageType(contentType) && isSupportedType(contentType);
}
public static boolean isSupportedAudioType(String contentType) {
return isAudioType(contentType) && isSupportedType(contentType);
}
public static boolean isSupportedVideoType(String contentType) {
return isVideoType(contentType) && isSupportedType(contentType);
}
public static boolean isTextType(String contentType) {
return (null != contentType) && contentType.startsWith("text/");
}
public static boolean isImageType(String contentType) {
return (null != contentType) && contentType.startsWith("image/");
}
public static boolean isAudioType(String contentType) {
return (null != contentType) && contentType.startsWith("audio/");
}
public static boolean isVideoType(String contentType) {
return (null != contentType) && contentType.startsWith("video/");
}
public static boolean isDrmType(String contentType) {
return (null != contentType)
&& (contentType.equals(APP_DRM_CONTENT)
|| contentType.equals(APP_DRM_MESSAGE));
}
public static boolean isUnspecified(String contentType) {
return (null != contentType) && contentType.endsWith("*");
}
@SuppressWarnings("unchecked")
public static ArrayList<String> getImageTypes() {
return (ArrayList<String>) sSupportedImageTypes.clone();
}
@SuppressWarnings("unchecked")
public static ArrayList<String> getAudioTypes() {
return (ArrayList<String>) sSupportedAudioTypes.clone();
}
@SuppressWarnings("unchecked")
public static ArrayList<String> getVideoTypes() {
return (ArrayList<String>) sSupportedVideoTypes.clone();
}
@SuppressWarnings("unchecked")
public static ArrayList<String> getSupportedTypes() {
return (ArrayList<String>) sSupportedContentTypes.clone();
}
}