summaryrefslogtreecommitdiff
authorLawrence Mok <lawrence.mok@amlogic.com>2015-05-15 04:19:57 (GMT)
committer Gerrit Code Review <gituser@scgit.amlogic.com>2015-05-15 04:19:57 (GMT)
commit21c958fb00ee329b666c7a640e3084456a2438c7 (patch)
tree76bb070f072a2837d700a03446b64fb70e2fcc92
parent415e168d8da16be4a99cfa311ac9343911ee6c52 (diff)
parent0aeed21fc296df44f8c0f945bed1c126709ab4da (diff)
downloadPPPoE-21c958fb00ee329b666c7a640e3084456a2438c7.zip
PPPoE-21c958fb00ee329b666c7a640e3084456a2438c7.tar.gz
PPPoE-21c958fb00ee329b666c7a640e3084456a2438c7.tar.bz2
Merge "PD#106222:fix PPPoE can not automatic access network when plug" into l-amlogic
Diffstat
-rw-r--r--AndroidManifest.xml3
-rw-r--r--src/com/droidlogic/PPPoE/MyPppoeService.java43
-rw-r--r--src/com/droidlogic/PPPoE/PppoeBroadcastReceiver.java106
-rw-r--r--src/com/droidlogic/PPPoE/PppoeConfigDialog.java9
4 files changed, 107 insertions, 54 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b097164..019d448 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -64,8 +64,7 @@
<receiver android:name=".PppoeBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
- <action android:name="android.net.ethernet.ETH_STATE_CHANGED"/>
- <action android:name="android.net.wifi.STATE_CHANGE"/>
+ <action android:name="com.droidlogic.linkchange"/>
</intent-filter>
</receiver>
diff --git a/src/com/droidlogic/PPPoE/MyPppoeService.java b/src/com/droidlogic/PPPoE/MyPppoeService.java
index db9c774..c1548bd 100644
--- a/src/com/droidlogic/PPPoE/MyPppoeService.java
+++ b/src/com/droidlogic/PPPoE/MyPppoeService.java
@@ -15,6 +15,11 @@ import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import com.amlogic.pppoe.PppoeOperation;
+import com.android.server.net.BaseNetworkObserver;
+import android.os.INetworkManagementService;
+import android.os.ServiceManager;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
public class MyPppoeService extends Service
@@ -23,15 +28,24 @@ public class MyPppoeService extends Service
private NotificationManager mNM;
private Handler mHandler;
private PppoeOperation operation = null;
-
+ private InterfaceObserver mInterfaceObserver;
+ private INetworkManagementService mNMService;
@Override
public void onCreate() {
Log.d(TAG, ">>>>>>onCreate");
+ IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
+ mNMService = INetworkManagementService.Stub.asInterface(b);
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mHandler = new DMRHandler();
+ mInterfaceObserver = new InterfaceObserver();
+ try {
+ mNMService.registerObserver(mInterfaceObserver);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not register InterfaceObserver " + e);
+ }
/* start check after 5s */
mHandler.sendEmptyMessageDelayed(0, 5000);
@@ -40,8 +54,8 @@ public class MyPppoeService extends Service
f.addAction(Intent.ACTION_SHUTDOWN);
f.addAction(Intent.ACTION_SCREEN_OFF);
+ f.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(mShutdownReceiver, new IntentFilter(f));
-
}
@Override
@@ -55,7 +69,24 @@ public class MyPppoeService extends Service
public IBinder onBind(Intent intent) {
return null;
}
+ private void updateInterfaceState(String iface, boolean up) {
+ Intent intent = new Intent("com.droidlogic.linkchange");
+ if (!iface.contains("eth0")) {
+ return;
+ }
+ if (up) {
+ this.sendBroadcast(intent);
+ }
+ }
+
+ private class InterfaceObserver extends BaseNetworkObserver {
+ @Override
+ public void interfaceLinkStateChanged(String iface, boolean up) {
+ updateInterfaceState(iface, up);
+ }
+
+ }
private class DMRHandler extends Handler
{
@@ -77,9 +108,13 @@ private BroadcastReceiver mShutdownReceiver =
Log.d(TAG , "onReceive :" +intent.getAction());
if ((Intent.ACTION_SCREEN_OFF).equals(intent.getAction())) {
- operation = new PppoeOperation();
- operation.disconnect();
+ operation = new PppoeOperation();
+ operation.disconnect();
+ }
+ if ((Intent.ACTION_SCREEN_ON).equals(intent.getAction())) {
+ updateInterfaceState("eth0", true);
}
+
}
};
diff --git a/src/com/droidlogic/PPPoE/PppoeBroadcastReceiver.java b/src/com/droidlogic/PPPoE/PppoeBroadcastReceiver.java
index 9baeff6..1facc26 100644
--- a/src/com/droidlogic/PPPoE/PppoeBroadcastReceiver.java
+++ b/src/com/droidlogic/PPPoE/PppoeBroadcastReceiver.java
@@ -7,8 +7,10 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.util.Log;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo.State;
import android.net.wifi.WifiManager;
+import android.util.Log;
import android.content.SharedPreferences;
import com.amlogic.pppoe.PppoeOperation;
import android.os.Handler;
@@ -88,69 +90,81 @@ public class PppoeBroadcastReceiver extends BroadcastReceiver {
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
context.startService(new Intent(context,
MyPppoeService.class));
+ mFirstAutoDialDone = true;
}
if (null == mInterfaceSelected
|| !mAutoDialFlag
|| null == mUserName
- || null == mPassword)
+ || null == mPassword) {
+ mFirstAutoDialDone = false;
return;
+ }
+
if (mHandler == null) {
mHandler = new PppoeHandler();
}
if (operation == null) {
- operation = new PppoeOperation();
+ operation = new PppoeOperation();
}
-
Log.d(TAG , ">>>>>onReceive :" +intent.getAction());
- if (!mInterfaceSelected.startsWith("eth"))
- return;
-
- int event = intent.getIntExtra(EXTRA_ETH_STATE, -1);
- if (event == EVENT_HW_PHYCONNECTED) {
- Log.d(TAG, "EVENT_HW_PHYCONNECTED");
- if (mMandatoryDialTimer != null) {
- mMandatoryDialTimer.cancel();
- mMandatoryDialTimer = null;
- }
- mFirstAutoDialDone = true;
+ if ("com.droidlogic.linkchange".equals(action) || mFirstAutoDialDone) {
+ mFirstAutoDialDone = false;
+ if (!mInterfaceSelected.startsWith("eth") )
+ return;
+ int event = intent.getIntExtra(EXTRA_ETH_STATE, -1);
+ if (event == EVENT_HW_PHYCONNECTED) {
+ Log.d(TAG, "EVENT_HW_PHYCONNECTED");
+ if (mMandatoryDialTimer != null) {
+ mMandatoryDialTimer.cancel();
+ mMandatoryDialTimer = null;
+ }
+
+ Log.d(TAG, "EVENT_HW_PHYCONNECTED trigger AUTO DIAL");
- Log.d(TAG, "EVENT_HW_PHYCONNECTED trigger AUTO DIAL");
-
- set_pppoe_running_flag();
- operation.terminate();
- operation.disconnect();
- mHandler.sendEmptyMessageDelayed(PPPoEActivity.MSG_START_DIAL, 30000);
- }
- else {
- if (event == EVENT_HW_DISCONNECTED ) {
- Log.d(TAG, "EVENT_HW_DISCONNECTED");
+ set_pppoe_running_flag();
+ operation.terminate();
+ operation.disconnect();
+ mHandler.sendEmptyMessageDelayed(PPPoEActivity.MSG_START_DIAL, 30000);
}
- else if (event == EVENT_HW_CONNECTED )
- Log.d(TAG, "EVENT_HW_CONNECTED");
- else
- Log.d(TAG, "EVENT=" + event);
-
- if (event != EVENT_HW_DISCONNECTED&& !mFirstAutoDialDone) {
- Log.d(TAG, "EVENT_HW_PHYCONNECTED LOST");
- mFirstAutoDialDone = true;
- mMandatoryDialTimer = new Timer();
- TimerTask check_task = new TimerTask() {
- public void run()
- {
- Message message = new Message();
- message.what = PPPoEActivity.MSG_MANDATORY_DIAL;
- Log.d(TAG, "Send MSG_MANDATORY_DIAL");
- mHandler.sendMessage(message);
- }
- };
-
- //Timeout after 5 seconds
- mMandatoryDialTimer.schedule(check_task, 5000);
+ else {
+ if (event == EVENT_HW_DISCONNECTED ) {
+ Log.d(TAG, "EVENT_HW_DISCONNECTED");
+ }
+ else if (event == EVENT_HW_CONNECTED )
+ Log.d(TAG, "EVENT_HW_CONNECTED");
+ else
+ Log.d(TAG, "EVENT=" + event);
+
+ if (event != EVENT_HW_DISCONNECTED) {
+ Log.d(TAG, "EVENT_HW_PHYCONNECTED LOST");
+ mMandatoryDialTimer = new Timer();
+ TimerTask check_task = new TimerTask() {
+ public void run()
+ {
+ Message message = new Message();
+ message.what = PPPoEActivity.MSG_MANDATORY_DIAL;
+ Log.d(TAG, "Send MSG_MANDATORY_DIAL");
+ mHandler.sendMessage(message);
+ }
+ };
+
+ //Timeout after 5 seconds
+ mMandatoryDialTimer.schedule(check_task, 5000);
+ }
}
}
}
+ public static boolean isEthConnected(Context context) {
+ ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ State mEthState = connManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).getState();
+ if (State.CONNECTED == mEthState) {
+ return true;
+ }else{
+ return false;
+ }
+ }
void set_pppoe_running_flag()
{
diff --git a/src/com/droidlogic/PPPoE/PppoeConfigDialog.java b/src/com/droidlogic/PPPoE/PppoeConfigDialog.java
index 5e6b04a..fa0c188 100644
--- a/src/com/droidlogic/PPPoE/PppoeConfigDialog.java
+++ b/src/com/droidlogic/PPPoE/PppoeConfigDialog.java
@@ -275,8 +275,13 @@ public class PppoeConfigDialog extends AlertDialog implements DialogInterface.On
if (connectStatus() != PppoeOperation.PPP_STATUS_CONNECTED)
{
- isDialogOfDisconnect = false;
- this.setButton(BUTTON_POSITIVE, context.getText(R.string.pppoe_dial), this);
+ if (connectStatus() == PppoeOperation.PPP_STATUS_CONNECTING) {
+ isDialogOfDisconnect = false;
+ showWaitDialog(R.string.pppoe_dial_waiting_msg);
+ } else {
+ isDialogOfDisconnect = false;
+ this.setButton(BUTTON_POSITIVE, context.getText(R.string.pppoe_dial), this);
+ }
}
else {
Log.d(TAG, "connectStatus is CONNECTED");