зеркало из https://github.com/mozilla/gecko-dev.git
merge b2g-inbound to mozilla-central a=merge
This commit is contained in:
Коммит
33f3132a46
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="8d83715f08b7849f16a0dfc88f78d5c3a89c0a54">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="8d83715f08b7849f16a0dfc88f78d5c3a89c0a54">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
|
||||
<default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
|
||||
<!-- Gecko and Gaia -->
|
||||
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<!-- Gonk-specific things and forks -->
|
||||
<project name="platform_bionic" path="bionic" remote="b2g" revision="e2b3733ba3fa5e3f404e983d2e4142b1f6b1b846"/>
|
||||
<project name="platform_build" path="build" remote="b2g" revision="1b0db93fb6b870b03467aff50d6419771ba0d88c">
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</project>
|
||||
<project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
<project name="moztt" path="external/moztt" remote="b2g" revision="ac7e9ae8a24ab4a3f3da801ca53f95f39a32b89f"/>
|
||||
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="2d70fdfc0244a7217df1cfa7df9f4798cbfa3af6"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="8d83715f08b7849f16a0dfc88f78d5c3a89c0a54">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
<project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="c9d4fe680662ee44a4bdea42ae00366f5df399cf">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
<project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
|
||||
<default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
|
||||
<!-- Gecko and Gaia -->
|
||||
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<!-- Gonk-specific things and forks -->
|
||||
<project name="platform_bionic" path="bionic" remote="b2g" revision="e2b3733ba3fa5e3f404e983d2e4142b1f6b1b846"/>
|
||||
<project name="platform_build" path="build" remote="b2g" revision="1b0db93fb6b870b03467aff50d6419771ba0d88c">
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="8d83715f08b7849f16a0dfc88f78d5c3a89c0a54">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"git": {
|
||||
"git_revision": "6b430ea7274af4c352de16b75e6bb85d7621ca83",
|
||||
"git_revision": "961528f4391668bc89ec0be14fa367cea099b588",
|
||||
"remote": "https://git.mozilla.org/releases/gaia.git",
|
||||
"branch": ""
|
||||
},
|
||||
"revision": "fe5d8f39d545512899d4f7825c64ddd9c8553588",
|
||||
"revision": "6dbfaf37e8ce0fa2017b228aacfc8587850ae00f",
|
||||
"repo_path": "integration/gaia-central"
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="8d83715f08b7849f16a0dfc88f78d5c3a89c0a54">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
<project name="moztt" path="external/moztt" remote="b2g" revision="ac7e9ae8a24ab4a3f3da801ca53f95f39a32b89f"/>
|
||||
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="2d70fdfc0244a7217df1cfa7df9f4798cbfa3af6"/>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<project name="platform_build" path="build" remote="b2g" revision="c9d4fe680662ee44a4bdea42ae00366f5df399cf">
|
||||
<copyfile dest="Makefile" src="core/root.mk"/>
|
||||
</project>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="6b430ea7274af4c352de16b75e6bb85d7621ca83"/>
|
||||
<project name="gaia" path="gaia" remote="mozillaorg" revision="961528f4391668bc89ec0be14fa367cea099b588"/>
|
||||
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
|
||||
<project name="fake-qemu-kernel" path="prebuilts/qemu-kernel" remote="b2g" revision="939b377d55a2f081d94029a30a75d05e5a20daf3"/>
|
||||
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="4a962bdab532e18f53e9d2d114c349983262c6b7"/>
|
||||
|
|
|
@ -24,14 +24,16 @@ namespace mozilla {
|
|||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsReceived(jni::String::Param aSender,
|
||||
SmsManager::NotifySmsReceived(int32_t aId,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int32_t aMessageClass,
|
||||
int64_t aSentTimestamp,
|
||||
int64_t aTimestamp)
|
||||
{
|
||||
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
||||
SmsMessageData message;
|
||||
message.id() = 0;
|
||||
message.id() = aId;
|
||||
message.threadId() = 0;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = eDeliveryState_Received;
|
||||
|
@ -41,7 +43,7 @@ SmsManager::NotifySmsReceived(jni::String::Param aSender,
|
|||
message.body() = aBody ? nsString(aBody) : EmptyString();
|
||||
message.messageClass() = static_cast<MessageClass>(aMessageClass);
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aSentTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = false;
|
||||
|
||||
|
|
|
@ -16,9 +16,11 @@ private:
|
|||
SmsManager();
|
||||
|
||||
public:
|
||||
static void NotifySmsReceived(jni::String::Param aSender,
|
||||
static void NotifySmsReceived(int32_t aId,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int32_t aMessageClass,
|
||||
int64_t aSentTimestamp,
|
||||
int64_t aTimestamp);
|
||||
static void NotifySmsSent(int32_t aId,
|
||||
jni::String::Param aReceiver,
|
||||
|
|
|
@ -6,12 +6,46 @@ ANDROID_MANIFEST_FILE := src/main/AndroidManifest.xml
|
|||
|
||||
JAVAFILES := \
|
||||
src/main/java/org/mozilla/b2gdroid/Apps.java \
|
||||
src/main/java/org/mozilla/b2gdroid/GeckoEventReceiver.java \
|
||||
src/main/java/org/mozilla/b2gdroid/HeadlessSmsSendService.java \
|
||||
src/main/java/org/mozilla/b2gdroid/Launcher.java \
|
||||
src/main/java/org/mozilla/b2gdroid/MmsService.java \
|
||||
src/main/java/org/mozilla/b2gdroid/NotificationObserver.java \
|
||||
src/main/java/org/mozilla/b2gdroid/RemoteGeckoEventProxy.java \
|
||||
src/main/java/org/mozilla/b2gdroid/ScreenStateObserver.java \
|
||||
src/main/java/org/mozilla/b2gdroid/SettingsMapper.java \
|
||||
src/main/java/org/mozilla/b2gdroid/GeckoEventReceiver.java \
|
||||
src/main/java/org/mozilla/b2gdroid/NotificationObserver.java \
|
||||
src/main/java/org/mozilla/b2gdroid/RemoteGeckoEventProxy.java \
|
||||
src/main/java/com/google/android/mms/ContentType.java \
|
||||
src/main/java/com/google/android/mms/InvalidHeaderValueException.java \
|
||||
src/main/java/com/google/android/mms/MmsException.java \
|
||||
src/main/java/com/google/android/mms/pdu/AcknowledgeInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/Base64.java \
|
||||
src/main/java/com/google/android/mms/pdu/CharacterSets.java \
|
||||
src/main/java/com/google/android/mms/pdu/DeliveryInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/EncodedStringValue.java \
|
||||
src/main/java/com/google/android/mms/pdu/GenericPdu.java \
|
||||
src/main/java/com/google/android/mms/pdu/MultimediaMessagePdu.java \
|
||||
src/main/java/com/google/android/mms/pdu/NotificationInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/NotifyRespInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduBody.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduComposer.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduContentTypes.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduHeaders.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduParser.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduPart.java \
|
||||
src/main/java/com/google/android/mms/pdu/PduPersister.java \
|
||||
src/main/java/com/google/android/mms/pdu/QuotedPrintable.java \
|
||||
src/main/java/com/google/android/mms/pdu/ReadOrigInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/ReadRecInd.java \
|
||||
src/main/java/com/google/android/mms/pdu/RetrieveConf.java \
|
||||
src/main/java/com/google/android/mms/pdu/SendConf.java \
|
||||
src/main/java/com/google/android/mms/pdu/SendReq.java \
|
||||
src/main/java/com/google/android/mms/util/AbstractCache.java \
|
||||
src/main/java/com/google/android/mms/util/PduCache.java \
|
||||
src/main/java/com/google/android/mms/util/PduCacheEntry.java \
|
||||
src/main/java/com/google/android/mms/util/SqliteWrapper.java \
|
||||
$(NULL)
|
||||
|
||||
# The GeckoView consuming APK depends on the GeckoView JAR files. There are two
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||
<uses-permission android:name="android.permission.WRITE_SMS"/>
|
||||
<uses-permission android:name="android.permission.READ_SMS"/>
|
||||
<uses-permission android:name="android.permission.BROADCAST_SMS"/>
|
||||
<uses-permission android:name="android.permission.WAP_PUSH_DELIVER"/>
|
||||
<uses-permission android:name="android.permission.SEND_RESPOND_VIA_MESSAGE"/>
|
||||
|
||||
<uses-feature android:name="android.hardware.telephony"/>
|
||||
|
||||
|
@ -69,6 +72,37 @@
|
|||
|
||||
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true"/>
|
||||
|
||||
<!-- Listen for incoming SMS messages -->
|
||||
<receiver android:name="org.mozilla.gecko.GeckoSmsManager"
|
||||
android:permission="android.permission.BROADCAST_SMS">
|
||||
<intent-filter>
|
||||
<action android:name="android.provider.Telephony.SMS_DELIVER" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Listen for incoming MMS messages -->
|
||||
<receiver android:name=".MmsService"
|
||||
android:permission="android.permission.BROADCAST_WAP_PUSH">
|
||||
<intent-filter>
|
||||
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
|
||||
<data android:mimeType="application/vnd.wap.mms-message" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Service that delivers messages from the phone "quick response" -->
|
||||
<service android:name=".HeadlessSmsSendService"
|
||||
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="sms" />
|
||||
<data android:scheme="smsto" />
|
||||
<data android:scheme="mms" />
|
||||
<data android:scheme="mmsto" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity android:name="org.mozilla.b2gdroid.Launcher"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:icon="@drawable/b2g"
|
||||
|
@ -84,6 +118,18 @@
|
|||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Handle SMS intents -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="sms" />
|
||||
<data android:scheme="smsto" />
|
||||
<data android:scheme="mms" />
|
||||
<data android:scheme="mmsto" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Default browser intents -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* 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.google.android.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 IMAGE_X_MS_BMP = "image/x-ms-bmp";
|
||||
|
||||
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_X_WAV = "audio/x-wav";
|
||||
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);
|
||||
sSupportedContentTypes.add(IMAGE_X_MS_BMP);
|
||||
//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_MP4);
|
||||
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_X_WAV);
|
||||
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);
|
||||
sSupportedImageTypes.add(IMAGE_X_MS_BMP);
|
||||
|
||||
// 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_X_WAV);
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Thrown when an invalid header value was set.
|
||||
*/
|
||||
public class InvalidHeaderValueException extends MmsException {
|
||||
private static final long serialVersionUID = -2053384496042052262L;
|
||||
|
||||
/**
|
||||
* Constructs an InvalidHeaderValueException with no detailed message.
|
||||
*/
|
||||
public InvalidHeaderValueException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an InvalidHeaderValueException with the specified detailed message.
|
||||
*
|
||||
* @param message the detailed message.
|
||||
*/
|
||||
public InvalidHeaderValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A generic exception that is thrown by the Mms client.
|
||||
*/
|
||||
public class MmsException extends Exception {
|
||||
private static final long serialVersionUID = -7323249827281485390L;
|
||||
|
||||
/**
|
||||
* Creates a new MmsException.
|
||||
*/
|
||||
public MmsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MmsException with the specified detail message.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public MmsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MmsException with the specified cause.
|
||||
*
|
||||
* @param cause the cause.
|
||||
*/
|
||||
public MmsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MmsException with the specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause.
|
||||
*/
|
||||
public MmsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* M-Acknowledge.ind PDU.
|
||||
*/
|
||||
public class AcknowledgeInd extends GenericPdu {
|
||||
/**
|
||||
* Constructor, used when composing a M-Acknowledge.ind pdu.
|
||||
*
|
||||
* @param mmsVersion current viersion of mms
|
||||
* @param transactionId the transaction-id value
|
||||
* @throws InvalidHeaderValueException if parameters are invalid.
|
||||
* NullPointerException if transactionId is null.
|
||||
*/
|
||||
public AcknowledgeInd(int mmsVersion, byte[] transactionId)
|
||||
throws InvalidHeaderValueException {
|
||||
super();
|
||||
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND);
|
||||
setMmsVersion(mmsVersion);
|
||||
setTransactionId(transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
AcknowledgeInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Report-Allowed field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public int getReportAllowed() {
|
||||
return mPduHeaders.getOctet(PduHeaders.REPORT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Report-Allowed field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setReportAllowed(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.REPORT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CharacterSets {
|
||||
/**
|
||||
* IANA assigned MIB enum numbers.
|
||||
*
|
||||
* From wap-230-wsp-20010705-a.pdf
|
||||
* Any-charset = <Octet 128>
|
||||
* Equivalent to the special RFC2616 charset value "*"
|
||||
*/
|
||||
public static final int ANY_CHARSET = 0x00;
|
||||
public static final int US_ASCII = 0x03;
|
||||
public static final int ISO_8859_1 = 0x04;
|
||||
public static final int ISO_8859_2 = 0x05;
|
||||
public static final int ISO_8859_3 = 0x06;
|
||||
public static final int ISO_8859_4 = 0x07;
|
||||
public static final int ISO_8859_5 = 0x08;
|
||||
public static final int ISO_8859_6 = 0x09;
|
||||
public static final int ISO_8859_7 = 0x0A;
|
||||
public static final int ISO_8859_8 = 0x0B;
|
||||
public static final int ISO_8859_9 = 0x0C;
|
||||
public static final int SHIFT_JIS = 0x11;
|
||||
public static final int UTF_8 = 0x6A;
|
||||
public static final int BIG5 = 0x07EA;
|
||||
public static final int UCS2 = 0x03E8;
|
||||
public static final int UTF_16 = 0x03F7;
|
||||
|
||||
/**
|
||||
* If the encoding of given data is unsupported, use UTF_8 to decode it.
|
||||
*/
|
||||
public static final int DEFAULT_CHARSET = UTF_8;
|
||||
|
||||
/**
|
||||
* Array of MIB enum numbers.
|
||||
*/
|
||||
private static final int[] MIBENUM_NUMBERS = {
|
||||
ANY_CHARSET,
|
||||
US_ASCII,
|
||||
ISO_8859_1,
|
||||
ISO_8859_2,
|
||||
ISO_8859_3,
|
||||
ISO_8859_4,
|
||||
ISO_8859_5,
|
||||
ISO_8859_6,
|
||||
ISO_8859_7,
|
||||
ISO_8859_8,
|
||||
ISO_8859_9,
|
||||
SHIFT_JIS,
|
||||
UTF_8,
|
||||
BIG5,
|
||||
UCS2,
|
||||
UTF_16,
|
||||
};
|
||||
|
||||
/**
|
||||
* The Well-known-charset Mime name.
|
||||
*/
|
||||
public static final String MIMENAME_ANY_CHARSET = "*";
|
||||
public static final String MIMENAME_US_ASCII = "us-ascii";
|
||||
public static final String MIMENAME_ISO_8859_1 = "iso-8859-1";
|
||||
public static final String MIMENAME_ISO_8859_2 = "iso-8859-2";
|
||||
public static final String MIMENAME_ISO_8859_3 = "iso-8859-3";
|
||||
public static final String MIMENAME_ISO_8859_4 = "iso-8859-4";
|
||||
public static final String MIMENAME_ISO_8859_5 = "iso-8859-5";
|
||||
public static final String MIMENAME_ISO_8859_6 = "iso-8859-6";
|
||||
public static final String MIMENAME_ISO_8859_7 = "iso-8859-7";
|
||||
public static final String MIMENAME_ISO_8859_8 = "iso-8859-8";
|
||||
public static final String MIMENAME_ISO_8859_9 = "iso-8859-9";
|
||||
public static final String MIMENAME_SHIFT_JIS = "shift_JIS";
|
||||
public static final String MIMENAME_UTF_8 = "utf-8";
|
||||
public static final String MIMENAME_BIG5 = "big5";
|
||||
public static final String MIMENAME_UCS2 = "iso-10646-ucs-2";
|
||||
public static final String MIMENAME_UTF_16 = "utf-16";
|
||||
|
||||
public static final String DEFAULT_CHARSET_NAME = MIMENAME_UTF_8;
|
||||
|
||||
/**
|
||||
* Array of the names of character sets.
|
||||
*/
|
||||
private static final String[] MIME_NAMES = {
|
||||
MIMENAME_ANY_CHARSET,
|
||||
MIMENAME_US_ASCII,
|
||||
MIMENAME_ISO_8859_1,
|
||||
MIMENAME_ISO_8859_2,
|
||||
MIMENAME_ISO_8859_3,
|
||||
MIMENAME_ISO_8859_4,
|
||||
MIMENAME_ISO_8859_5,
|
||||
MIMENAME_ISO_8859_6,
|
||||
MIMENAME_ISO_8859_7,
|
||||
MIMENAME_ISO_8859_8,
|
||||
MIMENAME_ISO_8859_9,
|
||||
MIMENAME_SHIFT_JIS,
|
||||
MIMENAME_UTF_8,
|
||||
MIMENAME_BIG5,
|
||||
MIMENAME_UCS2,
|
||||
MIMENAME_UTF_16,
|
||||
};
|
||||
|
||||
private static final HashMap<Integer, String> MIBENUM_TO_NAME_MAP;
|
||||
private static final HashMap<String, Integer> NAME_TO_MIBENUM_MAP;
|
||||
|
||||
static {
|
||||
// Create the HashMaps.
|
||||
MIBENUM_TO_NAME_MAP = new HashMap<Integer, String>();
|
||||
NAME_TO_MIBENUM_MAP = new HashMap<String, Integer>();
|
||||
assert(MIBENUM_NUMBERS.length == MIME_NAMES.length);
|
||||
int count = MIBENUM_NUMBERS.length - 1;
|
||||
for(int i = 0; i <= count; i++) {
|
||||
MIBENUM_TO_NAME_MAP.put(MIBENUM_NUMBERS[i], MIME_NAMES[i]);
|
||||
NAME_TO_MIBENUM_MAP.put(MIME_NAMES[i], MIBENUM_NUMBERS[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private CharacterSets() {} // Non-instantiatable
|
||||
|
||||
/**
|
||||
* Map an MIBEnum number to the name of the charset which this number
|
||||
* is assigned to by IANA.
|
||||
*
|
||||
* @param mibEnumValue An IANA assigned MIBEnum number.
|
||||
* @return The name string of the charset.
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String getMimeName(int mibEnumValue)
|
||||
throws UnsupportedEncodingException {
|
||||
String name = MIBENUM_TO_NAME_MAP.get(mibEnumValue);
|
||||
if (name == null) {
|
||||
throw new UnsupportedEncodingException();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a well-known charset name to its assigned MIBEnum number.
|
||||
*
|
||||
* @param mimeName The charset name.
|
||||
* @return The MIBEnum number assigned by IANA for this charset.
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static int getMibEnumValue(String mimeName)
|
||||
throws UnsupportedEncodingException {
|
||||
if(null == mimeName) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Integer mibEnumValue = NAME_TO_MIBENUM_MAP.get(mimeName);
|
||||
if (mibEnumValue == null) {
|
||||
throw new UnsupportedEncodingException();
|
||||
}
|
||||
return mibEnumValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* M-Delivery.Ind Pdu.
|
||||
*/
|
||||
public class DeliveryInd extends GenericPdu {
|
||||
/**
|
||||
* Empty constructor.
|
||||
* Since the Pdu corresponding to this class is constructed
|
||||
* by the Proxy-Relay server, this class is only instantiated
|
||||
* by the Pdu Parser.
|
||||
*
|
||||
* @throws InvalidHeaderValueException if error occurs.
|
||||
*/
|
||||
public DeliveryInd() throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_DELIVERY_IND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
DeliveryInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Date value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getDate() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Date value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setDate(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Message-ID value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Message-ID value.
|
||||
*
|
||||
* @param value the value, should not be null
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Status value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Status value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get To value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getTo() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* set To value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTo(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*
|
||||
* public EncodedStringValue getStatusText() {return null;}
|
||||
* public void setStatusText(EncodedStringValue value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* 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.google.android.mms.pdu;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Encoded-string-value = Text-string | Value-length Char-set Text-string
|
||||
*/
|
||||
public class EncodedStringValue implements Cloneable {
|
||||
private static final String TAG = "EncodedStringValue";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean LOCAL_LOGV = false;
|
||||
|
||||
/**
|
||||
* The Char-set value.
|
||||
*/
|
||||
private int mCharacterSet;
|
||||
|
||||
/**
|
||||
* The Text-string value.
|
||||
*/
|
||||
private byte[] mData;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param charset the Char-set value
|
||||
* @param data the Text-string value
|
||||
* @throws NullPointerException if Text-string value is null.
|
||||
*/
|
||||
public EncodedStringValue(int charset, byte[] data) {
|
||||
// TODO: CharSet needs to be validated against MIBEnum.
|
||||
if(null == data) {
|
||||
throw new NullPointerException("EncodedStringValue: Text-string is null.");
|
||||
}
|
||||
|
||||
mCharacterSet = charset;
|
||||
mData = new byte[data.length];
|
||||
System.arraycopy(data, 0, mData, 0, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param data the Text-string value
|
||||
* @throws NullPointerException if Text-string value is null.
|
||||
*/
|
||||
public EncodedStringValue(byte[] data) {
|
||||
this(CharacterSets.DEFAULT_CHARSET, data);
|
||||
}
|
||||
|
||||
public EncodedStringValue(String data) {
|
||||
try {
|
||||
mData = data.getBytes(CharacterSets.DEFAULT_CHARSET_NAME);
|
||||
mCharacterSet = CharacterSets.DEFAULT_CHARSET;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(TAG, "Default encoding must be supported.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Char-set value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getCharacterSet() {
|
||||
return mCharacterSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Char-set value.
|
||||
*
|
||||
* @param charset the Char-set value
|
||||
*/
|
||||
public void setCharacterSet(int charset) {
|
||||
// TODO: CharSet needs to be validated against MIBEnum.
|
||||
mCharacterSet = charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Text-string value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getTextString() {
|
||||
byte[] byteArray = new byte[mData.length];
|
||||
|
||||
System.arraycopy(mData, 0, byteArray, 0, mData.length);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text-string value.
|
||||
*
|
||||
* @param textString the Text-string value
|
||||
* @throws NullPointerException if Text-string value is null.
|
||||
*/
|
||||
public void setTextString(byte[] textString) {
|
||||
if(null == textString) {
|
||||
throw new NullPointerException("EncodedStringValue: Text-string is null.");
|
||||
}
|
||||
|
||||
mData = new byte[textString.length];
|
||||
System.arraycopy(textString, 0, mData, 0, textString.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this object to a {@link java.lang.String}. If the encoding of
|
||||
* the EncodedStringValue is null or unsupported, it will be
|
||||
* treated as iso-8859-1 encoding.
|
||||
*
|
||||
* @return The decoded String.
|
||||
*/
|
||||
public String getString() {
|
||||
if (CharacterSets.ANY_CHARSET == mCharacterSet) {
|
||||
return new String(mData); // system default encoding.
|
||||
} else {
|
||||
try {
|
||||
String name = CharacterSets.getMimeName(mCharacterSet);
|
||||
return new String(mData, name);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
return new String(mData, CharacterSets.MIMENAME_ISO_8859_1);
|
||||
} catch (UnsupportedEncodingException _) {
|
||||
return new String(mData); // system default encoding.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to Text-string.
|
||||
*
|
||||
* @param textString the textString to append
|
||||
* @throws NullPointerException if the text String is null
|
||||
* or an IOException occured.
|
||||
*/
|
||||
public void appendTextString(byte[] textString) {
|
||||
if(null == textString) {
|
||||
throw new NullPointerException("Text-string is null.");
|
||||
}
|
||||
|
||||
if(null == mData) {
|
||||
mData = new byte[textString.length];
|
||||
System.arraycopy(textString, 0, mData, 0, textString.length);
|
||||
} else {
|
||||
ByteArrayOutputStream newTextString = new ByteArrayOutputStream();
|
||||
try {
|
||||
newTextString.write(mData);
|
||||
newTextString.write(textString);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new NullPointerException(
|
||||
"appendTextString: failed when write a new Text-string");
|
||||
}
|
||||
|
||||
mData = newTextString.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
super.clone();
|
||||
int len = mData.length;
|
||||
byte[] dstBytes = new byte[len];
|
||||
System.arraycopy(mData, 0, dstBytes, 0, len);
|
||||
|
||||
try {
|
||||
return new EncodedStringValue(mCharacterSet, dstBytes);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "failed to clone an EncodedStringValue: " + this);
|
||||
e.printStackTrace();
|
||||
throw new CloneNotSupportedException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Split this encoded string around matches of the given pattern.
|
||||
*
|
||||
* @param pattern the delimiting pattern
|
||||
* @return the array of encoded strings computed by splitting this encoded
|
||||
* string around matches of the given pattern
|
||||
*/
|
||||
public EncodedStringValue[] split(String pattern) {
|
||||
String[] temp = getString().split(pattern);
|
||||
EncodedStringValue[] ret = new EncodedStringValue[temp.length];
|
||||
for (int i = 0; i < ret.length; ++i) {
|
||||
try {
|
||||
ret[i] = new EncodedStringValue(mCharacterSet,
|
||||
temp[i].getBytes());
|
||||
} catch (NullPointerException _) {
|
||||
// Can't arrive here
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract an EncodedStringValue[] from a given String.
|
||||
*/
|
||||
public static EncodedStringValue[] extract(String src) {
|
||||
String[] values = src.split(";");
|
||||
|
||||
ArrayList<EncodedStringValue> list = new ArrayList<EncodedStringValue>();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (values[i].length() > 0) {
|
||||
list.add(new EncodedStringValue(values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
int len = list.size();
|
||||
if (len > 0) {
|
||||
return list.toArray(new EncodedStringValue[len]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate an EncodedStringValue[] into a single String.
|
||||
*/
|
||||
public static String concat(EncodedStringValue[] addr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int maxIndex = addr.length - 1;
|
||||
for (int i = 0; i <= maxIndex; i++) {
|
||||
sb.append(addr[i].getString());
|
||||
if (i < maxIndex) {
|
||||
sb.append(";");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static EncodedStringValue copy(EncodedStringValue value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EncodedStringValue(value.mCharacterSet, value.mData);
|
||||
}
|
||||
|
||||
public static EncodedStringValue[] encodeStrings(String[] array) {
|
||||
int count = array.length;
|
||||
if (count > 0) {
|
||||
EncodedStringValue[] encodedArray = new EncodedStringValue[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
encodedArray[i] = new EncodedStringValue(array[i]);
|
||||
}
|
||||
return encodedArray;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
public class GenericPdu {
|
||||
/**
|
||||
* The headers of pdu.
|
||||
*/
|
||||
PduHeaders mPduHeaders = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public GenericPdu() {
|
||||
mPduHeaders = new PduHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
GenericPdu(PduHeaders headers) {
|
||||
mPduHeaders = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers of this PDU.
|
||||
*
|
||||
* @return A PduHeaders of this PDU.
|
||||
*/
|
||||
PduHeaders getPduHeaders() {
|
||||
return mPduHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Message-Type field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public int getMessageType() {
|
||||
return mPduHeaders.getOctet(PduHeaders.MESSAGE_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Message-Type field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if field's value is not Octet.
|
||||
*/
|
||||
public void setMessageType(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.MESSAGE_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-MMS-Version field value.
|
||||
*
|
||||
* @return the X-Mms-MMS-Version value
|
||||
*/
|
||||
public int getMmsVersion() {
|
||||
return mPduHeaders.getOctet(PduHeaders.MMS_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-MMS-Version field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if field's value is not Octet.
|
||||
*/
|
||||
public void setMmsVersion(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.MMS_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get From value.
|
||||
* From-value = Value-length
|
||||
* (Address-present-token Encoded-string-value | Insert-address-token)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getFrom() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set From value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setFrom(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.FROM);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* Multimedia message PDU.
|
||||
*/
|
||||
public class MultimediaMessagePdu extends GenericPdu{
|
||||
/**
|
||||
* The body.
|
||||
*/
|
||||
private PduBody mMessageBody;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public MultimediaMessagePdu() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param header the header of this PDU
|
||||
* @param body the body of this PDU
|
||||
*/
|
||||
public MultimediaMessagePdu(PduHeaders header, PduBody body) {
|
||||
super(header);
|
||||
mMessageBody = body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
MultimediaMessagePdu(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get body of the PDU.
|
||||
*
|
||||
* @return the body
|
||||
*/
|
||||
public PduBody getBody() {
|
||||
return mMessageBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set body of the PDU.
|
||||
*
|
||||
* @param body the body
|
||||
*/
|
||||
public void setBody(PduBody body) {
|
||||
mMessageBody = body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subject.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getSubject() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.SUBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subject.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setSubject(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.SUBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get To value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getTo() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "To" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void addTo(EncodedStringValue value) {
|
||||
mPduHeaders.appendEncodedStringValue(value, PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Priority value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getPriority() {
|
||||
return mPduHeaders.getOctet(PduHeaders.PRIORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Priority value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setPriority(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.PRIORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Date value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getDate() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Date value in seconds.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setDate(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.DATE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* M-Notification.ind PDU.
|
||||
*/
|
||||
public class NotificationInd extends GenericPdu {
|
||||
/**
|
||||
* Empty constructor.
|
||||
* Since the Pdu corresponding to this class is constructed
|
||||
* by the Proxy-Relay server, this class is only instantiated
|
||||
* by the Pdu Parser.
|
||||
*
|
||||
* @throws InvalidHeaderValueException if error occurs.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public NotificationInd() throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
NotificationInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Content-Class Value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getContentClass() {
|
||||
return mPduHeaders.getOctet(PduHeaders.CONTENT_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Content-Class Value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setContentClass(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.CONTENT_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Content-Location value.
|
||||
* When used in a PDU other than M-Mbox-Delete.conf and M-Delete.conf:
|
||||
* Content-location-value = Uri-value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentLocation() {
|
||||
return mPduHeaders.getTextString(PduHeaders.CONTENT_LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Content-Location value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setContentLocation(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.CONTENT_LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Expiry value.
|
||||
*
|
||||
* Expiry-value = Value-length
|
||||
* (Absolute-token Date-value | Relative-token Delta-seconds-value)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getExpiry() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Expiry value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setExpiry(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get From value.
|
||||
* From-value = Value-length
|
||||
* (Address-present-token Encoded-string-value | Insert-address-token)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getFrom() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set From value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setFrom(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Message-Class value.
|
||||
* Message-class-value = Class-identifier | Token-text
|
||||
* Class-identifier = Personal | Advertisement | Informational | Auto
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageClass() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Message-Class value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setMessageClass(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Message-Size value.
|
||||
* Message-size-value = Long-integer
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getMessageSize() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Message-Size value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setMessageSize(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subject.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getSubject() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.SUBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subject.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setSubject(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.SUBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Delivery-Report Value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getDeliveryReport() {
|
||||
return mPduHeaders.getOctet(PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Delivery-Report Value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setDeliveryReport(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getDrmContent() {return 0x00;}
|
||||
* public void setDrmContent(byte value) {}
|
||||
*
|
||||
* public byte getDistributionIndicator() {return 0x00;}
|
||||
* public void setDistributionIndicator(byte value) {}
|
||||
*
|
||||
* public ElementDescriptorValue getElementDescriptor() {return null;}
|
||||
* public void getElementDescriptor(ElementDescriptorValue value) {}
|
||||
*
|
||||
* public byte getPriority() {return 0x00;}
|
||||
* public void setPriority(byte value) {}
|
||||
*
|
||||
* public byte getRecommendedRetrievalMode() {return 0x00;}
|
||||
* public void setRecommendedRetrievalMode(byte value) {}
|
||||
*
|
||||
* public byte getRecommendedRetrievalModeText() {return 0x00;}
|
||||
* public void setRecommendedRetrievalModeText(byte value) {}
|
||||
*
|
||||
* public byte[] getReplaceId() {return 0x00;}
|
||||
* public void setReplaceId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getReplyCharging() {return 0x00;}
|
||||
* public void setReplyCharging(byte value) {}
|
||||
*
|
||||
* public byte getReplyChargingDeadline() {return 0x00;}
|
||||
* public void setReplyChargingDeadline(byte value) {}
|
||||
*
|
||||
* public byte[] getReplyChargingId() {return 0x00;}
|
||||
* public void setReplyChargingId(byte[] value) {}
|
||||
*
|
||||
* public long getReplyChargingSize() {return 0;}
|
||||
* public void setReplyChargingSize(long value) {}
|
||||
*
|
||||
* public byte getStored() {return 0x00;}
|
||||
* public void setStored(byte value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* M-NofifyResp.ind PDU.
|
||||
*/
|
||||
public class NotifyRespInd extends GenericPdu {
|
||||
/**
|
||||
* Constructor, used when composing a M-NotifyResp.ind pdu.
|
||||
*
|
||||
* @param mmsVersion current version of mms
|
||||
* @param transactionId the transaction-id value
|
||||
* @param status the status value
|
||||
* @throws InvalidHeaderValueException if parameters are invalid.
|
||||
* NullPointerException if transactionId is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public NotifyRespInd(int mmsVersion,
|
||||
byte[] transactionId,
|
||||
int status) throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND);
|
||||
setMmsVersion(mmsVersion);
|
||||
setTransactionId(transactionId);
|
||||
setStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
NotifyRespInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Report-Allowed field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public int getReportAllowed() {
|
||||
return mPduHeaders.getOctet(PduHeaders.REPORT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Report-Allowed field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setReportAllowed(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.REPORT_ALLOWED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Status field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* GetX-Mms-Status field value.
|
||||
*
|
||||
* @return the X-Mms-Status value
|
||||
*/
|
||||
public int getStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
* RuntimeException if an undeclared error occurs.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
public class PduBody {
|
||||
private Vector<PduPart> mParts = null;
|
||||
|
||||
private Map<String, PduPart> mPartMapByContentId = null;
|
||||
private Map<String, PduPart> mPartMapByContentLocation = null;
|
||||
private Map<String, PduPart> mPartMapByName = null;
|
||||
private Map<String, PduPart> mPartMapByFileName = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public PduBody() {
|
||||
mParts = new Vector<PduPart>();
|
||||
|
||||
mPartMapByContentId = new HashMap<String, PduPart>();
|
||||
mPartMapByContentLocation = new HashMap<String, PduPart>();
|
||||
mPartMapByName = new HashMap<String, PduPart>();
|
||||
mPartMapByFileName = new HashMap<String, PduPart>();
|
||||
}
|
||||
|
||||
private void putPartToMaps(PduPart part) {
|
||||
// Put part to mPartMapByContentId.
|
||||
byte[] contentId = part.getContentId();
|
||||
if(null != contentId) {
|
||||
mPartMapByContentId.put(new String(contentId), part);
|
||||
}
|
||||
|
||||
// Put part to mPartMapByContentLocation.
|
||||
byte[] contentLocation = part.getContentLocation();
|
||||
if(null != contentLocation) {
|
||||
String clc = new String(contentLocation);
|
||||
mPartMapByContentLocation.put(clc, part);
|
||||
}
|
||||
|
||||
// Put part to mPartMapByName.
|
||||
byte[] name = part.getName();
|
||||
if(null != name) {
|
||||
String clc = new String(name);
|
||||
mPartMapByName.put(clc, part);
|
||||
}
|
||||
|
||||
// Put part to mPartMapByFileName.
|
||||
byte[] fileName = part.getFilename();
|
||||
if(null != fileName) {
|
||||
String clc = new String(fileName);
|
||||
mPartMapByFileName.put(clc, part);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified part to the end of this body.
|
||||
*
|
||||
* @param part part to be appended
|
||||
* @return true when success, false when fail
|
||||
* @throws NullPointerException when part is null
|
||||
*/
|
||||
public boolean addPart(PduPart part) {
|
||||
if(null == part) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
putPartToMaps(part);
|
||||
return mParts.add(part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the specified part at the specified position.
|
||||
*
|
||||
* @param index index at which the specified part is to be inserted
|
||||
* @param part part to be inserted
|
||||
* @throws NullPointerException when part is null
|
||||
*/
|
||||
public void addPart(int index, PduPart part) {
|
||||
if(null == part) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
putPartToMaps(part);
|
||||
mParts.add(index, part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the part at the specified position.
|
||||
*
|
||||
* @param index index of the part to return
|
||||
* @return part at the specified index
|
||||
*/
|
||||
public PduPart removePart(int index) {
|
||||
return mParts.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all of the parts.
|
||||
*/
|
||||
public void removeAll() {
|
||||
mParts.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the part at the specified position.
|
||||
*
|
||||
* @param index index of the part to return
|
||||
* @return part at the specified index
|
||||
*/
|
||||
public PduPart getPart(int index) {
|
||||
return mParts.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of the specified part.
|
||||
*
|
||||
* @param part the part object
|
||||
* @return index the index of the first occurrence of the part in this body
|
||||
*/
|
||||
public int getPartIndex(PduPart part) {
|
||||
return mParts.indexOf(part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of parts.
|
||||
*
|
||||
* @return the number of parts
|
||||
*/
|
||||
public int getPartsNum() {
|
||||
return mParts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pdu part by content id.
|
||||
*
|
||||
* @param cid the value of content id.
|
||||
* @return the pdu part.
|
||||
*/
|
||||
public PduPart getPartByContentId(String cid) {
|
||||
return mPartMapByContentId.get(cid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pdu part by Content-Location. Content-Location of part is
|
||||
* the same as filename and name(param of content-type).
|
||||
*
|
||||
* @param fileName the value of filename.
|
||||
* @return the pdu part.
|
||||
*/
|
||||
public PduPart getPartByContentLocation(String contentLocation) {
|
||||
return mPartMapByContentLocation.get(contentLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pdu part by name.
|
||||
*
|
||||
* @param fileName the value of filename.
|
||||
* @return the pdu part.
|
||||
*/
|
||||
public PduPart getPartByName(String name) {
|
||||
return mPartMapByName.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pdu part by filename.
|
||||
*
|
||||
* @param fileName the value of filename.
|
||||
* @return the pdu part.
|
||||
*/
|
||||
public PduPart getPartByFileName(String filename) {
|
||||
return mPartMapByFileName.get(filename);
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* 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 PduContentTypes {
|
||||
/**
|
||||
* All content types. From:
|
||||
* http://www.openmobilealliance.org/tech/omna/omna-wsp-content-type.htm
|
||||
*/
|
||||
static final String[] contentTypes = {
|
||||
"*/*", /* 0x00 */
|
||||
"text/*", /* 0x01 */
|
||||
"text/html", /* 0x02 */
|
||||
"text/plain", /* 0x03 */
|
||||
"text/x-hdml", /* 0x04 */
|
||||
"text/x-ttml", /* 0x05 */
|
||||
"text/x-vCalendar", /* 0x06 */
|
||||
"text/x-vCard", /* 0x07 */
|
||||
"text/vnd.wap.wml", /* 0x08 */
|
||||
"text/vnd.wap.wmlscript", /* 0x09 */
|
||||
"text/vnd.wap.wta-event", /* 0x0A */
|
||||
"multipart/*", /* 0x0B */
|
||||
"multipart/mixed", /* 0x0C */
|
||||
"multipart/form-data", /* 0x0D */
|
||||
"multipart/byterantes", /* 0x0E */
|
||||
"multipart/alternative", /* 0x0F */
|
||||
"application/*", /* 0x10 */
|
||||
"application/java-vm", /* 0x11 */
|
||||
"application/x-www-form-urlencoded", /* 0x12 */
|
||||
"application/x-hdmlc", /* 0x13 */
|
||||
"application/vnd.wap.wmlc", /* 0x14 */
|
||||
"application/vnd.wap.wmlscriptc", /* 0x15 */
|
||||
"application/vnd.wap.wta-eventc", /* 0x16 */
|
||||
"application/vnd.wap.uaprof", /* 0x17 */
|
||||
"application/vnd.wap.wtls-ca-certificate", /* 0x18 */
|
||||
"application/vnd.wap.wtls-user-certificate", /* 0x19 */
|
||||
"application/x-x509-ca-cert", /* 0x1A */
|
||||
"application/x-x509-user-cert", /* 0x1B */
|
||||
"image/*", /* 0x1C */
|
||||
"image/gif", /* 0x1D */
|
||||
"image/jpeg", /* 0x1E */
|
||||
"image/tiff", /* 0x1F */
|
||||
"image/png", /* 0x20 */
|
||||
"image/vnd.wap.wbmp", /* 0x21 */
|
||||
"application/vnd.wap.multipart.*", /* 0x22 */
|
||||
"application/vnd.wap.multipart.mixed", /* 0x23 */
|
||||
"application/vnd.wap.multipart.form-data", /* 0x24 */
|
||||
"application/vnd.wap.multipart.byteranges", /* 0x25 */
|
||||
"application/vnd.wap.multipart.alternative", /* 0x26 */
|
||||
"application/xml", /* 0x27 */
|
||||
"text/xml", /* 0x28 */
|
||||
"application/vnd.wap.wbxml", /* 0x29 */
|
||||
"application/x-x968-cross-cert", /* 0x2A */
|
||||
"application/x-x968-ca-cert", /* 0x2B */
|
||||
"application/x-x968-user-cert", /* 0x2C */
|
||||
"text/vnd.wap.si", /* 0x2D */
|
||||
"application/vnd.wap.sic", /* 0x2E */
|
||||
"text/vnd.wap.sl", /* 0x2F */
|
||||
"application/vnd.wap.slc", /* 0x30 */
|
||||
"text/vnd.wap.co", /* 0x31 */
|
||||
"application/vnd.wap.coc", /* 0x32 */
|
||||
"application/vnd.wap.multipart.related", /* 0x33 */
|
||||
"application/vnd.wap.sia", /* 0x34 */
|
||||
"text/vnd.wap.connectivity-xml", /* 0x35 */
|
||||
"application/vnd.wap.connectivity-wbxml", /* 0x36 */
|
||||
"application/pkcs7-mime", /* 0x37 */
|
||||
"application/vnd.wap.hashed-certificate", /* 0x38 */
|
||||
"application/vnd.wap.signed-certificate", /* 0x39 */
|
||||
"application/vnd.wap.cert-response", /* 0x3A */
|
||||
"application/xhtml+xml", /* 0x3B */
|
||||
"application/wml+xml", /* 0x3C */
|
||||
"text/css", /* 0x3D */
|
||||
"application/vnd.wap.mms-message", /* 0x3E */
|
||||
"application/vnd.wap.rollover-certificate", /* 0x3F */
|
||||
"application/vnd.wap.locc+wbxml", /* 0x40 */
|
||||
"application/vnd.wap.loc+xml", /* 0x41 */
|
||||
"application/vnd.syncml.dm+wbxml", /* 0x42 */
|
||||
"application/vnd.syncml.dm+xml", /* 0x43 */
|
||||
"application/vnd.syncml.notification", /* 0x44 */
|
||||
"application/vnd.wap.xhtml+xml", /* 0x45 */
|
||||
"application/vnd.wv.csp.cir", /* 0x46 */
|
||||
"application/vnd.oma.dd+xml", /* 0x47 */
|
||||
"application/vnd.oma.drm.message", /* 0x48 */
|
||||
"application/vnd.oma.drm.content", /* 0x49 */
|
||||
"application/vnd.oma.drm.rights+xml", /* 0x4A */
|
||||
"application/vnd.oma.drm.rights+wbxml", /* 0x4B */
|
||||
"application/vnd.wv.csp+xml", /* 0x4C */
|
||||
"application/vnd.wv.csp+wbxml", /* 0x4D */
|
||||
"application/vnd.syncml.ds.notification", /* 0x4E */
|
||||
"audio/*", /* 0x4F */
|
||||
"video/*", /* 0x50 */
|
||||
"application/vnd.oma.dd2+xml", /* 0x51 */
|
||||
"application/mikey" /* 0x52 */
|
||||
};
|
||||
}
|
|
@ -0,0 +1,721 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PduHeaders {
|
||||
/**
|
||||
* All pdu header fields.
|
||||
*/
|
||||
public static final int BCC = 0x81;
|
||||
public static final int CC = 0x82;
|
||||
public static final int CONTENT_LOCATION = 0x83;
|
||||
public static final int CONTENT_TYPE = 0x84;
|
||||
public static final int DATE = 0x85;
|
||||
public static final int DELIVERY_REPORT = 0x86;
|
||||
public static final int DELIVERY_TIME = 0x87;
|
||||
public static final int EXPIRY = 0x88;
|
||||
public static final int FROM = 0x89;
|
||||
public static final int MESSAGE_CLASS = 0x8A;
|
||||
public static final int MESSAGE_ID = 0x8B;
|
||||
public static final int MESSAGE_TYPE = 0x8C;
|
||||
public static final int MMS_VERSION = 0x8D;
|
||||
public static final int MESSAGE_SIZE = 0x8E;
|
||||
public static final int PRIORITY = 0x8F;
|
||||
|
||||
public static final int READ_REPLY = 0x90;
|
||||
public static final int READ_REPORT = 0x90;
|
||||
public static final int REPORT_ALLOWED = 0x91;
|
||||
public static final int RESPONSE_STATUS = 0x92;
|
||||
public static final int RESPONSE_TEXT = 0x93;
|
||||
public static final int SENDER_VISIBILITY = 0x94;
|
||||
public static final int STATUS = 0x95;
|
||||
public static final int SUBJECT = 0x96;
|
||||
public static final int TO = 0x97;
|
||||
public static final int TRANSACTION_ID = 0x98;
|
||||
public static final int RETRIEVE_STATUS = 0x99;
|
||||
public static final int RETRIEVE_TEXT = 0x9A;
|
||||
public static final int READ_STATUS = 0x9B;
|
||||
public static final int REPLY_CHARGING = 0x9C;
|
||||
public static final int REPLY_CHARGING_DEADLINE = 0x9D;
|
||||
public static final int REPLY_CHARGING_ID = 0x9E;
|
||||
public static final int REPLY_CHARGING_SIZE = 0x9F;
|
||||
|
||||
public static final int PREVIOUSLY_SENT_BY = 0xA0;
|
||||
public static final int PREVIOUSLY_SENT_DATE = 0xA1;
|
||||
public static final int STORE = 0xA2;
|
||||
public static final int MM_STATE = 0xA3;
|
||||
public static final int MM_FLAGS = 0xA4;
|
||||
public static final int STORE_STATUS = 0xA5;
|
||||
public static final int STORE_STATUS_TEXT = 0xA6;
|
||||
public static final int STORED = 0xA7;
|
||||
public static final int ATTRIBUTES = 0xA8;
|
||||
public static final int TOTALS = 0xA9;
|
||||
public static final int MBOX_TOTALS = 0xAA;
|
||||
public static final int QUOTAS = 0xAB;
|
||||
public static final int MBOX_QUOTAS = 0xAC;
|
||||
public static final int MESSAGE_COUNT = 0xAD;
|
||||
public static final int CONTENT = 0xAE;
|
||||
public static final int START = 0xAF;
|
||||
|
||||
public static final int ADDITIONAL_HEADERS = 0xB0;
|
||||
public static final int DISTRIBUTION_INDICATOR = 0xB1;
|
||||
public static final int ELEMENT_DESCRIPTOR = 0xB2;
|
||||
public static final int LIMIT = 0xB3;
|
||||
public static final int RECOMMENDED_RETRIEVAL_MODE = 0xB4;
|
||||
public static final int RECOMMENDED_RETRIEVAL_MODE_TEXT = 0xB5;
|
||||
public static final int STATUS_TEXT = 0xB6;
|
||||
public static final int APPLIC_ID = 0xB7;
|
||||
public static final int REPLY_APPLIC_ID = 0xB8;
|
||||
public static final int AUX_APPLIC_ID = 0xB9;
|
||||
public static final int CONTENT_CLASS = 0xBA;
|
||||
public static final int DRM_CONTENT = 0xBB;
|
||||
public static final int ADAPTATION_ALLOWED = 0xBC;
|
||||
public static final int REPLACE_ID = 0xBD;
|
||||
public static final int CANCEL_ID = 0xBE;
|
||||
public static final int CANCEL_STATUS = 0xBF;
|
||||
|
||||
/**
|
||||
* X-Mms-Message-Type field types.
|
||||
*/
|
||||
public static final int MESSAGE_TYPE_SEND_REQ = 0x80;
|
||||
public static final int MESSAGE_TYPE_SEND_CONF = 0x81;
|
||||
public static final int MESSAGE_TYPE_NOTIFICATION_IND = 0x82;
|
||||
public static final int MESSAGE_TYPE_NOTIFYRESP_IND = 0x83;
|
||||
public static final int MESSAGE_TYPE_RETRIEVE_CONF = 0x84;
|
||||
public static final int MESSAGE_TYPE_ACKNOWLEDGE_IND = 0x85;
|
||||
public static final int MESSAGE_TYPE_DELIVERY_IND = 0x86;
|
||||
public static final int MESSAGE_TYPE_READ_REC_IND = 0x87;
|
||||
public static final int MESSAGE_TYPE_READ_ORIG_IND = 0x88;
|
||||
public static final int MESSAGE_TYPE_FORWARD_REQ = 0x89;
|
||||
public static final int MESSAGE_TYPE_FORWARD_CONF = 0x8A;
|
||||
public static final int MESSAGE_TYPE_MBOX_STORE_REQ = 0x8B;
|
||||
public static final int MESSAGE_TYPE_MBOX_STORE_CONF = 0x8C;
|
||||
public static final int MESSAGE_TYPE_MBOX_VIEW_REQ = 0x8D;
|
||||
public static final int MESSAGE_TYPE_MBOX_VIEW_CONF = 0x8E;
|
||||
public static final int MESSAGE_TYPE_MBOX_UPLOAD_REQ = 0x8F;
|
||||
public static final int MESSAGE_TYPE_MBOX_UPLOAD_CONF = 0x90;
|
||||
public static final int MESSAGE_TYPE_MBOX_DELETE_REQ = 0x91;
|
||||
public static final int MESSAGE_TYPE_MBOX_DELETE_CONF = 0x92;
|
||||
public static final int MESSAGE_TYPE_MBOX_DESCR = 0x93;
|
||||
public static final int MESSAGE_TYPE_DELETE_REQ = 0x94;
|
||||
public static final int MESSAGE_TYPE_DELETE_CONF = 0x95;
|
||||
public static final int MESSAGE_TYPE_CANCEL_REQ = 0x96;
|
||||
public static final int MESSAGE_TYPE_CANCEL_CONF = 0x97;
|
||||
|
||||
/**
|
||||
* X-Mms-Delivery-Report |
|
||||
* X-Mms-Read-Report |
|
||||
* X-Mms-Report-Allowed |
|
||||
* X-Mms-Sender-Visibility |
|
||||
* X-Mms-Store |
|
||||
* X-Mms-Stored |
|
||||
* X-Mms-Totals |
|
||||
* X-Mms-Quotas |
|
||||
* X-Mms-Distribution-Indicator |
|
||||
* X-Mms-DRM-Content |
|
||||
* X-Mms-Adaptation-Allowed |
|
||||
* field types.
|
||||
*/
|
||||
public static final int VALUE_YES = 0x80;
|
||||
public static final int VALUE_NO = 0x81;
|
||||
|
||||
/**
|
||||
* Delivery-Time |
|
||||
* Expiry and Reply-Charging-Deadline |
|
||||
* field type components.
|
||||
*/
|
||||
public static final int VALUE_ABSOLUTE_TOKEN = 0x80;
|
||||
public static final int VALUE_RELATIVE_TOKEN = 0x81;
|
||||
|
||||
/**
|
||||
* X-Mms-MMS-Version field types.
|
||||
*/
|
||||
public static final int MMS_VERSION_1_3 = ((1 << 4) | 3);
|
||||
public static final int MMS_VERSION_1_2 = ((1 << 4) | 2);
|
||||
public static final int MMS_VERSION_1_1 = ((1 << 4) | 1);
|
||||
public static final int MMS_VERSION_1_0 = ((1 << 4) | 0);
|
||||
|
||||
// Current version is 1.2.
|
||||
public static final int CURRENT_MMS_VERSION = MMS_VERSION_1_2;
|
||||
|
||||
/**
|
||||
* From field type components.
|
||||
*/
|
||||
public static final int FROM_ADDRESS_PRESENT_TOKEN = 0x80;
|
||||
public static final int FROM_INSERT_ADDRESS_TOKEN = 0x81;
|
||||
|
||||
public static final String FROM_ADDRESS_PRESENT_TOKEN_STR = "address-present-token";
|
||||
public static final String FROM_INSERT_ADDRESS_TOKEN_STR = "insert-address-token";
|
||||
|
||||
/**
|
||||
* X-Mms-Status Field.
|
||||
*/
|
||||
public static final int STATUS_EXPIRED = 0x80;
|
||||
public static final int STATUS_RETRIEVED = 0x81;
|
||||
public static final int STATUS_REJECTED = 0x82;
|
||||
public static final int STATUS_DEFERRED = 0x83;
|
||||
public static final int STATUS_UNRECOGNIZED = 0x84;
|
||||
public static final int STATUS_INDETERMINATE = 0x85;
|
||||
public static final int STATUS_FORWARDED = 0x86;
|
||||
public static final int STATUS_UNREACHABLE = 0x87;
|
||||
|
||||
/**
|
||||
* MM-Flags field type components.
|
||||
*/
|
||||
public static final int MM_FLAGS_ADD_TOKEN = 0x80;
|
||||
public static final int MM_FLAGS_REMOVE_TOKEN = 0x81;
|
||||
public static final int MM_FLAGS_FILTER_TOKEN = 0x82;
|
||||
|
||||
/**
|
||||
* X-Mms-Message-Class field types.
|
||||
*/
|
||||
public static final int MESSAGE_CLASS_PERSONAL = 0x80;
|
||||
public static final int MESSAGE_CLASS_ADVERTISEMENT = 0x81;
|
||||
public static final int MESSAGE_CLASS_INFORMATIONAL = 0x82;
|
||||
public static final int MESSAGE_CLASS_AUTO = 0x83;
|
||||
|
||||
public static final String MESSAGE_CLASS_PERSONAL_STR = "personal";
|
||||
public static final String MESSAGE_CLASS_ADVERTISEMENT_STR = "advertisement";
|
||||
public static final String MESSAGE_CLASS_INFORMATIONAL_STR = "informational";
|
||||
public static final String MESSAGE_CLASS_AUTO_STR = "auto";
|
||||
|
||||
/**
|
||||
* X-Mms-Priority field types.
|
||||
*/
|
||||
public static final int PRIORITY_LOW = 0x80;
|
||||
public static final int PRIORITY_NORMAL = 0x81;
|
||||
public static final int PRIORITY_HIGH = 0x82;
|
||||
|
||||
/**
|
||||
* X-Mms-Response-Status field types.
|
||||
*/
|
||||
public static final int RESPONSE_STATUS_OK = 0x80;
|
||||
public static final int RESPONSE_STATUS_ERROR_UNSPECIFIED = 0x81;
|
||||
public static final int RESPONSE_STATUS_ERROR_SERVICE_DENIED = 0x82;
|
||||
|
||||
public static final int RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT = 0x83;
|
||||
public static final int RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED = 0x84;
|
||||
|
||||
public static final int RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND = 0x85;
|
||||
public static final int RESPONSE_STATUS_ERROR_NETWORK_PROBLEM = 0x86;
|
||||
public static final int RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED = 0x87;
|
||||
public static final int RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE = 0x88;
|
||||
public static final int RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0;
|
||||
|
||||
public static final int RESPONSE_STATUS_ERROR_TRANSIENT_SENDNG_ADDRESS_UNRESOLVED = 0xC1;
|
||||
public static final int RESPONSE_STATUS_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 0xC2;
|
||||
public static final int RESPONSE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC3;
|
||||
public static final int RESPONSE_STATUS_ERROR_TRANSIENT_PARTIAL_SUCCESS = 0xC4;
|
||||
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 0xE2;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_SENDING_ADDRESS_UNRESOLVED = 0xE3;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE4;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_CONTENT_NOT_ACCEPTED = 0xE5;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_LIMITATIONS_NOT_MET = 0xE6;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_REQUEST_NOT_ACCEPTED = 0xE6;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_FORWARDING_DENIED = 0xE8;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_NOT_SUPPORTED = 0xE9;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_ADDRESS_HIDING_NOT_SUPPORTED = 0xEA;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_LACK_OF_PREPAID = 0xEB;
|
||||
public static final int RESPONSE_STATUS_ERROR_PERMANENT_END = 0xFF;
|
||||
|
||||
/**
|
||||
* X-Mms-Retrieve-Status field types.
|
||||
*/
|
||||
public static final int RETRIEVE_STATUS_OK = 0x80;
|
||||
public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0;
|
||||
public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 0xC1;
|
||||
public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC2;
|
||||
public static final int RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0;
|
||||
public static final int RETRIEVE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1;
|
||||
public static final int RETRIEVE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE2;
|
||||
public static final int RETRIEVE_STATUS_ERROR_PERMANENT_CONTENT_UNSUPPORTED = 0xE3;
|
||||
public static final int RETRIEVE_STATUS_ERROR_END = 0xFF;
|
||||
|
||||
/**
|
||||
* X-Mms-Sender-Visibility field types.
|
||||
*/
|
||||
public static final int SENDER_VISIBILITY_HIDE = 0x80;
|
||||
public static final int SENDER_VISIBILITY_SHOW = 0x81;
|
||||
|
||||
/**
|
||||
* X-Mms-Read-Status field types.
|
||||
*/
|
||||
public static final int READ_STATUS_READ = 0x80;
|
||||
public static final int READ_STATUS__DELETED_WITHOUT_BEING_READ = 0x81;
|
||||
|
||||
/**
|
||||
* X-Mms-Cancel-Status field types.
|
||||
*/
|
||||
public static final int CANCEL_STATUS_REQUEST_SUCCESSFULLY_RECEIVED = 0x80;
|
||||
public static final int CANCEL_STATUS_REQUEST_CORRUPTED = 0x81;
|
||||
|
||||
/**
|
||||
* X-Mms-Reply-Charging field types.
|
||||
*/
|
||||
public static final int REPLY_CHARGING_REQUESTED = 0x80;
|
||||
public static final int REPLY_CHARGING_REQUESTED_TEXT_ONLY = 0x81;
|
||||
public static final int REPLY_CHARGING_ACCEPTED = 0x82;
|
||||
public static final int REPLY_CHARGING_ACCEPTED_TEXT_ONLY = 0x83;
|
||||
|
||||
/**
|
||||
* X-Mms-MM-State field types.
|
||||
*/
|
||||
public static final int MM_STATE_DRAFT = 0x80;
|
||||
public static final int MM_STATE_SENT = 0x81;
|
||||
public static final int MM_STATE_NEW = 0x82;
|
||||
public static final int MM_STATE_RETRIEVED = 0x83;
|
||||
public static final int MM_STATE_FORWARDED = 0x84;
|
||||
|
||||
/**
|
||||
* X-Mms-Recommended-Retrieval-Mode field types.
|
||||
*/
|
||||
public static final int RECOMMENDED_RETRIEVAL_MODE_MANUAL = 0x80;
|
||||
|
||||
/**
|
||||
* X-Mms-Content-Class field types.
|
||||
*/
|
||||
public static final int CONTENT_CLASS_TEXT = 0x80;
|
||||
public static final int CONTENT_CLASS_IMAGE_BASIC = 0x81;
|
||||
public static final int CONTENT_CLASS_IMAGE_RICH = 0x82;
|
||||
public static final int CONTENT_CLASS_VIDEO_BASIC = 0x83;
|
||||
public static final int CONTENT_CLASS_VIDEO_RICH = 0x84;
|
||||
public static final int CONTENT_CLASS_MEGAPIXEL = 0x85;
|
||||
public static final int CONTENT_CLASS_CONTENT_BASIC = 0x86;
|
||||
public static final int CONTENT_CLASS_CONTENT_RICH = 0x87;
|
||||
|
||||
/**
|
||||
* X-Mms-Store-Status field types.
|
||||
*/
|
||||
public static final int STORE_STATUS_SUCCESS = 0x80;
|
||||
public static final int STORE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0;
|
||||
public static final int STORE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC1;
|
||||
public static final int STORE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0;
|
||||
public static final int STORE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1;
|
||||
public static final int STORE_STATUS_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 0xE2;
|
||||
public static final int STORE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE3;
|
||||
public static final int STORE_STATUS_ERROR_PERMANENT_MMBOX_FULL = 0xE4;
|
||||
public static final int STORE_STATUS_ERROR_END = 0xFF;
|
||||
|
||||
/**
|
||||
* The map contains the value of all headers.
|
||||
*/
|
||||
private HashMap<Integer, Object> mHeaderMap = null;
|
||||
|
||||
/**
|
||||
* Constructor of PduHeaders.
|
||||
*/
|
||||
public PduHeaders() {
|
||||
mHeaderMap = new HashMap<Integer, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get octet value by header field.
|
||||
*
|
||||
* @param field the field
|
||||
* @return the octet value of the pdu header
|
||||
* with specified header field. Return 0 if
|
||||
* the value is not set.
|
||||
*/
|
||||
protected int getOctet(int field) {
|
||||
Integer octet = (Integer) mHeaderMap.get(field);
|
||||
if (null == octet) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return octet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set octet value to pdu header by header field.
|
||||
*
|
||||
* @param value the value
|
||||
* @param field the field
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
protected void setOctet(int value, int field)
|
||||
throws InvalidHeaderValueException{
|
||||
/**
|
||||
* Check whether this field can be set for specific
|
||||
* header and check validity of the field.
|
||||
*/
|
||||
switch (field) {
|
||||
case REPORT_ALLOWED:
|
||||
case ADAPTATION_ALLOWED:
|
||||
case DELIVERY_REPORT:
|
||||
case DRM_CONTENT:
|
||||
case DISTRIBUTION_INDICATOR:
|
||||
case QUOTAS:
|
||||
case READ_REPORT:
|
||||
case STORE:
|
||||
case STORED:
|
||||
case TOTALS:
|
||||
case SENDER_VISIBILITY:
|
||||
if ((VALUE_YES != value) && (VALUE_NO != value)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case READ_STATUS:
|
||||
if ((READ_STATUS_READ != value) &&
|
||||
(READ_STATUS__DELETED_WITHOUT_BEING_READ != value)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case CANCEL_STATUS:
|
||||
if ((CANCEL_STATUS_REQUEST_SUCCESSFULLY_RECEIVED != value) &&
|
||||
(CANCEL_STATUS_REQUEST_CORRUPTED != value)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case PRIORITY:
|
||||
if ((value < PRIORITY_LOW) || (value > PRIORITY_HIGH)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case STATUS:
|
||||
if ((value < STATUS_EXPIRED) || (value > STATUS_UNREACHABLE)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case REPLY_CHARGING:
|
||||
if ((value < REPLY_CHARGING_REQUESTED)
|
||||
|| (value > REPLY_CHARGING_ACCEPTED_TEXT_ONLY)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case MM_STATE:
|
||||
if ((value < MM_STATE_DRAFT) || (value > MM_STATE_FORWARDED)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case RECOMMENDED_RETRIEVAL_MODE:
|
||||
if (RECOMMENDED_RETRIEVAL_MODE_MANUAL != value) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case CONTENT_CLASS:
|
||||
if ((value < CONTENT_CLASS_TEXT)
|
||||
|| (value > CONTENT_CLASS_CONTENT_RICH)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
case RETRIEVE_STATUS:
|
||||
// According to oma-ts-mms-enc-v1_3, section 7.3.50, we modify the invalid value.
|
||||
if ((value > RETRIEVE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM) &&
|
||||
(value < RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE)) {
|
||||
value = RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE;
|
||||
} else if ((value > RETRIEVE_STATUS_ERROR_PERMANENT_CONTENT_UNSUPPORTED) &&
|
||||
(value <= RETRIEVE_STATUS_ERROR_END)) {
|
||||
value = RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE;
|
||||
} else if ((value < RETRIEVE_STATUS_OK) ||
|
||||
((value > RETRIEVE_STATUS_OK) &&
|
||||
(value < RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE)) ||
|
||||
(value > RETRIEVE_STATUS_ERROR_END)) {
|
||||
value = RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE;
|
||||
}
|
||||
break;
|
||||
case STORE_STATUS:
|
||||
// According to oma-ts-mms-enc-v1_3, section 7.3.58, we modify the invalid value.
|
||||
if ((value > STORE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM) &&
|
||||
(value < STORE_STATUS_ERROR_PERMANENT_FAILURE)) {
|
||||
value = STORE_STATUS_ERROR_TRANSIENT_FAILURE;
|
||||
} else if ((value > STORE_STATUS_ERROR_PERMANENT_MMBOX_FULL) &&
|
||||
(value <= STORE_STATUS_ERROR_END)) {
|
||||
value = STORE_STATUS_ERROR_PERMANENT_FAILURE;
|
||||
} else if ((value < STORE_STATUS_SUCCESS) ||
|
||||
((value > STORE_STATUS_SUCCESS) &&
|
||||
(value < STORE_STATUS_ERROR_TRANSIENT_FAILURE)) ||
|
||||
(value > STORE_STATUS_ERROR_END)) {
|
||||
value = STORE_STATUS_ERROR_PERMANENT_FAILURE;
|
||||
}
|
||||
break;
|
||||
case RESPONSE_STATUS:
|
||||
// According to oma-ts-mms-enc-v1_3, section 7.3.48, we modify the invalid value.
|
||||
if ((value > RESPONSE_STATUS_ERROR_TRANSIENT_PARTIAL_SUCCESS) &&
|
||||
(value < RESPONSE_STATUS_ERROR_PERMANENT_FAILURE)) {
|
||||
value = RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE;
|
||||
} else if (((value > RESPONSE_STATUS_ERROR_PERMANENT_LACK_OF_PREPAID) &&
|
||||
(value <= RESPONSE_STATUS_ERROR_PERMANENT_END)) ||
|
||||
(value < RESPONSE_STATUS_OK) ||
|
||||
((value > RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE) &&
|
||||
(value < RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE)) ||
|
||||
(value > RESPONSE_STATUS_ERROR_PERMANENT_END)) {
|
||||
value = RESPONSE_STATUS_ERROR_PERMANENT_FAILURE;
|
||||
}
|
||||
break;
|
||||
case MMS_VERSION:
|
||||
if ((value < MMS_VERSION_1_0)|| (value > MMS_VERSION_1_3)) {
|
||||
value = CURRENT_MMS_VERSION; // Current version is the default value.
|
||||
}
|
||||
break;
|
||||
case MESSAGE_TYPE:
|
||||
if ((value < MESSAGE_TYPE_SEND_REQ) || (value > MESSAGE_TYPE_CANCEL_CONF)) {
|
||||
// Invalid value.
|
||||
throw new InvalidHeaderValueException("Invalid Octet value!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// This header value should not be Octect.
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
mHeaderMap.put(field, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TextString value by header field.
|
||||
*
|
||||
* @param field the field
|
||||
* @return the TextString value of the pdu header
|
||||
* with specified header field
|
||||
*/
|
||||
protected byte[] getTextString(int field) {
|
||||
return (byte[]) mHeaderMap.get(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set TextString value to pdu header by header field.
|
||||
*
|
||||
* @param value the value
|
||||
* @param field the field
|
||||
* @return the TextString value of the pdu header
|
||||
* with specified header field
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
protected void setTextString(byte[] value, int field) {
|
||||
/**
|
||||
* Check whether this field can be set for specific
|
||||
* header and check validity of the field.
|
||||
*/
|
||||
if (null == value) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case TRANSACTION_ID:
|
||||
case REPLY_CHARGING_ID:
|
||||
case AUX_APPLIC_ID:
|
||||
case APPLIC_ID:
|
||||
case REPLY_APPLIC_ID:
|
||||
case MESSAGE_ID:
|
||||
case REPLACE_ID:
|
||||
case CANCEL_ID:
|
||||
case CONTENT_LOCATION:
|
||||
case MESSAGE_CLASS:
|
||||
case CONTENT_TYPE:
|
||||
break;
|
||||
default:
|
||||
// This header value should not be Text-String.
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
mHeaderMap.put(field, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EncodedStringValue value by header field.
|
||||
*
|
||||
* @param field the field
|
||||
* @return the EncodedStringValue value of the pdu header
|
||||
* with specified header field
|
||||
*/
|
||||
protected EncodedStringValue getEncodedStringValue(int field) {
|
||||
return (EncodedStringValue) mHeaderMap.get(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TO, CC or BCC header value.
|
||||
*
|
||||
* @param field the field
|
||||
* @return the EncodeStringValue array of the pdu header
|
||||
* with specified header field
|
||||
*/
|
||||
protected EncodedStringValue[] getEncodedStringValues(int field) {
|
||||
ArrayList<EncodedStringValue> list =
|
||||
(ArrayList<EncodedStringValue>) mHeaderMap.get(field);
|
||||
if (null == list) {
|
||||
return null;
|
||||
}
|
||||
EncodedStringValue[] values = new EncodedStringValue[list.size()];
|
||||
return list.toArray(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set EncodedStringValue value to pdu header by header field.
|
||||
*
|
||||
* @param value the value
|
||||
* @param field the field
|
||||
* @return the EncodedStringValue value of the pdu header
|
||||
* with specified header field
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
protected void setEncodedStringValue(EncodedStringValue value, int field) {
|
||||
/**
|
||||
* Check whether this field can be set for specific
|
||||
* header and check validity of the field.
|
||||
*/
|
||||
if (null == value) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case SUBJECT:
|
||||
case RECOMMENDED_RETRIEVAL_MODE_TEXT:
|
||||
case RETRIEVE_TEXT:
|
||||
case STATUS_TEXT:
|
||||
case STORE_STATUS_TEXT:
|
||||
case RESPONSE_TEXT:
|
||||
case FROM:
|
||||
case PREVIOUSLY_SENT_BY:
|
||||
case MM_FLAGS:
|
||||
break;
|
||||
default:
|
||||
// This header value should not be Encoded-String-Value.
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
|
||||
mHeaderMap.put(field, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set TO, CC or BCC header value.
|
||||
*
|
||||
* @param value the value
|
||||
* @param field the field
|
||||
* @return the EncodedStringValue value array of the pdu header
|
||||
* with specified header field
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
protected void setEncodedStringValues(EncodedStringValue[] value, int field) {
|
||||
/**
|
||||
* Check whether this field can be set for specific
|
||||
* header and check validity of the field.
|
||||
*/
|
||||
if (null == value) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case BCC:
|
||||
case CC:
|
||||
case TO:
|
||||
break;
|
||||
default:
|
||||
// This header value should not be Encoded-String-Value.
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
|
||||
ArrayList<EncodedStringValue> list = new ArrayList<EncodedStringValue>();
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
list.add(value[i]);
|
||||
}
|
||||
mHeaderMap.put(field, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append one EncodedStringValue to another.
|
||||
*
|
||||
* @param value the EncodedStringValue to append
|
||||
* @param field the field
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
protected void appendEncodedStringValue(EncodedStringValue value,
|
||||
int field) {
|
||||
if (null == value) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case BCC:
|
||||
case CC:
|
||||
case TO:
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
|
||||
ArrayList<EncodedStringValue> list =
|
||||
(ArrayList<EncodedStringValue>) mHeaderMap.get(field);
|
||||
if (null == list) {
|
||||
list = new ArrayList<EncodedStringValue>();
|
||||
}
|
||||
list.add(value);
|
||||
mHeaderMap.put(field, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get LongInteger value by header field.
|
||||
*
|
||||
* @param field the field
|
||||
* @return the LongInteger value of the pdu header
|
||||
* with specified header field. if return -1, the
|
||||
* field is not existed in pdu header.
|
||||
*/
|
||||
protected long getLongInteger(int field) {
|
||||
Long longInteger = (Long) mHeaderMap.get(field);
|
||||
if (null == longInteger) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return longInteger.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set LongInteger value to pdu header by header field.
|
||||
*
|
||||
* @param value the value
|
||||
* @param field the field
|
||||
*/
|
||||
protected void setLongInteger(long value, int field) {
|
||||
/**
|
||||
* Check whether this field can be set for specific
|
||||
* header and check validity of the field.
|
||||
*/
|
||||
switch (field) {
|
||||
case DATE:
|
||||
case REPLY_CHARGING_SIZE:
|
||||
case MESSAGE_SIZE:
|
||||
case MESSAGE_COUNT:
|
||||
case START:
|
||||
case LIMIT:
|
||||
case DELIVERY_TIME:
|
||||
case EXPIRY:
|
||||
case REPLY_CHARGING_DEADLINE:
|
||||
case PREVIOUSLY_SENT_DATE:
|
||||
break;
|
||||
default:
|
||||
// This header value should not be LongInteger.
|
||||
throw new RuntimeException("Invalid header field!");
|
||||
}
|
||||
mHeaderMap.put(field, value);
|
||||
}
|
||||
}
|
2011
mobile/android/b2gdroid/app/src/main/java/com/google/android/mms/pdu/PduParser.java
Executable file
2011
mobile/android/b2gdroid/app/src/main/java/com/google/android/mms/pdu/PduParser.java
Executable file
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,414 @@
|
|||
/*
|
||||
* 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.google.android.mms.pdu;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The pdu part.
|
||||
*/
|
||||
public class PduPart {
|
||||
/**
|
||||
* Well-Known Parameters.
|
||||
*/
|
||||
public static final int P_Q = 0x80;
|
||||
public static final int P_CHARSET = 0x81;
|
||||
public static final int P_LEVEL = 0x82;
|
||||
public static final int P_TYPE = 0x83;
|
||||
public static final int P_DEP_NAME = 0x85;
|
||||
public static final int P_DEP_FILENAME = 0x86;
|
||||
public static final int P_DIFFERENCES = 0x87;
|
||||
public static final int P_PADDING = 0x88;
|
||||
// This value of "TYPE" s used with Content-Type: multipart/related
|
||||
public static final int P_CT_MR_TYPE = 0x89;
|
||||
public static final int P_DEP_START = 0x8A;
|
||||
public static final int P_DEP_START_INFO = 0x8B;
|
||||
public static final int P_DEP_COMMENT = 0x8C;
|
||||
public static final int P_DEP_DOMAIN = 0x8D;
|
||||
public static final int P_MAX_AGE = 0x8E;
|
||||
public static final int P_DEP_PATH = 0x8F;
|
||||
public static final int P_SECURE = 0x90;
|
||||
public static final int P_SEC = 0x91;
|
||||
public static final int P_MAC = 0x92;
|
||||
public static final int P_CREATION_DATE = 0x93;
|
||||
public static final int P_MODIFICATION_DATE = 0x94;
|
||||
public static final int P_READ_DATE = 0x95;
|
||||
public static final int P_SIZE = 0x96;
|
||||
public static final int P_NAME = 0x97;
|
||||
public static final int P_FILENAME = 0x98;
|
||||
public static final int P_START = 0x99;
|
||||
public static final int P_START_INFO = 0x9A;
|
||||
public static final int P_COMMENT = 0x9B;
|
||||
public static final int P_DOMAIN = 0x9C;
|
||||
public static final int P_PATH = 0x9D;
|
||||
|
||||
/**
|
||||
* Header field names.
|
||||
*/
|
||||
public static final int P_CONTENT_TYPE = 0x91;
|
||||
public static final int P_CONTENT_LOCATION = 0x8E;
|
||||
public static final int P_CONTENT_ID = 0xC0;
|
||||
public static final int P_DEP_CONTENT_DISPOSITION = 0xAE;
|
||||
public static final int P_CONTENT_DISPOSITION = 0xC5;
|
||||
// The next header is unassigned header, use reserved header(0x48) value.
|
||||
public static final int P_CONTENT_TRANSFER_ENCODING = 0xC8;
|
||||
|
||||
/**
|
||||
* Content=Transfer-Encoding string.
|
||||
*/
|
||||
public static final String CONTENT_TRANSFER_ENCODING =
|
||||
"Content-Transfer-Encoding";
|
||||
|
||||
/**
|
||||
* Value of Content-Transfer-Encoding.
|
||||
*/
|
||||
public static final String P_BINARY = "binary";
|
||||
public static final String P_7BIT = "7bit";
|
||||
public static final String P_8BIT = "8bit";
|
||||
public static final String P_BASE64 = "base64";
|
||||
public static final String P_QUOTED_PRINTABLE = "quoted-printable";
|
||||
|
||||
/**
|
||||
* Value of disposition can be set to PduPart when the value is octet in
|
||||
* the PDU.
|
||||
* "from-data" instead of Form-data<Octet 128>.
|
||||
* "attachment" instead of Attachment<Octet 129>.
|
||||
* "inline" instead of Inline<Octet 130>.
|
||||
*/
|
||||
static final byte[] DISPOSITION_FROM_DATA = "from-data".getBytes();
|
||||
static final byte[] DISPOSITION_ATTACHMENT = "attachment".getBytes();
|
||||
static final byte[] DISPOSITION_INLINE = "inline".getBytes();
|
||||
|
||||
/**
|
||||
* Content-Disposition value.
|
||||
*/
|
||||
public static final int P_DISPOSITION_FROM_DATA = 0x80;
|
||||
public static final int P_DISPOSITION_ATTACHMENT = 0x81;
|
||||
public static final int P_DISPOSITION_INLINE = 0x82;
|
||||
|
||||
/**
|
||||
* Header of part.
|
||||
*/
|
||||
private Map<Integer, Object> mPartHeader = null;
|
||||
|
||||
/**
|
||||
* Data uri.
|
||||
*/
|
||||
private Uri mUri = null;
|
||||
|
||||
/**
|
||||
* Part data.
|
||||
*/
|
||||
private byte[] mPartData = null;
|
||||
|
||||
private static final String TAG = "PduPart";
|
||||
|
||||
/**
|
||||
* Empty Constructor.
|
||||
*/
|
||||
public PduPart() {
|
||||
mPartHeader = new HashMap<Integer, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set part data. The data are stored as byte array.
|
||||
*
|
||||
* @param data the data
|
||||
*/
|
||||
public void setData(byte[] data) {
|
||||
if(data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPartData = new byte[data.length];
|
||||
System.arraycopy(data, 0, mPartData, 0, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of the part data or null if the data wasn't set or
|
||||
* the data is stored as Uri.
|
||||
* @see #getDataUri
|
||||
*/
|
||||
public byte[] getData() {
|
||||
if(mPartData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] byteArray = new byte[mPartData.length];
|
||||
System.arraycopy(mPartData, 0, byteArray, 0, mPartData.length);
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The length of the data, if this object have data, else 0.
|
||||
*/
|
||||
public int getDataLength() {
|
||||
if(mPartData != null){
|
||||
return mPartData.length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set data uri. The data are stored as Uri.
|
||||
*
|
||||
* @param uri the uri
|
||||
*/
|
||||
public void setDataUri(Uri uri) {
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Uri of the part data or null if the data wasn't set or
|
||||
* the data is stored as byte array.
|
||||
* @see #getData
|
||||
*/
|
||||
public Uri getDataUri() {
|
||||
return mUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-id value
|
||||
*
|
||||
* @param contentId the content-id value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentId(byte[] contentId) {
|
||||
if((contentId == null) || (contentId.length == 0)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Content-Id may not be null or empty.");
|
||||
}
|
||||
|
||||
if ((contentId.length > 1)
|
||||
&& ((char) contentId[0] == '<')
|
||||
&& ((char) contentId[contentId.length - 1] == '>')) {
|
||||
mPartHeader.put(P_CONTENT_ID, contentId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert beginning '<' and trailing '>' for Content-Id.
|
||||
byte[] buffer = new byte[contentId.length + 2];
|
||||
buffer[0] = (byte) (0xff & '<');
|
||||
buffer[buffer.length - 1] = (byte) (0xff & '>');
|
||||
System.arraycopy(contentId, 0, buffer, 1, contentId.length);
|
||||
mPartHeader.put(P_CONTENT_ID, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-id value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentId() {
|
||||
return (byte[]) mPartHeader.get(P_CONTENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Char-set value.
|
||||
*
|
||||
* @param charset the value
|
||||
*/
|
||||
public void setCharset(int charset) {
|
||||
mPartHeader.put(P_CHARSET, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Char-set value
|
||||
*
|
||||
* @return the charset value. Return 0 if charset was not set.
|
||||
*/
|
||||
public int getCharset() {
|
||||
Integer charset = (Integer) mPartHeader.get(P_CHARSET);
|
||||
if(charset == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return charset.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-Location value.
|
||||
*
|
||||
* @param contentLocation the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentLocation(byte[] contentLocation) {
|
||||
if(contentLocation == null) {
|
||||
throw new NullPointerException("null content-location");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_CONTENT_LOCATION, contentLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Location value.
|
||||
*
|
||||
* @return the value
|
||||
* return PduPart.disposition[0] instead of <Octet 128> (Form-data).
|
||||
* return PduPart.disposition[1] instead of <Octet 129> (Attachment).
|
||||
* return PduPart.disposition[2] instead of <Octet 130> (Inline).
|
||||
*/
|
||||
public byte[] getContentLocation() {
|
||||
return (byte[]) mPartHeader.get(P_CONTENT_LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-Disposition value.
|
||||
* Use PduPart.disposition[0] instead of <Octet 128> (Form-data).
|
||||
* Use PduPart.disposition[1] instead of <Octet 129> (Attachment).
|
||||
* Use PduPart.disposition[2] instead of <Octet 130> (Inline).
|
||||
*
|
||||
* @param contentDisposition the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentDisposition(byte[] contentDisposition) {
|
||||
if(contentDisposition == null) {
|
||||
throw new NullPointerException("null content-disposition");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_CONTENT_DISPOSITION, contentDisposition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Disposition value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentDisposition() {
|
||||
return (byte[]) mPartHeader.get(P_CONTENT_DISPOSITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-Type value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentType(byte[] contentType) {
|
||||
if(contentType == null) {
|
||||
throw new NullPointerException("null content-type");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_CONTENT_TYPE, contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Type value of part.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentType() {
|
||||
return (byte[]) mPartHeader.get(P_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-Transfer-Encoding value
|
||||
*
|
||||
* @param contentId the content-id value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentTransferEncoding(byte[] contentTransferEncoding) {
|
||||
if(contentTransferEncoding == null) {
|
||||
throw new NullPointerException("null content-transfer-encoding");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_CONTENT_TRANSFER_ENCODING, contentTransferEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Transfer-Encoding value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentTransferEncoding() {
|
||||
return (byte[]) mPartHeader.get(P_CONTENT_TRANSFER_ENCODING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-type parameter: name.
|
||||
*
|
||||
* @param name the name value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setName(byte[] name) {
|
||||
if(null == name) {
|
||||
throw new NullPointerException("null content-id");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_NAME, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content-type parameter: name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public byte[] getName() {
|
||||
return (byte[]) mPartHeader.get(P_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-disposition parameter: filename
|
||||
*
|
||||
* @param fileName the filename value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setFilename(byte[] fileName) {
|
||||
if(null == fileName) {
|
||||
throw new NullPointerException("null content-id");
|
||||
}
|
||||
|
||||
mPartHeader.put(P_FILENAME, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-disposition parameter: filename
|
||||
*
|
||||
* @return the filename
|
||||
*/
|
||||
public byte[] getFilename() {
|
||||
return (byte[]) mPartHeader.get(P_FILENAME);
|
||||
}
|
||||
|
||||
public String generateLocation() {
|
||||
// Assumption: At least one of the content-location / name / filename
|
||||
// or content-id should be set. This is guaranteed by the PduParser
|
||||
// for incoming messages and by MM composer for outgoing messages.
|
||||
byte[] location = (byte[]) mPartHeader.get(P_NAME);
|
||||
if(null == location) {
|
||||
location = (byte[]) mPartHeader.get(P_FILENAME);
|
||||
|
||||
if (null == location) {
|
||||
location = (byte[]) mPartHeader.get(P_CONTENT_LOCATION);
|
||||
}
|
||||
}
|
||||
|
||||
if (null == location) {
|
||||
byte[] contentId = (byte[]) mPartHeader.get(P_CONTENT_ID);
|
||||
return "cid:" + new String(contentId);
|
||||
} else {
|
||||
return new String(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class QuotedPrintable {
|
||||
private static byte ESCAPE_CHAR = '=';
|
||||
|
||||
/**
|
||||
* Decodes an array quoted-printable characters into an array of original bytes.
|
||||
* Escaped characters are converted back to their original representation.
|
||||
*
|
||||
* <p>
|
||||
* This function implements a subset of
|
||||
* quoted-printable encoding specification (rule #1 and rule #2)
|
||||
* as defined in RFC 1521.
|
||||
* </p>
|
||||
*
|
||||
* @param bytes array of quoted-printable characters
|
||||
* @return array of original bytes,
|
||||
* null if quoted-printable decoding is unsuccessful.
|
||||
*/
|
||||
public static final byte[] decodeQuotedPrintable(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
int b = bytes[i];
|
||||
if (b == ESCAPE_CHAR) {
|
||||
try {
|
||||
if('\r' == (char)bytes[i + 1] &&
|
||||
'\n' == (char)bytes[i + 2]) {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
int u = Character.digit((char) bytes[++i], 16);
|
||||
int l = Character.digit((char) bytes[++i], 16);
|
||||
if (u == -1 || l == -1) {
|
||||
return null;
|
||||
}
|
||||
buffer.write((char) ((u << 4) + l));
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
buffer.write(b);
|
||||
}
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
public class ReadOrigInd extends GenericPdu {
|
||||
/**
|
||||
* Empty constructor.
|
||||
* Since the Pdu corresponding to this class is constructed
|
||||
* by the Proxy-Relay server, this class is only instantiated
|
||||
* by the Pdu Parser.
|
||||
*
|
||||
* @throws InvalidHeaderValueException if error occurs.
|
||||
*/
|
||||
public ReadOrigInd() throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_READ_ORIG_IND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
ReadOrigInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Date value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getDate() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Date value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setDate(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get From value.
|
||||
* From-value = Value-length
|
||||
* (Address-present-token Encoded-string-value | Insert-address-token)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getFrom() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set From value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setFrom(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Message-ID value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Message-ID value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-MMS-Read-status value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getReadStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.READ_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-MMS-Read-status value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setReadStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.READ_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get To value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getTo() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set To value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTo(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
public class ReadRecInd extends GenericPdu {
|
||||
/**
|
||||
* Constructor, used when composing a M-ReadRec.ind pdu.
|
||||
*
|
||||
* @param from the from value
|
||||
* @param messageId the message ID value
|
||||
* @param mmsVersion current viersion of mms
|
||||
* @param readStatus the read status value
|
||||
* @param to the to value
|
||||
* @throws InvalidHeaderValueException if parameters are invalid.
|
||||
* NullPointerException if messageId or to is null.
|
||||
*/
|
||||
public ReadRecInd(EncodedStringValue from,
|
||||
byte[] messageId,
|
||||
int mmsVersion,
|
||||
int readStatus,
|
||||
EncodedStringValue[] to) throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_READ_REC_IND);
|
||||
setFrom(from);
|
||||
setMessageId(messageId);
|
||||
setMmsVersion(mmsVersion);
|
||||
setTo(to);
|
||||
setReadStatus(readStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
ReadRecInd(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Date value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getDate() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Date value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setDate(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Message-ID value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Message-ID value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get To value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getTo() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set To value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTo(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-MMS-Read-status value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getReadStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.READ_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-MMS-Read-status value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setReadStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.READ_STATUS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
/**
|
||||
* M-Retrive.conf Pdu.
|
||||
*/
|
||||
public class RetrieveConf extends MultimediaMessagePdu {
|
||||
/**
|
||||
* Empty constructor.
|
||||
* Since the Pdu corresponding to this class is constructed
|
||||
* by the Proxy-Relay server, this class is only instantiated
|
||||
* by the Pdu Parser.
|
||||
*
|
||||
* @throws InvalidHeaderValueException if error occurs.
|
||||
*/
|
||||
public RetrieveConf() throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
RetrieveConf(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers and body
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
* @param body Body of this PDu.
|
||||
*/
|
||||
RetrieveConf(PduHeaders headers, PduBody body) {
|
||||
super(headers, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CC value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getCc() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.CC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "CC" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void addCc(EncodedStringValue value) {
|
||||
mPduHeaders.appendEncodedStringValue(value, PduHeaders.CC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-type value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentType() {
|
||||
return mPduHeaders.getTextString(PduHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-type value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentType(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Delivery-Report value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getDeliveryReport() {
|
||||
return mPduHeaders.getOctet(PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Delivery-Report value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setDeliveryReport(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get From value.
|
||||
* From-value = Value-length
|
||||
* (Address-present-token Encoded-string-value | Insert-address-token)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getFrom() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set From value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setFrom(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.FROM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Message-Class value.
|
||||
* Message-class-value = Class-identifier | Token-text
|
||||
* Class-identifier = Personal | Advertisement | Informational | Auto
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageClass() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Message-Class value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageClass(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Message-ID value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Message-ID value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Read-Report value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getReadReport() {
|
||||
return mPduHeaders.getOctet(PduHeaders.READ_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Read-Report value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setReadReport(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.READ_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Retrieve-Status value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getRetrieveStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.RETRIEVE_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Retrieve-Status value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setRetrieveStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.RETRIEVE_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Retrieve-Text value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue getRetrieveText() {
|
||||
return mPduHeaders.getEncodedStringValue(PduHeaders.RETRIEVE_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Retrieve-Text value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setRetrieveText(EncodedStringValue value) {
|
||||
mPduHeaders.setEncodedStringValue(value, PduHeaders.RETRIEVE_TEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getContentClass() {return 0x00;}
|
||||
* public void setApplicId(byte value) {}
|
||||
*
|
||||
* public byte getDrmContent() {return 0x00;}
|
||||
* public void setDrmContent(byte value) {}
|
||||
*
|
||||
* public byte getDistributionIndicator() {return 0x00;}
|
||||
* public void setDistributionIndicator(byte value) {}
|
||||
*
|
||||
* public PreviouslySentByValue getPreviouslySentBy() {return null;}
|
||||
* public void setPreviouslySentBy(PreviouslySentByValue value) {}
|
||||
*
|
||||
* public PreviouslySentDateValue getPreviouslySentDate() {}
|
||||
* public void setPreviouslySentDate(PreviouslySentDateValue value) {}
|
||||
*
|
||||
* public MmFlagsValue getMmFlags() {return null;}
|
||||
* public void setMmFlags(MmFlagsValue value) {}
|
||||
*
|
||||
* public MmStateValue getMmState() {return null;}
|
||||
* public void getMmState(MmStateValue value) {}
|
||||
*
|
||||
* public byte[] getReplaceId() {return 0x00;}
|
||||
* public void setReplaceId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getReplyCharging() {return 0x00;}
|
||||
* public void setReplyCharging(byte value) {}
|
||||
*
|
||||
* public byte getReplyChargingDeadline() {return 0x00;}
|
||||
* public void setReplyChargingDeadline(byte value) {}
|
||||
*
|
||||
* public byte[] getReplyChargingId() {return 0x00;}
|
||||
* public void setReplyChargingId(byte[] value) {}
|
||||
*
|
||||
* public long getReplyChargingSize() {return 0;}
|
||||
* public void setReplyChargingSize(long value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
public class SendConf extends GenericPdu {
|
||||
/**
|
||||
* Empty constructor.
|
||||
* Since the Pdu corresponding to this class is constructed
|
||||
* by the Proxy-Relay server, this class is only instantiated
|
||||
* by the Pdu Parser.
|
||||
*
|
||||
* @throws InvalidHeaderValueException if error occurs.
|
||||
*/
|
||||
public SendConf() throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_SEND_CONF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
SendConf(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Message-ID value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Message-ID value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Response-Status.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getResponseStatus() {
|
||||
return mPduHeaders.getOctet(PduHeaders.RESPONSE_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Response-Status.
|
||||
*
|
||||
* @param value the values
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setResponseStatus(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.RESPONSE_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte[] getContentLocation() {return null;}
|
||||
* public void setContentLocation(byte[] value) {}
|
||||
*
|
||||
* public EncodedStringValue getResponseText() {return null;}
|
||||
* public void setResponseText(EncodedStringValue value) {}
|
||||
*
|
||||
* public byte getStoreStatus() {return 0x00;}
|
||||
* public void setStoreStatus(byte value) {}
|
||||
*
|
||||
* public byte[] getStoreStatusText() {return null;}
|
||||
* public void setStoreStatusText(byte[] value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,345 @@
|
|||
/*
|
||||
* 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.google.android.mms.pdu;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.mms.InvalidHeaderValueException;
|
||||
|
||||
public class SendReq extends MultimediaMessagePdu {
|
||||
private static final String TAG = "SendReq";
|
||||
|
||||
public SendReq() {
|
||||
super();
|
||||
|
||||
try {
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_SEND_REQ);
|
||||
setMmsVersion(PduHeaders.CURRENT_MMS_VERSION);
|
||||
// FIXME: Content-type must be decided according to whether
|
||||
// SMIL part present.
|
||||
setContentType("application/vnd.wap.multipart.related".getBytes());
|
||||
setFrom(new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()));
|
||||
setTransactionId(generateTransactionId());
|
||||
} catch (InvalidHeaderValueException e) {
|
||||
// Impossible to reach here since all headers we set above are valid.
|
||||
Log.e(TAG, "Unexpected InvalidHeaderValueException.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] generateTransactionId() {
|
||||
String transactionId = "T" + Long.toHexString(System.currentTimeMillis());
|
||||
return transactionId.getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, used when composing a M-Send.req pdu.
|
||||
*
|
||||
* @param contentType the content type value
|
||||
* @param from the from value
|
||||
* @param mmsVersion current viersion of mms
|
||||
* @param transactionId the transaction-id value
|
||||
* @throws InvalidHeaderValueException if parameters are invalid.
|
||||
* NullPointerException if contentType, form or transactionId is null.
|
||||
*/
|
||||
public SendReq(byte[] contentType,
|
||||
EncodedStringValue from,
|
||||
int mmsVersion,
|
||||
byte[] transactionId) throws InvalidHeaderValueException {
|
||||
super();
|
||||
setMessageType(PduHeaders.MESSAGE_TYPE_SEND_REQ);
|
||||
setContentType(contentType);
|
||||
setFrom(from);
|
||||
setMmsVersion(mmsVersion);
|
||||
setTransactionId(transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers.
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
*/
|
||||
SendReq(PduHeaders headers) {
|
||||
super(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given headers and body
|
||||
*
|
||||
* @param headers Headers for this PDU.
|
||||
* @param body Body of this PDu.
|
||||
*/
|
||||
SendReq(PduHeaders headers, PduBody body) {
|
||||
super(headers, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bcc value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getBcc() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.BCC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "BCC" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void addBcc(EncodedStringValue value) {
|
||||
mPduHeaders.appendEncodedStringValue(value, PduHeaders.BCC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "BCC" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setBcc(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.BCC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get CC value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public EncodedStringValue[] getCc() {
|
||||
return mPduHeaders.getEncodedStringValues(PduHeaders.CC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "CC" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void addCc(EncodedStringValue value) {
|
||||
mPduHeaders.appendEncodedStringValue(value, PduHeaders.CC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "CC" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setCc(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.CC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-type value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getContentType() {
|
||||
return mPduHeaders.getTextString(PduHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Content-type value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setContentType(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Delivery-Report value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getDeliveryReport() {
|
||||
return mPduHeaders.getOctet(PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Delivery-Report value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setDeliveryReport(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.DELIVERY_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Expiry value.
|
||||
*
|
||||
* Expiry-value = Value-length
|
||||
* (Absolute-token Date-value | Relative-token Delta-seconds-value)
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getExpiry() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Expiry value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setExpiry(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-MessageSize value.
|
||||
*
|
||||
* Expiry-value = size of message
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public long getMessageSize() {
|
||||
return mPduHeaders.getLongInteger(PduHeaders.MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-MessageSize value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setMessageSize(long value) {
|
||||
mPduHeaders.setLongInteger(value, PduHeaders.MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Message-Class value.
|
||||
* Message-class-value = Class-identifier | Token-text
|
||||
* Class-identifier = Personal | Advertisement | Informational | Auto
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public byte[] getMessageClass() {
|
||||
return mPduHeaders.getTextString(PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Message-Class value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setMessageClass(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Read-Report value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getReadReport() {
|
||||
return mPduHeaders.getOctet(PduHeaders.READ_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Read-Report value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws InvalidHeaderValueException if the value is invalid.
|
||||
*/
|
||||
public void setReadReport(int value) throws InvalidHeaderValueException {
|
||||
mPduHeaders.setOctet(value, PduHeaders.READ_REPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "To" value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTo(EncodedStringValue[] value) {
|
||||
mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @return the X-Mms-Report-Allowed value
|
||||
*/
|
||||
public byte[] getTransactionId() {
|
||||
return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X-Mms-Transaction-Id field value.
|
||||
*
|
||||
* @param value the value
|
||||
* @throws NullPointerException if the value is null.
|
||||
*/
|
||||
public void setTransactionId(byte[] value) {
|
||||
mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional, not supported header fields:
|
||||
*
|
||||
* public byte getAdaptationAllowed() {return 0};
|
||||
* public void setAdaptationAllowed(btye value) {};
|
||||
*
|
||||
* public byte[] getApplicId() {return null;}
|
||||
* public void setApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte[] getAuxApplicId() {return null;}
|
||||
* public void getAuxApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getContentClass() {return 0x00;}
|
||||
* public void setApplicId(byte value) {}
|
||||
*
|
||||
* public long getDeliveryTime() {return 0};
|
||||
* public void setDeliveryTime(long value) {};
|
||||
*
|
||||
* public byte getDrmContent() {return 0x00;}
|
||||
* public void setDrmContent(byte value) {}
|
||||
*
|
||||
* public MmFlagsValue getMmFlags() {return null;}
|
||||
* public void setMmFlags(MmFlagsValue value) {}
|
||||
*
|
||||
* public MmStateValue getMmState() {return null;}
|
||||
* public void getMmState(MmStateValue value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getReplyCharging() {return 0x00;}
|
||||
* public void setReplyCharging(byte value) {}
|
||||
*
|
||||
* public byte getReplyChargingDeadline() {return 0x00;}
|
||||
* public void setReplyChargingDeadline(byte value) {}
|
||||
*
|
||||
* public byte[] getReplyChargingId() {return 0x00;}
|
||||
* public void setReplyChargingId(byte[] value) {}
|
||||
*
|
||||
* public long getReplyChargingSize() {return 0;}
|
||||
* public void setReplyChargingSize(long value) {}
|
||||
*
|
||||
* public byte[] getReplyApplicId() {return 0x00;}
|
||||
* public void setReplyApplicId(byte[] value) {}
|
||||
*
|
||||
* public byte getStore() {return 0x00;}
|
||||
* public void setStore(byte value) {}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* 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.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class AbstractCache<K, V> {
|
||||
private static final String TAG = "AbstractCache";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean LOCAL_LOGV = false;
|
||||
|
||||
private static final int MAX_CACHED_ITEMS = 500;
|
||||
|
||||
private final HashMap<K, CacheEntry<V>> mCacheMap;
|
||||
|
||||
protected AbstractCache() {
|
||||
mCacheMap = new HashMap<K, CacheEntry<V>>();
|
||||
}
|
||||
|
||||
public boolean put(K key, V value) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Trying to put " + key + " into cache.");
|
||||
}
|
||||
|
||||
if (mCacheMap.size() >= MAX_CACHED_ITEMS) {
|
||||
// TODO Should remove the oldest or least hit cached entry
|
||||
// and then cache the new one.
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Failed! size limitation reached.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key != null) {
|
||||
CacheEntry<V> cacheEntry = new CacheEntry<V>();
|
||||
cacheEntry.value = value;
|
||||
mCacheMap.put(key, cacheEntry);
|
||||
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, key + " cached, " + mCacheMap.size() + " items total.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public V get(K key) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Trying to get " + key + " from cache.");
|
||||
}
|
||||
|
||||
if (key != null) {
|
||||
CacheEntry<V> cacheEntry = mCacheMap.get(key);
|
||||
if (cacheEntry != null) {
|
||||
cacheEntry.hit++;
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, key + " hit " + cacheEntry.hit + " times.");
|
||||
}
|
||||
return cacheEntry.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public V purge(K key) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Trying to purge " + key);
|
||||
}
|
||||
|
||||
CacheEntry<V> v = mCacheMap.remove(key);
|
||||
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, mCacheMap.size() + " items cached.");
|
||||
}
|
||||
|
||||
return v != null ? v.value : null;
|
||||
}
|
||||
|
||||
public void purgeAll() {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Purging cache, " + mCacheMap.size()
|
||||
+ " items dropped.");
|
||||
}
|
||||
mCacheMap.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mCacheMap.size();
|
||||
}
|
||||
|
||||
private static class CacheEntry<V> {
|
||||
int hit;
|
||||
V value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* 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.content.ContentUris;
|
||||
import android.content.UriMatcher;
|
||||
import android.net.Uri;
|
||||
import android.provider.Telephony.Mms;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class PduCache extends AbstractCache<Uri, PduCacheEntry> {
|
||||
private static final String TAG = "PduCache";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean LOCAL_LOGV = false;
|
||||
|
||||
private static final int MMS_ALL = 0;
|
||||
private static final int MMS_ALL_ID = 1;
|
||||
private static final int MMS_INBOX = 2;
|
||||
private static final int MMS_INBOX_ID = 3;
|
||||
private static final int MMS_SENT = 4;
|
||||
private static final int MMS_SENT_ID = 5;
|
||||
private static final int MMS_DRAFTS = 6;
|
||||
private static final int MMS_DRAFTS_ID = 7;
|
||||
private static final int MMS_OUTBOX = 8;
|
||||
private static final int MMS_OUTBOX_ID = 9;
|
||||
private static final int MMS_CONVERSATION = 10;
|
||||
private static final int MMS_CONVERSATION_ID = 11;
|
||||
|
||||
private static final UriMatcher URI_MATCHER;
|
||||
private static final HashMap<Integer, Integer> MATCH_TO_MSGBOX_ID_MAP;
|
||||
|
||||
private static PduCache sInstance;
|
||||
|
||||
static {
|
||||
URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
URI_MATCHER.addURI("mms", null, MMS_ALL);
|
||||
URI_MATCHER.addURI("mms", "#", MMS_ALL_ID);
|
||||
URI_MATCHER.addURI("mms", "inbox", MMS_INBOX);
|
||||
URI_MATCHER.addURI("mms", "inbox/#", MMS_INBOX_ID);
|
||||
URI_MATCHER.addURI("mms", "sent", MMS_SENT);
|
||||
URI_MATCHER.addURI("mms", "sent/#", MMS_SENT_ID);
|
||||
URI_MATCHER.addURI("mms", "drafts", MMS_DRAFTS);
|
||||
URI_MATCHER.addURI("mms", "drafts/#", MMS_DRAFTS_ID);
|
||||
URI_MATCHER.addURI("mms", "outbox", MMS_OUTBOX);
|
||||
URI_MATCHER.addURI("mms", "outbox/#", MMS_OUTBOX_ID);
|
||||
URI_MATCHER.addURI("mms-sms", "conversations", MMS_CONVERSATION);
|
||||
URI_MATCHER.addURI("mms-sms", "conversations/#", MMS_CONVERSATION_ID);
|
||||
|
||||
MATCH_TO_MSGBOX_ID_MAP = new HashMap<Integer, Integer>();
|
||||
MATCH_TO_MSGBOX_ID_MAP.put(MMS_INBOX, Mms.MESSAGE_BOX_INBOX);
|
||||
MATCH_TO_MSGBOX_ID_MAP.put(MMS_SENT, Mms.MESSAGE_BOX_SENT);
|
||||
MATCH_TO_MSGBOX_ID_MAP.put(MMS_DRAFTS, Mms.MESSAGE_BOX_DRAFTS);
|
||||
MATCH_TO_MSGBOX_ID_MAP.put(MMS_OUTBOX, Mms.MESSAGE_BOX_OUTBOX);
|
||||
}
|
||||
|
||||
private final HashMap<Integer, HashSet<Uri>> mMessageBoxes;
|
||||
private final HashMap<Long, HashSet<Uri>> mThreads;
|
||||
private final HashSet<Uri> mUpdating;
|
||||
|
||||
private PduCache() {
|
||||
mMessageBoxes = new HashMap<Integer, HashSet<Uri>>();
|
||||
mThreads = new HashMap<Long, HashSet<Uri>>();
|
||||
mUpdating = new HashSet<Uri>();
|
||||
}
|
||||
|
||||
synchronized public static final PduCache getInstance() {
|
||||
if (sInstance == null) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Constructing new PduCache instance.");
|
||||
}
|
||||
sInstance = new PduCache();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public boolean put(Uri uri, PduCacheEntry entry) {
|
||||
int msgBoxId = entry.getMessageBox();
|
||||
HashSet<Uri> msgBox = mMessageBoxes.get(msgBoxId);
|
||||
if (msgBox == null) {
|
||||
msgBox = new HashSet<Uri>();
|
||||
mMessageBoxes.put(msgBoxId, msgBox);
|
||||
}
|
||||
|
||||
long threadId = entry.getThreadId();
|
||||
HashSet<Uri> thread = mThreads.get(threadId);
|
||||
if (thread == null) {
|
||||
thread = new HashSet<Uri>();
|
||||
mThreads.put(threadId, thread);
|
||||
}
|
||||
|
||||
Uri finalKey = normalizeKey(uri);
|
||||
boolean result = super.put(finalKey, entry);
|
||||
if (result) {
|
||||
msgBox.add(finalKey);
|
||||
thread.add(finalKey);
|
||||
}
|
||||
setUpdating(uri, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
synchronized public void setUpdating(Uri uri, boolean updating) {
|
||||
if (updating) {
|
||||
mUpdating.add(uri);
|
||||
} else {
|
||||
mUpdating.remove(uri);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public boolean isUpdating(Uri uri) {
|
||||
return mUpdating.contains(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public PduCacheEntry purge(Uri uri) {
|
||||
int match = URI_MATCHER.match(uri);
|
||||
switch (match) {
|
||||
case MMS_ALL_ID:
|
||||
return purgeSingleEntry(uri);
|
||||
case MMS_INBOX_ID:
|
||||
case MMS_SENT_ID:
|
||||
case MMS_DRAFTS_ID:
|
||||
case MMS_OUTBOX_ID:
|
||||
String msgId = uri.getLastPathSegment();
|
||||
return purgeSingleEntry(Uri.withAppendedPath(Mms.CONTENT_URI, msgId));
|
||||
// Implicit batch of purge, return null.
|
||||
case MMS_ALL:
|
||||
case MMS_CONVERSATION:
|
||||
purgeAll();
|
||||
return null;
|
||||
case MMS_INBOX:
|
||||
case MMS_SENT:
|
||||
case MMS_DRAFTS:
|
||||
case MMS_OUTBOX:
|
||||
purgeByMessageBox(MATCH_TO_MSGBOX_ID_MAP.get(match));
|
||||
return null;
|
||||
case MMS_CONVERSATION_ID:
|
||||
purgeByThreadId(ContentUris.parseId(uri));
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PduCacheEntry purgeSingleEntry(Uri key) {
|
||||
mUpdating.remove(key);
|
||||
PduCacheEntry entry = super.purge(key);
|
||||
if (entry != null) {
|
||||
removeFromThreads(key, entry);
|
||||
removeFromMessageBoxes(key, entry);
|
||||
return entry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void purgeAll() {
|
||||
super.purgeAll();
|
||||
|
||||
mMessageBoxes.clear();
|
||||
mThreads.clear();
|
||||
mUpdating.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to be normalized.
|
||||
* @return Uri The normalized key of cached entry.
|
||||
*/
|
||||
private Uri normalizeKey(Uri uri) {
|
||||
int match = URI_MATCHER.match(uri);
|
||||
Uri normalizedKey = null;
|
||||
|
||||
switch (match) {
|
||||
case MMS_ALL_ID:
|
||||
normalizedKey = uri;
|
||||
break;
|
||||
case MMS_INBOX_ID:
|
||||
case MMS_SENT_ID:
|
||||
case MMS_DRAFTS_ID:
|
||||
case MMS_OUTBOX_ID:
|
||||
String msgId = uri.getLastPathSegment();
|
||||
normalizedKey = Uri.withAppendedPath(Mms.CONTENT_URI, msgId);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, uri + " -> " + normalizedKey);
|
||||
}
|
||||
return normalizedKey;
|
||||
}
|
||||
|
||||
private void purgeByMessageBox(Integer msgBoxId) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Purge cache in message box: " + msgBoxId);
|
||||
}
|
||||
|
||||
if (msgBoxId != null) {
|
||||
HashSet<Uri> msgBox = mMessageBoxes.remove(msgBoxId);
|
||||
if (msgBox != null) {
|
||||
for (Uri key : msgBox) {
|
||||
mUpdating.remove(key);
|
||||
PduCacheEntry entry = super.purge(key);
|
||||
if (entry != null) {
|
||||
removeFromThreads(key, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromThreads(Uri key, PduCacheEntry entry) {
|
||||
HashSet<Uri> thread = mThreads.get(entry.getThreadId());
|
||||
if (thread != null) {
|
||||
thread.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private void purgeByThreadId(long threadId) {
|
||||
if (LOCAL_LOGV) {
|
||||
Log.v(TAG, "Purge cache in thread: " + threadId);
|
||||
}
|
||||
|
||||
HashSet<Uri> thread = mThreads.remove(threadId);
|
||||
if (thread != null) {
|
||||
for (Uri key : thread) {
|
||||
mUpdating.remove(key);
|
||||
PduCacheEntry entry = super.purge(key);
|
||||
if (entry != null) {
|
||||
removeFromMessageBoxes(key, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromMessageBoxes(Uri key, PduCacheEntry entry) {
|
||||
HashSet<Uri> msgBox = mThreads.get(Long.valueOf(entry.getMessageBox()));
|
||||
if (msgBox != null) {
|
||||
msgBox.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 com.google.android.mms.pdu.GenericPdu;
|
||||
|
||||
public final class PduCacheEntry {
|
||||
private final GenericPdu mPdu;
|
||||
private final int mMessageBox;
|
||||
private final long mThreadId;
|
||||
|
||||
public PduCacheEntry(GenericPdu pdu, int msgBox, long threadId) {
|
||||
mPdu = pdu;
|
||||
mMessageBox = msgBox;
|
||||
mThreadId = threadId;
|
||||
}
|
||||
|
||||
public GenericPdu getPdu() {
|
||||
return mPdu;
|
||||
}
|
||||
|
||||
public int getMessageBox() {
|
||||
return mMessageBox;
|
||||
}
|
||||
|
||||
public long getThreadId() {
|
||||
return mThreadId;
|
||||
}
|
||||
}
|
|
@ -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, org.mozilla.b2gdroid.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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.b2gdroid;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
|
||||
public class HeadlessSmsSendService extends IntentService {
|
||||
private final static String ACTION_RESPOND_VIA_MESSAGE = "android.intent.action.RESPOND_VIA_MESSAGE";
|
||||
|
||||
public HeadlessSmsSendService() {
|
||||
super("HeadlessSmsSendService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
if (!ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String recipient = intent.getData().getPath();
|
||||
String message = extras.getString(Intent.EXTRA_TEXT);
|
||||
|
||||
if (recipient.length() == 0 || message.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GeckoAppShell.sendMessage(recipient, message, 0, /* shouldNotify */ false);
|
||||
}
|
||||
}
|
|
@ -235,7 +235,7 @@ public class Launcher extends FragmentActivity
|
|||
try {
|
||||
obj.put("action", "view");
|
||||
obj.put("url", intent.getDataString());
|
||||
} catch(Exception ex) {
|
||||
} catch(JSONException ex) {
|
||||
Log.wtf(LOGTAG, "Error building Android:Launcher view message", ex);
|
||||
}
|
||||
GeckoEvent e = GeckoEvent.createBroadcastEvent("Android:Launcher", obj.toString());
|
||||
|
@ -269,6 +269,21 @@ public class Launcher extends FragmentActivity
|
|||
}
|
||||
GeckoEvent e = GeckoEvent.createBroadcastEvent("Android:Launcher", obj.toString());
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
} else if (Intent.ACTION_SENDTO.equals(action) ||
|
||||
Intent.ACTION_SEND.equals(action)) {
|
||||
Log.d(LOGTAG, "Sending new SMS intent to Gecko");
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("action", "send_sms");
|
||||
if (Intent.ACTION_SENDTO.equals(action)) {
|
||||
obj.put("number", intent.getData().getPath());
|
||||
}
|
||||
obj.put("body", intent.getStringExtra("sms_body"));
|
||||
} catch (JSONException ex) {
|
||||
Log.wtf(LOGTAG, "Error building Android:Launcher message", ex);
|
||||
}
|
||||
GeckoEvent e = GeckoEvent.createBroadcastEvent("Android:Launcher", obj.toString());
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.b2gdroid;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Telephony;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
|
||||
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_DELIVERY_IND;
|
||||
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
|
||||
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND;
|
||||
|
||||
import com.google.android.mms.MmsException;
|
||||
import com.google.android.mms.pdu.DeliveryInd;
|
||||
import com.google.android.mms.pdu.GenericPdu;
|
||||
import com.google.android.mms.pdu.NotificationInd;
|
||||
import com.google.android.mms.pdu.PduHeaders;
|
||||
import com.google.android.mms.pdu.PduParser;
|
||||
import com.google.android.mms.pdu.PduPersister;
|
||||
import com.google.android.mms.pdu.ReadOrigInd;
|
||||
import com.google.android.mms.util.SqliteWrapper;
|
||||
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoSmsManager;
|
||||
|
||||
public class MmsService extends BroadcastReceiver {
|
||||
private final static String LOGTAG = "MmsService";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION)) {
|
||||
final byte[] data = intent.getByteArrayExtra("data");
|
||||
writeInboxMessage(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldParseContentDisposition() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return SmsManager.getDefault().getCarrierConfigValues().getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeInboxMessage(byte[] pushData) {
|
||||
final Context context = GeckoAppShell.getContext();
|
||||
final GenericPdu pdu = new PduParser(pushData, shouldParseContentDisposition()).parse();
|
||||
if (pdu == null) {
|
||||
Log.e(LOGTAG, "Invalid PUSH PDU");
|
||||
}
|
||||
final PduPersister persister = PduPersister.getPduPersister(context);
|
||||
final int type = pdu.getMessageType();
|
||||
try {
|
||||
switch (type) {
|
||||
case MESSAGE_TYPE_DELIVERY_IND:
|
||||
case MESSAGE_TYPE_READ_ORIG_IND: {
|
||||
final long threadId = getDeliveryOrReadReportThreadId(context, pdu);
|
||||
if (threadId == -1) {
|
||||
// The associated SendReq isn't found, therefore skip
|
||||
// processing this PDU.
|
||||
Log.e(LOGTAG, "Failed to find delivery or read report's thread id");
|
||||
break;
|
||||
}
|
||||
final Uri uri = persister.persist(
|
||||
pdu,
|
||||
Telephony.Mms.Inbox.CONTENT_URI,
|
||||
true/*createThreadId*/,
|
||||
true/*groupMmsEnabled*/,
|
||||
null/*preOpenedFiles*/);
|
||||
if (uri == null) {
|
||||
Log.e(LOGTAG, "Failed to persist delivery or read report");
|
||||
break;
|
||||
}
|
||||
// Update thread ID for ReadOrigInd & DeliveryInd.
|
||||
final ContentValues values = new ContentValues(1);
|
||||
values.put(Telephony.Mms.THREAD_ID, threadId);
|
||||
if (SqliteWrapper.update(
|
||||
context,
|
||||
context.getContentResolver(),
|
||||
uri,
|
||||
values,
|
||||
null/*where*/,
|
||||
null/*selectionArgs*/) != 1) {
|
||||
Log.e(LOGTAG, "Failed to update delivery or read report thread id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TYPE_NOTIFICATION_IND: {
|
||||
final NotificationInd nInd = (NotificationInd) pdu;
|
||||
if (!isDuplicateNotification(context, nInd)) {
|
||||
final Uri uri = persister.persist(
|
||||
pdu,
|
||||
Telephony.Mms.Inbox.CONTENT_URI,
|
||||
true/*createThreadId*/,
|
||||
true/*groupMmsEnabled*/,
|
||||
null/*preOpenedFiles*/);
|
||||
if (uri == null) {
|
||||
Log.e(LOGTAG, "Failed to save MMS WAP push notification ind");
|
||||
}
|
||||
} else {
|
||||
Log.d(LOGTAG, "Skip storing duplicate MMS WAP push notification ind: "
|
||||
+ new String(nInd.getContentLocation()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Log.e(LOGTAG, "Received unrecognized WAP Push PDU.");
|
||||
}
|
||||
} catch (MmsException e) {
|
||||
Log.e(LOGTAG, "Failed to save MMS WAP push data: type=" + type, e);
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(LOGTAG, "Unexpected RuntimeException in persisting MMS WAP push data", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String THREAD_ID_SELECTION =
|
||||
Telephony.Mms.MESSAGE_ID + "=? AND " + Telephony.Mms.MESSAGE_TYPE + "=?";
|
||||
|
||||
private static long getDeliveryOrReadReportThreadId(Context context, GenericPdu pdu) {
|
||||
String messageId;
|
||||
if (pdu instanceof DeliveryInd) {
|
||||
messageId = new String(((DeliveryInd) pdu).getMessageId());
|
||||
} else if (pdu instanceof ReadOrigInd) {
|
||||
messageId = new String(((ReadOrigInd) pdu).getMessageId());
|
||||
} else {
|
||||
Log.e(LOGTAG, "WAP Push data is neither delivery or read report type: "
|
||||
+ pdu.getClass().getCanonicalName());
|
||||
return -1L;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = SqliteWrapper.query(
|
||||
context,
|
||||
context.getContentResolver(),
|
||||
Telephony.Mms.CONTENT_URI,
|
||||
new String[]{ Telephony.Mms.THREAD_ID },
|
||||
THREAD_ID_SELECTION,
|
||||
new String[]{
|
||||
DatabaseUtils.sqlEscapeString(messageId),
|
||||
Integer.toString(PduHeaders.MESSAGE_TYPE_SEND_REQ)
|
||||
},
|
||||
null/*sortOrder*/);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getLong(0);
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
Log.e(LOGTAG, "Failed to query delivery or read report thread id", e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
private static final String LOCATION_SELECTION =
|
||||
Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?";
|
||||
|
||||
private static boolean isDuplicateNotification(Context context, NotificationInd nInd) {
|
||||
final byte[] rawLocation = nInd.getContentLocation();
|
||||
if (rawLocation != null) {
|
||||
String location = new String(rawLocation);
|
||||
String[] selectionArgs = new String[] { location };
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = SqliteWrapper.query(
|
||||
context,
|
||||
context.getContentResolver(),
|
||||
Telephony.Mms.CONTENT_URI,
|
||||
new String[]{Telephony.Mms._ID},
|
||||
LOCATION_SELECTION,
|
||||
new String[]{
|
||||
Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
|
||||
new String(rawLocation)
|
||||
},
|
||||
null/*sortOrder*/);
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
// We already received the same notification before.
|
||||
return true;
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
Log.e(LOGTAG, "failed to query existing notification ind", e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -3,4 +3,9 @@
|
|||
|
||||
<string name="b2g">Firefox OS developer preview</string>
|
||||
|
||||
<!-- If MMS discovers there isn't much space left on the device, it will show a toast with this message. -->
|
||||
<string name="low_memory" product="tablet">Tablet storage is full! Delete some files to free space.</string>
|
||||
<!-- If MMS discovers there isn't much space left on the device, it will show a toast with this message. -->
|
||||
<string name="low_memory" product="default">Phone storage is full! Delete some files to free space.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -105,6 +105,16 @@ this.MessagesBridge = {
|
|||
data: { type: "url",
|
||||
url: data.url } });
|
||||
break;
|
||||
case "send_sms":
|
||||
new window.MozActivity({
|
||||
name: "new",
|
||||
data: {
|
||||
type: "websms/sms",
|
||||
number: data.number,
|
||||
body: data.body
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "home-key":
|
||||
window.dispatchEvent(new window.KeyboardEvent("keydown", { key: "Home" }));
|
||||
window.dispatchEvent(new window.KeyboardEvent("keyup", { key: "Home" }));
|
||||
|
|
|
@ -2319,13 +2319,17 @@ public class GeckoAppShell
|
|||
/*
|
||||
* WebSMS related methods.
|
||||
*/
|
||||
@WrapForJNI(stubName = "SendMessageWrapper")
|
||||
public static void sendMessage(String aNumber, String aMessage, int aRequestId) {
|
||||
public static void sendMessage(String aNumber, String aMessage, int aRequestId, boolean aShouldNotify) {
|
||||
if (!SmsManager.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmsManager.getInstance().send(aNumber, aMessage, aRequestId);
|
||||
SmsManager.getInstance().send(aNumber, aMessage, aRequestId, aShouldNotify);
|
||||
}
|
||||
|
||||
@WrapForJNI(stubName = "SendMessageWrapper")
|
||||
public static void sendMessage(String aNumber, String aMessage, int aRequestId) {
|
||||
sendMessage(aNumber, aMessage, aRequestId, /* shouldNotify */ true);
|
||||
}
|
||||
|
||||
@WrapForJNI(stubName = "GetMessageWrapper")
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.provider.Telephony;
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SmsMessage;
|
||||
import android.util.Log;
|
||||
|
@ -267,7 +268,6 @@ public class GeckoSmsManager
|
|||
extends BroadcastReceiver
|
||||
implements ISmsManager
|
||||
{
|
||||
public final static String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
|
||||
public final static String ACTION_SMS_SENT = "org.mozilla.gecko.SMS_SENT";
|
||||
public final static String ACTION_SMS_DELIVERED = "org.mozilla.gecko.SMS_DELIVERED";
|
||||
|
||||
|
@ -297,12 +297,12 @@ public class GeckoSmsManager
|
|||
|
||||
private final static int kMaxMessageSize = 160;
|
||||
|
||||
private final static Uri kSmsContentUri = Uri.parse("content://sms");
|
||||
private final static Uri kSmsSentContentUri = Uri.parse("content://sms/sent");
|
||||
private final static Uri kSmsThreadsContentUri = Uri.parse("content://sms/conversations");
|
||||
private final static Uri kSmsContentUri = Telephony.Sms.Inbox.CONTENT_URI;
|
||||
private final static Uri kSmsSentContentUri = Telephony.Sms.Sent.CONTENT_URI;
|
||||
private final static Uri kSmsThreadsContentUri = Telephony.Sms.Conversations.CONTENT_URI;
|
||||
|
||||
private final static int kSmsTypeInbox = 1;
|
||||
private final static int kSmsTypeSentbox = 2;
|
||||
private final static int kSmsTypeInbox = Telephony.Sms.MESSAGE_TYPE_INBOX;
|
||||
private final static int kSmsTypeSentbox = Telephony.Sms.MESSAGE_TYPE_SENT;
|
||||
|
||||
/*
|
||||
* Keep the following state codes in syng with |DeliveryState| in:
|
||||
|
@ -325,15 +325,6 @@ public class GeckoSmsManager
|
|||
private final static int kDeliveryStatusPending = 2;
|
||||
private final static int kDeliveryStatusError = 3;
|
||||
|
||||
/*
|
||||
* android.provider.Telephony.Sms.STATUS_*. Duplicated because they're not
|
||||
* part of Android public API.
|
||||
*/
|
||||
private final static int kInternalDeliveryStatusNone = -1;
|
||||
private final static int kInternalDeliveryStatusComplete = 0;
|
||||
private final static int kInternalDeliveryStatusPending = 32;
|
||||
private final static int kInternalDeliveryStatusFailed = 64;
|
||||
|
||||
/*
|
||||
* Keep the following values in sync with |MessageClass| in:
|
||||
* dom/mobilemessage/Types.h
|
||||
|
@ -355,45 +346,91 @@ public class GeckoSmsManager
|
|||
private static final long UNSIGNED_INTEGER_MAX_VALUE = Integer.MAX_VALUE * 2L + 1L;
|
||||
|
||||
public GeckoSmsManager() {
|
||||
if (SmsIOThread.getInstance().getState() == Thread.State.NEW) {
|
||||
SmsIOThread.getInstance().start();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDefaultSmsApp(Context context) {
|
||||
String myPackageName = context.getPackageName();
|
||||
return Telephony.Sms.getDefaultSmsPackage(context).equals(myPackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
IntentFilter smsFilter = new IntentFilter();
|
||||
smsFilter.addAction(ACTION_SMS_RECEIVED);
|
||||
smsFilter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
|
||||
smsFilter.addAction(ACTION_SMS_SENT);
|
||||
smsFilter.addAction(ACTION_SMS_DELIVERED);
|
||||
|
||||
GeckoAppShell.getContext().registerReceiver(this, smsFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the SMS message body from the SmsMessage array of received SMS
|
||||
*
|
||||
* @param msgs The SmsMessage array of the received SMS
|
||||
* @return The text message body
|
||||
*/
|
||||
private static String buildMessageBodyFromPdus(SmsMessage[] msgs) {
|
||||
if (msgs.length == 1) {
|
||||
// There is only one part, so grab the body directly.
|
||||
return replaceFormFeeds(msgs[0].getDisplayMessageBody());
|
||||
} else {
|
||||
// Build up the body from the parts.
|
||||
StringBuilder body = new StringBuilder();
|
||||
for (SmsMessage msg : msgs) {
|
||||
// getDisplayMessageBody() can NPE if mWrappedMessage inside is null.
|
||||
body.append(msg.getDisplayMessageBody());
|
||||
}
|
||||
return replaceFormFeeds(body.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Some providers send formfeeds in their messages. Convert those formfeeds to newlines.
|
||||
private static String replaceFormFeeds(String s) {
|
||||
return s == null ? "" : s.replace('\f', '\n');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
|
||||
// TODO: Try to find the receiver number to be able to populate
|
||||
// SmsMessage.receiver.
|
||||
// TODO: Get the id and the date from the stock app saved message.
|
||||
// Using the stock app saved message require us to wait for it to
|
||||
// be saved which can lead to race conditions.
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
|
||||
if (bundle == null) {
|
||||
if (intent.getAction().equals(Telephony.Sms.Intents.SMS_DELIVER_ACTION) ||
|
||||
intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
|
||||
// If we're the default SMS, ignore SMS_RECEIVED intents since we'll handle
|
||||
// the SMS_DELIVER intent instead.
|
||||
if (isDefaultSmsApp(GeckoAppShell.getContext()) && intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object[] pdus = (Object[]) bundle.get("pdus");
|
||||
|
||||
for (int i=0; i<pdus.length; ++i) {
|
||||
SmsMessage msg = SmsMessage.createFromPdu((byte[])pdus[i]);
|
||||
|
||||
notifySmsReceived(msg.getDisplayOriginatingAddress(),
|
||||
msg.getDisplayMessageBody(),
|
||||
getGeckoMessageClass(msg.getMessageClass()),
|
||||
System.currentTimeMillis());
|
||||
// TODO: Try to find the receiver number to be able to populate
|
||||
// SmsMessage.receiver.
|
||||
SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
|
||||
if (messages == null || messages.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmsMessage sms = messages[0];
|
||||
String body = buildMessageBodyFromPdus(messages);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
int id = 0;
|
||||
// We only need to save the message if we're the default SMS app
|
||||
if (intent.getAction().equals(Telephony.Sms.Intents.SMS_DELIVER_ACTION)) {
|
||||
id = saveReceivedMessage(context,
|
||||
sms.getDisplayOriginatingAddress(),
|
||||
body,
|
||||
sms.getTimestampMillis(),
|
||||
timestamp,
|
||||
sms.getPseudoSubject());
|
||||
}
|
||||
|
||||
notifySmsReceived(id,
|
||||
sms.getDisplayOriginatingAddress(),
|
||||
body,
|
||||
getGeckoMessageClass(sms.getMessageClass()),
|
||||
sms.getTimestampMillis(),
|
||||
timestamp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -447,7 +484,9 @@ public class GeckoSmsManager
|
|||
|
||||
if (envelope.isFailing(part)) {
|
||||
if (part == Envelope.SubParts.SENT_PART) {
|
||||
if (bundle.getBoolean("shouldNotify")) {
|
||||
notifySmsSendFailed(envelope.getError(), bundle.getInt("requestId"));
|
||||
}
|
||||
Log.i("GeckoSmsManager", "SMS sending failed!");
|
||||
} else {
|
||||
notifySmsDelivery(envelope.getMessageId(),
|
||||
|
@ -463,16 +502,24 @@ public class GeckoSmsManager
|
|||
String message = bundle.getString("message");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
int id = saveSentMessage(number, message, timestamp);
|
||||
// save message only if we're default SMS app, otherwise sendTextMessage does it for us
|
||||
int id = 0;
|
||||
if (isDefaultSmsApp(GeckoAppShell.getContext())) {
|
||||
id = saveSentMessage(number, message, timestamp);
|
||||
}
|
||||
|
||||
notifySmsSent(id, number, message, timestamp,
|
||||
bundle.getInt("requestId"));
|
||||
if (bundle.getBoolean("shouldNotify")) {
|
||||
notifySmsSent(id, number, message, timestamp, bundle.getInt("requestId"));
|
||||
}
|
||||
|
||||
envelope.setMessageId(id);
|
||||
envelope.setMessageTimestamp(timestamp);
|
||||
|
||||
Log.i("GeckoSmsManager", "SMS sending was successful!");
|
||||
} else {
|
||||
Uri id = ContentUris.withAppendedId(kSmsContentUri, envelope.getMessageId());
|
||||
updateMessageStatus(id, Telephony.Sms.STATUS_COMPLETE);
|
||||
|
||||
notifySmsDelivery(envelope.getMessageId(),
|
||||
kDeliveryStatusSuccess,
|
||||
bundle.getString("number"),
|
||||
|
@ -491,19 +538,22 @@ public class GeckoSmsManager
|
|||
}
|
||||
|
||||
@Override
|
||||
public void send(String aNumber, String aMessage, int aRequestId) {
|
||||
public void send(String aNumber, String aMessage, int aRequestId, boolean aShouldNotify) {
|
||||
int envelopeId = Postman.kUnknownEnvelopeId;
|
||||
|
||||
try {
|
||||
SmsManager sm = SmsManager.getDefault();
|
||||
|
||||
Intent sentIntent = new Intent(ACTION_SMS_SENT);
|
||||
Intent deliveredIntent = new Intent(ACTION_SMS_DELIVERED);
|
||||
Intent sentIntent = new Intent(GeckoAppShell.getContext(), GeckoSmsManager.class);
|
||||
sentIntent.setAction(ACTION_SMS_SENT);
|
||||
Intent deliveredIntent = new Intent(GeckoAppShell.getContext(), GeckoSmsManager.class);
|
||||
deliveredIntent.setAction(ACTION_SMS_DELIVERED);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("number", aNumber);
|
||||
bundle.putString("message", aMessage);
|
||||
bundle.putInt("requestId", aRequestId);
|
||||
bundle.putBoolean("shouldNotify", aShouldNotify);
|
||||
|
||||
if (aMessage.length() <= kMaxMessageSize) {
|
||||
envelopeId = Postman.getInstance().createEnvelope(1);
|
||||
|
@ -533,7 +583,7 @@ public class GeckoSmsManager
|
|||
pendingIntentGuid.incrementAndGet(), deliveredIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
sm.sendTextMessage(aNumber, "", aMessage,
|
||||
sm.sendTextMessage(aNumber, null, aMessage,
|
||||
sentPendingIntent, deliveredPendingIntent);
|
||||
} else {
|
||||
ArrayList<String> parts = sm.divideMessage(aMessage);
|
||||
|
@ -562,7 +612,7 @@ public class GeckoSmsManager
|
|||
);
|
||||
}
|
||||
|
||||
sm.sendMultipartTextMessage(aNumber, "", parts, sentPendingIntents,
|
||||
sm.sendMultipartTextMessage(aNumber, null, parts, sentPendingIntents,
|
||||
deliveredPendingIntents);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -579,11 +629,13 @@ public class GeckoSmsManager
|
|||
public int saveSentMessage(String aRecipient, String aBody, long aDate) {
|
||||
try {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("address", aRecipient);
|
||||
values.put("body", aBody);
|
||||
values.put("date", aDate);
|
||||
values.put(Telephony.Sms.ADDRESS, aRecipient);
|
||||
values.put(Telephony.Sms.BODY, aBody);
|
||||
values.put(Telephony.Sms.DATE, aDate);
|
||||
// Always 'PENDING' because we always request status report.
|
||||
values.put("status", kInternalDeliveryStatusPending);
|
||||
values.put(Telephony.Sms.STATUS, Telephony.Sms.STATUS_PENDING);
|
||||
values.put(Telephony.Sms.SEEN, 0);
|
||||
values.put(Telephony.Sms.READ, 0);
|
||||
|
||||
ContentResolver cr = GeckoAppShell.getContext().getContentResolver();
|
||||
Uri uri = cr.insert(kSmsSentContentUri, values);
|
||||
|
@ -606,6 +658,41 @@ public class GeckoSmsManager
|
|||
}
|
||||
}
|
||||
|
||||
public void updateMessageStatus(Uri aId, int aStatus) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(Telephony.Sms.STATUS, aStatus);
|
||||
|
||||
ContentResolver cr = GeckoAppShell.getContext().getContentResolver();
|
||||
if (cr.update(aId, values, null, null) != 1) {
|
||||
Log.i("GeckoSmsManager", "Failed to update message status!");
|
||||
}
|
||||
}
|
||||
|
||||
public int saveReceivedMessage(Context aContext, String aSender, String aBody, long aDateSent, long aDate, String aSubject) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Telephony.Sms.Inbox.ADDRESS, aSender);
|
||||
values.put(Telephony.Sms.Inbox.BODY, aBody);
|
||||
values.put(Telephony.Sms.Inbox.DATE_SENT, aDateSent);
|
||||
values.put(Telephony.Sms.Inbox.DATE, aDate);
|
||||
values.put(Telephony.Sms.Inbox.STATUS, Telephony.Sms.STATUS_COMPLETE);
|
||||
values.put(Telephony.Sms.Inbox.READ, 0);
|
||||
values.put(Telephony.Sms.Inbox.SEEN, 0);
|
||||
|
||||
ContentResolver cr = aContext.getContentResolver();
|
||||
Uri uri = cr.insert(kSmsContentUri, values);
|
||||
|
||||
long id = ContentUris.parseId(uri);
|
||||
|
||||
// The DOM API takes a 32bits unsigned int for the id. It's unlikely that
|
||||
// we happen to need more than that but it doesn't cost to check.
|
||||
if (id > UNSIGNED_INTEGER_MAX_VALUE) {
|
||||
Log.i("GeckoSmsManager", "The id we received is higher than the higher allowed value.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getMessage(int aMessageId, int aRequestId) {
|
||||
class GetMessageRunnable implements Runnable {
|
||||
|
@ -1079,13 +1166,13 @@ public class GeckoSmsManager
|
|||
}
|
||||
|
||||
private int getGeckoDeliveryStatus(int aDeliveryStatus) {
|
||||
if (aDeliveryStatus == kInternalDeliveryStatusNone) {
|
||||
if (aDeliveryStatus == Telephony.Sms.STATUS_NONE) {
|
||||
return kDeliveryStatusNotApplicable;
|
||||
}
|
||||
if (aDeliveryStatus >= kInternalDeliveryStatusFailed) {
|
||||
if (aDeliveryStatus >= Telephony.Sms.STATUS_FAILED) {
|
||||
return kDeliveryStatusError;
|
||||
}
|
||||
if (aDeliveryStatus >= kInternalDeliveryStatusPending) {
|
||||
if (aDeliveryStatus >= Telephony.Sms.STATUS_PENDING) {
|
||||
return kDeliveryStatusPending;
|
||||
}
|
||||
return kDeliveryStatusSuccess;
|
||||
|
@ -1127,7 +1214,7 @@ public class GeckoSmsManager
|
|||
}
|
||||
|
||||
@WrapForJNI
|
||||
private static native void notifySmsReceived(String aSender, String aBody, int aMessageClass, long aTimestamp);
|
||||
public static native void notifySmsReceived(int aId, String aSender, String aBody, int aMessageClass, long aSentTimestamp, long aTimestamp);
|
||||
@WrapForJNI
|
||||
private static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp, int aRequestId);
|
||||
@WrapForJNI
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SmsManager {
|
|||
void stop();
|
||||
void shutdown();
|
||||
|
||||
void send(String aNumber, String aMessage, int aRequestId);
|
||||
void send(String aNumber, String aMessage, int aRequestId, boolean aShouldNotify);
|
||||
void getMessage(int aMessageId, int aRequestId);
|
||||
void deleteMessage(int aMessageId, int aRequestId);
|
||||
void markMessageRead(int aMessageId, boolean aValue, boolean aSendReadReport, int aRequestId);
|
||||
|
|
|
@ -362,16 +362,16 @@ Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv * arg0, jclass ar
|
|||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef void (*Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived_t)(JNIEnv *, jclass, jstring, jstring, jint, jlong);
|
||||
typedef void (*Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived_t)(JNIEnv *, jclass, jint, jstring, jstring, jint, jlong, jlong);
|
||||
static Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived_t f_Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived;
|
||||
extern "C" NS_EXPORT void MOZ_JNICALL
|
||||
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(JNIEnv * arg0, jclass arg1, jstring arg2, jstring arg3, jint arg4, jlong arg5) {
|
||||
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(JNIEnv * arg0, jclass arg1, jint arg2, jstring arg3, jstring arg4, jint arg5, jlong arg6, jlong arg7) {
|
||||
if (!f_Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return ;
|
||||
}
|
||||
f_Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(arg0, arg1, arg2, arg3, arg4, arg5);
|
||||
f_Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2391,13 +2391,15 @@ public:
|
|||
typedef void ReturnType;
|
||||
typedef void SetterType;
|
||||
typedef mozilla::jni::Args<
|
||||
int32_t,
|
||||
mozilla::jni::String::Param,
|
||||
mozilla::jni::String::Param,
|
||||
int32_t,
|
||||
int64_t,
|
||||
int64_t> Args;
|
||||
static constexpr char name[] = "notifySmsReceived";
|
||||
static constexpr char signature[] =
|
||||
"(Ljava/lang/String;Ljava/lang/String;IJ)V";
|
||||
"(ILjava/lang/String;Ljava/lang/String;IJJ)V";
|
||||
static const bool isStatic = true;
|
||||
static const bool isMultithreaded = false;
|
||||
static const mozilla::jni::ExceptionMode exceptionMode =
|
||||
|
|
Загрузка…
Ссылка в новой задаче