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

PhoneFactory

public class PhoneFactory extends Object
{@hide}

Fields Summary
static final String
LOG_TAG
static final int
SOCKET_OPEN_RETRY_MILLIS
static final int
SOCKET_OPEN_MAX_RETRY
private static ArrayList
sPhones
private static boolean
sMadeDefaults
private static PhoneNotifier
sPhoneNotifier
private static android.os.Looper
sLooper
private static Object
testMailbox
Constructors Summary
Methods Summary
public static PhonegetDefaultPhone()

        if (!sMadeDefaults) {
            throw new IllegalStateException("Default phones haven't been made yet!");
        }

        if (sLooper != Looper.myLooper()) {
            throw new RuntimeException(
                "PhoneFactory.getDefaultPhone must be called from Looper thread");
        }

        synchronized (sPhones) {
            return sPhones.isEmpty() ? null : sPhones.get(0);
        }
    
public static voidmakeDefaultPhones(android.content.Context context)
FIXME replace this with some other way of making these instances

        synchronized(Phone.class) {        
            if (!sMadeDefaults) {  
                sLooper = Looper.myLooper();

                if (sLooper == null) {
                    throw new RuntimeException(
                        "PhoneFactory.makeDefaultPhones must be called from Looper thread");
                }

                int retryCount = 0;
                for(;;) {
                    boolean hasException = false;
                    retryCount ++;

                    try {
                        // use UNIX domain socket to
                        // prevent subsequent initialization
                        new LocalServerSocket("com.android.internal.telephony");
                    } catch (java.io.IOException ex) {
                        hasException = true;
                    }

                    if ( !hasException ) {
                        break;
                    } else if (retryCount > SOCKET_OPEN_MAX_RETRY) {
                        throw new RuntimeException("PhoneFactory probably already running");
                    }else {
                        try {
                            Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
                        } catch (InterruptedException er) {
                        }
                    }
                }

                sPhoneNotifier = new DefaultPhoneNotifier();

                if ((SystemProperties.get("ro.radio.noril","")).equals("")) {
                    useNewRIL(context);
                } else {
                    GSMPhone phone;
                    phone = new GSMPhone(context, new SimulatedCommands(), sPhoneNotifier);
                    registerPhone (phone);
                }

                sMadeDefaults = true;
            }
        }
    
public static voidregisterPhone(Phone p)

        if (sLooper != Looper.myLooper()) {
            throw new RuntimeException(
                "PhoneFactory.getDefaultPhone must be called from Looper thread");
        }
        synchronized (sPhones) {
            sPhones.add(p);
        }
    
private static voiduseNewRIL(android.content.Context context)


    //***** Class Methods

      
     
    
        ModelInterpreter mi = null;
        GSMPhone phone;

        try {
            if (false) {
                mi = new ModelInterpreter(new InetSocketAddress("127.0.0.1", 6502));
            }
            
            phone = new GSMPhone(context, new RIL(context), sPhoneNotifier);

            registerPhone (phone);
        } catch (IOException ex) {
            Log.e(LOG_TAG, "Error creating ModelInterpreter", ex);
        }