Ver Fonte

[ManagerSetting]
1. 관리자 설정 Ping 수정

jglee há 8 meses atrás
pai
commit
e02ba15a53

+ 44 - 10
ManagerSetting/src/main/java/com/artncore/managersetting/ui/fragments/CheckNetworkFragment.java

@@ -4,8 +4,10 @@ import android.app.Activity;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.os.AsyncTask;
+import android.os.Build;
 import android.os.Bundle;
 //import android.support.v4.app.Fragment;
+import androidx.annotation.RequiresApi;
 import androidx.fragment.app.Fragment;
 import androidx.core.view.MotionEventCompat;
 import android.util.Log;
@@ -39,11 +41,14 @@ import com.artncore.wallpadapi.WallPadAPI;
 import com.artncore.wallpadimap.RetProci;
 import com.util.LogUtil;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import kr.co.icontrols.managersetting.imap.iMAP_ctrl_config_read;
 import kr.co.icontrols.managersetting.imap.iMAP_hn_config_read;
@@ -828,6 +833,7 @@ public class CheckNetworkFragment extends Fragment {
 
     private final int PING_TIMEOUT = 3000;
     private class PingTestTask extends AsyncTask<Object, Void, String[]> {
+        @RequiresApi(api = Build.VERSION_CODES.O)
         @Override
         protected String[] doInBackground(Object... params) {
             String title = (String)params[0];
@@ -837,19 +843,47 @@ public class CheckNetworkFragment extends Fragment {
 
             StringBuilder result = new StringBuilder();
 
-            try {
-                InetAddress ia = InetAddress.getByName(testIP);
-                if(ia.isReachable(PING_TIMEOUT) == true) {
+//            try {
+//                InetAddress ia = InetAddress.getByName(testIP);
+//                if(ia.isReachable(PING_TIMEOUT) == true) {
+//                    result.append("Reachable in 3 sec");
+//                } else {
+//                    result.append("Unreachable in 3 sec");
+//                }
+//            } catch (UnknownHostException e){
+//                result.append("UnknownHost Exception");
+//            } catch (IOException e) {
+//                result.append("IO Exception : " + e.toString());
+//            } catch (IllegalArgumentException e) {
+//                result.append("IllegalArgumentExceptio");
+//            }
+
+
+
+            try
+            {
+                StringBuffer output = new StringBuffer();
+
+                //Runtime.getRuntime().exec( "adb shell");
+//                Process p = Runtime.getRuntime().exec("ping " + testIP);
+//                p.waitFor(PING_TIMEOUT, TimeUnit.MICROSECONDS); //프로세스의 명령이 끝날때까지 대기한다.
+                Runtime runtime = Runtime.getRuntime();
+                Process  mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 " + testIP);
+                //p.waitFor(PING_TIMEOUT, TimeUnit.MICROSECONDS); //프로세스의 명령이 끝날때까지 대기한다.
+                int mExitValue = mIpAddrProcess.waitFor();
+                System.out.println(" mExitValue "+mExitValue);
+                if(mExitValue==0){
                     result.append("Reachable in 3 sec");
-                } else {
+                }else{
                     result.append("Unreachable in 3 sec");
                 }
-            } catch (UnknownHostException e){
-                result.append("UnknownHost Exception");
-            } catch (IOException e) {
-                result.append("IO Exception : " + e.toString());
-            } catch (IllegalArgumentException e) {
-                result.append("IllegalArgumentExceptio");
+
+//                reader.close();/
+
+            }
+            catch (Exception e)
+            {
+                e.toString();
             }
 
             arrResult[0] = title;