1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.marre.sms.nokia;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27
28 import org.marre.sms.SmsConstants;
29 import org.marre.sms.SmsPduUtil;
30 import org.marre.sms.SmsPortAddressedMessage;
31 import org.marre.sms.SmsUserData;
32
33 /***
34 * Nokia Operator Logo message
35 *
36 * @author Markus Eriksson
37 * @version $Id: NokiaOperatorLogo.java,v 1.13 2004/11/20 19:02:35 c95men Exp $
38 */
39 public class NokiaOperatorLogo extends SmsPortAddressedMessage
40 {
41 /***
42 * If set to true it will make the message two bytes shorter to make it
43 * possible to fit a 72x14 pixel image in one SMS instead of two. <br>
44 * <b>Note! </b> This will probably only work on Nokia phones...
45 */
46 protected boolean myDiscardNokiaHeaders;
47
48 /*** The ota image as a byte array */
49 protected byte[] myBitmap;
50
51 /*** GSM Mobile Country Code */
52 protected int myMcc;
53
54 /*** GSM Mobile Network Code */
55 protected int myMnc;
56
57 /***
58 * Creates a Nokia Operator Logo message
59 *
60 * @param theOtaBitmap
61 * @param theMcc
62 * GSM Mobile Country Code
63 * @param theMnc
64 * GSM Mobile Network Code
65 */
66 public NokiaOperatorLogo(OtaBitmap theOtaBitmap, int theMcc, int theMnc)
67 {
68 this(theOtaBitmap.getBytes(), theMcc, theMnc);
69 }
70
71 /***
72 * Creates a Nokia Operator Logo message
73 *
74 * @param theOtaImage
75 * The ota image as a byte array
76 * @param theMcc
77 * GSM Mobile Country Code
78 * @param theMnc
79 * GSM Mobile Network Code
80 */
81 public NokiaOperatorLogo(byte[] theOtaImage, int theMcc, int theMnc)
82 {
83 super(SmsConstants.PORT_NOKIA_OPERATOR_LOGO, 0);
84
85 myBitmap = theOtaImage;
86 myMcc = theMcc;
87 myMnc = theMnc;
88 }
89
90 /***
91 * Creates a Nokia Operator Logo message
92 *
93 * @param theOtaImage
94 * The ota image as a byte array
95 * @param theMcc
96 * GSM Mobile Country Code
97 * @param theMnc
98 * GSM Mobile Network Code
99 */
100 public NokiaOperatorLogo(byte[] theOtaImage, int theMcc, int theMnc, boolean discardHeaders)
101 {
102 super(SmsConstants.PORT_NOKIA_OPERATOR_LOGO, 0);
103
104 myDiscardNokiaHeaders = discardHeaders;
105 myBitmap = theOtaImage;
106 myMcc = theMcc;
107 myMnc = theMnc;
108 }
109
110 /***
111 * Creates a Nokia Operator Logo message
112 *
113 * @param theBitmap
114 * @param theOperatorMccMnc
115 * Operator defined in org.marre.sms.util.GsmOperators
116 */
117 public NokiaOperatorLogo(OtaBitmap theBitmap, int[] theOperatorMccMnc)
118 {
119 this(theBitmap, theOperatorMccMnc[0], theOperatorMccMnc[1]);
120 }
121
122 /***
123 * Creates a Nokia Operator Logo message
124 *
125 * @param theOtaImage
126 * The ota image as a byte array
127 * @param theOperatorMccMnc
128 */
129 public NokiaOperatorLogo(byte[] theOtaImage, int[] theOperatorMccMnc)
130 {
131 this(theOtaImage, theOperatorMccMnc[0], theOperatorMccMnc[1]);
132 }
133
134 public SmsUserData getUserData()
135 {
136 ByteArrayOutputStream baos = new ByteArrayOutputStream(140);
137
138 try
139 {
140 if (!myDiscardNokiaHeaders)
141 {
142
143 baos.write(0x30);
144 }
145
146
147 SmsPduUtil.writeBcdNumber(baos, "" + myMcc);
148
149 if (myMnc < 10)
150 {
151 SmsPduUtil.writeBcdNumber(baos, "0" + myMnc);
152 }
153 else
154 {
155 SmsPduUtil.writeBcdNumber(baos, "" + myMnc);
156 }
157
158 if (!myDiscardNokiaHeaders)
159 {
160
161 baos.write(0x0A);
162 }
163
164 baos.write(myBitmap);
165
166 baos.close();
167 }
168 catch (IOException ex)
169 {
170
171 }
172
173 return new SmsUserData(baos.toByteArray());
174 }
175 }