Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ethernet: modify broadcast receiver to receive connectivity changes
Previously the network connectivity receiver was only created along the Activity where it is now started at bootup and stays in background. Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
- Loading branch information
Showing
5 changed files
with
61 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2015 Boundary Devices, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.fsl.ethernet; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import android.net.NetworkInfo.State; | ||
import android.util.Log; | ||
import com.fsl.ethernet.EthernetManager; | ||
|
||
public class EthernetReceiver extends BroadcastReceiver { | ||
|
||
private static final String TAG = "EthernetReceiver"; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Log.d(TAG, "onReceive " + intent.getAction()); | ||
|
||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { | ||
Log.d(TAG, "resetting interface"); | ||
EthernetManager ethManager = new EthernetManager(context); | ||
ethManager.resetInterface(); | ||
} else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { | ||
NetworkInfo info = | ||
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); | ||
if (info != null) { | ||
if (info.getType() == ConnectivityManager.TYPE_ETHERNET) { | ||
Log.i(TAG,"Ethernet state: " + info.getState()); | ||
if (info.getState() == State.DISCONNECTED) { | ||
ConnectivityManager connMgr = (ConnectivityManager)context. | ||
getSystemService(Context.CONNECTIVITY_SERVICE); | ||
connMgr.setGlobalProxy(null); | ||
} else if (info.getState() == State.CONNECTED) { | ||
EthernetManager ethManager = new EthernetManager(context); | ||
ethManager.resetInterface(); | ||
ethManager.initProxy(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters