增加使用时间同步
This commit is contained in:
64
app/src/main/java/com/uiui/sn/bean/MyAppUsageBean.java
Normal file
64
app/src/main/java/com/uiui/sn/bean/MyAppUsageBean.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package com.uiui.sn.bean;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MyAppUsageBean implements Serializable {
|
||||||
|
private static final long serialVersionUID = 5340688429095924160L;
|
||||||
|
|
||||||
|
int id;
|
||||||
|
String app_name;
|
||||||
|
String app_img;
|
||||||
|
String class_name;
|
||||||
|
long use_time;//s
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApp_name() {
|
||||||
|
return app_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApp_name(String app_name) {
|
||||||
|
this.app_name = app_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApp_img() {
|
||||||
|
return app_img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApp_img(String app_img) {
|
||||||
|
this.app_img = app_img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClass_name() {
|
||||||
|
return class_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClass_name(String class_name) {
|
||||||
|
this.class_name = class_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUse_time() {
|
||||||
|
return use_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUse_time(long use_time) {
|
||||||
|
this.use_time = use_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,13 +30,16 @@ import com.tencent.mmkv.MMKV;
|
|||||||
import com.uiui.sn.BuildConfig;
|
import com.uiui.sn.BuildConfig;
|
||||||
import com.uiui.sn.Statistics.AppInformation;
|
import com.uiui.sn.Statistics.AppInformation;
|
||||||
import com.uiui.sn.Statistics.StatisticsInfo;
|
import com.uiui.sn.Statistics.StatisticsInfo;
|
||||||
|
import com.uiui.sn.bean.AppInfo;
|
||||||
import com.uiui.sn.bean.AppUsageTime;
|
import com.uiui.sn.bean.AppUsageTime;
|
||||||
|
import com.uiui.sn.bean.MyAppUsageBean;
|
||||||
import com.uiui.sn.bean.PartTime;
|
import com.uiui.sn.bean.PartTime;
|
||||||
import com.uiui.sn.bean.RemainTime;
|
import com.uiui.sn.bean.RemainTime;
|
||||||
import com.uiui.sn.config.CommonConfig;
|
import com.uiui.sn.config.CommonConfig;
|
||||||
import com.uiui.sn.disklrucache.CacheHelper;
|
import com.uiui.sn.disklrucache.CacheHelper;
|
||||||
import com.uiui.sn.gson.GsonUtils;
|
import com.uiui.sn.gson.GsonUtils;
|
||||||
import com.uiui.sn.network.NetInterfaceManager;
|
import com.uiui.sn.network.NetInterfaceManager;
|
||||||
|
import com.uiui.sn.network.UrlAddress;
|
||||||
import com.uiui.sn.utils.JGYUtils;
|
import com.uiui.sn.utils.JGYUtils;
|
||||||
import com.uiui.sn.utils.ToastUtil;
|
import com.uiui.sn.utils.ToastUtil;
|
||||||
|
|
||||||
@@ -106,7 +109,7 @@ public class RunningAppManager {
|
|||||||
private RunningAppManager(Context context) {
|
private RunningAppManager(Context context) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
throw new RuntimeException("Context is NULL");
|
throw new RuntimeException("Context is NULL");
|
||||||
}
|
}
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mCacheHelper = new CacheHelper(context);
|
this.mCacheHelper = new CacheHelper(context);
|
||||||
registerTimeReceiver(mContext);
|
registerTimeReceiver(mContext);
|
||||||
@@ -366,7 +369,6 @@ public class RunningAppManager {
|
|||||||
mContext.startActivity(i);
|
mContext.startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a list of the recents tasks.
|
* @return a list of the recents tasks.
|
||||||
* 获取近期任务列表
|
* 获取近期任务列表
|
||||||
@@ -454,6 +456,19 @@ public class RunningAppManager {
|
|||||||
Log.i(TAG, "syncAppRemainingTime: Finish" + mRemainingTimeMap);
|
Log.i(TAG, "syncAppRemainingTime: Finish" + mRemainingTimeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*同步所有应用使用时间*/
|
||||||
|
public void synvAllAppUsageTime(List<MyAppUsageBean> myAppList) {
|
||||||
|
if (myAppList == null || myAppList.size() == 0) {
|
||||||
|
mAllAppUsageTime.clear();
|
||||||
|
} else {
|
||||||
|
// mAllAppUsageTime.clear();
|
||||||
|
for (MyAppUsageBean bean : myAppList) {
|
||||||
|
AppUsageTime appUsageTime = new AppUsageTime();
|
||||||
|
appUsageTime.setPkg(bean.getApp_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存剩余时间到缓存
|
* 保存剩余时间到缓存
|
||||||
*/
|
*/
|
||||||
@@ -534,6 +549,7 @@ public class RunningAppManager {
|
|||||||
appUsageTime.setUsageTime(1);
|
appUsageTime.setUsageTime(1);
|
||||||
} else {
|
} else {
|
||||||
appUsageTime = mGlobalUsageTime.get(pkg);
|
appUsageTime = mGlobalUsageTime.get(pkg);
|
||||||
|
appUsageTime.setAppName(getAppName(pkg));
|
||||||
appUsageTime.setUsageTime(appUsageTime.getUsageTime() + 1);
|
appUsageTime.setUsageTime(appUsageTime.getUsageTime() + 1);
|
||||||
}
|
}
|
||||||
mGlobalUsageTime.put(pkg, appUsageTime);
|
mGlobalUsageTime.put(pkg, appUsageTime);
|
||||||
@@ -549,6 +565,7 @@ public class RunningAppManager {
|
|||||||
singleAppUsageTime.setUsageTime(1);
|
singleAppUsageTime.setUsageTime(1);
|
||||||
} else {
|
} else {
|
||||||
singleAppUsageTime = mAllAppUsageTime.get(pkg);
|
singleAppUsageTime = mAllAppUsageTime.get(pkg);
|
||||||
|
singleAppUsageTime.setAppName(getAppName(pkg));
|
||||||
long singleTime = singleAppUsageTime.getUsageTime();
|
long singleTime = singleAppUsageTime.getUsageTime();
|
||||||
Log.e(TAG, "reduceAppRemainingTime: " + singleTime);
|
Log.e(TAG, "reduceAppRemainingTime: " + singleTime);
|
||||||
singleAppUsageTime.setUsageTime(singleTime + 1);
|
singleAppUsageTime.setUsageTime(singleTime + 1);
|
||||||
@@ -580,8 +597,27 @@ public class RunningAppManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getAppName(String pkg) {
|
private String getAppName(String pkg) {
|
||||||
if (TextUtils.isEmpty(pkg)) return "未知";
|
if (TextUtils.isEmpty(pkg)) {
|
||||||
|
return "未知";
|
||||||
|
}
|
||||||
|
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_ALL_PACKAGE);
|
||||||
|
if (!TextUtils.isEmpty(jsonString)) {
|
||||||
|
Type type = new TypeToken<List<AppInfo>>() {
|
||||||
|
}.getType();
|
||||||
|
Gson gson = new Gson();
|
||||||
|
List<AppInfo> appInfoList = gson.fromJson(jsonString, type);
|
||||||
|
if (appInfoList != null && appInfoList.size() != 0) {
|
||||||
|
List<AppInfo> temp = appInfoList.stream().filter(new Predicate<AppInfo>() {
|
||||||
|
@Override
|
||||||
|
public boolean test(AppInfo appInfo) {
|
||||||
|
return pkg.equals(appInfo.getApp_package());
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
if (temp.size() != 0) {
|
||||||
|
return temp.get(0).getApp_name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
PackageInfo info = null;
|
PackageInfo info = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.trello.rxlifecycle4.android.ActivityEvent;
|
|||||||
import com.uiui.sn.BuildConfig;
|
import com.uiui.sn.BuildConfig;
|
||||||
import com.uiui.sn.bean.AppInfo;
|
import com.uiui.sn.bean.AppInfo;
|
||||||
import com.uiui.sn.bean.AppStart;
|
import com.uiui.sn.bean.AppStart;
|
||||||
|
import com.uiui.sn.bean.MyAppUsageBean;
|
||||||
import com.uiui.sn.bean.OverallAppBean;
|
import com.uiui.sn.bean.OverallAppBean;
|
||||||
import com.uiui.sn.desktop.AppTimeControl;
|
import com.uiui.sn.desktop.AppTimeControl;
|
||||||
import com.uiui.sn.bean.AppUploadInfo;
|
import com.uiui.sn.bean.AppUploadInfo;
|
||||||
@@ -63,6 +64,7 @@ import com.uiui.sn.network.api.GetControlScreenshotApi;
|
|||||||
import com.uiui.sn.network.api.GetGuideApi;
|
import com.uiui.sn.network.api.GetGuideApi;
|
||||||
import com.uiui.sn.network.api.GetPublicIPApi;
|
import com.uiui.sn.network.api.GetPublicIPApi;
|
||||||
import com.uiui.sn.network.api.MachineTimeControlApi;
|
import com.uiui.sn.network.api.MachineTimeControlApi;
|
||||||
|
import com.uiui.sn.network.api.MyAppListApi;
|
||||||
import com.uiui.sn.network.api.NewestAppUpdate;
|
import com.uiui.sn.network.api.NewestAppUpdate;
|
||||||
import com.uiui.sn.network.api.OverallAppByPlatformApi;
|
import com.uiui.sn.network.api.OverallAppByPlatformApi;
|
||||||
import com.uiui.sn.network.api.QRCodeApi;
|
import com.uiui.sn.network.api.QRCodeApi;
|
||||||
@@ -477,6 +479,13 @@ public class NetInterfaceManager {
|
|||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Observable<BaseResponse<List<MyAppUsageBean>>> getMyAppListObservable() {
|
||||||
|
return mRetrofit.create(MyAppListApi.class)
|
||||||
|
.getMyAppList(Utils.getSerial())
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* execution
|
* execution
|
||||||
@@ -1856,7 +1865,7 @@ public class NetInterfaceManager {
|
|||||||
Log.e("getAllappPackage", "onNext: " + listBaseResponse);
|
Log.e("getAllappPackage", "onNext: " + listBaseResponse);
|
||||||
List<AppInfo> appInfoList = listBaseResponse.data;
|
List<AppInfo> appInfoList = listBaseResponse.data;
|
||||||
if (null != appInfoList && appInfoList.size() != 0) {
|
if (null != appInfoList && appInfoList.size() != 0) {
|
||||||
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, listBaseResponse.toString());
|
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, appInfoList.toString());
|
||||||
HashSet<String> allAppPkg = new HashSet<>();
|
HashSet<String> allAppPkg = new HashSet<>();
|
||||||
for (AppInfo appInfo : appInfoList) {
|
for (AppInfo appInfo : appInfoList) {
|
||||||
allAppPkg.add(appInfo.getApp_package());
|
allAppPkg.add(appInfo.getApp_package());
|
||||||
@@ -2570,4 +2579,36 @@ public class NetInterfaceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MyAppListCallback {
|
||||||
|
void setMyAppList(List<MyAppUsageBean> myAppList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getMyAppList(MyAppListCallback callback) {
|
||||||
|
getMyAppListObservable()
|
||||||
|
.subscribe(new Observer<BaseResponse<List<MyAppUsageBean>>>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(@NonNull Disposable d) {
|
||||||
|
Log.e("getMyAppList", "onSubscribe: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(@NonNull BaseResponse<List<MyAppUsageBean>> listBaseResponse) {
|
||||||
|
Log.e("getMyAppList", "onNext: " + listBaseResponse);
|
||||||
|
List<MyAppUsageBean> myAppUsageBeanList = listBaseResponse.data;
|
||||||
|
callback.setMyAppList(myAppUsageBeanList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(@NonNull Throwable e) {
|
||||||
|
Log.e("getMyAppList", "onError: " + e.getMessage());
|
||||||
|
onComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
Log.e("getMyAppList", "onComplete: ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public class UrlAddress {
|
|||||||
public final static String GET_APP_TIME_CONTROL = "Control/getAppTimeControl";
|
public final static String GET_APP_TIME_CONTROL = "Control/getAppTimeControl";
|
||||||
/*获取整机管控配置*/
|
/*获取整机管控配置*/
|
||||||
public final static String GET_SN_TIME_CONTROL = "Control/getSnTimeControl";
|
public final static String GET_SN_TIME_CONTROL = "Control/getSnTimeControl";
|
||||||
|
/*获取所有应用时间*/
|
||||||
|
public final static String GET_MY_APP_LIST = "app/myAppList";
|
||||||
/*浏览器网址管控*/
|
/*浏览器网址管控*/
|
||||||
public final static String SET_BROWSER_URL = "control/getBrowser";
|
public final static String SET_BROWSER_URL = "control/getBrowser";
|
||||||
/*浏览器书签管控*/
|
/*浏览器书签管控*/
|
||||||
|
|||||||
19
app/src/main/java/com/uiui/sn/network/api/MyAppListApi.java
Normal file
19
app/src/main/java/com/uiui/sn/network/api/MyAppListApi.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.uiui.sn.network.api;
|
||||||
|
|
||||||
|
import com.uiui.sn.bean.BaseResponse;
|
||||||
|
import com.uiui.sn.bean.BatchID;
|
||||||
|
import com.uiui.sn.bean.MyAppUsageBean;
|
||||||
|
import com.uiui.sn.network.UrlAddress;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
|
import retrofit2.http.GET;
|
||||||
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
|
public interface MyAppListApi {
|
||||||
|
@GET(UrlAddress.GET_MY_APP_LIST)
|
||||||
|
Observable<BaseResponse<List<MyAppUsageBean>>> getMyAppList(
|
||||||
|
@Query("sn") String sn
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -163,7 +163,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
|||||||
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, "");
|
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, "");
|
||||||
ApkUtils.writeAppPackageList(mContext, "");
|
ApkUtils.writeAppPackageList(mContext, "");
|
||||||
} else {
|
} else {
|
||||||
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, listBaseResponse.toString());
|
mCacheHelper.put(UrlAddress.GET_ALL_PACKAGE, appInfoList.toString());
|
||||||
HashSet allPkgSet = new HashSet<String>();
|
HashSet allPkgSet = new HashSet<String>();
|
||||||
for (AppInfo pkg : appInfoList) {
|
for (AppInfo pkg : appInfoList) {
|
||||||
allPkgSet.add(pkg.getApp_package());
|
allPkgSet.add(pkg.getApp_package());
|
||||||
|
|||||||
Reference in New Issue
Block a user