|
|
boolean
autoConn = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.PPPOE_AUTO_CONN, 0) != 0 ? true : false;
boolean
enable = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.PPPOE_ENABLE, 0) != 0 ? true : false;
String
iface = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.PPPOE_INTERFACE);
|
if (ACTION_STATE_CHANGE.equals(action)) {
if (enable) {
Intent startIntent = new Intent(PPPoEService.ACTION_START_PPPOE);
context.startService(startIntent);
} else if (PPPoEService.isConnect()) {
PPPoEService.stop();
}
}
|
if (Intent.ACTION_BOOT_COMPLETED.equals(action) && autoConn && enable) {
Intent startIntent = new Intent(PPPoEService.ACTION_START_PPPOE); // 要开启某个服务, 需要一个Intent和对应服务监听的Action, PPPoEService在AndroidManifest.xml中设置了监听此Action
context.startService(startIntent);
}
|
Thread.sleep(CONN_TRY_TIME_OUT); // 5 * 1000, 也就是5s
|
private static final int STATE_STOPED = 0;
private static final int STATE_STARTING = 1;
private static final int STATE_STARTED = 2;
private static final int STATE_RETRY = 3;
private static final int STATE_EXIT = 4;
private static final int STATE_UNKWON = 5;
|
Intent intent = new Intent(EthernetManager.PPPOE_STATE_CHANGED_ACTION);
intent.putExtra(EthernetManager.EXTRA_PPPOE_STATE, EthernetManager.PPPOE_STATE_DISABLED);
sendBroadcast(intent);
|
Intent intent = new Intent(EthernetManager.PPPOE_STATE_CHANGED_ACTION);
intent.putExtra(EthernetManager.EXTRA_PPPOE_STATE, EthernetManager.PPPOE_STATE_ENABLED);
sendBroadcast(intent);
|
Intent intent = new Intent(EthernetManager.PPPOE_STATE_CHANGED_ACTION);
intent.putExtra(EthernetManager.EXTRA_PPPOE_STATE, EthernetManager.PPPOE_STATE_DISABLED);
|
private static final String SVC_STATE_CMD_PREFIX = "init.svc.";
private static final String SVC_START_CMD = "ctl.start";
private static final String SVC_STOP_CMD = "ctl.stop";
private static final String PPPOE_PROTOCOL = "pppoe";
|
public static void connect(String iface,String username) throws InterruptedException{
SystemProperties.set(SVC_START_CMD, PPPOE_PROTOCOL +
":" + iface + " " + username); // ctl.start, pppoe:eth0 username
if(DEBUG) Log.d(TAG,"SystemProperties.set" + PPPOE_PROTOCOL +
":" + iface + " " + username);
}
|
public static boolean stop(){
//SystemProperties.set(SVC_STOP_CMD, PPPOE_PROTOCOL);
// 目前不清楚为何将此种关闭方式注释掉了?
execCmd("pppoe-disconnect");
return isStoped();
}
|