FileDocCategorySizeDatePackage
PhoneBase.javaAPI DocAndroid 1.5 API13225Wed May 06 22:42:00 BST 2009com.android.internal.telephony

PhoneBase

public abstract class PhoneBase extends Object implements Phone
(Not for SDK use) A base implementation for the com.android.internal.telephony.Phone interface. Note that implementations of Phone.java are expected to be used from a single application thread. This should be the same thread that originally called PhoneFactory to obtain the interface. {@hide}

Fields Summary
private static final String
LOG_TAG
protected final android.os.RegistrantList
mPhoneStateRegistrants
protected final android.os.RegistrantList
mNewRingingConnectionRegistrants
protected final android.os.RegistrantList
mIncomingRingRegistrants
protected final android.os.RegistrantList
mDisconnectRegistrants
protected final android.os.RegistrantList
mServiceStateRegistrants
protected final android.os.RegistrantList
mMmiCompleteRegistrants
protected final android.os.RegistrantList
mMmiRegistrants
protected final android.os.RegistrantList
mUnknownConnectionRegistrants
protected final android.os.RegistrantList
mSuppServiceFailedRegistrants
protected android.os.Looper
mLooper
protected android.content.Context
mContext
protected PhoneNotifier
mNotifier
PhoneNotifier is an abstraction for all system-wide state change notification. DefaultPhoneNotifier is used here unless running we're inside a unit test.
protected com.android.internal.telephony.test.SimulatedRadioControl
mSimulatedRadioControl
boolean
mUnitTestMode
Constructors Summary
protected PhoneBase(PhoneNotifier notifier, android.content.Context context)
Constructs a PhoneBase in normal (non-unit test) mode.

param
context Context object from hosting application
param
notifier An instance of DefaultPhoneNotifier, unless unit testing.


                                  
         
        this(notifier, context, false);
    
protected PhoneBase(PhoneNotifier notifier, android.content.Context context, boolean unitTestMode)
Constructs a PhoneBase in normal (non-unit test) mode.

param
context Context object from hosting application
param
notifier An instance of DefaultPhoneNotifier, unless unit testing.
param
unitTestMode when true, prevents notifications of state change events

        this.mNotifier = notifier;
        this.mContext = context;
        mLooper = Looper.myLooper();

        setLocaleByCarrier();

        setUnitTestMode(unitTestMode);
    
Methods Summary
private voidcheckCorrectThread(android.os.Handler h)
Verifies the current thread is the same as the thread originally used in the initialization of this instance. Throws RuntimeException if not.

exception
RuntimeException if the current thread is not the thread that originally obtained this PhoneBase instance.

        if (h.getLooper() != mLooper) {
            throw new RuntimeException(
                "com.android.internal.telephony.Phone must be used from within one thread");
        }
    
public android.content.ContextgetContext()

        return mContext;
    
public abstract java.util.ListgetPendingMmiCodes()
Subclasses should override this. See documentation in superclass.

public com.android.internal.telephony.test.SimulatedRadioControlgetSimulatedRadioControl()

        return mSimulatedRadioControl;
    
public booleangetUnitTestMode()

        return mUnitTestMode;
    
protected voidnotifyCallStateChangedP()
Notify registrants of a PhoneStateChanged. Subclasses of Phone probably want to replace this with a version scoped to their packages

        AsyncResult ar = new AsyncResult(null, this, null);
        mPhoneStateRegistrants.notifyRegistrants(ar);
    
protected voidnotifyDisconnectP(Connection cn)
To be invoked when a voice call Connection disconnects. Subclasses of Phone probably want to replace this with a version scoped to their packages

        AsyncResult ar = new AsyncResult(null, cn, null);
        mDisconnectRegistrants.notifyRegistrants(ar);
    
protected voidnotifyNewRingingConnectionP(Connection cn)
Notifiy registrants of a new ringing Connection. Subclasses of Phone probably want to replace this with a version scoped to their packages

    
        AsyncResult ar = new AsyncResult(null, cn, null);
        mNewRingingConnectionRegistrants.notifyRegistrants(ar);
    
protected voidnotifyServiceStateChangedP(android.telephony.ServiceState ss)
Subclasses of Phone probably want to replace this with a version scoped to their packages

        AsyncResult ar = new AsyncResult(null, ss, null);
        mServiceStateRegistrants.notifyRegistrants(ar);

        mNotifier.notifyServiceState(this);
    
public voidregisterForDisconnect(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mDisconnectRegistrants.addUnique(h, what, obj);
    
public voidregisterForIncomingRing(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);
        
        mIncomingRingRegistrants.addUnique(h, what, obj);
    
public voidregisterForMmiComplete(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mMmiCompleteRegistrants.addUnique(h, what, obj);
    
public voidregisterForMmiInitiate(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mMmiRegistrants.addUnique(h, what, obj);
    
public voidregisterForNewRingingConnection(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mNewRingingConnectionRegistrants.addUnique(h, what, obj);
    
public voidregisterForPhoneStateChanged(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mPhoneStateRegistrants.addUnique(h, what, obj);
    
public voidregisterForServiceStateChanged(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);

        mServiceStateRegistrants.add(h, what, obj);
    
public voidregisterForSuppServiceFailed(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);
        
        mSuppServiceFailedRegistrants.addUnique(h, what, obj);
    
public voidregisterForUnknownConnection(android.os.Handler h, int what, java.lang.Object obj)

        checkCorrectThread(h);
        
        mUnknownConnectionRegistrants.addUnique(h, what, obj);
    
private voidsetLocaleByCarrier()
Set the locale by matching the carrier string in a string-array resource

        String carrier = SystemProperties.get("ro.carrier");

        if (null == carrier || 0 == carrier.length()) {
            return;
        }

        CharSequence[] carrierLocales = mContext.
                getResources().getTextArray(R.array.carrier_locales);

        for (int i = 0; i < carrierLocales.length-1; i+=2) {
            String c = carrierLocales[i].toString();
            String l = carrierLocales[i+1].toString();
            if (carrier.equals(c)) {
                String language = l.substring(0, 2);
                String country = "";
                if (l.length() >=5) {
                    country = l.substring(3, 5);
                }
                setSystemLocale(language, country);
                return;
            }
        }
    
public voidsetSystemLocale(java.lang.String language, java.lang.String country)
Utility code to set the system locale if it's not set already

param
langauge Two character language code desired
param
country Two character country code desired {@hide}

        String l = SystemProperties.get("persist.sys.language");
        String c = SystemProperties.get("persist.sys.country");

        if (null == language) {
            return; // no match possible
        }
        language.toLowerCase();
        if (null == country) {
            country = "";
        }
        country = country.toUpperCase();

        if((null == l || 0 == l.length()) && (null == c || 0 == c.length())) {
            try {
                // try to find a good match
                String[] locales = mContext.getAssets().getLocales();
                final int N = locales.length;
                String bestMatch = null;
                for(int i = 0; i < N; i++) {
                    if (locales[i]!=null && locales[i].length() >= 2 &&
                            locales[i].substring(0,2).equals(language)) {
                        if (locales[i].length() >= 5) {
                            if (locales[i].substring(3,5).equals(country)) {
                                bestMatch = locales[i];
                                break;
                            }
                        } else if (null == bestMatch) {
                            bestMatch = locales[i];
                        }
                    }
                }
                if (null != bestMatch) {
                    IActivityManager am = ActivityManagerNative.getDefault();
                    Configuration config = am.getConfiguration();
                    if (bestMatch.length() >= 5) {
                        config.locale = new Locale(bestMatch.substring(0,2),
                                                   bestMatch.substring(3,5));
                    } else {
                        config.locale = new Locale(bestMatch.substring(0,2));
                    }
                    config.userSetLocale = true;
                    am.updateConfiguration(config);
                }
            } catch (Exception e) {
                // Intentionally left blank
            }
        }
    
public voidsetUnitTestMode(boolean f)

        mUnitTestMode = f;
    
public voidunregisterForDisconnect(android.os.Handler h)

        mDisconnectRegistrants.remove(h);
    
public voidunregisterForIncomingRing(android.os.Handler h)

        mIncomingRingRegistrants.remove(h);
    
public voidunregisterForMmiComplete(android.os.Handler h)

        checkCorrectThread(h);

        mMmiCompleteRegistrants.remove(h);
    
public voidunregisterForMmiInitiate(android.os.Handler h)

        mMmiRegistrants.remove(h);
    
public voidunregisterForNewRingingConnection(android.os.Handler h)

        mNewRingingConnectionRegistrants.remove(h);
    
public voidunregisterForPhoneStateChanged(android.os.Handler h)

        mPhoneStateRegistrants.remove(h);
    
public voidunregisterForServiceStateChanged(android.os.Handler h)

        mServiceStateRegistrants.remove(h);
    
public voidunregisterForSuppServiceFailed(android.os.Handler h)

        mSuppServiceFailedRegistrants.remove(h);
    
public voidunregisterForUnknownConnection(android.os.Handler h)

        mUnknownConnectionRegistrants.remove(h);