| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.carrier; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.SdkConstant; |
| 23 |
import android.app.Service; |
| 24 |
import android.content.Intent; |
| 25 |
import android.net.Uri; |
| 26 |
import android.os.IBinder; |
| 27 |
import android.os.RemoteException; |
| 28 |
|
| 29 |
import java.lang.annotation.Retention; |
| 30 |
import java.lang.annotation.RetentionPolicy; |
| 31 |
import java.util.List; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public abstract class CarrierMessagingService extends Service { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
@SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
| 53 |
public static final String SERVICE_INTERFACE |
| 54 |
= "android.service.carrier.CarrierMessagingService"; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public static final int RECEIVE_OPTIONS_DEFAULT = 0; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static final int RECEIVE_OPTIONS_DROP = 0x1; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE = 0x2; |
| 79 |
|
| 80 |
|
| 81 |
@IntDef(flag = true, prefix = { "RECEIVE_OPTIONS_" }, value = { |
| 82 |
RECEIVE_OPTIONS_DEFAULT, |
| 83 |
RECEIVE_OPTIONS_DROP, |
| 84 |
RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE |
| 85 |
}) |
| 86 |
@Retention(RetentionPolicy.SOURCE) |
| 87 |
public @interface FilterCompleteResult{} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public static final int SEND_STATUS_OK = 0; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public static final int SEND_STATUS_RETRY_ON_CARRIER_NETWORK = 1; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public static final int SEND_STATUS_ERROR = 2; |
| 103 |
|
| 104 |
|
| 105 |
@IntDef(prefix = { "SEND_STATUS_" }, value = { |
| 106 |
SEND_STATUS_OK, |
| 107 |
SEND_STATUS_RETRY_ON_CARRIER_NETWORK, |
| 108 |
SEND_STATUS_ERROR |
| 109 |
}) |
| 110 |
@Retention(RetentionPolicy.SOURCE) |
| 111 |
public @interface SendResult {} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public static final int DOWNLOAD_STATUS_OK = 0; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK = 1; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public static final int DOWNLOAD_STATUS_ERROR = 2; |
| 127 |
|
| 128 |
|
| 129 |
@IntDef(prefix = { "DOWNLOAD_STATUS_" }, value = { |
| 130 |
DOWNLOAD_STATUS_OK, |
| 131 |
DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK, |
| 132 |
DOWNLOAD_STATUS_ERROR |
| 133 |
}) |
| 134 |
@Retention(RetentionPolicy.SOURCE) |
| 135 |
public @interface DownloadResult {} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS = 0x1; |
| 141 |
|
| 142 |
|
| 143 |
@IntDef(flag = true, prefix = { "SEND_FLAG_" }, value = { |
| 144 |
SEND_FLAG_REQUEST_DELIVERY_STATUS |
| 145 |
}) |
| 146 |
@Retention(RetentionPolicy.SOURCE) |
| 147 |
public @interface SendRequest {} |
| 148 |
|
| 149 |
private final ICarrierMessagingWrapper mWrapper = new ICarrierMessagingWrapper(); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
@Deprecated |
| 163 |
public void onFilterSms(@NonNull MessagePdu pdu, @NonNull String format, int destPort, |
| 164 |
int subId, @NonNull ResultCallback<Boolean> callback) { |
| 165 |
|
| 166 |
try { |
| 167 |
callback.onReceiveResult(true); |
| 168 |
} catch (RemoteException ex) { |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public void onReceiveTextSms(@NonNull MessagePdu pdu, @NonNull String format, |
| 192 |
int destPort, int subId, @NonNull final ResultCallback<Integer> callback) { |
| 193 |
onFilterSms(pdu, format, destPort, subId, new ResultCallback<Boolean>() { |
| 194 |
@Override |
| 195 |
public void onReceiveResult(Boolean result) throws RemoteException { |
| 196 |
callback.onReceiveResult(result ? RECEIVE_OPTIONS_DEFAULT : RECEIVE_OPTIONS_DROP |
| 197 |
| RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE); |
| 198 |
} |
| 199 |
}); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
@Deprecated |
| 212 |
public void onSendTextSms( |
| 213 |
@NonNull String text, int subId, @NonNull String destAddress, |
| 214 |
@NonNull ResultCallback<SendSmsResult> callback) { |
| 215 |
|
| 216 |
try { |
| 217 |
callback.onReceiveResult(new SendSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, 0)); |
| 218 |
} catch (RemoteException ex) { |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public void onSendTextSms( |
| 233 |
@NonNull String text, int subId, @NonNull String destAddress, |
| 234 |
int sendSmsFlag, @NonNull ResultCallback<SendSmsResult> callback) { |
| 235 |
|
| 236 |
onSendTextSms(text, subId, destAddress, callback); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
@Deprecated |
| 250 |
public void onSendDataSms(@NonNull byte[] data, int subId, |
| 251 |
@NonNull String destAddress, int destPort, |
| 252 |
@NonNull ResultCallback<SendSmsResult> callback) { |
| 253 |
|
| 254 |
try { |
| 255 |
callback.onReceiveResult(new SendSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, 0)); |
| 256 |
} catch (RemoteException ex) { |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public void onSendDataSms(@NonNull byte[] data, int subId, |
| 272 |
@NonNull String destAddress, int destPort, int sendSmsFlag, |
| 273 |
@NonNull ResultCallback<SendSmsResult> callback) { |
| 274 |
|
| 275 |
onSendDataSms(data, subId, destAddress, destPort, callback); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
@Deprecated |
| 288 |
public void onSendMultipartTextSms(@NonNull List<String> parts, |
| 289 |
int subId, @NonNull String destAddress, |
| 290 |
@NonNull ResultCallback<SendMultipartSmsResult> callback) { |
| 291 |
|
| 292 |
try { |
| 293 |
callback.onReceiveResult( |
| 294 |
new SendMultipartSmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null)); |
| 295 |
} catch (RemoteException ex) { |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public void onSendMultipartTextSms(@NonNull List<String> parts, |
| 310 |
int subId, @NonNull String destAddress, int sendSmsFlag, |
| 311 |
@NonNull ResultCallback<SendMultipartSmsResult> callback) { |
| 312 |
|
| 313 |
onSendMultipartTextSms(parts, subId, destAddress, callback); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
public void onSendMms(@NonNull Uri pduUri, int subId, |
| 326 |
@Nullable Uri location, @NonNull ResultCallback<SendMmsResult> callback) { |
| 327 |
|
| 328 |
try { |
| 329 |
callback.onReceiveResult(new SendMmsResult(SEND_STATUS_RETRY_ON_CARRIER_NETWORK, null)); |
| 330 |
} catch (RemoteException ex) { |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
public void onDownloadMms(@NonNull Uri contentUri, int subId, @NonNull Uri location, |
| 345 |
@NonNull ResultCallback<Integer> callback) { |
| 346 |
|
| 347 |
try { |
| 348 |
callback.onReceiveResult(DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK); |
| 349 |
} catch (RemoteException ex) { |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
@Override |
| 354 |
public @Nullable IBinder onBind(@NonNull Intent intent) { |
| 355 |
if (!SERVICE_INTERFACE.equals(intent.getAction())) { |
| 356 |
return null; |
| 357 |
} |
| 358 |
return mWrapper; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public static final class SendMmsResult { |
| 365 |
private int mSendStatus; |
| 366 |
private byte[] mSendConfPdu; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public SendMmsResult(int sendStatus, @Nullable byte[] sendConfPdu) { |
| 379 |
mSendStatus = sendStatus; |
| 380 |
mSendConfPdu = sendConfPdu; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public int getSendStatus() { |
| 390 |
return mSendStatus; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
public @Nullable byte[] getSendConfPdu() { |
| 399 |
return mSendConfPdu; |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
public static final class SendSmsResult { |
| 407 |
private final int mSendStatus; |
| 408 |
private final int mMessageRef; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public SendSmsResult(int sendStatus, int messageRef) { |
| 420 |
mSendStatus = sendStatus; |
| 421 |
mMessageRef = messageRef; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
public int getMessageRef() { |
| 430 |
return mMessageRef; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
public int getSendStatus() { |
| 439 |
return mSendStatus; |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public static final class SendMultipartSmsResult { |
| 447 |
private final int mSendStatus; |
| 448 |
private final int[] mMessageRefs; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public SendMultipartSmsResult(int sendStatus, @Nullable int[] messageRefs) { |
| 461 |
mSendStatus = sendStatus; |
| 462 |
mMessageRefs = messageRefs; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
public @Nullable int[] getMessageRefs() { |
| 471 |
return mMessageRefs; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
public int getSendStatus() { |
| 480 |
return mSendStatus; |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
public interface ResultCallback<T> { |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
public void onReceiveResult(@NonNull T result) throws RemoteException; |
| 494 |
}; |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
private class ICarrierMessagingWrapper extends ICarrierMessagingService.Stub { |
| 501 |
@Override |
| 502 |
public void filterSms(MessagePdu pdu, String format, int destPort, |
| 503 |
int subId, final ICarrierMessagingCallback callback) { |
| 504 |
onReceiveTextSms(pdu, format, destPort, subId, |
| 505 |
new ResultCallback<Integer>() { |
| 506 |
@Override |
| 507 |
public void onReceiveResult(Integer options) throws RemoteException { |
| 508 |
callback.onFilterComplete(options); |
| 509 |
} |
| 510 |
}); |
| 511 |
} |
| 512 |
|
| 513 |
@Override |
| 514 |
public void sendTextSms(String text, int subId, String destAddress, |
| 515 |
int sendSmsFlag, final ICarrierMessagingCallback callback) { |
| 516 |
onSendTextSms(text, subId, destAddress, sendSmsFlag, |
| 517 |
new ResultCallback<SendSmsResult>() { |
| 518 |
@Override |
| 519 |
public void onReceiveResult(final SendSmsResult result) throws RemoteException { |
| 520 |
callback.onSendSmsComplete(result.getSendStatus(), result.getMessageRef()); |
| 521 |
} |
| 522 |
}); |
| 523 |
} |
| 524 |
|
| 525 |
@Override |
| 526 |
public void sendDataSms(byte[] data, int subId, String destAddress, int destPort, |
| 527 |
int sendSmsFlag, final ICarrierMessagingCallback callback) { |
| 528 |
onSendDataSms(data, subId, destAddress, destPort, sendSmsFlag, |
| 529 |
new ResultCallback<SendSmsResult>() { |
| 530 |
@Override |
| 531 |
public void onReceiveResult(final SendSmsResult result) throws RemoteException { |
| 532 |
callback.onSendSmsComplete(result.getSendStatus(), result.getMessageRef()); |
| 533 |
} |
| 534 |
}); |
| 535 |
} |
| 536 |
|
| 537 |
@Override |
| 538 |
public void sendMultipartTextSms(List<String> parts, int subId, String destAddress, |
| 539 |
int sendSmsFlag, final ICarrierMessagingCallback callback) { |
| 540 |
onSendMultipartTextSms(parts, subId, destAddress, sendSmsFlag, |
| 541 |
new ResultCallback<SendMultipartSmsResult>() { |
| 542 |
@Override |
| 543 |
public void onReceiveResult(final SendMultipartSmsResult result) |
| 544 |
throws RemoteException { |
| 545 |
callback.onSendMultipartSmsComplete( |
| 546 |
result.getSendStatus(), result.getMessageRefs()); |
| 547 |
} |
| 548 |
}); |
| 549 |
} |
| 550 |
|
| 551 |
@Override |
| 552 |
public void sendMms(Uri pduUri, int subId, Uri location, |
| 553 |
final ICarrierMessagingCallback callback) { |
| 554 |
onSendMms(pduUri, subId, location, new ResultCallback<SendMmsResult>() { |
| 555 |
@Override |
| 556 |
public void onReceiveResult(final SendMmsResult result) throws RemoteException { |
| 557 |
callback.onSendMmsComplete(result.getSendStatus(), result.getSendConfPdu()); |
| 558 |
} |
| 559 |
}); |
| 560 |
} |
| 561 |
|
| 562 |
@Override |
| 563 |
public void downloadMms(Uri pduUri, int subId, Uri location, |
| 564 |
final ICarrierMessagingCallback callback) { |
| 565 |
onDownloadMms(pduUri, subId, location, new ResultCallback<Integer>() { |
| 566 |
@Override |
| 567 |
public void onReceiveResult(Integer result) throws RemoteException { |
| 568 |
callback.onDownloadMmsComplete(result); |
| 569 |
} |
| 570 |
}); |
| 571 |
} |
| 572 |
} |
| 573 |
} |