-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siamak
committed
Jun 1, 2019
1 parent
2f8d57c
commit 5c8a1fb
Showing
4 changed files
with
74 additions
and
60 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 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
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 |
---|---|---|
@@ -1,62 +1,63 @@ | ||
package ir.drax.netwatch; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import android.os.AsyncTask; | ||
|
||
import java.io.IOException; | ||
|
||
import ir.drax.netwatch.cb.Ping_navigator; | ||
|
||
class Ping implements Runnable { | ||
class Ping extends AsyncTask<Context, Void, Context> { | ||
private Ping_navigator cb; | ||
private Context context; | ||
private int mExitValue = 0; | ||
|
||
|
||
Ping() { } | ||
|
||
public Ping(Ping_navigator cb) { | ||
this.cb = cb; | ||
} | ||
|
||
Ping setCb(Ping_navigator cb) { | ||
this.cb = cb; | ||
return this; | ||
} | ||
|
||
Ping setContext(Context context) { | ||
this.context = context; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
Runtime runtime = Runtime.getRuntime(); | ||
protected Context doInBackground(Context... contexts) { | ||
try | ||
{ | ||
Process mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 "+ context.getString(R.string.netwatch_target_ping_server_ip_add)); | ||
int mExitValue = mIpAddrProcess.waitFor(); | ||
if (BuildConfig.DEBUG) | ||
Thread.sleep(NetworkChangeReceiver.getDelay()); | ||
Runtime runtime = Runtime.getRuntime(); | ||
Process mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 "+ contexts[0].getString(R.string.netwatch_target_ping_server_ip_add)); | ||
mExitValue = mIpAddrProcess.waitFor(); | ||
if (NetworkChangeReceiver.isLogsEnabled()) | ||
System.out.println(" Ping mExitValue "+mExitValue); | ||
if(mExitValue==0){ | ||
cb.replied(context); | ||
|
||
}else{ | ||
cb.timeout(context); | ||
|
||
} | ||
} | ||
catch (InterruptedException ignore) | ||
{ | ||
ignore.printStackTrace(); | ||
if (BuildConfig.DEBUG) | ||
if (NetworkChangeReceiver.isLogsEnabled()) | ||
System.out.println("Ping Exception:"+ignore); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
if (BuildConfig.DEBUG) | ||
System.out.println("Ping Exception:"+e); | ||
if (NetworkChangeReceiver.isLogsEnabled()) | ||
System.out.println("Ping Exception:"+e); | ||
} | ||
return contexts[0]; | ||
} | ||
@Override | ||
protected void onPostExecute(Context context) { | ||
if(mExitValue==0){ | ||
cb.replied(context); | ||
|
||
}else{ | ||
cb.timeout(context); | ||
|
||
} | ||
cb.ended(context); | ||
super.onPostExecute(context); | ||
} | ||
|
||
public Ping(Ping_navigator cb) { | ||
this.cb = cb; | ||
} | ||
|
||
Ping setCb(Ping_navigator cb) { | ||
this.cb = cb; | ||
return this; | ||
} | ||
} |