refactor(layer): 消除 feature 对 runtime 的反向依赖
DeviceSyncGateway 增加 SN、白名单、应用更新、设备类型与下载服务动作;HomeViewModel、HomeActivity、UpdateActivity 改走 core 网关,runtime 仅保留纯转发实现;HomeActivity 的日志 TAG 同步改为类名。 验证::app:assembleOfficialZhanRuiRelease 编译通过,feature 层已无 runtime import。
This commit is contained in:
1 parent
e62d0443ec
commit
d8742f18ff
5 files changed
+155
-21
No files matched your search
@@ -1,15 +1,19 @@
|
||||
package com.fuying.sn.core.common.sync;
|
||||
|
||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||
import com.fuying.sn.core.data.dto.device.SnInfo;
|
||||
import com.fuying.sn.core.data.dto.statistics.MyAppUsageBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Completable;
|
||||
|
||||
/**
|
||||
* 运行时同步网关。
|
||||
*
|
||||
* <p>平台层的时间管控、前台应用管控、定位在运行过程中需要触发安装清单上报、
|
||||
* 使用时长上报与管控策略刷新,这些能力实际由 runtime 层的同步类提供。
|
||||
* 为避免 platform 反向依赖 runtime,这里只声明平台层所需的动作,
|
||||
* 为避免 platform 与 feature 反向依赖 runtime,这里只声明外部层所需的动作,
|
||||
* 由 runtime 层实现并在 Application 启动时注册到 {@link DeviceSyncGateways}。
|
||||
*
|
||||
* <p>网关只做依赖解耦,调用时机与回调顺序必须与原先的直接调用保持一致。
|
||||
@@ -68,6 +72,88 @@ public interface DeviceSyncGateway {
|
||||
*/
|
||||
void requestMyAppList(MyAppListCallback callback);
|
||||
|
||||
/**
|
||||
* 请求设备 SN 信息。
|
||||
*
|
||||
* @param callback 请求结果回调
|
||||
* @return 请求完成信号
|
||||
*/
|
||||
Completable requestSnInfo(SnInfoCallback callback);
|
||||
|
||||
/**
|
||||
* 拉取应用白名单配置。
|
||||
*
|
||||
* @param callback 拉取完成回调
|
||||
* @return 请求完成信号
|
||||
*/
|
||||
Completable requestAppWhitelist(RequestCallback callback);
|
||||
|
||||
/**
|
||||
* 检查全部已安装应用是否有新版本。
|
||||
*
|
||||
* @param callback 检查完成回调
|
||||
* @return 请求完成信号
|
||||
*/
|
||||
Completable requestAllAppUpdate(RequestCallback callback);
|
||||
|
||||
/**
|
||||
* 拉取应用总览数据。
|
||||
*
|
||||
* @param callback 拉取完成回调
|
||||
* @return 请求完成信号
|
||||
*/
|
||||
Completable requestOverallApp(RequestCallback callback);
|
||||
|
||||
/**
|
||||
* 根据 SN 返回的设备类型更新下载配置。
|
||||
*
|
||||
* @param typeId 设备类型标识
|
||||
*/
|
||||
void checkDeviceType(int typeId);
|
||||
|
||||
/**
|
||||
* 启动下载服务。
|
||||
*
|
||||
* <p>使用 Application Context 启动,避免持有界面 Context。
|
||||
*/
|
||||
void startDownloadService();
|
||||
|
||||
/**
|
||||
* SN 信息请求回调。
|
||||
*/
|
||||
interface SnInfoCallback {
|
||||
|
||||
/**
|
||||
* 收到服务端响应。
|
||||
*
|
||||
* @param response 设备 SN 响应体
|
||||
*/
|
||||
void onNext(BaseResponse<SnInfo> response);
|
||||
|
||||
/**
|
||||
* 请求失败。
|
||||
*
|
||||
* @param e 异常
|
||||
*/
|
||||
void onError(Throwable e);
|
||||
|
||||
/**
|
||||
* 请求结束。
|
||||
*/
|
||||
void onComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 无数据返回的请求完成回调。
|
||||
*/
|
||||
interface RequestCallback {
|
||||
|
||||
/**
|
||||
* 请求结束。
|
||||
*/
|
||||
void onComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装清单上报结果。
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.fuying.sn.core.base.BaseFragment;
|
||||
import com.fuying.sn.core.base.mvvm.BaseMvvmActivity;
|
||||
import com.fuying.sn.core.common.config.CommonConfig;
|
||||
import com.fuying.sn.core.common.crypto.DebugPasswordVerifier;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateways;
|
||||
import com.fuying.sn.core.common.ui.BaseFragmentPagerAdapter;
|
||||
import com.fuying.sn.core.common.ui.ToastUtil;
|
||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||
@@ -32,13 +33,12 @@ import com.fuying.sn.feature.usage.UsageFragment;
|
||||
import com.fuying.sn.platform.control.ControlManager;
|
||||
import com.fuying.sn.platform.system.DeviceManager;
|
||||
import com.fuying.sn.platform.time.TimeManager;
|
||||
import com.fuying.sn.runtime.sync.AppUpdateCoordinator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HomeActivity extends BaseMvvmActivity<HomeViewModel, ActivityHomeBinding> implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||
private static final String TAG = "MainActivity";
|
||||
private static final String TAG = "HomeActivity";
|
||||
|
||||
private String[] mAllTitle = new String[]{
|
||||
"使用统计",
|
||||
@@ -132,7 +132,7 @@ public class HomeActivity extends BaseMvvmActivity<HomeViewModel, ActivityHomeBi
|
||||
//设备已经绑定
|
||||
if (snInfoBaseResponse.code == 200) {
|
||||
SnInfo snInfo = snInfoBaseResponse.data;
|
||||
AppUpdateCoordinator.getInstance().checkDeviceType(snInfo.getType_id());
|
||||
DeviceSyncGateways.get().checkDeviceType(snInfo.getType_id());
|
||||
// mViewDataBinding.tvBindStatu.setText("设备已绑定");
|
||||
}
|
||||
//设备没有绑定
|
||||
|
||||
@@ -11,13 +11,11 @@ import com.fuying.sn.core.base.mvvm.BaseAndroidViewModel;
|
||||
import com.fuying.sn.core.common.image.BitmapUtils;
|
||||
import com.fuying.sn.core.common.crypto.CXAESUtil;
|
||||
import com.fuying.sn.core.common.device.DeviceIdUtils;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateway;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateways;
|
||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||
import com.fuying.sn.core.data.dto.device.SnInfo;
|
||||
import com.fuying.sn.core.data.remote.RequestCompletion;
|
||||
import com.fuying.sn.runtime.sync.AppInventorySync;
|
||||
import com.fuying.sn.runtime.sync.AppUpdateCoordinator;
|
||||
import com.fuying.sn.runtime.sync.DeviceProfileSync;
|
||||
import com.fuying.sn.runtime.sync.RequestCallbacks;
|
||||
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
@@ -32,8 +30,8 @@ public class HomeViewModel extends BaseAndroidViewModel {
|
||||
}
|
||||
|
||||
public void getSnInfo() {
|
||||
Disposable disposable = DeviceProfileSync.getInstance()
|
||||
.getSnInfoRequest(new DeviceProfileSync.ObserverCallback<SnInfo>() {
|
||||
Disposable disposable = DeviceSyncGateways.get()
|
||||
.requestSnInfo(new DeviceSyncGateway.SnInfoCallback() {
|
||||
@Override
|
||||
public void onNext(BaseResponse<SnInfo> response) {
|
||||
Log.e("getSnInfo", "onNext: " + response);
|
||||
@@ -64,9 +62,9 @@ public class HomeViewModel extends BaseAndroidViewModel {
|
||||
}
|
||||
|
||||
public void getAllApp() {
|
||||
Disposable disposable = AppInventorySync.getInstance().getAppWhiteListRequest(new AppInventorySync.WhiteListCallback() {
|
||||
Disposable disposable = DeviceSyncGateways.get().requestAppWhitelist(new DeviceSyncGateway.RequestCallback() {
|
||||
@Override
|
||||
public void onComplet() {
|
||||
public void onComplete() {
|
||||
}
|
||||
})
|
||||
.subscribeWith(new RequestCompletion(mDisposables, "getAppWhiteList"));
|
||||
@@ -74,7 +72,7 @@ public class HomeViewModel extends BaseAndroidViewModel {
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
Disposable disposable = AppUpdateCoordinator.getInstance().checkAllAppUpdateRequest(new RequestCallbacks.CompleteCallback() {
|
||||
Disposable disposable = DeviceSyncGateways.get().requestAllAppUpdate(new DeviceSyncGateway.RequestCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
@@ -93,7 +91,7 @@ public class HomeViewModel extends BaseAndroidViewModel {
|
||||
}
|
||||
|
||||
public void getOverallApp() {
|
||||
Disposable disposable = AppUpdateCoordinator.getInstance().getOverallAppRequest(new RequestCallbacks.CompleteCallback() {
|
||||
Disposable disposable = DeviceSyncGateways.get().requestOverallApp(new DeviceSyncGateway.RequestCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.fuying.sn.R;
|
||||
import com.fuying.sn.core.base.mvvm.BaseMvvmActivity;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateways;
|
||||
import com.fuying.sn.core.data.dto.app.AppInfo;
|
||||
import com.fuying.sn.databinding.ActivityUpdateBinding;
|
||||
import com.fuying.sn.runtime.service.DownloadService;
|
||||
import com.fuying.sn.platform.app.ApkUtils;
|
||||
import com.hjq.toast.Toaster;
|
||||
|
||||
@@ -59,12 +59,7 @@ public class UpdateActivity extends BaseMvvmActivity<UpdateViewModel, ActivityUp
|
||||
}
|
||||
|
||||
public void upgrade(View view) {
|
||||
Intent intent = new Intent(UpdateActivity.this, DownloadService.class);
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// startForegroundService(intent);
|
||||
// } else {
|
||||
startService(intent);
|
||||
// }
|
||||
DeviceSyncGateways.get().startDownloadService();
|
||||
if (mAppInfoData != null) {
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(mAppInfoData.getApp_url());
|
||||
if (null != entity) {
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package com.fuying.sn.runtime.sync;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateway;
|
||||
import com.fuying.sn.core.common.system.AppEnvironment;
|
||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||
import com.fuying.sn.core.data.dto.device.SnInfo;
|
||||
import com.fuying.sn.core.data.dto.statistics.MyAppUsageBean;
|
||||
import com.fuying.sn.runtime.service.DownloadService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.core.Completable;
|
||||
|
||||
/**
|
||||
* 同步网关实现:把平台层的动作转发给既有同步类。
|
||||
*
|
||||
@@ -66,4 +75,50 @@ public final class DeviceSyncGatewayImpl implements DeviceSyncGateway {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable requestSnInfo(SnInfoCallback callback) {
|
||||
return DeviceProfileSync.getInstance().getSnInfoRequest(new DeviceProfileSync.ObserverCallback<SnInfo>() {
|
||||
@Override
|
||||
public void onNext(BaseResponse<SnInfo> response) {
|
||||
callback.onNext(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
callback.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
callback.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable requestAppWhitelist(RequestCallback callback) {
|
||||
return AppInventorySync.getInstance().getAppWhiteListRequest(callback::onComplete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable requestAllAppUpdate(RequestCallback callback) {
|
||||
return AppUpdateCoordinator.getInstance().checkAllAppUpdateRequest(callback::onComplete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable requestOverallApp(RequestCallback callback) {
|
||||
return AppUpdateCoordinator.getInstance().getOverallAppRequest(callback::onComplete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDeviceType(int typeId) {
|
||||
AppUpdateCoordinator.getInstance().checkDeviceType(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDownloadService() {
|
||||
Context context = AppEnvironment.getContext();
|
||||
context.startService(new Intent(context, DownloadService.class));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user