初步完成服务访问连接
This commit is contained in:
		@@ -1,8 +1,8 @@
 | 
				
			|||||||
#Created by .winboll/winboll_app_build.gradle
 | 
					#Created by .winboll/winboll_app_build.gradle
 | 
				
			||||||
#Sat Mar 29 12:08:03 HKT 2025
 | 
					#Sat Mar 29 09:33:15 GMT 2025
 | 
				
			||||||
stageCount=2
 | 
					stageCount=2
 | 
				
			||||||
libraryProject=libaes
 | 
					libraryProject=libaes
 | 
				
			||||||
baseVersion=15.2
 | 
					baseVersion=15.2
 | 
				
			||||||
publishVersion=15.2.1
 | 
					publishVersion=15.2.1
 | 
				
			||||||
buildCount=0
 | 
					buildCount=16
 | 
				
			||||||
baseBetaVersion=15.2.2
 | 
					baseBetaVersion=15.2.2
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,8 @@
 | 
				
			|||||||
        android:label="@string/app_name"
 | 
					        android:label="@string/app_name"
 | 
				
			||||||
        android:theme="@style/MyAESTheme"
 | 
					        android:theme="@style/MyAESTheme"
 | 
				
			||||||
        android:requestLegacyExternalStorage="true"
 | 
					        android:requestLegacyExternalStorage="true"
 | 
				
			||||||
        android:supportsRtl="true">
 | 
					        android:supportsRtl="true"
 | 
				
			||||||
 | 
					        android:networkSecurityConfig="@xml/network_security_config">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <activity
 | 
					        <activity
 | 
				
			||||||
            android:name=".MainActivity"
 | 
					            android:name=".MainActivity"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								aes/src/main/res/xml/network_security_config.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								aes/src/main/res/xml/network_security_config.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<network-security-config>
 | 
				
			||||||
 | 
					    <domain-config cleartextTrafficPermitted="true">
 | 
				
			||||||
 | 
					        <domain includeSubdomains="false">www.winboll.cc</domain>
 | 
				
			||||||
 | 
					        <domain includeSubdomains="false">dev.winboll.cc</domain>
 | 
				
			||||||
 | 
					    </domain-config>
 | 
				
			||||||
 | 
					</network-security-config>
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
#Created by .winboll/winboll_app_build.gradle
 | 
					#Created by .winboll/winboll_app_build.gradle
 | 
				
			||||||
#Sat Mar 29 12:07:46 HKT 2025
 | 
					#Sat Mar 29 09:33:15 GMT 2025
 | 
				
			||||||
stageCount=2
 | 
					stageCount=2
 | 
				
			||||||
libraryProject=libaes
 | 
					libraryProject=libaes
 | 
				
			||||||
baseVersion=15.2
 | 
					baseVersion=15.2
 | 
				
			||||||
publishVersion=15.2.1
 | 
					publishVersion=15.2.1
 | 
				
			||||||
buildCount=0
 | 
					buildCount=16
 | 
				
			||||||
baseBetaVersion=15.2.2
 | 
					baseBetaVersion=15.2.2
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ import cc.winboll.studio.libaes.beans.AESThemeBean;
 | 
				
			|||||||
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
 | 
					import cc.winboll.studio.libaes.beans.DrawerMenuBean;
 | 
				
			||||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
 | 
					import cc.winboll.studio.libaes.utils.AESThemeUtil;
 | 
				
			||||||
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
 | 
					import cc.winboll.studio.libaes.views.ADrawerMenuListView;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.GlobalApplication;
 | 
				
			||||||
import cc.winboll.studio.libappbase.LogUtils;
 | 
					import cc.winboll.studio.libappbase.LogUtils;
 | 
				
			||||||
import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
 | 
					import cc.winboll.studio.libappbase.winboll.IWinBollActivity;
 | 
				
			||||||
import com.baoyz.widget.PullRefreshLayout;
 | 
					import com.baoyz.widget.PullRefreshLayout;
 | 
				
			||||||
@@ -175,6 +176,8 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
 | 
				
			|||||||
            for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
 | 
					            for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
 | 
				
			||||||
                getString(i);
 | 
					                getString(i);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else if (R.id.item_log == item.getItemId()) {
 | 
				
			||||||
 | 
					            GlobalApplication.getWinBollActivityManager().startLogActivity(this);
 | 
				
			||||||
        } else if (R.id.item_about == item.getItemId()) {
 | 
					        } else if (R.id.item_about == item.getItemId()) {
 | 
				
			||||||
            LogUtils.d(TAG, "onAbout");
 | 
					            LogUtils.d(TAG, "onAbout");
 | 
				
			||||||
        } else if (android.R.id.home == item.getItemId()) {
 | 
					        } else if (android.R.id.home == item.getItemId()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,8 +13,10 @@ import android.content.ServiceConnection;
 | 
				
			|||||||
import android.graphics.drawable.Drawable;
 | 
					import android.graphics.drawable.Drawable;
 | 
				
			||||||
import android.os.IBinder;
 | 
					import android.os.IBinder;
 | 
				
			||||||
import cc.winboll.studio.libaes.winboll.AssistantService;
 | 
					import cc.winboll.studio.libaes.winboll.AssistantService;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.GlobalApplication;
 | 
				
			||||||
import cc.winboll.studio.libappbase.LogUtils;
 | 
					import cc.winboll.studio.libappbase.LogUtils;
 | 
				
			||||||
import cc.winboll.studio.libappbase.utils.ServiceUtils;
 | 
					import cc.winboll.studio.libappbase.utils.ServiceUtils;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libapputils.utils.PrefUtils;
 | 
				
			||||||
import com.hjq.toast.ToastUtils;
 | 
					import com.hjq.toast.ToastUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class WinBollClientService extends Service implements IWinBollClientServiceBinder {
 | 
					public class WinBollClientService extends Service implements IWinBollClientServiceBinder {
 | 
				
			||||||
@@ -161,16 +163,40 @@ public class WinBollClientService extends Service implements IWinBollClientServi
 | 
				
			|||||||
                    // 设置运行状态
 | 
					                    // 设置运行状态
 | 
				
			||||||
                    mIsWinBollClientThreadRunning = true;
 | 
					                    mIsWinBollClientThreadRunning = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    //ToastUtils.show("run()");
 | 
					                    ToastUtils.show("run()");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // 唤醒守护进程
 | 
					                    // 唤醒守护进程
 | 
				
			||||||
                    //wakeupAndBindAssistant();
 | 
					                    //wakeupAndBindAssistant();
 | 
				
			||||||
 | 
					                    String username = "";
 | 
				
			||||||
 | 
					                    String password = "";
 | 
				
			||||||
 | 
					                    String targetUrl= "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (GlobalApplication.isDebuging()) {
 | 
				
			||||||
 | 
					                        username = PrefUtils.getString(WinBollClientService.this, "metDevUserName", "");
 | 
				
			||||||
 | 
					                        password = PrefUtils.getString(WinBollClientService.this, "metDevUserPassword", "");
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        username = "WinBoll";
 | 
				
			||||||
 | 
					                        password = "WinBollPowerByZhanGSKen";
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    targetUrl = "https://" + (GlobalApplication.isDebuging() ?"dev": "www") + ".winboll.cc/api"; // 替换为实际测试的URL
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    while (mIsEnableService) {
 | 
					                    while (mIsEnableService) {
 | 
				
			||||||
                        // 显示运行状态
 | 
					                        // 显示运行状态
 | 
				
			||||||
                        ToastUtils.show(TAG + " is running.");
 | 
					                        LogUtils.d(TAG, String.format("targetUrl %s", targetUrl));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        WinBollServerConnectionTestThread testThread = new WinBollServerConnectionTestThread(
 | 
				
			||||||
 | 
					                            targetUrl,
 | 
				
			||||||
 | 
					                            username,
 | 
				
			||||||
 | 
					                            password,
 | 
				
			||||||
 | 
					                            15000,  // 连接超时15秒
 | 
				
			||||||
 | 
					                            20000,  // 读取超时20秒
 | 
				
			||||||
 | 
					                            3       // 最大重试次数
 | 
				
			||||||
 | 
					                        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        testThread.start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        try {
 | 
					                        try {
 | 
				
			||||||
                            Thread.sleep(2 * 1000);
 | 
					                            Thread.sleep(60 * 1000);
 | 
				
			||||||
                        } catch (InterruptedException e) {
 | 
					                        } catch (InterruptedException e) {
 | 
				
			||||||
                            LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
 | 
					                            LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,118 @@
 | 
				
			|||||||
 | 
					package cc.winboll.studio.libaes.winboll;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @Author ZhanGSKen@AliYun.Com
 | 
				
			||||||
 | 
					 * @Date 2025/03/29 15:57:28
 | 
				
			||||||
 | 
					 * @Describe WinBoll 服务器服务情况测试访问进程。
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.LogUtils;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import okhttp3.Authenticator;
 | 
				
			||||||
 | 
					import okhttp3.Credentials;
 | 
				
			||||||
 | 
					import okhttp3.OkHttpClient;
 | 
				
			||||||
 | 
					import okhttp3.Request;
 | 
				
			||||||
 | 
					import okhttp3.Response;
 | 
				
			||||||
 | 
					import okhttp3.Route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class WinBollServerConnectionTestThread extends Thread {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static final String TAG = "WinBollClientService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final String url;
 | 
				
			||||||
 | 
					    private final String username;
 | 
				
			||||||
 | 
					    private final String password;
 | 
				
			||||||
 | 
					    private final int connectTimeout;
 | 
				
			||||||
 | 
					    private final int readTimeout;
 | 
				
			||||||
 | 
					    private final int maxRetries;
 | 
				
			||||||
 | 
					    private boolean testComplete = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public WinBollServerConnectionTestThread(String url, String username, String password) {
 | 
				
			||||||
 | 
					        this(url, username, password, 10000, 10000, 5);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public WinBollServerConnectionTestThread(String url, String username, String password, 
 | 
				
			||||||
 | 
					                                             int connectTimeout, int readTimeout, int maxRetries) {
 | 
				
			||||||
 | 
					        this.url = url;
 | 
				
			||||||
 | 
					        this.username = username;
 | 
				
			||||||
 | 
					        this.password = password;
 | 
				
			||||||
 | 
					        this.connectTimeout = connectTimeout;
 | 
				
			||||||
 | 
					        this.readTimeout = readTimeout;
 | 
				
			||||||
 | 
					        this.maxRetries = maxRetries;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void run() {
 | 
				
			||||||
 | 
					        OkHttpClient client = new OkHttpClient.Builder()
 | 
				
			||||||
 | 
					            .connectTimeout(connectTimeout, java.util.concurrent.TimeUnit.MILLISECONDS)
 | 
				
			||||||
 | 
					            .readTimeout(readTimeout, java.util.concurrent.TimeUnit.MILLISECONDS)
 | 
				
			||||||
 | 
					            .authenticator(new Authenticator() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public Request authenticate(Route route, Response response) throws IOException {
 | 
				
			||||||
 | 
					                    return response.request().newBuilder()
 | 
				
			||||||
 | 
					                        .header("Authorization", Credentials.basic(username, password))
 | 
				
			||||||
 | 
					                        .build();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Request request = new Request.Builder()
 | 
				
			||||||
 | 
					            .url(url)
 | 
				
			||||||
 | 
					            .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int retryCount = 0;
 | 
				
			||||||
 | 
					        while (!testComplete && retryCount <= maxRetries) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                Response response = client.newCall(request).execute();
 | 
				
			||||||
 | 
					                if (response.isSuccessful()) {
 | 
				
			||||||
 | 
					                    String responseBody = response.body().string();
 | 
				
			||||||
 | 
					                    if ("OK".equalsIgnoreCase(responseBody.trim())) {
 | 
				
			||||||
 | 
					                        LogUtils.d(TAG, "[" + new java.util.Date() + "] 测试成功,服务器返回OK");
 | 
				
			||||||
 | 
					                        testComplete = true;
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        LogUtils.d(TAG, "[" + new java.util.Date() + "] 响应内容不符合预期:" + responseBody);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    LogUtils.d(TAG, "[" + new java.util.Date() + "] 请求失败,状态码:" + response.code());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } catch (IOException e) {
 | 
				
			||||||
 | 
					                LogUtils.d(TAG, "[" + new java.util.Date() + "] 连接异常:" + e.getMessage());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!testComplete) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    Thread.sleep(2000); // 等待2秒后重试
 | 
				
			||||||
 | 
					                } catch (InterruptedException e) {
 | 
				
			||||||
 | 
					                    Thread.currentThread().interrupt();
 | 
				
			||||||
 | 
					                    LogUtils.d(TAG, "测试线程被中断");
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                retryCount++;
 | 
				
			||||||
 | 
					                LogUtils.d(TAG, "[" + new java.util.Date() + "] 第" + retryCount + "次重试...");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (testComplete) {
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "[" + new java.util.Date() + "] 达到最大重试次数,测试失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//    public static void main(String[] args) {
 | 
				
			||||||
 | 
					//        String targetUrl = "http://your-protected-server.com";
 | 
				
			||||||
 | 
					//        String username = "your_username";
 | 
				
			||||||
 | 
					//        String password = "your_password";
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//        WinBollServerConnectionTestThread testThread = new WinBollServerConnectionTestThread(
 | 
				
			||||||
 | 
					//            targetUrl,
 | 
				
			||||||
 | 
					//            username,
 | 
				
			||||||
 | 
					//            password,
 | 
				
			||||||
 | 
					//            15000,  // 连接超时15秒
 | 
				
			||||||
 | 
					//            20000,  // 读取超时20秒
 | 
				
			||||||
 | 
					//            3       // 最大重试次数
 | 
				
			||||||
 | 
					//        );
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//        testThread.start();
 | 
				
			||||||
 | 
					//    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -9,6 +9,9 @@
 | 
				
			|||||||
                android:title="TestAppCrash"/>
 | 
					                android:title="TestAppCrash"/>
 | 
				
			||||||
        </menu>
 | 
					        </menu>
 | 
				
			||||||
    </item>
 | 
					    </item>
 | 
				
			||||||
 | 
					    <item
 | 
				
			||||||
 | 
					        android:id="@+id/item_log"
 | 
				
			||||||
 | 
					        android:title="Log"/>
 | 
				
			||||||
    <item
 | 
					    <item
 | 
				
			||||||
        android:id="@+id/item_about"
 | 
					        android:id="@+id/item_about"
 | 
				
			||||||
        android:title="About"/>
 | 
					        android:title="About"/>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user