version:3.3.3

fix:
update:优化网络连接
This commit is contained in:
tongtong committed 2025-05-23 17:30:23 +08:00
1 parent d4f699a7c7
commit 3dcd25b5bf
49 files changed
+581 -464

No files matched your search

@@ -12,7 +12,7 @@ import android.os.IBinder;
import android.util.Log;
public class ControlPanelService extends Service {
private static final String TAG = ControlPanelService.class.getSimpleName();
private static final String TAG = "ControlPanelService";
public ControlPanelService() {
}
@@ -28,7 +28,7 @@ import java.io.File;
// 下载管理服务
public class DownloadService extends Service {
private static final String TAG = DownloadService.class.getSimpleName();
private static final String TAG = "DownloadService";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
@@ -28,7 +28,7 @@ import com.fuying.sn.utils.ServiceAliveUtils;
* @time Created by 2018/8/17 11:27
*/
public class GuardService extends Service {
private final static String TAG = GuardService.class.getSimpleName();
private static final String TAG = "GuardService";
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
@@ -35,7 +35,7 @@ import okhttp3.RequestBody;
public class LogcatService extends Service {
public final static String LOGCAT_START_ACTION = "START";
public final static String LOGCAT_STOP_ACTION = "STOP";
private String TAG = LogcatService.class.getSimpleName();
private static final String TAG = "LogcatService";
public LogcatService() {
@@ -51,7 +51,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
* @author jgy02
*/
public class ManagerService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
private String TAG = ManagerService.class.getSimpleName();
private static final String TAG = "ManagerService";
public static final String ACTION_LOCK = "LockScreenReceiver_lockscreen";
public static final String ACTION_UNLOCK = "LockScreenReceiver_unlockscreen";
@@ -528,13 +528,13 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta
switch (action) {
case Intent.ACTION_USER_PRESENT:
case Intent.ACTION_SCREEN_ON:
sendScreenState(1);
// sendScreenState(1);
break;
case Intent.ACTION_SCREEN_OFF:
case Intent.ACTION_SHUTDOWN:
case Intent.ACTION_FACTORY_RESET:
case Intent.ACTION_MASTER_CLEAR:
sendScreenState(0);
// sendScreenState(0);
break;
default:
break;
@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.List;
public class RemoteService extends Service {
private String TAG = RemoteService.class.getSimpleName();
private static final String TAG = "RemoteService";
public RemoteService() {
}
@@ -43,7 +43,7 @@ import java.net.URI;
* @time Created by 2018/8/17 11:26
*/
public class StepService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
private final static String TAG = StepService.class.getSimpleName();
private static final String TAG = "StepService";
public JWebSocketClient client;
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
@@ -37,7 +37,7 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject;
* @author jgy02
*/
public class MainSPresenter implements MainSContact.Presenter {
private static final String TAG = MainSPresenter.class.getSimpleName();
private static final String TAG = "MainSPresenter";
private MainSContact.MainView mView;
private Context mContext;
@@ -1,7 +1,5 @@
package com.fuying.sn.service.main;
import android.app.AlarmManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -25,6 +23,7 @@ import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.blankj.utilcode.util.NetworkUtils;
import com.fuying.sn.BuildConfig;
import com.fuying.sn.base.rx.BaseRxService;
import com.fuying.sn.bean.BaseResponse;
import com.fuying.sn.bean.SnInfo;
import com.fuying.sn.config.CommonConfig;
@@ -48,12 +47,7 @@ import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import com.trello.rxlifecycle4.LifecycleProvider;
import com.trello.rxlifecycle4.LifecycleTransformer;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.ArrayList;
@@ -65,40 +59,16 @@ import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
/**
* @author jgy02
*/
public class MainService extends Service implements MainSContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
private String TAG = MainService.class.getSimpleName();
public class MainService extends BaseRxService implements MainSContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
private static final String TAG = "MainService";
public MainSPresenter mPresenter;
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
//执行所有请求的时间
long runningTime;
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
@NotNull
@Override
public Observable<ActivityEvent> lifecycle() {
return lifecycleSubject.hide();
}
@NotNull
@Override
public <T> LifecycleTransformer<T> bindUntilEvent(@NotNull ActivityEvent event) {
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
@NotNull
@Override
public <T> LifecycleTransformer<T> bindToLifecycle() {
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
}
@Override
public void onDisconnected() {
Log.e(TAG, "网络未连接");
@@ -111,27 +81,38 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
ToastUtil.show("网络已连接");
String WiFiAlias = Utils.getWifiAlias(this);
Log.e(TAG, "onConnected: WiFiAlias = " + WiFiAlias);
// NTPTimeTask task = new NTPTimeTask();
// task.execute("ntp.aliyun.com");
NTPTimeTask task = new NTPTimeTask();
task.execute("ntp.aliyun.com");
boolean reboot = mMMKV.decodeBool(CommonConfig.DEVICES_REBOOT, false);
Log.e(TAG, "onConnected: reboot = " + reboot);
// if (reboot) {
//第一次开机联网后直接连接
// TODO: 2022/11/21 有些设备联网了但是立刻请求还是失败
Log.e(TAG, "onConnected run: 15秒后请求网络");
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
// NetInterfaceManager.getInstance().updateAdminInfo();
if (JGYUtils.getInstance().isScreenOn()) {
Log.e(TAG, "getSnInfo1");
NetInterfaceManager.getInstance().getAppWhiteList(() -> {
Log.e("onConnected", "onNext: getAppWhiteList");
});
mPresenter.getSnInfo();
mPresenter.getAppAndWhite();
SPUtils.put(MainService.this, CommonConfig.JGY_FIRST_BOOT, 1);
tPushInit();
}
·// NetInterfaceManager.getInstance().updateAdminInfo();
// if (JGYUtils.getInstance().isScreenOn()) {
Log.e(TAG, "getSnInfo1");
NetInterfaceManager.getInstance().getAppWhiteList(() -> {
Log.e("onConnected", "onNext: getAppWhiteList");
});
mPresenter.getSnInfo();
mPresenter.getAppAndWhite();
SPUtils.put(MainService.this, CommonConfig.JGY_FIRST_BOOT, 1);
tPushInit();
// }
}
}, 15000);
mMMKV.encode(CommonConfig.DEVICES_REBOOT, false);
// }
// NetInterfaceManager.getInstance().updateAdminInfo();
// NetInterfaceManager.getInstance().getAppTimeControl();
// NetInterfaceManager.getInstance().getSnTimeControl();
}
@Override
@@ -150,11 +131,11 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void onCreate() {
super.onCreate();
Log.e(TAG, "onCreate: ");
NetworkUtils.registerNetworkStatusChangedListener(this);
lifecycleSubject.onNext(ActivityEvent.CREATE);
mPresenter = new MainSPresenter(this);
mPresenter.setLifecycle(lifecycleSubject);
mPresenter.setLifecycle(getLifecycleSubject());
mPresenter.attachView(this);
// if (BuildConfig.DEBUG){
@@ -163,6 +144,11 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
// Settings.System.putInt(getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, 1);
// }
boolean reboot = mMMKV.decodeBool(CommonConfig.DEVICES_REBOOT, false);
Log.e(TAG, "onCreate: reboot = " + reboot);
boolean networkConnected = JGYUtils.getInstance().isNetworkConnected();
Log.e(TAG, "onCreate: networkConnected = " + networkConnected);
// if (networkConnected && reboot) {
Log.e(TAG, "onCreate run: 20秒后请求网络");
Handler.getMain().postDelayed(new Runnable() {
@Override
@@ -180,6 +166,12 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
}
}
}, 20000);
mMMKV.encode(CommonConfig.DEVICES_REBOOT, false);
// } else {
// NetInterfaceManager.getInstance().updateAdminInfo();
// NetInterfaceManager.getInstance().getAppTimeControl();
// NetInterfaceManager.getInstance().getSnTimeControl();
// }
Log.e(TAG, "onCreate: IMEI = " + Utils.getIMEI(MainService.this));
String aole_app_forbid = Settings.System.getString(getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID);
@@ -203,13 +195,17 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
versionIsUpdate();
registerReceivers();
startService();
Settings.System.putString(getContentResolver(), CommonConfig.APP_SOURCE_WHITE_LIST, DEFAULT_SOURCE);
}
private static final String DEFAULT_SOURCE = "com.fuying.sn,com.fuying.appstore,com.fuying.fuxiaoying";
private void versionIsUpdate() {
int oldVersionCode = (int) SPUtils.get(this, CommonConfig.SN_VERSIONCODE, 0);
if (oldVersionCode < BuildConfig.VERSION_CODE) {
Log.e(TAG, "onCreate: " + "upgrade successful");
try {
Settings.System.putString(getContentResolver(), CommonConfig.APP_SOURCE_WHITE_LIST, DEFAULT_SOURCE);
new CacheUtils().cleanApplicationUserData(this, "com.aoleyun.os");
File file = new File(JGYUtils.getInstance().getDownLoadPath());
Log.e(TAG, "versionIsUpdate: " + file.getAbsolutePath());
@@ -290,7 +286,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void onDestroy() {
super.onDestroy();
lifecycleSubject.onNext(ActivityEvent.DESTROY);
NetworkUtils.unregisterNetworkStatusChangedListener(this);
mPresenter.detachView();
unregisterReceivers();
@@ -311,8 +306,9 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
protected void onPostExecute(Long aLong) {
super.onPostExecute(aLong);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setTime(aLong);
// AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// am.setTime(aLong);
SystemClock.setCurrentTimeMillis(aLong);
Log.e(TAG, "getTimeFromNtpServer: " + aLong);
tPushInit();
}
@@ -604,6 +600,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void setMyAppList() {
Log.e(TAG, "SettingFinish: " + (SystemClock.elapsedRealtime() - runningTime) + " ms");
}
}