From cee1bc58575dced437cbcce568af30689a6f5b98 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Mon, 23 Mar 2026 09:41:05 +0800 Subject: [PATCH] =?UTF-8?q?version:1.3.2=20fix:=20update:=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +-- .../com/xwad/os/base/BaseApplication.java | 21 +++++++ .../java/com/xwad/os/manager/AmapManager.java | 9 ++- .../com/xwad/os/service/ManagerService.java | 4 +- .../xwad/os/service/main/MainSPresenter.java | 37 +++++++++++ .../com/xwad/os/service/main/MainService.java | 61 ++++++++++++++++++- .../main/java/com/xwad/os/utils/JgyUtils.java | 11 +++- .../main/java/com/xwad/os/utils/Utils.java | 10 +-- app/src/main/res/layout/activity_download.xml | 3 +- 9 files changed, 145 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6ae1d1b..e7626c2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { minSdkVersion 23 targetSdkVersion 29 - versionCode 27 - versionName "1.2.6" + versionCode 33 + versionName "1.3.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -90,7 +90,7 @@ android { minifyEnabled false //Zipalign优化 zipAlignEnabled true - buildConfigField "String", "platform", '"tuixin"' + buildConfigField "String", "platform", '"Nature"' signingConfig signingConfigs.tuixin applicationVariants.all { variant -> variant.outputs.each { output -> @@ -111,7 +111,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //签名 signingConfig signingConfigs.tuixin - buildConfigField "String", "platform", '"tuixin"' + buildConfigField "String", "platform", '"Nature"' // 将release版本的包名重命名,加上版本及日期 applicationVariants.all { variant -> variant.outputs.each { output -> diff --git a/app/src/main/java/com/xwad/os/base/BaseApplication.java b/app/src/main/java/com/xwad/os/base/BaseApplication.java index c55ba89..3b40813 100644 --- a/app/src/main/java/com/xwad/os/base/BaseApplication.java +++ b/app/src/main/java/com/xwad/os/base/BaseApplication.java @@ -37,6 +37,11 @@ import com.xwad.os.utils.JgyUtils; import com.xwad.os.utils.OpenApkUtils; import com.xwad.os.utils.SystemUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + public class BaseApplication extends Application { private static final String TAG = "BaseApplication"; @@ -136,6 +141,22 @@ public class BaseApplication extends Application { Log.e("AliyunPush", "init cloudchannel success"); Log.e("AliyunPush", "init cloudchannel success " + pushService.getDeviceId()); MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE).encode(CommonConfig.ALIYUN_PUSH_ID, pushService.getDeviceId()); + + Set tagSets = new HashSet<>(); + tagSets.add(BuildConfig.platform); + String[] tag = new ArrayList<>(tagSets).toArray(new String[tagSets.size()]); + pushService.bindTag(CloudPushService.DEVICE_TARGET, tag, null, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(tag) + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(tag) + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n"); + } + }); } @Override diff --git a/app/src/main/java/com/xwad/os/manager/AmapManager.java b/app/src/main/java/com/xwad/os/manager/AmapManager.java index f26df0b..bec9e99 100644 --- a/app/src/main/java/com/xwad/os/manager/AmapManager.java +++ b/app/src/main/java/com/xwad/os/manager/AmapManager.java @@ -24,6 +24,7 @@ import com.xwad.os.network.NetInterfaceManager; import com.xwad.os.utils.ActivationUtil; import java.lang.reflect.Type; +import java.math.BigDecimal; import io.reactivex.rxjava3.annotations.NonNull; import io.reactivex.rxjava3.core.Observer; @@ -235,8 +236,8 @@ public class AmapManager { private void saveMapResult(MapBean mapBean) { Log.e(TAG, "saveMapResult: " + GsonUtils.toJSONString(mapBean)); mMMKV.encode(CommonConfig.MAP_LOCATION_JSON_KEY, GsonUtils.toJSONString(mapBean)); - mMMKV.encode(CommonConfig.MAP_LONGITUDE_KEY, mapBean.getLongitude()); - mMMKV.encode(CommonConfig.MAP_LATITUDE_KEY, mapBean.getLatitude()); + mMMKV.encode(CommonConfig.MAP_LONGITUDE_KEY, doubleToStringExact(mapBean.getLongitude())); + mMMKV.encode(CommonConfig.MAP_LATITUDE_KEY, doubleToStringExact(mapBean.getLatitude())); mMMKV.encode(CommonConfig.MAP_ADDRESS_KEY, mapBean.getAddress()); mMMKV.encode(CommonConfig.MAP_PROVINCE_KEY, mapBean.getProvince()); mMMKV.encode(CommonConfig.MAP_CITY_KEY, mapBean.getCity()); @@ -245,4 +246,8 @@ public class AmapManager { mMMKV.encode(CommonConfig.MAP_LOCATION_DESCRIBE_KEY, mapBean.getLocationDescribe()); } + public static String doubleToStringExact(double value) { + // 使用 BigDecimal 避免科学计数法 + return new BigDecimal(Double.toString(value)).toPlainString(); + } } diff --git a/app/src/main/java/com/xwad/os/service/ManagerService.java b/app/src/main/java/com/xwad/os/service/ManagerService.java index a570b79..c116ab5 100644 --- a/app/src/main/java/com/xwad/os/service/ManagerService.java +++ b/app/src/main/java/com/xwad/os/service/ManagerService.java @@ -251,7 +251,7 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta if (!isServiceRunning) { startService(new Intent(this, MainService.class)); } - bindService(new Intent(this, MainService.class), mServiceConnection, Context.BIND_IMPORTANT); +// bindService(new Intent(this, MainService.class), mServiceConnection, Context.BIND_IMPORTANT); PushServiceFactory.getPushControlService().setConnectionChangeListener(new PushControlService.ConnectionChangeListener() { @Override @@ -802,7 +802,7 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta soundPool.release(); soundPool = null; } - unbindService(mServiceConnection); +// unbindService(mServiceConnection); } } diff --git a/app/src/main/java/com/xwad/os/service/main/MainSPresenter.java b/app/src/main/java/com/xwad/os/service/main/MainSPresenter.java index 7f8ba92..99b3642 100644 --- a/app/src/main/java/com/xwad/os/service/main/MainSPresenter.java +++ b/app/src/main/java/com/xwad/os/service/main/MainSPresenter.java @@ -12,6 +12,8 @@ import com.hjq.toast.Toaster; import com.tencent.mmkv.MMKV; import com.trello.rxlifecycle4.RxLifecycle; import com.trello.rxlifecycle4.android.ActivityEvent; +import com.xwad.os.BuildConfig; +import com.xwad.os.activity.update.UpdateActivity; import com.xwad.os.bean.AppInfo; import com.xwad.os.bean.BaseResponse; import com.xwad.os.bean.UserInfo; @@ -285,7 +287,42 @@ public class MainSPresenter implements MainSContact.Presenter { @Override public void checkUpdate() { + NetInterfaceManager.getInstance().getUpdateObservable(BuildConfig.APPLICATION_ID) + .compose(RxLifecycle.bindUntilEvent(getLifecycle(), ActivityEvent.DESTROY)) + .subscribe(new Observer>() { + @Override + public void onSubscribe(@NonNull Disposable d) { + Log.e("checkUpdate", "onSubscribe: "); + } + @Override + public void onNext(@NonNull BaseResponse appUpdateInfoBaseResponse) { + Log.e("checkUpdate", "onNext: " + appUpdateInfoBaseResponse); + if (appUpdateInfoBaseResponse.code == 200) { + AppInfo appInfo = appUpdateInfoBaseResponse.data; + if (ApkUtils.isUpdate(mContext, appInfo)) { + Intent intent = new Intent(mContext, UpdateActivity.class); + intent.putExtra("appUpdateInfo", appInfo); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + Toaster.show("有新的版本需要更新"); + } + } else { + + } + } + + @Override + public void onError(@NonNull Throwable e) { + Log.e("checkUpdate", "onError: " + e.getMessage()); +// Toaster.show("网络连接失败"); + } + + @Override + public void onComplete() { + Log.e("checkUpdate", "onComplete: "); + } + }); } @Override diff --git a/app/src/main/java/com/xwad/os/service/main/MainService.java b/app/src/main/java/com/xwad/os/service/main/MainService.java index ec3de0a..3ce1b4a 100644 --- a/app/src/main/java/com/xwad/os/service/main/MainService.java +++ b/app/src/main/java/com/xwad/os/service/main/MainService.java @@ -30,10 +30,18 @@ import com.xwad.os.bean.SnInfo; import com.xwad.os.config.CommonConfig; import com.xwad.os.network.NetInterfaceManager; import com.xwad.os.service.SocketService; +import com.xwad.os.utils.Utils; import java.util.Calendar; import java.util.HashMap; import java.util.List; +import java.util.concurrent.TimeUnit; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.ObservableEmitter; +import io.reactivex.rxjava3.core.ObservableOnSubscribe; +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; public class MainService extends BaseRxService implements MainSContact.MainSView, NetworkUtils.OnNetworkStatusChangedListener { private static final String TAG = "MainService"; @@ -54,11 +62,54 @@ public class MainService extends BaseRxService implements MainSContact.MainSView @Override public void onConnected(NetworkUtils.NetworkType networkType) { Log.e(TAG, "onConnected: "); -// if (Utils.isScreenOn(MainService.this)) { -// mPresenter.getCloudLessonSettings(); -// } + if (Utils.isScreenOn(MainService.this)) { + mPresenter.checkUpdate(); + } + mInternetConnected.onConnected(networkType.name()); } + private InternetConnected mInternetConnected; + + public interface InternetConnected { + void onConnected(String alias); + } + + private final ObservableOnSubscribe networkSubscribe = new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + mInternetConnected = new InternetConnected() { + @Override + public void onConnected(String alias) { + Log.e(TAG, "networkSubscribe: onConnected " + alias); + emitter.onNext(alias); + } + }; + } + }; + + private Observer networkObserver = new Observer() { + @Override + public void onSubscribe(Disposable d) { + Log.e("networkObserver", "onSubscribe: "); + } + + @Override + public void onNext(String action) { + Log.e("networkObserver", "onNext: " + action); + getSystemSettings(); + } + + @Override + public void onError(Throwable e) { + Log.e("networkObserver", "onError: " + e.getMessage()); + } + + @Override + public void onComplete() { + Log.e("networkObserver", "onComplete: "); + } + }; + @Override public IBinder onBind(Intent intent) { Log.e(TAG, "onBind: "); @@ -88,7 +139,11 @@ public class MainService extends BaseRxService implements MainSContact.MainSView Log.e(TAG, "setDefault: startServices time = " + (System.currentTimeMillis() - time) + "ms"); getSystemSettings(); + mPresenter.checkUpdate(); + Observable.create(networkSubscribe) + .throttleFirst(1, TimeUnit.HOURS) + .subscribe(networkObserver); } private void getSystemSettings() { diff --git a/app/src/main/java/com/xwad/os/utils/JgyUtils.java b/app/src/main/java/com/xwad/os/utils/JgyUtils.java index aa402a1..2d7eb15 100644 --- a/app/src/main/java/com/xwad/os/utils/JgyUtils.java +++ b/app/src/main/java/com/xwad/os/utils/JgyUtils.java @@ -82,11 +82,13 @@ public class JgyUtils { public static final int HONOR_PLATFORM = 1; public static final int LENOVO_PLATFORM = 2; + public static final int NATURE_PLATFORM = 3; public static final int UNKNOW_PLATFORM = 0; public static final String HONOR_TAG = "HONOR"; public static final String LENOVO_TAG = "lenovo"; + public static final String NATURE_TAG = "Nature"; private HashSet ownApp = new HashSet() {{ @@ -475,8 +477,11 @@ public class JgyUtils { Log.i(TAG, "checkAppPlatform: " + "honer"); return HONOR_PLATFORM; } else if (LENOVO_TAG.equalsIgnoreCase(platform)) { - Log.i(TAG, "checkAppPlatform: " + "6gen1s"); + Log.i(TAG, "checkAppPlatform: " + "lenovo"); return LENOVO_PLATFORM; + } else if (NATURE_TAG.equalsIgnoreCase(platform)) { + Log.i(TAG, "checkAppPlatform: " + "nature"); + return NATURE_PLATFORM; } else { Log.i(TAG, "checkAppPlatform: " + "没有数据"); return UNKNOW_PLATFORM; @@ -493,6 +498,8 @@ public class JgyUtils { getAppPlatformCallback.AppPlatform(HONOR_PLATFORM); } else if (LENOVO_TAG.equalsIgnoreCase(platform)) { getAppPlatformCallback.AppPlatform(LENOVO_PLATFORM); + } else if (NATURE_TAG.equalsIgnoreCase(platform)) { + getAppPlatformCallback.AppPlatform(NATURE_PLATFORM); } else { getAppPlatformCallback.AppPlatform(UNKNOW_PLATFORM); } @@ -1287,7 +1294,7 @@ public class JgyUtils { // mContext.startForegroundService(new Intent(mContext, MainService.class)); // Log.e(TAG, "setDefault: startServices time = " + (System.currentTimeMillis() - time) + "ms"); // } else { - mContext.startService(new Intent(mContext, MainService.class)); + mContext.startService(new Intent(mContext, MainService.class)); // } // } } diff --git a/app/src/main/java/com/xwad/os/utils/Utils.java b/app/src/main/java/com/xwad/os/utils/Utils.java index b3c1595..6288f74 100644 --- a/app/src/main/java/com/xwad/os/utils/Utils.java +++ b/app/src/main/java/com/xwad/os/utils/Utils.java @@ -783,12 +783,12 @@ public class Utils { // Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); // context.startActivity(intent); } else { - Set devices = bluetoothAdapter.getBondedDevices(); +// Set devices = bluetoothAdapter.getBondedDevices(); StringBuilder stringBuilder = new StringBuilder(); - for (Iterator iterator = devices.iterator(); iterator.hasNext(); ) { - BluetoothDevice device = iterator.next(); - stringBuilder.append(device.getAlias()).append(";"); - } +// for (Iterator iterator = devices.iterator(); iterator.hasNext(); ) { +// BluetoothDevice device = iterator.next(); +// stringBuilder.append(device.getAlias()).append(";"); +// } Log.e(TAG, "getBluetoothList: " + stringBuilder.toString()); return stringBuilder.toString(); } diff --git a/app/src/main/res/layout/activity_download.xml b/app/src/main/res/layout/activity_download.xml index fc48b55..fbfb0e8 100644 --- a/app/src/main/res/layout/activity_download.xml +++ b/app/src/main/res/layout/activity_download.xml @@ -98,7 +98,7 @@ android:layout_height="wrap_content" android:layout_marginStart="80dp" android:layout_marginEnd="80dp" - android:layout_marginBottom="8dp" + android:layout_marginBottom="24dp" android:orientation="vertical" app:layout_constraintBottom_toTopOf="@+id/download_ok"> @@ -170,6 +170,7 @@ android:text="点击一键下载必备组件" android:textColor="#ffffff" android:textSize="12sp" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" />