Home | History | Annotate | Download | only in engine
      1 /*
      2  * Copyright (C) 2008 Esmertec AG.
      3  * Copyright (C) 2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 package com.android.im.engine;
     18 
     19 /**
     20  * An abstract interface to access system SMS service.
     21  */
     22 public interface SmsService {
     23     public static final String ANY_ADDRESS = "*";
     24 
     25     /**
     26      * The listener which will be notified when an incoming SMS is received.
     27      *
     28      */
     29     public interface SmsListener {
     30         /**
     31          * Called on new SMS received.
     32          *
     33          * @param data
     34          */
     35         public void onIncomingSms(byte[] data);
     36     }
     37 
     38     /**
     39      * Callback on send SMS failure.
     40      *
     41      */
     42     public interface SmsSendFailureCallback {
     43         /** Generic failure case.*/
     44         int ERROR_GENERIC_FAILURE = 1;
     45         /** Failed because radio was explicitly turned off.*/
     46         int ERROR_RADIO_OFF = 2;
     47 
     48         /**
     49          * Called when send an SMS failed.
     50          *
     51          * @param errorCode the error code; will be one of
     52          *            {@link #ERROR_GENERIC_FAILURE},
     53          *            {@link #ERROR_RADIO_OFF}
     54          */
     55         public void onFailure(int errorCode);
     56     }
     57 
     58     /**
     59      * The max number of bytes an SMS can take.
     60      *
     61      * @return the max number of bytes an SMS can take.
     62      */
     63     public int getMaxSmsLength();
     64 
     65     /**
     66      * Sends a data SMS to the destination.
     67      *
     68      * @param dest
     69      *            The address to send the message to.
     70      * @param port
     71      *            The port to deliver the message to.
     72      * @param data
     73      *            The body of the message to send.
     74      */
     75     public void sendSms(String dest, int port, byte[] data);
     76 
     77     /**
     78      * Sends a data SMS to the destination.
     79      *
     80      * @param dest
     81      *            The address to send the message to.
     82      * @param port
     83      *            The port to deliver the message to.
     84      * @param data
     85      *            The body of the message to send.
     86      * @param callback
     87      *            If not null, it will be notified if the message could not be
     88      *            sent.
     89      */
     90     public void sendSms(String dest, int port, byte[] data,
     91             SmsSendFailureCallback callback);
     92 
     93     /**
     94      * Add a SmsListener so that it can be notified when new SMS from specific
     95      * address and application port has been received.
     96      *
     97      * @param from
     98      *            The address of the sender.
     99      * @param port
    100      *            The application port.
    101      * @param listener
    102      *            The listener which will be notified when SMS received.
    103      */
    104     public void addSmsListener(String from, int port, SmsListener listener);
    105 
    106     /**
    107      * Remove a SmsListener from the service so that it won't be notified
    108      * anymore.
    109      *
    110      * @param listener
    111      *            The listener to be removed.
    112      */
    113     public void removeSmsListener(SmsListener listener);
    114 }
    115