今天,来简单看一下SIM卡开机流程中的另一个重要的类,RIL.java
首先,进入RIL.java文件中
/**
* RIL implementation of the CommandsInterface.
*
* {@hide}
*/
// Leo,需要注意这个地方,继承自BaseCommands,实现了CommandsInterface的接口
public final class RIL extends BaseCommands implements CommandsInterface {
......
}
注意,这个类是继承自BaseCommands,并实现了CommandsInterface接口
再来看看,PhoneFactory.java文件中的makeDefaultPhone方法中对于RIL类的创建
for (int i = 0; i < numPhones; i++) {
// reads the system properties and makes commandsinterface
// Get preferred network type.
networkModes[i] = RILConstants.PREFERRED_NETWORK_MODE;
Rlog.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkModes[i]));
// Leo,为每一个卡槽新建一个RIL对象
// RIL是实现了CommandsInterface的接口,因此这个地方的名称为sCommandsInterfaces
sCommandsInterfaces[i] = new RIL(context, networkModes[i], cdmaSubscription, i);
}
// Leo,获取Settings.Global.CDMA_SUBSCRIPTION_MODE的值
int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
CdmaSubscriptionSourceManager.java
/**
* Gets the default CDMA subscription source
*
* @return Default CDMA subscription source from Settings DB if present.
*/
public static int getDefault(Context context) {
// Get the default value from the Settings
int subscriptionSource = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.CDMA_SUBSCRIPTION_MODE, PREFERRED_CDMA_SUBSCRIPTION);
Rlog.d(LOG_TAG, "subscriptionSource from settings: " + subscriptionSource);
return subscriptionSource;
}
networkModes[i]参数,从上面可以看到,是直接赋值的,cdmaSubscription参数,从上文中看值为指定的值,暂不追究,i参数是之的第几张卡槽,接下来,看看RIL的构造函数
// Leo, RIL的构造方法
// 第四个参数是第instanceId个卡槽
// 第二个参数是第instanceId个卡槽的PreferredNetworkMode值
// 第三个参数cdmaSubscription,是Settings.Global.CDMA_SUBSCRIPTION_MODE的值
public RIL(Context context, int preferredNetworkType, int cdmaSubscription, Integer instanceId) {
super(context);
......
mContext = context;
mCdmaSubscription = cdmaSubscription;
mPreferredNetworkType = preferredNetworkType;
mPhoneType = RILConstants.NO_PHONE;
mInstanceId = instanceId;
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
// Leo, 这个WakeLock是干嘛用的?
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG);
mWakeLock.setReferenceCounted(false);
mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT, DEFAULT_WAKE_LOCK_TIMEOUT);
mWakeL