update:2021.03.29
fix:修改为mvp架构,顺序执行,优化连接的次数
add:
This commit is contained in:
FHT
2021-03-29 09:45:15 +08:00
parent 4c2a93cdce
commit 402fe64045
55 changed files with 6040 additions and 2906 deletions

View File

@@ -0,0 +1,127 @@
package com.mjsheng.myappstore.activity;
import android.view.View;
import com.google.gson.JsonObject;
import com.mjsheng.myappstore.base.BasePresenter;
import com.mjsheng.myappstore.base.BaseView;
public class MainContact {
public interface MainView extends BaseView {
void setBatchText(String text, int visibility);
//设置批次信息
void setClassText(String text, int visibility);
//设置班级信息
void setNumberText(String text, int visibility);
//设置学号信息
void setNameText(String text, int visibility);
//设置姓名信息
void setLockedState(boolean loocked);
//获取设备锁定状态
void setFirstConnect(boolean state);
//是否第一次联网
void sendMACFinished();
//发送mac地址
void updateDeviceInfoFinished();
//更新设备信息
void getSnTimeControlFinished();
//获取时间管控
void setAliasFinished();
//设置击关推送别名
void setTagsFinished();
//设置极光推送标签
void checkStoreUpdateFinished();
//获取应用市场更新
void checkTestUpdateFinished();
//获取测试应用更新
void buttonCheckUpdateFinished(boolean update, JsonObject jsonObject);
//手动获取设备信息更新
void getSystemSettingbegin();
//开始
//设置设备后台设置
void getAppLimitFinished(String packageList);
//获取可被写入的安装包名结束
void getDeviceBatchFinished();
//获取设备批次结束
void getForceDownloadFinished();
//获取强制下载apk结束
void getBrowserListFinished();
//获取浏览器上网管控设置结束
void getBrowserBookmarksFinished();
//获取浏览器书签设置管控结束
void getDesktopIconFinished();
//获取应用图标桌面可见性管控结束
void getAppAutoStartUpdateAndNetFinished();
//获取应用自启升级和网络权限管理结束
void getAppIDControlFinished();
//获取第三方应用子页面ID连网限制结束
void setAppinsideWebFinished();
//获取第三方应用内部网页跳转屏蔽结束
void setSystemSettingFinished();
//获取系统其他管控设置结束
/*
* MainService
* */
void setScreenLockStateFinished(boolean locked, String tips);
//设置屏幕锁状态结束
void getDefaultDesktopFinished();
//获取桌面结束
}
public interface Presenter extends BasePresenter<MainView> {
void getStudesInfo();
//获取学生信息
void getLockedState();
//获取设备锁定状态
void getFirstConnect();
//是否第一次联网
void setDisableSetting();
//关闭所有功能
void sendMACAddress();
//发送mac地址
void updateDeviceInfo();
//更新设备信息
void getSnTimeControl();
//获取时间管控
void setJpushAlias();
//设置击关推送别名
void setJpushTags();
//设置极光推送标签
void checkStoreUpdate();
//获取应用更新
void buttonCheckUpdate(View view);
//手动获取设备信息更新
void checkTestUpdate();
//获取测试应用更新
void getSystemSettingbegin();
//开始
//获取设备后台设置
void getAppLimit();
//获取可被写入的安装包名
void getDeviceBatch(String packageList);
//获取设备批次
void getForceDownload();
//获取强制下载apk
void getBrowserList();
//获取浏览器上网管控设置
void getBrowserBookmarks();
//获取浏览器书签设置管控
void getDesktopIcon();
//获取应用图标桌面可见性管控
void getAppAutoStartUpdateAndNet();
//获取应用自启升级和网络权限管理
void getAppIDControl();
//获取第三方应用子页面ID连网限制
void setAppinsideWeb();
//获取第三方应用内部网页跳转屏蔽
void setSystemSetting();
//获取系统其他管控设置
/*
* MainService
* */
void getScreenLockState();
//获取屏幕锁状态
void getDefaultDesktop();
//获取桌面
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
package com.mjsheng.myappstore.base;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public abstract class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(this.getLayoutId());
initView();
initData();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
/**
* 设置布局
*
*/
public abstract int getLayoutId();
/**
* 初始化视图
*/
public abstract void initView();
/**
* 初始化数据
*/
public abstract void initData();
}

View File

@@ -1,6 +1,5 @@
package com.mjsheng.myappstore;
package com.mjsheng.myappstore.base;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -15,42 +14,35 @@ import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.provider.Settings;
import androidx.multidex.MultiDexApplication;
import android.text.TextUtils;
import android.util.Log;
import androidx.multidex.MultiDexApplication;
import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.cookie.store.PersistentCookieStore;
import com.mjsheng.myappstore.statistics.AppInformation;
import com.mjsheng.myappstore.statistics.StatisticsInfo;
import com.mjsheng.myappstore.activity.MainActivity;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.manager.AmapManager;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.newapi.GetLockState;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.network.api.newapi.GetLockStateApi;
import com.mjsheng.myappstore.receiver.NewAppReceiver;
import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.server.StepService;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.statistics.AppInformation;
import com.mjsheng.myappstore.statistics.StatisticsInfo;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.NetworkUtils;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SystemUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.Utils;
@@ -60,11 +52,7 @@ import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@@ -80,29 +68,17 @@ import okhttp3.Response;
import okhttp3.ResponseBody;
import rx.Observable;
import rx.functions.Action1;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
/**
* Created by Administrator on 2016/2/17 0017.
*/
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
public class MyApplication extends MultiDexApplication {
private final String TAG = MyApplication.class.getSimpleName();
public static String userName = null;
public class BaseApplication extends MultiDexApplication {
private final String TAG = BaseApplication.class.getSimpleName();
public static Context context;
public static boolean LOOP_STOPING = false; //停止 循环
public static MainActivity mainActivity;
public static int ageType = 1;
private static int mSelectTimeLong = 10;
private static MyApplication instance;
private Date mStartTime;
private Date mEndTime;
private Calendar mCurrentCalendar = null;
private SimpleDateFormat mDateFormat = null;
private static List<Activity> activityList = new LinkedList();
private Handler mHandler;
public static AMapLocationClient locationClient = null;
private static BaseApplication instance;
public static Context getAppContext() {
@@ -110,9 +86,9 @@ public class MyApplication extends MultiDexApplication {
}
// 单例模式中获取唯一的ExitApplication实例
public static MyApplication getInstance() {
public static BaseApplication getInstance() {
if (null == instance) {
instance = new MyApplication();
instance = new BaseApplication();
}
return instance;
}
@@ -122,21 +98,21 @@ public class MyApplication extends MultiDexApplication {
public void onCreate() {
super.onCreate();
if (SystemUtils.IsMainProcessName(this, Process.myPid())) {
//非主进程不初始化
init();
}
}
private void init() {
NetInterfaceManager.init(this);
JGYUtils.init(this);
Configuration config = getResources().getConfiguration();
int smallestScreenWidthDp = config.smallestScreenWidthDp;
Log.e("mjsheng", "smallestScreenWidthDp=" + smallestScreenWidthDp);
//by mjsheng 激活
MySQLData.SetData(this, CommonDatas.SP_USER_VIP, "1");
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
// .setDefaultFontPath("fonts/1234.ttf")
// .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
// .setDefaultFontPath("fonts/1234.ttf")
// .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
// .setFontAttrId(R.attr.fontPath)
// .build()
// );
@@ -147,86 +123,33 @@ public class MyApplication extends MultiDexApplication {
// 初始化 JPush
//JPushInterface.init(this);
//解锁设备不需要初始化
context = getApplicationContext();
//Thread.setDefaultUncaughtExceptionHandler(this);
mDateFormat = new SimpleDateFormat("HH:mm");
initOKHttp();
context = getApplicationContext();
initOKHttp();
Aria.init(this);
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
ToastUtil.init(this);
if (!BuildConfig.DEBUG) {
catchException();
}
mHandler = new Handler();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 8.0之后需要在
registmNewAppReceiver();
startService(new Intent(this, InitJpushServer.class));
startService(new Intent(this, MainService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class));
startService(new Intent(this, MyDownloadService.class));
}
registerTimeReceiver();
registerBatteryReceiver();
registerNetworkReceiver();
//忽略电池优化
// ignoreBatteryOptimization(this);
initAmap();
}
public static AMapLocationClient getLocationClient() {
if (null == locationClient) {
initAmap();
}
return locationClient;
}
private static void initAmap() {
locationClient = new AMapLocationClient(context);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
//获取一次定位结果
//该方法默认为false
option.setOnceLocation(true);
//获取最近3s内精度最高的一次定位结果
//设置setOnceLocationLatest(boolean b)接口为true启动定位时SDK会返回最近3s内精度最高的一次定位结果
// 如果设置其为truesetOnceLocation(boolean b)接口也会被设置为true反之不会默认为false
option.setOnceLocationLatest(true);
locationClient.setLocationOption(option);
//设置定位模式为AMapLocationMode.Hight_Accuracy高精度模式
//设置定位监听
locationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
StringBuffer sb = new StringBuffer();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
sb.append(aMapLocation.getAddress() + "\n");
SPUtils.put(context, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(context, "longitude", aMapLocation.getLongitude());
SPUtils.put(context, "latitude", aMapLocation.getLatitude());
} else {
//定位失败
sb.append("定位失败" + "\n");
SPUtils.put(context, "AmapError", aMapLocation.getErrorInfo());
}
Log.e("AmapAddress", (String) SPUtils.get(context, "AmapAddress", ""));
Log.e("AmapError", (String) SPUtils.get(context, "AmapError", ""));
Log.e("addr", sb.toString());
}
});
//设置场景模式后最好调用一次stop再调用start以保证场景模式生效
locationClient.stopLocation();
locationClient.startLocation();
AmapManager.init(this);
}
@@ -249,7 +172,6 @@ public class MyApplication extends MultiDexApplication {
}
}
private NewAppReceiver mNewAppReceiver;
private void registmNewAppReceiver() {
@@ -287,10 +209,9 @@ public class MyApplication extends MultiDexApplication {
Log.e(TAG, "action:" + action);
if (action.equals(Intent.ACTION_SCREEN_ON)) {
long time = System.currentTimeMillis();
if (null != locationClient) {
locationClient.stopLocation();
locationClient.startLocation();
}
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
aMapLocationClient.stopLocation();
aMapLocationClient.startLocation();
getLockState("2", String.valueOf(time));
}
// else if (action.equals(Intent.ACTION_USER_PRESENT)) {
@@ -351,7 +272,6 @@ public class MyApplication extends MultiDexApplication {
System.exit(0);
}
}
}
private void registerBatteryReceiver() {
@@ -382,8 +302,8 @@ public class MyApplication extends MultiDexApplication {
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
int elec = (level * 100) / scale;
Log.e(TAG, "electricity:=" + elec + "%");
if (elec == 80 || elec == 50 || elec == 30) {
startService(new Intent(getBaseContext(), InitJpushServer.class));
if (elec == 50) {
startService(new Intent(getBaseContext(), MainService.class));
}
} else if (Intent.ACTION_POWER_CONNECTED.equals(action)
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)
@@ -391,9 +311,8 @@ public class MyApplication extends MultiDexApplication {
|| Intent.ACTION_BATTERY_OKAY.equals(action)
) {
Log.e(TAG, action);
startService(new Intent(getBaseContext(), InitJpushServer.class));
startService(new Intent(getBaseContext(), MainService.class));
}
}
}
@@ -424,7 +343,7 @@ public class MyApplication extends MultiDexApplication {
}
if (NetworkUtils.isConnected(getBaseContext())) {
Log.e(TAG, "NetworkStateReceiver: 网络连接成功");
startService(new Intent(getBaseContext(), InitJpushServer.class));
startService(new Intent(getBaseContext(), MainService.class));
} else {
Log.e(TAG, "NetworkStateReceiver: 网络连接失败");
}
@@ -445,7 +364,7 @@ public class MyApplication extends MultiDexApplication {
}
private void getLockState(String status, String time) {
GetLockState getLockState = Network.getLockState();
GetLockStateApi getLockState = NetInterfaceManager.getLockState();
getLockState.getLockState(Utils.getSerial(), status, time)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@@ -657,7 +576,6 @@ public class MyApplication extends MultiDexApplication {
.setCookieStore(new PersistentCookieStore()) //cookie持久化存储如果cookie不过期则一直有效
//可以设置https的证书,以下几种方案根据需要自己设置 方法一信任所有证书,不安全有风险
.setCertificates();
// com.lzy.okserver.download.DownloadManager downloadManager = DownloadService.getDownloadManager();
// downloadManager.setTargetFolder(StorageUtils.getFileRoot(this));
// downloadManager.setTargetFolder(PathUtils.getExternalDownloadsPath() + "/jgy/");
@@ -682,8 +600,12 @@ public class MyApplication extends MultiDexApplication {
localAppList.add(appInformation);
}
}
} else Log.e("fht", "今日没有打开的应用");
} else Log.e("fht", "获取信息失败");
} else {
Log.e("fht", "今日没有打开的应用");
}
} else {
Log.e("fht", "获取信息失败");
}
JSONObject data = new JSONObject();
JSONArray appinfo = new JSONArray();
@@ -756,7 +678,7 @@ public class MyApplication extends MultiDexApplication {
synchronized public void getWhitePackageList() {
OkGo.post(URLAddress.SET_WHITE_PACKAGE_LIST)
.params("sn", Utils.getSerial())
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
@@ -785,7 +707,7 @@ public class MyApplication extends MultiDexApplication {
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
if (!TextUtils.isEmpty(result)) {
LogUtils.e(result);
Log.e("writeAppPackageList", result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
@@ -920,19 +842,15 @@ public class MyApplication extends MultiDexApplication {
public void checkIsDownloading() {
List<DownloadEntity> list = Aria.download(this).getDRunningTask();
if (list == null || list.size() == 0) {
MyApplication.getInstance().setDownloadState(false);
BaseApplication.getInstance().setDownloadState(false);
} else {
MyApplication.getInstance().setDownloadState(true);
BaseApplication.getInstance().setDownloadState(true);
}
Log.e("MyApplication", "isDownloading=" + MyApplication.getInstance().isDownloading());
Log.e("MyApplication", "isDownloading=" + BaseApplication.getInstance().isDownloading());
}
@Override
public void onTerminate() {
super.onTerminate();
//销毁时需要销毁定位client
if (null != locationClient) {
locationClient.onDestroy();
}
}
}

View File

@@ -0,0 +1,10 @@
package com.mjsheng.myappstore.base;
import androidx.annotation.NonNull;
public interface BasePresenter<V extends BaseView> {
void attachView(@NonNull V view);
void detachView();
}

View File

@@ -0,0 +1,4 @@
package com.mjsheng.myappstore.base;
public interface BaseView {
}

View File

@@ -3,6 +3,7 @@ package com.mjsheng.myappstore.bean;
import java.io.Serializable;
public class Appground implements Serializable {
private static final long serialVersionUID = 4623189862812297724L;
private String packages;
private String address;

View File

@@ -17,10 +17,6 @@ public class BaseResponse<T> implements Serializable {
@NonNull
@Override
public String toString() {
return "{\n" +//
"\tcode=" + code + "\n" +//
"\tmsg='" + msg + "\'\n" +//
"\tdata=" + data + "\n" +//
'}';
return "{" + "code:" + code + "," + "msg:" + msg + "," + "data:" + data + "," + '}';
}
}

View File

@@ -0,0 +1,25 @@
package com.mjsheng.myappstore.bean;
import java.io.Serializable;
public class BrowserBookmarks implements Serializable {
private static final long serialVersionUID = 596864357553413994L;
private String homepage;
private String labelpage;
public String getHomepage() {
return homepage;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public String getLabelpage() {
return labelpage;
}
public void setLabelpage(String labelpage) {
this.labelpage = labelpage;
}
}

View File

@@ -0,0 +1,25 @@
package com.mjsheng.myappstore.bean;
import java.io.Serializable;
public class BrowserData implements Serializable {
private static final long serialVersionUID = 5199831572891077086L;
private String white;
private String black;
public String getWhite() {
return white;
}
public void setWhite(String white) {
this.white = white;
}
public String getBlack() {
return black;
}
public void setBlack(String black) {
this.black = black;
}
}

View File

@@ -8,6 +8,8 @@ public class StudentsInfo implements Serializable {
private String realname;
private String classes;
private int admin_id;
public String getBatch() {
return batch;
}

View File

@@ -1,84 +1,15 @@
package com.mjsheng.myappstore.comm;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.network.Network;
public class CommonDatas {
public static final String PACKAGE = "colorflykids";
public static String BABYINFO_CHANGE = PACKAGE + "babyinfo_change"; // 宝宝信息变更标识
public final static String SP_LOCK = "lock";//锁定用户
public final static String SP_BABY_AGE_KEY = "age_system";//子系统选择
public final static String SP_LOCK__KEY = "lock_key";//主界面选择
public final static String SP_USER_NAME = "user_name";//用户名字
public final static String SP_USER_PASSWORD = "user_password";//用户密码
public final static String SP_USER_EMAIL = "user_email";//用户信箱
public final static String SP_VERSION = "user_version";//版本信息
public final static String SP_USER_VIP = "user_vip";//用户等级
public final static String SP_USER_DATE = "user_vip_date";//体验用户使用时间段
public final static String SP_USER_ALIVE_DATE = "SP_USER_ALIVE_DATE";//用户激活时的时间
public final static String SP_USER_ALIVE_CODE = "SP_USER_ALIVE_CODE";//用户激活码
public final static String SP_BABY_HEAD = "age_head";//宝宝头像
public final static String SP_BABY_NAME = "age_name";//宝宝名字
public final static String SP_BABY_SEX = "age_sex";//宝宝性别
public final static String SP_BABY_BIRTHDAY = "age_birthday";//宝宝生日
public final static String SP_BABY_TITLE = "user_title";//宝宝称谓
public final static String SP_TOTAL_POINT = "total_point";//总积分
public final static String SP_TODAY_POINT = "today_point";//今日积分
public final static String SP_NATIONAL_RANK = "national_rank";//全国排名
public final static String SP_YESTERDAY_RANK = "yesterday_rank";//历史排名
public final static String SP_TODAY_RANK = "today_rank";//今日排名
public final static String SP_PARENT_PASSWORD = "parent_password";//家长密码
public final static String SP_OLD_PARENT_PASSWORD = "old_parent_password";//旧的家长密码
public final static String SP_CHANGE_PARENT_PASSWORD = "change_parent_password";//上传家长密码标识
public final static String SP_CHANGE_BABY_INFO = "change_baby_info";//上传宝宝信息标识
public final static String SP_CHANGE_LEARN_INFO = "change_learn_info";//上传学习日志标识
public final static String SP_TIME_CONTROL_NOW = "time_control_now";//时间控制功能临时开关
public final static String SP_TIME_CONTROL_KEY = "time_control";//时间控制功能开关
public final static String SP_TIME_CURRENT_REMAINING = "current_remaining_time";//当前剩余时间
public final static String SP_TIME_REST_REMAINING = "current_rest_time";//当前剩余休息时间
public final static String SP_BATTEY_CONTROL_KEY = "battey_control";//充电保护开关
public final static String SP_PASSWORD_LOCK = "password_lock";//家长密码开关
public final static String SP_DISTANCE_CONTROL_KEY = "distance_control";//距离感应开关
// 使用时间段
public final static String SP_SELECT_START_TIME = "start_time";
public final static String SP_SELECT_END_TIME = "end_time";
public final static String SP_OLD_START_TIME = "old_start_time";
public final static String SP_OLD_END_TIME = "old_end_time";
public final static String SP_SELECT_USE_TIME = "useTimeLong";//使用时长
public final static String SP_SELECT_REST_TIME = "restTimeLong";//休息时长
//eventbus 事件
public final static String SP_LOGIN_SUCCESS = "SP_LOGIN_SUCCESS";//账号登陆成功
public final static String ENTER_KEY = "enter_key";
// public final static String UPDATE_URL = "http://www.jiaoguanyi.com/api/update/index";
public final static String UPDATE_URL = Network.ROOT_URL + "update/index";
public final static String UPDATE_PKG = BuildConfig.APPLICATION_ID;
public static boolean IS_UPDATE_DOLOADING = false;
public static String IS_RESET = "IS_RESET";
public static int MIN_POWER = 21;
public static String FORCE_INSTALL = "FORCE_INSTALL";
public static final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
public static final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
public static final String FLAG_FIRST_ENTER = "qch_first_enter";
public final static String IS_RESET = "IS_RESET";
public final static int MIN_POWER = 21;
public final static String FORCE_INSTALL = "FORCE_INSTALL";
public final static String FLAG_FIRST_ENTER = "qch_first_enter";
}

View File

@@ -1,126 +0,0 @@
package com.mjsheng.myappstore.download;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.storage.StorageManager;
import com.blankj.utilcode.util.PathUtils;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
public class StorageUtils {
// 获取存储空间 false 内置sd卡路径true 外置sd卡路径
public static File getStoragePath(Context mContext, boolean isSDcard) {
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
Class<?> storageVolumeClazz = null;
try {
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
Method getPath = storageVolumeClazz.getMethod("getPath");
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
Object result = getVolumeList.invoke(mStorageManager);
final int length = Array.getLength(result);
for (int i = 0; i < length; i++) {
Object storageVolumeElement = Array.get(result, i);
String path = (String) getPath.invoke(storageVolumeElement);
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
if (isSDcard == removable) {
File file = new File(path);
if (file.exists()) {
return file;
}else {
if (!isSDcard) {
return Environment.getExternalStorageDirectory();
} else {
File file1 = new File("root/storage/sdcard1");
if (file1.exists()){
return file1;
}else {
File file2 = new File("storage/sdcard1");
if (file2.exists()){
return file2;
}else {
File file3 = new File("/storage/emulated/0");
if (file3.exists()){
return file3;
}else {
return null;
}
}
}
}
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static String getFileCache(Context context, String s) {
return getExternalFilesDir(context, s).getAbsolutePath();
}
public static String getFileRoot(Context context) {
return getExternalFilesDir(context, "Download").getAbsolutePath();
}
public static File getExternalFilesDir(Context context, String s) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
File path = context.getExternalFilesDir(s);
if (path != null) {
return path;
}
}
final String cacheDir = "/Android/data/" + context.getPackageName() + "/files/" + s;
return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}
// 检测文件是否存在
public static boolean isFileIsExists(String filePath){
try{
File f=new File(filePath);
if(!f.exists()){
return false;
}
}catch (Exception e) {
return false;
}
return true;
}
public static String size(long size) {
if (size / (1024 * 1024) > 0) {
float tmpSize = (float) (size) / (float) (1024 * 1024 );
DecimalFormat df = new DecimalFormat("#.##");
return "" + df.format(tmpSize) + "GB";
} else if (size / 1024 > 0) {
float tmpSize = (float) (size) / (float) 1024 ;
DecimalFormat df = new DecimalFormat("#.##");
return "" + df.format(tmpSize) + "MB";
} else if (size > 0) {
return "" + (size ) + "KB";
} else {
return "" + (size) + "KB";
}
}
}

View File

@@ -2,7 +2,7 @@ package com.mjsheng.myappstore.jpush;
import android.content.Context;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.base.BaseApplication;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
@@ -17,7 +17,7 @@ public class MyJPushMessageReceiver extends JPushMessageReceiver {
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
super.onTagOperatorResult(context, jPushMessage);
MyApplication.getInstance().onTagOperatorResult(jPushMessage);
BaseApplication.getInstance().onTagOperatorResult(jPushMessage);
}
@Override
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
@@ -28,7 +28,7 @@ public class MyJPushMessageReceiver extends JPushMessageReceiver {
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);
super.onAliasOperatorResult(context, jPushMessage);
MyApplication.getInstance().onAliasOperatorResult(jPushMessage);
BaseApplication.getInstance().onAliasOperatorResult(jPushMessage);
}
@Override

View File

@@ -0,0 +1,83 @@
package com.mjsheng.myappstore.manager;
import android.content.Context;
import android.util.Log;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.mjsheng.myappstore.utils.SPUtils;
public class AmapManager {
private static AmapManager sInstance;
private Context mContext;
public static AMapLocationClient locationClient = null;
private AmapManager(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new AmapManager(context);
}
}
public static AmapManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init AmapManager first");
}
return sInstance;
}
public AMapLocationClient getLocationClient() {
if (null == locationClient) {
initAmap();
}
return locationClient;
}
private void initAmap() {
locationClient = new AMapLocationClient(mContext);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
//获取一次定位结果:
//该方法默认为false。
option.setOnceLocation(true);
//获取最近3s内精度最高的一次定位结果
//设置setOnceLocationLatest(boolean b)接口为true启动定位时SDK会返回最近3s内精度最高的一次定位结果。
// 如果设置其为truesetOnceLocation(boolean b)接口也会被设置为true反之不会默认为false。
option.setOnceLocationLatest(true);
locationClient.setLocationOption(option);
//设置定位模式为AMapLocationMode.Hight_Accuracy高精度模式。
//设置定位监听
locationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
StringBuilder sb = new StringBuilder();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
sb.append(aMapLocation.getAddress()).append("\n");
SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(mContext, "longitude", aMapLocation.getLongitude());
SPUtils.put(mContext, "latitude", aMapLocation.getLatitude());
} else {
//定位失败
sb.append("定位失败" + "\n");
SPUtils.put(mContext, "AmapError", aMapLocation.getErrorInfo());
}
Log.e("AmapAddress", (String) SPUtils.get(mContext, "AmapAddress", ""));
Log.e("AmapError", (String) SPUtils.get(mContext, "AmapError", ""));
Log.e("addr", sb.toString());
}
});
//设置场景模式后最好调用一次stop再调用start以保证场景模式生效
locationClient.stopLocation();
locationClient.startLocation();
}
}

View File

@@ -0,0 +1,43 @@
package com.mjsheng.myappstore.manager;
import android.content.Context;
import android.util.Log;
import com.blankj.utilcode.util.PathUtils;
import java.io.File;
public class FileManager {
private static FileManager sInstance;
private Context mContext;
public FileManager(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new FileManager(context);
initFolder();
}
}
public static FileManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init FileManager first");
}
return sInstance;
}
private static void initFolder() {
File file = new File(PathUtils.getExternalDownloadsPath() + File.separator + "jgy" + File.separator);
if (!file.exists()) {
if (file.mkdirs()) {
Log.e("initFolder", "initFolder: success");
} else {
Log.e("initFolder", "initFolder: failed");
}
}
}
}

View File

@@ -0,0 +1,532 @@
package com.mjsheng.myappstore.manager;
import android.content.Context;
import android.os.Environment;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.bean.Appground;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.BrowserBookmarks;
import com.mjsheng.myappstore.bean.BrowserData;
import com.mjsheng.myappstore.bean.ForceDownloadBean;
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
import com.mjsheng.myappstore.bean.StudentsInfo;
import com.mjsheng.myappstore.network.api.AppLimitApi;
import com.mjsheng.myappstore.network.api.BrankPicApi;
import com.mjsheng.myappstore.network.api.CategoryPicApi;
import com.mjsheng.myappstore.network.api.DeselectBrowserIDApi;
import com.mjsheng.myappstore.network.api.DeselectIDApi;
import com.mjsheng.myappstore.network.api.ForceDownloadApi;
import com.mjsheng.myappstore.network.api.NetAndLaunchApi;
import com.mjsheng.myappstore.network.api.ProjectPicApi;
import com.mjsheng.myappstore.network.api.RankAppApi;
import com.mjsheng.myappstore.network.api.SystemSettingApi;
import com.mjsheng.myappstore.network.api.UploadAppInfoApi;
import com.mjsheng.myappstore.network.api.newapi.AppinsideWebApi;
import com.mjsheng.myappstore.network.api.newapi.BrowserBookmarksApi;
import com.mjsheng.myappstore.network.api.newapi.BrowserListApi;
import com.mjsheng.myappstore.network.api.newapi.CheckTestUpdateApi;
import com.mjsheng.myappstore.network.api.newapi.CheckUpdateApi;
import com.mjsheng.myappstore.network.api.newapi.DesktopIconApi;
import com.mjsheng.myappstore.network.api.newapi.DevicesLockedStateApi;
import com.mjsheng.myappstore.network.api.newapi.GetBatchApi;
import com.mjsheng.myappstore.network.api.newapi.GetDesktopApi;
import com.mjsheng.myappstore.network.api.newapi.GetLockStateApi;
import com.mjsheng.myappstore.network.api.newapi.JpushTagsApi;
import com.mjsheng.myappstore.network.api.newapi.MACAddressApi;
import com.mjsheng.myappstore.network.api.newapi.ScreenLockStateApi;
import com.mjsheng.myappstore.network.api.newapi.SnTimeControl;
import com.mjsheng.myappstore.network.api.newapi.StudentsInfosApi;
import com.mjsheng.myappstore.network.api.newapi.TopAppControlApi;
import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfoApi;
import com.mjsheng.myappstore.utils.Utils;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class NetInterfaceManager {
private static NetInterfaceManager sInstance;
private Context mContext;
public static final String ROOT_URL = BuildConfig.ROOT_URL;
public static final String WEBSOCKET_URL = BuildConfig.WebsocketURL;
public static final String HTTP_KEY = "YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=";
private NetInterfaceManager(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new NetInterfaceManager(context);
}
}
public static NetInterfaceManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init NetworkManager first");
}
return sInstance;
}
private static final long cacheSize = 1024 * 1024 * 32;// 缓存文件最大限制大小20M
private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径
private static Cache cache = new Cache(new File(cacheDirectory), cacheSize); //
private static final OkHttpClient okHttpClient;
private static final int timeOut = 5;
static {
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(timeOut, TimeUnit.SECONDS); // 设置连接超时时间
builder.writeTimeout(timeOut, TimeUnit.SECONDS);// 设置写入超时时间
builder.readTimeout(timeOut, TimeUnit.SECONDS);// 设置读取数据超时时间
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
builder.cache(cache);// 设置缓存
okHttpClient = builder.build();
}
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
/**
* 通过sn获取设备的信息
*
* @return
*/
public Observable<BaseResponse<StudentsInfo>> getStudesInfoObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(StudentsInfosApi.class)
.getStudentsInfo(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
/**
* 获取设备锁状态
*
* @return
*/
public Observable<BaseResponse> getDevicesLockedStateObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(DevicesLockedStateApi.class)
.getLockedState(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
/**
* 发送设备mac地址
*
* @return
*/
public Observable<BaseResponse> sendMACAddressObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(MACAddressApi.class)
.sendMACaddress(Utils.getSerial(),
Utils.getAndroid7MAC(),
JPushInterface.getRegistrationID(mContext),
Utils.getProperty("ro.custom.build.version", "获取失败"),
BuildConfig.VERSION_NAME,
Utils.getAPPVersionName(mContext)
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
/**
* 获取极光推送的tag
*
* @return
*/
public Observable<BaseResponse> getJpushTagsObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(JpushTagsApi.class)
.getJpushTags(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<BrowserData>> getBrowserListSettingObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(BrowserListApi.class)
.getBrowserList(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<BrowserBookmarks>> getBrowserBookmarksObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(BrowserBookmarksApi.class)
.getBrowserBookmarks(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getDesktopIconObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(DesktopIconApi.class)
.getDesktopIcon(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<NetAndLaunchBean> getAppAutoStartUpdateAndNetObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(NetAndLaunchApi.class)
.getNetAndLaunchApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<ResponseBody> getAppIDControlObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(DeselectIDApi.class)
.getDeselectIDApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<List<Appground>>> getAppinsideWebObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(AppinsideWebApi.class)
.getAppinsideWeb(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<ResponseBody> getSystemSettingObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(SystemSettingApi.class)
.getSystemSettingApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<ResponseBody> getAppLimitObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(AppLimitApi.class)
.getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<ForceDownloadBean> getForceDownloadObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(ForceDownloadApi.class)
.getForceDownloadApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getTestUpdateObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(CheckTestUpdateApi.class)
.getTestUpdate(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getSnTimeObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(SnTimeControl.class)
.getSnTimeControl(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getScreenLockObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(ScreenLockStateApi.class)
.getScreenLockState(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getDesktopObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(GetDesktopApi.class)
.getDesktop(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<ResponseBody> getBatchObservable() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(GetBatchApi.class)
.getBatch(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
/*
*
* API
*
* */
public static UploadAppInfoApi getUploadAppInfoApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(UploadAppInfoApi.class);
}
public static DeselectIDApi getDeselectIDApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(DeselectIDApi.class);
}
public static DeselectBrowserIDApi getDeselectBrowserIDApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(DeselectBrowserIDApi.class);
}
public static RankAppApi getRankAppApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(RankAppApi.class);
}
public static CategoryPicApi getCategoryPicApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(CategoryPicApi.class);
}
public static ProjectPicApi getProjectPicApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(ProjectPicApi.class);
}
public static BrankPicApi getBrankPicApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(BrankPicApi.class);
}
public static AppLimitApi getAppLimitApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(AppLimitApi.class);
}
public static SystemSettingApi getSystemSettingApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(SystemSettingApi.class);
}
public static NetAndLaunchApi getNetAndLaunchApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(NetAndLaunchApi.class);
}
public static ForceDownloadApi getForceDownloadApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(ForceDownloadApi.class);
}
public static GetLockStateApi getLockState() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(GetLockStateApi.class);
}
public static UpdateDeviceInfoApi getUpdateDeviceInfo() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(UpdateDeviceInfoApi.class);
}
public static GetBatchApi getBatchApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(GetBatchApi.class);
}
public static SnTimeControl getSnTimeControlApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(SnTimeControl.class);
}
public static TopAppControlApi getTopAppControlApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build().create(TopAppControlApi.class);
}
public CheckUpdateApi getUpdateApi() {
return new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build()
.create(CheckUpdateApi.class);
}
}

View File

@@ -1,5 +1,6 @@
package com.mjsheng.myappstore.network;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
@@ -15,19 +16,19 @@ import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.bean.Appground;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
import com.mjsheng.myappstore.bean.NetAndLaunchData;
import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.api.newapi.SnTimeControl;
import com.mjsheng.myappstore.network.api.newapi.TopAppControl;
import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfo;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.network.api.newapi.TopAppControlApi;
import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfoApi;
import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.ForegroundAppUtil;
import com.mjsheng.myappstore.utils.Logger;
@@ -200,7 +201,7 @@ public class HTTPInterface {
// JSONObject object = JSON.parseObject(s);
// int code = object.getInteger("code");
// String msg = object.getString("msg");
// LogUtils.e("setAppinstallInfo", msg);
// Log.e("setAppinstallInfo", msg);
// if (code == 200) {
//
// } else {
@@ -232,7 +233,7 @@ public class HTTPInterface {
// @Override
// public void onSuccess(String s, Call call, okhttp3.Response response) {
// String body = s;
// LogUtils.e("sendStartTime", body);
// Log.e("sendStartTime", body);
// }
//
// @Override
@@ -341,7 +342,6 @@ public class HTTPInterface {
} else {
Log.e("installTestAPK", "APK: " + "无更新");
}
}
synchronized public static void setJpushTags(final Context context) {
@@ -403,7 +403,7 @@ public class HTTPInterface {
synchronized public static void setHomepagtag(final Context context) {
//7.0setPackage不加没有问题,.setPackage("com.android.settings")10.0需要加上,待底层修改后
OkGo.post(URLAddress.SET_HOMEPAG_TAG)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
@@ -442,7 +442,6 @@ public class HTTPInterface {
websiteBookMark.putExtra("websiteBookMark", "Invalid");
}
context.sendBroadcast(websiteBookMark);
} else {
Intent intent1 = new Intent("qch_app_brower_homepage");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -475,7 +474,7 @@ public class HTTPInterface {
synchronized public static void setAppinsideWeb(final Context context) {
OkGo.post(URLAddress.SET_APPINSIDEWEB)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
@@ -560,7 +559,7 @@ public class HTTPInterface {
//设置浏览器黑白名单
synchronized public static void setBrowserList(final Context context) {
OkGo.post(URLAddress.SET_BROWSER_LIST)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
@@ -602,7 +601,7 @@ public class HTTPInterface {
public static void setHideDesktopIcon(final Context context) {
OkGo.post(URLAddress.GET_HIDE_DESKTOPICON)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
@@ -655,13 +654,12 @@ public class HTTPInterface {
synchronized public static void getNetAndLaunchSetting(final Context context) {
OkGo.post(URLAddress.NET_AND_LAUNCH_API)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
NetAndLaunchBean netAndLaunchBeanList = JSON.parseObject(s, NetAndLaunchBean.class);
LogUtils.e(s);
switch (netAndLaunchBeanList.getCode()) {
case 200:
setNetAndlaunch(netAndLaunchBeanList, context);
@@ -678,7 +676,7 @@ public class HTTPInterface {
}
private static void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean, Context context) {
LogUtils.e("联网和自启管控:" + netAndLaunchBean.toString());
Log.e("setNetAndlaunch", netAndLaunchBean.toString());
String net_ok = "";
String net_not = "";
String launch = "";
@@ -754,15 +752,15 @@ public class HTTPInterface {
if (!TextUtils.isEmpty(slide_not)) {
slide_not = slide_not.substring(0, slide_not.length() - 1);
boolean writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_disable_slide", slide_not);
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
Log.e("setNetAndlaunch", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
} else {
boolean writeSucceed = Settings.System.putString(context.getContentResolver(), "qch_disable_slide", "Invalid");
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
Log.e("setNetAndlaunch", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
}
Utils.writeDisableUpdateList(context, upgrade_not.split(","), upgrade_ok.split(","));
LogUtils.e("launch:" + launch + "-----------net_ok:" + net_ok + "-----------net_not:" + net_not);
Log.e("setNetAndlaunch", "launch:" + launch + "-----------net_ok:" + net_ok + "-----------net_not:" + net_not);
boolean qch_app_power_on = Settings.System.putString(context.getContentResolver(), "qch_app_power_on", launch);
// Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
@@ -778,7 +776,7 @@ public class HTTPInterface {
Log.e("fht", "ban::" + net_not);
}
MyApplication.getInstance().setFinished(true);
BaseApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", net_ok);
@@ -794,6 +792,7 @@ public class HTTPInterface {
// context.sendBroadcast(intent1);
}
@SuppressLint("NewApi")
public static void updateDeviceInfo(Context context) {
String address = String.valueOf(SPUtils.get(context, "AmapAddress", "-"));
String longitude = String.valueOf(SPUtils.get(context, "longitude", "0"));
@@ -802,10 +801,10 @@ public class HTTPInterface {
jsonObject.put("address", address);
jsonObject.put("longitude", longitude);
jsonObject.put("latitude", latitude);
UpdateDeviceInfo updateDeviceInfo = Network.getUpdateDeviceInfo();
UpdateDeviceInfoApi updateDeviceInfo = NetInterfaceManager.getUpdateDeviceInfo();
updateDeviceInfo.updateDeviceInfo(
Utils.getSerial(),
URLAddress.HTTP_KEY,
NetInterfaceManager.HTTP_KEY,
Utils.getMachine(context),
Utils.getHardware(context),
jsonObject.toJSONString()
@@ -841,7 +840,7 @@ public class HTTPInterface {
}
public static void getSnTimeControl(final Context context) {
SnTimeControl snTimeControl = Network.getSnTimeControlApi();
SnTimeControl snTimeControl = NetInterfaceManager.getSnTimeControlApi();
snTimeControl.getSnTimeControl(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@@ -879,14 +878,14 @@ public class HTTPInterface {
@Override
public void onComplete() {
Intent intent = new Intent();
intent.setAction(InitJpushServer.TimeChangedReceiver.ACTION_UPDATE);
intent.setAction(MainService.TimeChangedReceiver.ACTION_UPDATE);
context.sendBroadcast(intent);
}
});
}
public static void getTopAppControl(final Context context) {
TopAppControl topAppControl = Network.getTopAppControlApi();
TopAppControlApi topAppControl = NetInterfaceManager.getTopAppControlApi();
topAppControl.getSnAppControl(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())

View File

@@ -1,330 +0,0 @@
package com.mjsheng.myappstore.network;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.network.api.AppLimitApi;
import com.mjsheng.myappstore.network.api.BrankPicApi;
import com.mjsheng.myappstore.network.api.CategoryPicApi;
import com.mjsheng.myappstore.network.api.DeselectBrowserIDApi;
import com.mjsheng.myappstore.network.api.DeselectIDApi;
import com.mjsheng.myappstore.network.api.ForceDownloadApi;
import com.mjsheng.myappstore.network.api.NetAndLaunchApi;
import com.mjsheng.myappstore.network.api.ProjectPicApi;
import com.mjsheng.myappstore.network.api.RankAppApi;
import com.mjsheng.myappstore.network.api.SystemSettingApi;
import com.mjsheng.myappstore.network.api.UpdateApi;
import com.mjsheng.myappstore.network.api.UploadAppInfoApi;
import com.mjsheng.myappstore.network.api.newapi.GetBatchApi;
import com.mjsheng.myappstore.network.api.newapi.GetLockState;
import com.mjsheng.myappstore.network.api.newapi.SnTimeControl;
import com.mjsheng.myappstore.network.api.newapi.TopAppControl;
import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfo;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* 作者 mjsheng
* 日期 2018/5/7 04:10
* 邮箱 501802639@qq.com
* 来自:
*/
public class Network {
// public static final String ROOT_URL = "http://www.as.xueshibao.com.cn/api/"; 弃用
// public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用
// public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式
// public static final String WebsocketURL = "ws://47.107.133.19:1234";
// public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试
// public static final String WebsocketURL = "ws://47.107.133.19:2345";
public static final String ROOT_URL = BuildConfig.ROOT_URL;
public static final String WebsocketURL = BuildConfig.WebsocketURL;
private static UploadAppInfoApi uploadAppInfoApi;
private static DeselectIDApi deselectIDApi;
private static DeselectBrowserIDApi deselectBrowserIDApi;
private static RankAppApi rankAppApi;
private static CategoryPicApi categoryPicApi;
private static ProjectPicApi projectPicApi;
private static BrankPicApi brankPicApi;
private static AppLimitApi appLimitApi;
private static SystemSettingApi systemSettingApi;
private static UpdateApi updateApi;
private static NetAndLaunchApi netAndLaunchApi;
private static ForceDownloadApi forceDownloadApi;
private static GetLockState getLockState;
private static UpdateDeviceInfo updateDeviceInfo;
private static GetBatchApi getBatchApi;
private static SnTimeControl SnTimeControlApi;
private static TopAppControl TopAppControlApi;
private static final long cacheSize = 1024 * 1024 * 20;// 缓存文件最大限制大小20M
private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径
private static Cache cache = new Cache(new File(cacheDirectory), cacheSize); //
private static final OkHttpClient cacheClient;
static {
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(8, TimeUnit.SECONDS); // 设置连接超时时间
builder.writeTimeout(8, TimeUnit.SECONDS);// 设置写入超时时间
builder.readTimeout(8, TimeUnit.SECONDS);// 设置读取数据超时时间
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
// builder.cache(cache);// 设置缓存
cacheClient = builder.build();
}
private static OkHttpClient okHttpClient = new OkHttpClient();
// private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
public static UploadAppInfoApi getUploadAppInfoApi() {
if (uploadAppInfoApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
uploadAppInfoApi = retrofit.create(UploadAppInfoApi.class);
}
Log.e("mjsheng", "UploadAppInfoApi");
return uploadAppInfoApi;
}
public static DeselectIDApi getDeselectIDApi() {
if (deselectIDApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
deselectIDApi = retrofit.create(DeselectIDApi.class);
}
Log.e("mjsheng", "DeselectIDApi");
return deselectIDApi;
}
public static DeselectBrowserIDApi getDeselectBrowserIDApi() {
if (deselectBrowserIDApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
deselectBrowserIDApi = retrofit.create(DeselectBrowserIDApi.class);
}
Log.e("mjsheng", "DeselectIDApi");
return deselectBrowserIDApi;
}
public static RankAppApi getRankAppApi() {
if (rankAppApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
rankAppApi = retrofit.create(RankAppApi.class);
}
Log.e("mjsheng", "RankAppApi");
return rankAppApi;
}
public static CategoryPicApi getCategoryPicApi() {
if (categoryPicApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
categoryPicApi = retrofit.create(CategoryPicApi.class);
}
Log.e("mjsheng", "CategoryPicApi");
return categoryPicApi;
}
public static ProjectPicApi getProjectPicApi() {
if (projectPicApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
projectPicApi = retrofit.create(ProjectPicApi.class);
}
Log.e("mjsheng", "projectPicApi");
return projectPicApi;
}
public static BrankPicApi getBrankPicApi() {
if (brankPicApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
brankPicApi = retrofit.create(BrankPicApi.class);
}
Log.e("mjsheng", "brankPicApi");
return brankPicApi;
}
public static AppLimitApi getAppLimitApi() {
if (appLimitApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
appLimitApi = retrofit.create(AppLimitApi.class);
}
Log.e("mjsheng", "appLimitApi");
return appLimitApi;
}
public static SystemSettingApi getSystemSettingApi() {
if (systemSettingApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
systemSettingApi = retrofit.create(SystemSettingApi.class);
}
Log.e("mjsheng", "systemSettingApi");
return systemSettingApi;
}
public static UpdateApi getUpdateApi() {
if (updateApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
updateApi = retrofit.create(UpdateApi.class);
}
Log.e("mjsheng", "systemSettingApi");
return updateApi;
}
public static NetAndLaunchApi getNetAndLaunchApi() {
if (netAndLaunchApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
netAndLaunchApi = retrofit.create(NetAndLaunchApi.class);
}
Log.e("mjsheng", "netAndLaunchApi");
return netAndLaunchApi;
}
public static ForceDownloadApi getForceDownloadApi() {
if (forceDownloadApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
forceDownloadApi = retrofit.create(ForceDownloadApi.class);
}
Log.e("mjsheng", "forceDownloadApi");
return forceDownloadApi;
}
public static GetLockState getLockState() {
if (getLockState == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
getLockState = retrofit.create(GetLockState.class);
}
Log.e("mjsheng", "forceDownloadApi");
return getLockState;
}
public static UpdateDeviceInfo getUpdateDeviceInfo() {
if (updateDeviceInfo == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
updateDeviceInfo = retrofit.create(UpdateDeviceInfo.class);
}
return updateDeviceInfo;
}
public static GetBatchApi getBatchApi() {
if (getBatchApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
getBatchApi = retrofit.create(GetBatchApi.class);
}
return getBatchApi;
}
public static SnTimeControl getSnTimeControlApi() {
if (SnTimeControlApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
SnTimeControlApi = retrofit.create(SnTimeControl.class);
}
return SnTimeControlApi;
}
public static TopAppControl getTopAppControlApi() {
if (TopAppControlApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(cacheClient)
.baseUrl(ROOT_URL)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
TopAppControlApi = retrofit.create(TopAppControl.class);
}
return TopAppControlApi;
}
}

View File

@@ -1,20 +1,18 @@
package com.mjsheng.myappstore.network;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
/**
* @author Administrator
*/
public class URLAddress {
//http tag
public static final String HTTP_KEY = "YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=";
private static final String HTTP_TAG_HEAD_NEW = NetInterfaceManager.ROOT_URL;
private static final String HTTP_TAG_HEAD_NEW = Network.ROOT_URL;
// 下载接口 根据包名匹配 请求后更新下载次数
public static final String HTTP_TAG_DOWNLOAD_URL = HTTP_TAG_HEAD_NEW + "count/index";
// 下载接口 根据包名匹配 请求后更新下载次数
public static final String SEND_DOWNLOAD_FILE_INFO = HTTP_TAG_HEAD_NEW + "app/downloadApp";
public static final String HTTP_TAG_FIRST = HTTP_TAG_HEAD_NEW + "lock/index";
public static final String GET_DEVICES_LOCKED = HTTP_TAG_HEAD_NEW + "lock/index";
public static final String SEND_DEVICES = HTTP_TAG_HEAD_NEW + "Mac/getMac";
@@ -42,7 +40,7 @@ public class URLAddress {
//通过sn获取信息
public static final String SEND_SCREENSHOT = HTTP_TAG_HEAD_NEW + "Screenshot/addImg";
//上传截图
// public static final String UPDATE_DEVICEINFO = HTTP_TAG_HEAD_NEW + "Mac/getInfo";
//public static final String UPDATE_DEVICEINFO = HTTP_TAG_HEAD_NEW + "Mac/getInfo";
//上传我的设备
public final static String GET_LOCK_SCREEN_STATE = HTTP_TAG_HEAD_NEW + "Sn/getSnScreen";
//获取霸屏状态

View File

@@ -0,0 +1,22 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.Appground;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface AppinsideWebApi {
@FormUrlEncoded
@POST(URLAddress.SET_APPINSIDEWEB)
Observable<BaseResponse<List<Appground>>> getAppinsideWeb(
@Field("key") String key,
@Field("sn") String sn
);
}

View File

@@ -0,0 +1,19 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.BrowserBookmarks;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface BrowserBookmarksApi {
@FormUrlEncoded
@POST(URLAddress.SET_HOMEPAG_TAG)
Observable<BaseResponse<BrowserBookmarks>> getBrowserBookmarks(
@Field("key") String key,
@Field("sn") String sn
);
}

View File

@@ -0,0 +1,19 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.BrowserData;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface BrowserListApi {
@FormUrlEncoded
@POST(URLAddress.SET_BROWSER_LIST)
Observable<BaseResponse<BrowserData>> getBrowserList(
@Field("key") String key,
@Field("sn") String sn
);
}

View File

@@ -0,0 +1,15 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface CheckTestUpdateApi {
@GET(URLAddress.GET_SN_APP_TEST)
Observable<BaseResponse> getTestUpdate(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,17 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface CheckUpdateApi {
@FormUrlEncoded
@POST(URLAddress.CHECK_UPDATE)
Observable<BaseResponse> getUpdate(
@Field("package") String packages
);
}

View File

@@ -0,0 +1,19 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.BrowserBookmarks;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface DesktopIconApi {
@FormUrlEncoded
@POST(URLAddress.GET_HIDE_DESKTOPICON)
Observable<BaseResponse> getDesktopIcon(
@Field("key") String key,
@Field("sn") String sn
);
}

View File

@@ -0,0 +1,17 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface DevicesLockedStateApi {
@FormUrlEncoded
@POST(URLAddress.GET_DEVICES_LOCKED)
Observable<BaseResponse> getLockedState(
@Field("sn") String sn
);
}

View File

@@ -0,0 +1,15 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface GetDesktopApi {
@GET(URLAddress.GET_DESKTOP)
Observable<BaseResponse> getDesktop(
@Query("sn") String sn
);
}

View File

@@ -6,7 +6,7 @@ import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface GetLockState {
public interface GetLockStateApi {
@FormUrlEncoded
@POST("Application/getLockState")
Observable<ResponseBody> getLockState(

View File

@@ -0,0 +1,15 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface JpushTagsApi {
@GET(URLAddress.GET_DEVICES_TAGS)
Observable<BaseResponse> getJpushTags(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,23 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.StudentsInfo;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface MACAddressApi {
@FormUrlEncoded
@POST(URLAddress.SEND_DEVICES)
Observable<BaseResponse> sendMACaddress(
@Field("sn") String sn,
@Field("mac") String mac,
@Field("jpush_id") String jpushId,
@Field("devices_version") String devicesVersion,
@Field("appstore_version") String appstoreVersion,
@Field("store_version") String storeVersion
);
}

View File

@@ -0,0 +1,15 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface ScreenLockStateApi {
@GET(URLAddress.GET_LOCK_SCREEN_STATE)
Observable<BaseResponse> getScreenLockState(
@Query("sn") String sn
);
}

View File

@@ -0,0 +1,18 @@
package com.mjsheng.myappstore.network.api.newapi;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.StudentsInfo;
import com.mjsheng.myappstore.network.URLAddress;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface StudentsInfosApi {
@FormUrlEncoded
@POST(URLAddress.GET_STUDENTS_INFO)
Observable<BaseResponse<StudentsInfo>> getStudentsInfo(
@Field("sn") String sn
);
}

View File

@@ -7,7 +7,7 @@ import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface TopAppControl {
public interface TopAppControlApi {
@GET(URLAddress.GET_TOP_APP_CONTROL)
Observable<BaseResponse> getSnAppControl(
@Query("sn") String sn

View File

@@ -6,7 +6,7 @@ import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface UpdateDeviceInfo {
public interface UpdateDeviceInfoApi {
@FormUrlEncoded
@POST("Mac/getInfo")
Observable<ResponseBody> updateDeviceInfo(

View File

@@ -7,8 +7,7 @@ import android.util.Log;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.server.StepService;
public class BootReceiver extends BroadcastReceiver {
@@ -56,12 +55,8 @@ public class BootReceiver extends BroadcastReceiver {
}
private void startService(Context context) {
Intent intent = new Intent(context, InitJpushServer.class);
// intent.putExtra("boot","BOOT_COMPLETED");
context.startService(intent);
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, MyDownloadService.class));
context.startService(new Intent(context, MainService.class));
}
}

View File

@@ -20,18 +20,18 @@ import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.manager.AmapManager;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.CmdUtil;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.utils.ForegroundAppUtil;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.SPUtils;
@@ -61,8 +61,6 @@ import okhttp3.ResponseBody;
public class MyJPushReceiver extends BroadcastReceiver {
private static final String TAG = "MyJPushReceiver";
private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
private final String MSG_DELETE = "1";//删除应用
@@ -122,15 +120,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private Context mContext;
private int changeNum(int paramInt) {
switch (paramInt) {
default:
return 1;
case 0:
return 1;
case 1:
break;
}
return 0;
return paramInt == 0 ? 1 : 0;
}
@Override
@@ -153,7 +143,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA));
// doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA));
// LogUtils.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------");
// Log.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
@@ -176,7 +166,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
String package_name = bundle.getString("package_name");
LogUtils.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
Log.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
// ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name);
// Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show();
switch (message) {
@@ -233,7 +223,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
settingCamera(extras);
break;
case MSG_ONEPACKAGES:
if (MyApplication.getInstance().isFinished()) {
if (BaseApplication.getInstance().isFinished()) {
settingOneNet(extras);
}
break;
@@ -241,11 +231,11 @@ public class MyJPushReceiver extends BroadcastReceiver {
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(extras);
String random = jsonObject.getString("random");
String sendType = jsonObject.getString("type");
MyApplication.sendAppUsedTime(random, sendType);
BaseApplication.sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/");
if (!file.exists()){
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(extras)) {
@@ -299,7 +289,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
Utils.rebootDevices(mContext);
break;
case GET_DEVICES_INFO:
AMapLocationClient aMapLocationClient = MyApplication.getLocationClient();
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
aMapLocationClient.stopLocation();
aMapLocationClient.startLocation();
aMapLocationClient.setLocationListener(new AMapLocationListener() {
@@ -354,14 +344,14 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void setLock_screen(int state, Context context, String name) {
if (ServiceAliveUtils.isServiceAlice(context)) {
context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, MainService.class));
}
Intent intent = new Intent();
intent.putExtra("name", name);
if (state == 1) {
intent.setAction(InitJpushServer.LockScreenReceiver.action_lock);
intent.setAction(MainService.LockScreenReceiver.action_lock);
} else if (state == 0) {
intent.setAction(InitJpushServer.LockScreenReceiver.action_unlock);
intent.setAction(MainService.LockScreenReceiver.action_unlock);
}
context.sendBroadcast(intent);
}
@@ -631,7 +621,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void doDownloadAndInstall(String s) {
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/");
if (!file.exists()){
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(s)) {
@@ -693,42 +683,46 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void getAppLimitApi() {
Network.getAppLimitApi().getAppLimitApi(URLAddress.HTTP_KEY, Utils.getSerial()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ResponseBody>() {
@Override
public void onComplete() {
}
@Override
public void onError(Throwable param1Throwable) {
Log.e("mjsheng", "getAppLimitApi=onError:");
}
@Override
public void onNext(ResponseBody param1ResponseBody) {
try {
String str1;
String str2 = param1ResponseBody.string();
Log.e("mjsheng", str2);
JSONObject jSONObject = new JSONObject(str2);
switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
case 200:
str1 = jSONObject.getJSONObject("data").optString("result");
writeAppPackageList(str1);
return;
NetInterfaceManager.getAppLimitApi()
.getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@Override
public void onComplete() {
}
Log.e("mjsheng", "getAppLimitApi---code is -200");
return;
} catch (Exception e) {
Log.e("mjsheng", "getAppLimitApi---woring----" + e.getMessage());
e.printStackTrace();
return;
}
}
@Override
public void onSubscribe(Disposable param1Disposable) {
}
});
@Override
public void onError(Throwable param1Throwable) {
Log.e("mjsheng", "getAppLimitApi=onError:");
}
@Override
public void onNext(ResponseBody param1ResponseBody) {
try {
String str1;
String str2 = param1ResponseBody.string();
Log.e("mjsheng", str2);
JSONObject jSONObject = new JSONObject(str2);
switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
case 200:
str1 = jSONObject.getJSONObject("data").optString("result");
writeAppPackageList(str1);
return;
}
Log.e("mjsheng", "getAppLimitApi---code is -200");
return;
} catch (Exception e) {
Log.e("mjsheng", "getAppLimitApi---woring----" + e.getMessage());
e.printStackTrace();
return;
}
}
@Override
public void onSubscribe(Disposable param1Disposable) {
}
});
}
// private void getForceDownload() {
@@ -758,7 +752,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
// Log.e("fht", "qch_force_app:" + qch_force_app);
// break;
// default:
// LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg());
// Log.e("getForceDownload is error:" + forceDownloadBean.getMsg());
// }
// }
//
@@ -885,7 +879,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private void getDeselectID() {
Network.getDeselectIDApi()
NetInterfaceManager.getDeselectIDApi()
.getDeselectIDApi("YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=",
Utils.getSerial())
.subscribeOn(Schedulers.io())
@@ -1102,7 +1096,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
JSONObject jSONObject = new JSONObject(s);
jSONObject.optString("ban");
String str = jSONObject.optString("not");
LogUtils.e("mjsheng", "settingPowerOn<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + str);
Log.e("mjsheng", "settingPowerOn<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + str);
Settings.System.putString(this.mContext.getContentResolver(), "qch_app_power_on", str);
Log.e("SystemSetting", "qch_app_power_on---------" + str);
return;
@@ -1118,7 +1112,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
String jgy1 = "com.uiuios.jgy1";
String jgy2 = "com.uiuios.jgy2";
if (!TextUtils.isEmpty(result)) {
LogUtils.e(result);
Log.e("writeAppPackageList", result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
@@ -1197,7 +1191,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) {
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
LogUtils.e(result);
Log.e("writeDeselectIDtoSystem", result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}

View File

@@ -20,23 +20,24 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import androidx.annotation.Nullable;
import android.text.format.Formatter;
import android.util.Log;
import androidx.annotation.Nullable;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask;
import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.mjsheng.myappstore.KeepAliveConnection;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
@@ -63,10 +64,10 @@ public class GuardService extends Service {
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
LogUtils.e(TAG, "GuardService:建立链接");
Log.e(TAG, "GuardService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(GuardService.this);
if (!isServiceRunning) {
Intent i = new Intent(GuardService.this, MyDownloadService.class);
Intent i = new Intent(GuardService.this, GuardService.class);
startService(i);
}
}
@@ -212,13 +213,13 @@ public class GuardService extends Service {
//获取移动数据连接的信息
NetworkInfo dataNetworkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) {
Log.e("fht", "WIFI已连接,移动数据已连接");
Log.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已连接");
} else if (wifiNetworkInfo.isConnected() && !dataNetworkInfo.isConnected()) {
Log.e("fht", "WIFI已连接,移动数据已断开");
Log.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已断开");
} else if (!wifiNetworkInfo.isConnected() && dataNetworkInfo.isConnected()) {
Log.e("fht", "WIFI已连接,移动数据已连接");
Log.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已连接");
} else {
Log.e("fht", "WIFI已连接,移动数据已断开");
Log.e("NetworkChangedRecceiver", "WIFI已连接,移动数据已断开");
}
//API大于23时使用下面的方式进行网络监听
} else {
@@ -236,30 +237,30 @@ public class GuardService extends Service {
sb.append(networkInfo.getTypeName() + " connect is " + networkInfo.isConnected());
}
}
Log.e("fht", sb.toString());
Log.e("NetworkChangedRecceiver", sb.toString());
}
if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) {
Log.e("fht", "wifi信号强度变化");
Log.e("NetworkChangedRecceiver", "wifi信号强度变化");
}
//wifi连接上与否
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
Log.e("fht", "wifi断开");
Log.e("NetworkChangedRecceiver", "wifi断开");
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
//获取当前wifi名称
Log.e("fht", "连接到网络 " + wifiInfo.getSSID());
Log.e("NetworkChangedRecceiver", "连接到网络 " + wifiInfo.getSSID());
time2 = System.currentTimeMillis();
if ((time2 - time1) > 60 * 1000) {
//可能会多次触发1分钟之内不执行
//application中启动服务,startcommand执行会两次
startService(new Intent(context, InitJpushServer.class));
startService(new Intent(context, MainService.class));
Aria.download(this).resumeAllTask();
time1 = time2;
Log.e("fht", "onReceive");
Log.e("NetworkChangedRecceiver", "onReceive");
}
}
}
@@ -267,9 +268,9 @@ public class GuardService extends Service {
if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
Log.e("fht", "系统关闭wifi");
Log.e("NetworkChangedRecceiver", "系统关闭wifi");
} else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
Log.e("fht", "系统开启wifi");
Log.e("NetworkChangedRecceiver", "系统开启wifi");
}
}
}
@@ -297,7 +298,7 @@ public class GuardService extends Service {
String app_package = jsonObject.getString("app_package");
ToastUtil.show(app_name + "\t:下载完成");
OkGo.post(URLAddress.HTTP_TAG_DOWNLOAD_URL)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.params("package", app_package)
.tag(this)
@@ -316,7 +317,7 @@ public class GuardService extends Service {
int userId = (int) SPUtils.get(GuardService.this, "admin_id", 0);
long app_size = task.getFileSize();
OkGo.post(URLAddress.SEND_DOWNLOAD_FILE_INFO)
.params("key", URLAddress.HTTP_KEY)
.params("key", NetInterfaceManager.HTTP_KEY)
.params("sn", Utils.getSerial())
.params("userId", userId)
.params("package_name", packageName)
@@ -342,8 +343,8 @@ public class GuardService extends Service {
// }
List<DownloadEntity> list = Aria.download(this).getDRunningTask();
if (list == null || list.size() == 0) {
MyApplication.getInstance().setDownloadState(false);
Log.e("aria", "isDownloading=" + MyApplication.getInstance().isDownloading());
BaseApplication.getInstance().setDownloadState(false);
Log.e("aria", "isDownloading=" + BaseApplication.getInstance().isDownloading());
}
}
@@ -358,7 +359,7 @@ public class GuardService extends Service {
Log.e("aria", "下载失败:" + filepath);
// ToastUtil.show(app_name + "\t:下载失败");
} catch (Exception e) {
Log.e("fht", "taskFail");
Log.e("aria", "taskFail");
}
}

View File

@@ -1,5 +1,6 @@
package com.mjsheng.myappstore.server;
import android.annotation.SuppressLint;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
@@ -28,12 +29,11 @@ import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.bean.Batch;
import com.mjsheng.myappstore.bean.ForceDownloadBean;
@@ -44,8 +44,8 @@ import com.mjsheng.myappstore.bean.NetAndLaunchData;
import com.mjsheng.myappstore.bean.StudentsInfo;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.AppLimitApi;
import com.mjsheng.myappstore.network.api.DeselectBrowserIDApi;
import com.mjsheng.myappstore.network.api.DeselectIDApi;
@@ -110,7 +110,7 @@ public class InitJpushServer extends Service {
registReceiver();
registerTimeReceiver();
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/");
if (!file.exists()){
if (!file.exists()) {
file.mkdirs();
}
// android.os.Debug.waitForDebugger();
@@ -128,9 +128,9 @@ public class InitJpushServer extends Service {
getScreenLockState();
getAppLimitApi();//获取可以写入的app包名
HTTPInterface.getNetAndLaunchSetting(this);
int first = (int) SPUtils.get(InitJpushServer.this, "first_connect", 0);
int first = (int) SPUtils.get(this, "first_connect", 0);
if (first == 0) {
SysSettingUtils.setDisableSetting(InitJpushServer.this);//设置系统管控
SysSettingUtils.setDisableSetting(this);//设置系统管控
}
timerImitate();
// getNetworkState();
@@ -140,7 +140,7 @@ public class InitJpushServer extends Service {
return START_STICKY;
}
private void getInfo() {
private void getInfo(Context context) {
OkGo.post(URLAddress.GET_STUDENTS_INFO)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@@ -150,10 +150,10 @@ public class InitJpushServer extends Service {
LzyResponse<StudentsInfo> lzyResponse = (LzyResponse<StudentsInfo>) JSON.parseObject(s, LzyResponse.class);
StudentsInfo info = lzyResponse.data;
if (lzyResponse.code == 200) {
SPUtils.put(InitJpushServer.this, "batch", info.getBatch());
SPUtils.put(InitJpushServer.this, "classes", info.getClasses());
SPUtils.put(InitJpushServer.this, "sno", info.getSno());
SPUtils.put(InitJpushServer.this, "realname", info.getRealname());
SPUtils.put(context, "batch", info.getBatch());
SPUtils.put(context, "classes", info.getClasses());
SPUtils.put(context, "sno", info.getSno());
SPUtils.put(context, "realname", info.getRealname());
}
} catch (Exception e) {
Log.e("fht", "getInfo:" + e.getMessage());
@@ -200,7 +200,7 @@ public class InitJpushServer extends Service {
screenlocked = false;
}
} catch (Exception e) {
Log.e("getScreenLockState", "onSuccess: "+e.getMessage() );
Log.e("getScreenLockState", "onSuccess: " + e.getMessage());
}
}
@@ -220,11 +220,92 @@ public class InitJpushServer extends Service {
}
};
private int changeNum(int status) {
int num = 1;
switch (status) {
case 0:
num = 1;
break;
case 1:
num = 0;
break;
default:
num = 1;
}
return num;
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 200:
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) msg.obj;
installAPK(jsonObject);
break;
case -200:
Log.e("fht", "no update");
}
}
};
private void installAPK(com.alibaba.fastjson.JSONObject jsonObject) {
String url = jsonObject.getString("url");
int versionCode = jsonObject.getInteger("version_code");
String packageName = jsonObject.getString("package");
String app_name = jsonObject.getString("app_name");
com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.versionCode < versionCode) {
// Aria.download(this)
// .load(url) //读取下载地址
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(packageName) + ".apk", true)
// .setExtendField(object.toJSONString())
// .create(); //启动下载}
Utils.ariaDownload(this, url, object);
} else {
Log.e("fht", "无需更新");
}
}
private void showTopAcivity() {
// if (true) {
// Intent intent = new Intent(this, TopActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// startActivity(intent);
// }
}
@Override
public void onDestroy() {
super.onDestroy();
if (null != lockScreenReceiver) {
unregisterReceiver(lockScreenReceiver);
}
Log.e("fht", "InitJpushServer onDestroy");
}
private static WindowManager windowManager;
private View topView;
boolean screenlocked = false;
boolean timelocked = false;
@SuppressLint("NewApi")
private void showFloatingWindow(String name) {
if (Settings.canDrawOverlays(this)) {
// 获取WindowManager服务
@@ -316,13 +397,13 @@ public class InitJpushServer extends Service {
if (TextUtils.isEmpty(action)) {
return;
}
if (action.equals(action_lock)) {
if (action_lock.equals(action)) {
String name = intent.getStringExtra("name");
if (!timelocked) {
showFloatingWindow(name);
}
screenlocked = true;
} else if (action.equals(action_unlock)) {
} else if (action_unlock.equals(action)) {
if (!timelocked) {
hideFloatingWindow();
}
@@ -353,20 +434,21 @@ public class InitJpushServer extends Service {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
String action = intent.getAction();
if (Intent.ACTION_DATE_CHANGED.equals(action)) {
Log.e("fht", "TimeChangedReceiver:" + "data changed");
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
} else if (Intent.ACTION_TIME_CHANGED.equals(action)) {
Log.e("fht", "TimeChangedReceiver:" + "time changed");
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
Log.e("fht", "TimeChangedReceiver:" + "timezone changed");
} else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
} else if (Intent.ACTION_TIME_TICK.equals(action)) {
Log.e("fht", "TimeChangedReceiver:" + "time tick");
} else if (ACTION_UPDATE.equals(intent.getAction())) {
} else if (ACTION_UPDATE.equals(action)) {
Log.e("fht", "TimeChangedReceiver:" + "date update");
}
ForegroundAppUtil.openTopApp(context);
long nowTime = System.currentTimeMillis();
TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(InitJpushServer.this);
TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(context);
if (null != contralTime) {
if (contralTime.inControlTime(nowTime)) {
if (!screenlocked) {
@@ -400,7 +482,7 @@ public class InitJpushServer extends Service {
sequence++;
tagAliasBean.alias = Utils.getSerial();
tagAliasBean.isAliasAction = true;
TagAliasOperatorHelper.getInstance().handleAction(InitJpushServer.this, sequence, tagAliasBean);
TagAliasOperatorHelper.getInstance().handleAction(this, sequence, tagAliasBean);
// JPushInterface.setAlias(this, Utils.getSerial(), new TagAliasCallback() {
// @Override
// public void gotResult(int i, String s, Set<String> set) {
@@ -496,12 +578,12 @@ public class InitJpushServer extends Service {
}
if (app_version_code > versionCode) {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(InitJpushServer.this, app_url, jsonObject);
Utils.ariaDownload(this, app_url, jsonObject);
}
}
} else {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(InitJpushServer.this, app_url, jsonObject);
Utils.ariaDownload(this, app_url, jsonObject);
}
}
}
@@ -509,8 +591,8 @@ public class InitJpushServer extends Service {
}
private void getDeselectID() {
DeselectIDApi deselectIDApi = Network.getDeselectIDApi();
deselectIDApi.getDeselectIDApi(URLAddress.HTTP_KEY, Utils.getSerial())
DeselectIDApi deselectIDApi = NetInterfaceManager.getDeselectIDApi();
deselectIDApi.getDeselectIDApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@@ -523,7 +605,7 @@ public class InitJpushServer extends Service {
public void onNext(ResponseBody responseBody) {
try {
String responString = responseBody.string();
LogUtils.e("initmjsheng", "应用联网管控::" + responString);
Log.e("initmjsheng", "应用联网管控::" + responString);
JSONObject jsonObject = new JSONObject(responString);
Integer code = jsonObject.optInt("code");
switch (code) {
@@ -556,8 +638,8 @@ public class InitJpushServer extends Service {
}
private void getDeselectBrowerID() {
DeselectBrowserIDApi deselectBrowserIDApi = Network.getDeselectBrowserIDApi();
deselectBrowserIDApi.getDeselectBrowserIDApi(URLAddress.HTTP_KEY, Utils.getSerial())
DeselectBrowserIDApi deselectBrowserIDApi = NetInterfaceManager.getDeselectBrowserIDApi();
deselectBrowserIDApi.getDeselectBrowserIDApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@@ -571,7 +653,7 @@ public class InitJpushServer extends Service {
public void onNext(ResponseBody responseBody) {
try {
String responString = responseBody.string();
LogUtils.e("initmjsheng", "浏览器ID管控::" + responString);
Log.e("initmjsheng", "浏览器ID管控::" + responString);
JSONObject jsonObject = new JSONObject(responString);
Integer code = jsonObject.optInt("code");
switch (code) {
@@ -603,8 +685,8 @@ public class InitJpushServer extends Service {
}
private void getAppLimitApi() {
AppLimitApi appLimitApi = Network.getAppLimitApi();
appLimitApi.getAppLimitApi(URLAddress.HTTP_KEY, Utils.getSerial())
AppLimitApi appLimitApi = NetInterfaceManager.getAppLimitApi();
appLimitApi.getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@@ -655,7 +737,7 @@ public class InitJpushServer extends Service {
String jgy1 = "com.uiuios.jgy1";
String jgy2 = "com.uiuios.jgy2";
if (!TextUtils.isEmpty(result)) {
LogUtils.e(result);
Log.e("writeAppPackageList", result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
@@ -673,15 +755,15 @@ public class InitJpushServer extends Service {
} else {
Log.e("mjsheng", "writeAppPackageList is null:");
}
int locked = Settings.System.getInt(InitJpushServer.this.getContentResolver(), "qch_unlock_ipad", 1);
int locked = Settings.System.getInt(this.getContentResolver(), "qch_unlock_ipad", 1);
if (locked == 0) {
getDeviceBatch(result);
}
}
private void getDeviceBatch(final String result) {
GetBatchApi getBatchApi = Network.getBatchApi();
GetBatchApi getBatchApi = NetInterfaceManager.getBatchApi();
getBatchApi.getBatch(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@@ -735,12 +817,12 @@ public class InitJpushServer extends Service {
Log.e("deleteOtherApp", "packageList:" + packageList);
String[] result = packageList.split(",");
List<String> resultList = new ArrayList<>(Arrays.asList(result));
List<String> packageLists = ApkUtils.queryFilterAppInfo(InitJpushServer.this);
List<String> packageLists = ApkUtils.queryFilterAppInfo(this);
Log.e("deleteOtherApp", "packageLists:" + packageLists.toString());
if (resultList.size() > 0) {
for (final String packageName : packageLists) {
if (Utils.isSystemApp(InitJpushServer.this, packageName)) {
if (Utils.isSystemApp(this, packageName)) {
Log.e("deleteOtherApp", "is systemApp:" + packageName);
continue;
}
@@ -765,8 +847,8 @@ public class InitJpushServer extends Service {
}
private void getNetAndLaunchSetting() {
NetAndLaunchApi netAndLaunchApi = Network.getNetAndLaunchApi();
netAndLaunchApi.getNetAndLaunchApi(URLAddress.HTTP_KEY, Utils.getSerial())
NetAndLaunchApi netAndLaunchApi = NetInterfaceManager.getNetAndLaunchApi();
netAndLaunchApi.getNetAndLaunchApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<NetAndLaunchBean>() {
@@ -801,8 +883,8 @@ public class InitJpushServer extends Service {
//强制下载
private void getForceDownload() {
ForceDownloadApi forceDownloadApi = Network.getForceDownloadApi();
forceDownloadApi.getForceDownloadApi(URLAddress.HTTP_KEY, Utils.getSerial())
ForceDownloadApi forceDownloadApi = NetInterfaceManager.getForceDownloadApi();
forceDownloadApi.getForceDownloadApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ForceDownloadBean>() {
@@ -816,9 +898,9 @@ public class InitJpushServer extends Service {
public void onNext(ForceDownloadBean forceDownloadBean) {
switch (forceDownloadBean.getCode()) {
case 200:
Log.e("getForceDownload", "isDownloading=" + MyApplication.getInstance().isDownloading());
MyApplication.getInstance().checkIsDownloading();
if (!MyApplication.getInstance().isDownloading()) {
Log.e("getForceDownload", "isDownloading=" + BaseApplication.getInstance().isDownloading());
BaseApplication.getInstance().checkIsDownloading();
if (!BaseApplication.getInstance().isDownloading()) {
Aria.download(this).removeAllTask(true);
forceDownload(forceDownloadBean.getData());
} else {
@@ -826,11 +908,11 @@ public class InitJpushServer extends Service {
}
break;
case -200:
boolean qch_force_app = Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_force_app", "invalid");
boolean qch_force_app = Settings.System.putString(getContentResolver(), "qch_force_app", "invalid");
Log.e("fht", "qch_force_app:" + qch_force_app);
break;
default:
LogUtils.e("getForceDownload is error:" + forceDownloadBean.getMsg());
Log.e("getForceDownload", forceDownloadBean.getMsg());
break;
}
}
@@ -930,7 +1012,7 @@ public class InitJpushServer extends Service {
}
private void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) {
LogUtils.e("联网和自启管控:" + netAndLaunchBean.toString());
Log.e("setNetAndlaunch", netAndLaunchBean.toString());
String net_ok = "";
String net_not = "";
String launch = "";
@@ -1013,10 +1095,10 @@ public class InitJpushServer extends Service {
}
Utils.writeDisableUpdateList(this, upgrade_not.split(","), upgrade_ok.split(","));
LogUtils.e("UpdateList:upgrade_not:" + upgrade_not + "-----------upgrade_ok:" + upgrade_ok);
Log.e("setNetAndlaunch", "UpdateList:upgrade_not:" + upgrade_not + "-----------upgrade_ok:" + upgrade_ok);
LogUtils.e("launch:" + launch + "-----------net_ok:" + net_ok + "-----------net_not:" + net_not);
boolean qch_app_power_on = Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_app_power_on", launch);
Log.e("setNetAndlaunch", "launch:" + launch + "-----------net_ok:" + net_ok + "-----------net_not:" + net_not);
boolean qch_app_power_on = Settings.System.putString(this.getContentResolver(), "qch_app_power_on", launch);
// Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
// netControlIntent.putExtra("package_name", net_not);
@@ -1031,7 +1113,7 @@ public class InitJpushServer extends Service {
Log.e("fht", "ban::" + net_not);
}
MyApplication.getInstance().setFinished(true);
BaseApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", net_ok);
@@ -1050,7 +1132,7 @@ public class InitJpushServer extends Service {
private void writeDeselectBrowserIDtoSystem(String ids) {
// if (!TextUtils.isEmpty(ids)) {
boolean deselectBrowserArray = Settings.System.putString(InitJpushServer.this.getContentResolver(), "DeselectBrowserArray", ids);
boolean deselectBrowserArray = Settings.System.putString(this.getContentResolver(), "DeselectBrowserArray", ids);
Log.e("SystemSetting", "DeselectBrowserArray---------" + deselectBrowserArray);
// } else {
// Log.e("mjsheng", "writeDeselectBrowserIDtoSystem is null:");
@@ -1062,7 +1144,7 @@ public class InitJpushServer extends Service {
if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) {
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
LogUtils.e(result);
Log.e("writeDeselectIDtoSystem", result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
@@ -1082,8 +1164,8 @@ public class InitJpushServer extends Service {
}
private void getSystemSetting() {
final SystemSettingApi systemSettingApi = Network.getSystemSettingApi();
systemSettingApi.getSystemSettingApi(URLAddress.HTTP_KEY, Utils.getSerial())
final SystemSettingApi systemSettingApi = NetInterfaceManager.getSystemSettingApi();
systemSettingApi.getSystemSettingApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@@ -1096,7 +1178,7 @@ public class InitJpushServer extends Service {
try {
// Log.e("mjsheng", "systemSettingBean::" + systemSettingBean);
String responString = responseBody.string();
LogUtils.e("mjsheng1", "系统管控::" + responString);
Log.e("mjsheng1", "系统管控::" + responString);
JSONObject jsonObject = new JSONObject(responString);
Integer code = jsonObject.optInt("code");
switch (code) {
@@ -1144,7 +1226,7 @@ public class InitJpushServer extends Service {
}
synchronized public void sendMACaddress() {
String rid = JPushInterface.getRegistrationID(InitJpushServer.this);
String rid = JPushInterface.getRegistrationID(this);
OkGo.post(URLAddress.SEND_DEVICES)
.params("sn", Utils.getSerial())
@@ -1174,7 +1256,7 @@ public class InitJpushServer extends Service {
boolean locked = false;
synchronized public void getLockedState() {
OkGo.post(URLAddress.HTTP_TAG_FIRST)
OkGo.post(URLAddress.GET_DEVICES_LOCKED)
.params("sn", Utils.getSerial())
.execute(new StringCallback() {
@Override
@@ -1190,17 +1272,17 @@ public class InitJpushServer extends Service {
Log.e("jpttlocked", String.valueOf(lock));
if (lock == 0) {
locked = false;
boolean se = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_unlock_ipad", 1);
boolean se = Settings.System.putInt(getContentResolver(), "qch_unlock_ipad", 1);
SysSettingUtils.setEnableSetting(InitJpushServer.this);
SPUtils.put(InitJpushServer.this, "first_connect", 1);
Log.e("fht", "getLockedState---------" + Settings.System.getString(InitJpushServer.this.getContentResolver(), "qch_unlock_ipad"));
Log.e("fht", "getLockedState---------" + Settings.System.getString(getContentResolver(), "qch_unlock_ipad"));
Log.e("jpttlocked1", "qch_unlock_ipad---------" + locked + se);
} else {
locked = true;
Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_unlock_ipad", 0);
Settings.System.putInt(getContentResolver(), "qch_unlock_ipad", 0);
Log.e("jpttlocked2", "qch_unlock_ipad---------" + locked);
// Settings.System.putString(InitJpushServer.this.getContentResolver(), "DeselectBrowserArray", "http://www.baidu.com");
String ss = Settings.System.getString(InitJpushServer.this.getContentResolver(), "DeselectBrowserArray");
// Settings.System.putString(this.getContentResolver(), "DeselectBrowserArray", "http://www.baidu.com");
String ss = Settings.System.getString(getContentResolver(), "DeselectBrowserArray");
Log.e("jpttlocked2", "DeselectBrowserArray---------" + ss);
// 初始化 JPush
JPushInterface.init(InitJpushServer.this);
@@ -1226,7 +1308,7 @@ public class InitJpushServer extends Service {
}
} else if (code == -300) {
// ApkUtils.uninstallAllApp(InitJpushServer.this);
// ApkUtils.uninstallAllApp(this);
}
}
@@ -1242,7 +1324,7 @@ public class InitJpushServer extends Service {
private void resetDevice() {
boolean isReset = MySQLData.GetBooleanData(this, CommonDatas.IS_RESET);
int batteryLevel = getBatteryLevel();
LogUtils.e(batteryLevel + "------------------" + isReset);
Log.e("resetDevice", "batteryLevel: " + batteryLevel + "isReset: " + isReset);
if (isReset && batteryLevel >= CommonDatas.MIN_POWER) {
Utils.doMasterClear(this);
}
@@ -1253,7 +1335,7 @@ public class InitJpushServer extends Service {
BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} else {
Intent intent = new ContextWrapper(InitJpushServer.this).
Intent intent = new ContextWrapper(this).
registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) /
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
@@ -1262,31 +1344,31 @@ public class InitJpushServer extends Service {
private void checkUpdate() {
HTTPInterface.checkUpdate(mHandler, "com.jiaoguanyi.store");
HTTPInterface.checkTestUpdate(InitJpushServer.this);
HTTPInterface.checkTestUpdate(this);
}
private BluetoothAdapter mBluetoothAdapter;
private void SettingSysData(JSONObject data) {
SPUtils.put(InitJpushServer.this, "first_connect", 1);
SysSettingUtils.setSystemSetting(InitJpushServer.this, data.toString());
SPUtils.put(this, "first_connect", 1);
SysSettingUtils.setSystemSetting(this, data.toString());
// try {
// int setting_call = changeNum(data.optInt("setting_call"));
// boolean qch_call_forbid = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_call_forbid", setting_call);
// boolean qch_call_forbid = Settings.System.putInt(this.getContentResolver(), "qch_call_forbid", setting_call);
// Log.e("SystemSetting", "qch_call_forbid---------" + qch_call_forbid);
//
// int setting_phone = changeNum(data.optInt("setting_phone"));
// boolean qch_white_list_on = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_white_list_on", setting_phone);
// boolean qch_white_list_on = Settings.System.putInt(this.getContentResolver(), "qch_white_list_on", setting_phone);
// Log.e("SystemSetting", "qch_white_list_on---------" + qch_white_list_on);
//
// String setting_phones = data.optString("setting_phones");
// boolean qch_white_list_Array = Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_white_list_Array", setting_phones);
// boolean qch_white_list_Array = Settings.System.putString(this.getContentResolver(), "qch_white_list_Array", setting_phones);
// // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid);
// Log.e("SystemSetting", "qch_white_list_Array---------" + qch_white_list_Array + "---" + setting_phones);
//
// int setting_memory = changeNum(data.optInt("setting_memory"));
// boolean qch_sdcard_forbid_on = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
// boolean qch_sdcard_forbid_on = Settings.System.putInt(this.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
// Log.e("SystemSetting", "qch_sdcard_forbid_on---------" + qch_sdcard_forbid_on);
//
//
@@ -1296,7 +1378,7 @@ public class InitJpushServer extends Service {
// //Midi模式usb_midi
// String setting_usb = data.optString("setting_usb");
// if (!BuildConfig.DEBUG) {
// boolean qch_usb_choose = Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_usb_choose", setting_usb);
// boolean qch_usb_choose = Settings.System.putString(this.getContentResolver(), "qch_usb_choose", setting_usb);
// Log.e("SystemSetting", "qch_usb_choose---------" + qch_usb_choose);
// String usbStatus = "";
// switch (setting_usb) {
@@ -1335,7 +1417,7 @@ public class InitJpushServer extends Service {
// int setting_bhtvideo = changeNum(data.optInt("setting_bhtvideo"));//蓝牙音频开关
// int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));//蓝牙传输开关
//
// boolean qch_bht_forbid_on = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_bht_forbid_on", setting_bht);//写入系统数据库
// boolean qch_bht_forbid_on = Settings.System.putInt(this.getContentResolver(), "qch_bht_forbid_on", setting_bht);//写入系统数据库
// Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on);
// if (qch_bht_forbid_on) {//成功
// if (null == mBluetoothAdapter) {
@@ -1346,14 +1428,14 @@ public class InitJpushServer extends Service {
// if (setting_bhtvideo == 0) {
// if (null != setting_context && !setting_context.equals("") && !setting_context.equals(" ") && !setting_context.equals("null")) {
// Log.e("SystemSetting", "setting_context:" + setting_context);
// Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context);
// Settings.System.putString(this.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context);
// } else {
// Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
// Settings.System.putString(this.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
// }
// } else if (setting_bhtvideo == 1) {
// Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
// Settings.System.putString(this.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
// }
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
// Settings.System.putInt(this.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
// } else {
// mBluetoothAdapter.disable();//设置关闭时关闭蓝牙
// }
@@ -1373,7 +1455,7 @@ public class InitJpushServer extends Service {
//
// //系统导航条显示开关
// int setting_navigation = changeNum(data.optInt("setting_navigation"));
// boolean qch_hide_navigationBar = Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_hide_NavigationBar", setting_navigation);
// boolean qch_hide_navigationBar = Settings.System.putInt(this.getContentResolver(), "qch_hide_NavigationBar", setting_navigation);
// Log.e("SystemSetting", "qch_hide_navigationBar---------" + qch_hide_navigationBar);
//
// String navigationStatus = "";
@@ -1412,8 +1494,8 @@ public class InitJpushServer extends Service {
//
// //摄像头开关
// int setting_camera = changeNum(data.optInt("setting_camera"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_camera", setting_camera);
//// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.mediatek.camera");
// Settings.System.putInt(this.getContentResolver(), "qch_app_camera", setting_camera);
//// ApkUtils.hideSystemSettingAPP(this, "com.mediatek.camera");
// Log.e("SystemSetting", "setting_camera---------" + setting_camera);
// String cameraStatus = "";
// switch (setting_camera) {
@@ -1430,7 +1512,7 @@ public class InitJpushServer extends Service {
//
// //tfmedia开关
// int setting_tfmedia = changeNum(data.optInt("setting_tfmedia"));
// boolean qch_tfmedia_forbid = Settings.System.putInt(InitJpushServer.this.getContentResolver(),
// boolean qch_tfmedia_forbid = Settings.System.putInt(this.getContentResolver(),
// "qch_tfmedia_forbid", setting_tfmedia);
// Log.e("SystemSetting", "setting_tfmedia---------" + qch_tfmedia_forbid);
// String tfmediaStatus = "";
@@ -1457,7 +1539,7 @@ public class InitJpushServer extends Service {
// i++;
// }
// stringBuffer.deleteCharAt(stringBuffer.length() - 1);
// Settings.System.putString(InitJpushServer.this.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控
// Settings.System.putString(this.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控
// Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + stringBuffer.toString());
//
// } catch (JSONException e) {
@@ -1465,41 +1547,41 @@ public class InitJpushServer extends Service {
//
// }
// } else {
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_tfmedia_forbid", 0);
// Settings.System.putInt(this.getContentResolver(), "qch_tfmedia_forbid", 0);
// }
// //added:2019.12.6
// //设置5个app的开关
// //时钟
// int deskclock = changeNum(data.optInt("setting_clock"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_deskclock", deskclock);
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.android.deskclock");
// Settings.System.putInt(this.getContentResolver(), "qch_app_deskclock", deskclock);
// ApkUtils.hideSystemSettingAPP(this, "com.android.deskclock");
// Log.e("SystemSetting", "qch_app_deskclock" + deskclock);
// //录音机
// int soundrecorder = changeNum(data.optInt("setting_recording"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.android.soundrecorder");
// Settings.System.putInt(this.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
// ApkUtils.hideSystemSettingAPP(this, "com.android.soundrecorder");
// Log.e("SystemSetting", "qch_app_soundrecorder" + soundrecorder);
// //音乐
// int music = changeNum(data.optInt("setting_music"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_music", music);
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.android.music");
// Settings.System.putInt(this.getContentResolver(), "qch_app_music", music);
// ApkUtils.hideSystemSettingAPP(this, "com.android.music");
// Log.e("SystemSetting", "qch_app_music" + music);
// //图库
// int gallery = changeNum(data.optInt("setting_picture"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_gallery", gallery);
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.android.gallery3d");
// Settings.System.putInt(this.getContentResolver(), "qch_app_gallery", gallery);
// ApkUtils.hideSystemSettingAPP(this, "com.android.gallery3d");
// Log.e("SystemSetting", "qch_app_gallery" + gallery);
// //壁纸
// int wallpaper = changeNum(data.optInt("setting_wallpaper"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_wallpaper", wallpaper);
// Settings.System.putInt(this.getContentResolver(), "qch_app_wallpaper", wallpaper);
// Log.e("SystemSetting", "qch_app_wallpaper" + wallpaper);
// //文件管理器
// int filemanager = changeNum(data.optInt("setting_file"));
// Settings.System.putInt(InitJpushServer.this.getContentResolver(), "qch_app_filemanager", filemanager);
// Settings.System.putInt(this.getContentResolver(), "qch_app_filemanager", filemanager);
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.mediatek.filemanager");
// ApkUtils.hideSystemSettingAPP(this, "com.mediatek.filemanager");
// } else {
// ApkUtils.hideSystemSettingAPP(InitJpushServer.this, "com.android.documentsui");
// ApkUtils.hideSystemSettingAPP(this, "com.android.documentsui");
// }
// Log.e("SystemSetting", "qch_app_filemanager" + filemanager);
// } catch (Exception e) {
@@ -1508,83 +1590,5 @@ public class InitJpushServer extends Service {
// }
}
private int changeNum(int status) {
int num = 1;
switch (status) {
case 0:
num = 1;
break;
case 1:
num = 0;
break;
default:
num = 1;
}
return num;
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 200:
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) msg.obj;
installAPK(jsonObject);
break;
case -200:
Log.e("fht", "no update");
}
}
};
private void installAPK(com.alibaba.fastjson.JSONObject jsonObject) {
String url = jsonObject.getString("url");
int versionCode = jsonObject.getInteger("version_code");
String packageName = jsonObject.getString("package");
String app_name = jsonObject.getString("app_name");
com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.versionCode < versionCode) {
// Aria.download(this)
// .load(url) //读取下载地址
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(packageName) + ".apk", true)
// .setExtendField(object.toJSONString())
// .create(); //启动下载}
Utils.ariaDownload(this, url, object);
} else {
Log.e("fht", "无需更新");
}
}
private void showTopAcivity() {
// if (true) {
// Intent intent = new Intent(InitJpushServer.this, TopActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// startActivity(intent);
// }
}
@Override
public void onDestroy() {
super.onDestroy();
if (null != lockScreenReceiver) {
unregisterReceiver(lockScreenReceiver);
}
Log.e("fht", "InitJpushServer onDestroy");
}
}

View File

@@ -0,0 +1,449 @@
package com.mjsheng.myappstore.server;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.IBinder;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import com.google.gson.JsonObject;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.activity.MainActivity;
import com.mjsheng.myappstore.activity.MainContact;
import com.mjsheng.myappstore.activity.MainPresenter;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.ForegroundAppUtil;
import com.mjsheng.myappstore.utils.SaveListUtils;
import com.mjsheng.myappstore.utils.SysSettingUtils;
import com.mjsheng.myappstore.utils.TimeUtils;
public class MainService extends Service implements MainContact.MainView {
private MainPresenter mPresenter;
private static final String TAG = MainService.class.getSimpleName();
private boolean netWorkIsRunning = false;
public MainService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
mPresenter = new MainPresenter(this);
mPresenter.attachView(this);
registerReceivers();
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
unRegisterReceivers();
mPresenter.detachView();
}
long timeMillis;
long startCommandTime = 0;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ((SystemClock.elapsedRealtime() - startCommandTime) < 60000) {
Log.e(TAG, "onStartCommand: " + "启动时间过短");
//一分钟内防止多次调用
} else {
startCommandTime = SystemClock.elapsedRealtime();
if (MainActivity.isForeground){
mPresenter.getFirstConnect();
timeMillis = System.currentTimeMillis();
mPresenter.getLockedState();
Log.e(TAG, "onStartCommand: "+(SystemClock.elapsedRealtime() - startCommandTime));
}else {
Log.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground);
}
}
return START_STICKY;
}
private void registerReceivers() {
registerLockScreenReceiver();
registerTimeReceiver();
}
private void unRegisterReceivers() {
if (null != lockScreenReceiver) {
unregisterReceiver(lockScreenReceiver);
}
if (null != mTimeChangedReceiver) {
unregisterReceiver(mTimeChangedReceiver);
}
}
private static WindowManager windowManager;
private View topView;
boolean screenlocked = false;
boolean timelocked = false;
@SuppressLint("NewApi")
private void showFloatingWindow(String name) {
if (Settings.canDrawOverlays(this)) {
// 获取WindowManager服务
if (null == windowManager) {
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
}
DisplayMetrics dm = new DisplayMetrics();
windowManager.getDefaultDisplay().getRealMetrics(dm);
int width = dm.widthPixels; // 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
// 新建悬浮窗控件
final Button button = new Button(getApplicationContext());
button.setText("霸屏测试");
button.setAlpha(0.9f);
button.setBackgroundColor(Color.WHITE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// windowManager.removeView(button);
}
});
if (null == topView) {
topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_top, null);
TextView textView = topView.findViewById(R.id.textView);
textView.setText(name);
} else {
if (topView.getTag().equals("added")) {
TextView textView = topView.findViewById(R.id.textView);
textView.setText(name);
return;
}
}
// topView.setAlpha(0.8f);
TextView textView = topView.findViewById(R.id.textView);
textView.setText(name);
// 设置LayoutParam
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
}
layoutParams.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
layoutParams.format = PixelFormat.RGBA_8888;
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.x = 0;
layoutParams.y = 0;
// 将悬浮窗控件添加到WindowManager
windowManager.addView(topView, layoutParams);
topView.setTag("added");
}
}
private void hideFloatingWindow() {
if (null == windowManager) {
return;
}
if (null != topView) {
windowManager.removeView(topView);
topView = null;
}
}
private LockScreenReceiver lockScreenReceiver;
private void registerLockScreenReceiver() {
if (null == lockScreenReceiver) {
lockScreenReceiver = new LockScreenReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(LockScreenReceiver.action_lock);
filter.addAction(LockScreenReceiver.action_unlock);
registerReceiver(lockScreenReceiver, filter);
}
}
public class LockScreenReceiver extends BroadcastReceiver {
public static final String action_lock = "LockScreenReceiver_lockscreen";
public static final String action_unlock = "LockScreenReceiver_unlockscreen";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (TextUtils.isEmpty(action)) {
return;
}
if (action_lock.equals(action)) {
String name = intent.getStringExtra("name");
if (!timelocked) {
showFloatingWindow(name);
}
screenlocked = true;
} else if (action_unlock.equals(action)) {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
}
}
}
private TimeChangedReceiver mTimeChangedReceiver;
/**
* 监听时间变化
*/
public void registerTimeReceiver() {
mTimeChangedReceiver = new TimeChangedReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(TimeChangedReceiver.ACTION_UPDATE);
registerReceiver(mTimeChangedReceiver, filter);
}
public class TimeChangedReceiver extends BroadcastReceiver {
public static final String ACTION_UPDATE = "TimeChangedReceiver_update";
@SuppressLint("NewApi")
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
Log.e("fht", "TimeChangedReceiver:" + "data changed");
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
Log.e("fht", "TimeChangedReceiver:" + "time changed");
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
Log.e("fht", "TimeChangedReceiver:" + "timezone changed");
} else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
Log.e("fht", "TimeChangedReceiver:" + "time tick");
} else if (ACTION_UPDATE.equals(intent.getAction())) {
Log.e("fht", "TimeChangedReceiver:" + "date update");
}
ForegroundAppUtil.openTopApp(context);
long nowTime = System.currentTimeMillis();
TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(MainService.this);
if (null != contralTime) {
if (contralTime.inControlTime(nowTime)) {
if (!screenlocked) {
showFloatingWindow("管控时间:" + contralTime.toString());
} else {
TextView textView = topView.findViewById(R.id.textView);
textView.setText("管控时间:" + contralTime.toString());
}
timelocked = true;
} else {
mPresenter.getScreenLockState();
if (!screenlocked) {
hideFloatingWindow();
}
timelocked = false;
}
} else {
if (!screenlocked) {
hideFloatingWindow();
}
mPresenter.getScreenLockState();
timelocked = false;
}
}
}
@Override
public void setBatchText(String text, int visibility) {
}
@Override
public void setClassText(String text, int visibility) {
}
@Override
public void setNumberText(String text, int visibility) {
}
@Override
public void setNameText(String text, int visibility) {
}
@Override
public void setLockedState(boolean loocked) {
if (loocked) {
ApkUtils.getAppInfo(this);
//上传APP信息
if (netWorkIsRunning) {
//如果正在执行,不执行
return;
}
mPresenter.sendMACAddress();
//发送设备mac地址和信息
mPresenter.setJpushAlias();
//设置极光推送别名
SaveListUtils.getList();
mPresenter.getSystemSettingbegin();
netWorkIsRunning = true;
} else {
netWorkIsRunning = false;
SysSettingUtils.setEnableSetting(this);
}
}
@Override
public void setFirstConnect(boolean state) {
Log.e(TAG, "isFirstConnect: " + "end request");
if (state) {
mPresenter.setDisableSetting();
} else {
}
}
@Override
public void sendMACFinished() {
mPresenter.updateDeviceInfo();
}
@Override
public void updateDeviceInfoFinished() {
mPresenter.getSnTimeControl();
}
@Override
public void getSnTimeControlFinished() {
}
@Override
public void setAliasFinished() {
mPresenter.setJpushTags();
//设置极光推送tag
}
@Override
public void setTagsFinished() {
mPresenter.checkStoreUpdate();
}
@Override
public void checkStoreUpdateFinished() {
mPresenter.checkTestUpdate();
}
@Override
public void checkTestUpdateFinished() {
mPresenter.getDefaultDesktop();
}
@Override
public void buttonCheckUpdateFinished(boolean update, JsonObject jsonObject) {
}
@Override
public void getSystemSettingbegin() {
mPresenter.getAppLimit();
}
@Override
public void getAppLimitFinished(String packageList) {
mPresenter.getDeviceBatch(packageList);
}
@Override
public void getDeviceBatchFinished() {
mPresenter.getForceDownload();
}
@Override
public void getForceDownloadFinished() {
mPresenter.getBrowserList();
}
@Override
public void getBrowserListFinished() {
mPresenter.getBrowserBookmarks();
}
@Override
public void getBrowserBookmarksFinished() {
mPresenter.getDesktopIcon();
}
@Override
public void getDesktopIconFinished() {
mPresenter.getAppAutoStartUpdateAndNet();
}
@Override
public void getAppAutoStartUpdateAndNetFinished() {
mPresenter.getAppIDControl();
}
@Override
public void getAppIDControlFinished() {
mPresenter.setAppinsideWeb();
}
@Override
public void setAppinsideWebFinished() {
mPresenter.setSystemSetting();
}
@Override
public void setSystemSettingFinished() {
netWorkIsRunning = false;
Log.e(TAG, "SettingFinished: " + (System.currentTimeMillis() - timeMillis) + " ms");
}
@Override
public void setScreenLockStateFinished(boolean locked, String tips) {
if (locked) {
if (!timelocked) {
showFloatingWindow(tips);
}
screenlocked = true;
} else {
if (!timelocked) {
hideFloatingWindow();
}
screenlocked = false;
}
}
@Override
public void getDefaultDesktopFinished() {
}
}

View File

@@ -15,12 +15,12 @@ import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import androidx.annotation.Nullable;
import android.util.Log;
import com.blankj.utilcode.util.LogUtils;
import androidx.annotation.Nullable;
import com.mjsheng.myappstore.KeepAliveConnection;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.Utils;
@@ -49,10 +49,10 @@ public class StepService extends Service {
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
LogUtils.e(TAG, "StepService:建立链接");
Log.e(TAG, "StepService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this);
if (!isServiceRunning) {
Intent i = new Intent(StepService.this, MyDownloadService.class);
Intent i = new Intent(StepService.this, StepService.class);
startService(i);
}
}
@@ -107,7 +107,7 @@ public class StepService extends Service {
* 初始化websocket连接
*/
private void initSocketClient() {
URI uri = URI.create(Network.WebsocketURL);
URI uri = URI.create(NetInterfaceManager.WEBSOCKET_URL);
// URI uri = URI.create("ws://echo.websocket.org");
// URI uri = URI.create("ws://123.207.136.134:9010/ajaxchattest");
client = new JWebSocketClient(uri) {

View File

@@ -34,8 +34,8 @@ import com.google.gson.Gson;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.bean.UploadAppInfo;
import com.mjsheng.myappstore.manager.NetInterfaceManager;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.UploadAppInfoApi;
import java.io.BufferedReader;
@@ -1072,8 +1072,8 @@ public class ApkUtils {
String jsonString = gson.toJson(appList);
// Log.e("mjsheng", "json========" + jsonString);
UploadAppInfoApi uploadAppInfoApi = Network.getUploadAppInfoApi();
uploadAppInfoApi.getUploadAppInfoApi(URLAddress.HTTP_KEY, Utils.getSerial(), jsonString)
UploadAppInfoApi uploadAppInfoApi = NetInterfaceManager.getUploadAppInfoApi();
uploadAppInfoApi.getUploadAppInfoApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial(), jsonString)
.subscribeOn(io.reactivex.schedulers.Schedulers.io())
.observeOn(io.reactivex.android.schedulers.AndroidSchedulers.mainThread())
.subscribe(new io.reactivex.Observer<ResponseBody>() {
@@ -1085,7 +1085,7 @@ public class ApkUtils {
@Override
public void onNext(ResponseBody responseBody) {
try {
Log.e("mjhseng", "上传的结果" + responseBody.string());
Log.e("getAppInfo", "上传的结果" + responseBody.string());
} catch (IOException e) {
e.printStackTrace();
}
@@ -1093,7 +1093,7 @@ public class ApkUtils {
@Override
public void onError(Throwable e) {
Log.e("mjsheng", "UploadAppInfoApi=onError:");
Log.e("getAppInfo", "UploadAppInfoApi=onError:");
}
@Override

View File

@@ -7,11 +7,19 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Looper;
import android.os.storage.StorageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -129,4 +137,116 @@ public class ExampleUtil {
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
public static class StorageUtils {
// 获取存储空间 false 内置sd卡路径true 外置sd卡路径
public static File getStoragePath(Context mContext, boolean isSDcard) {
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
Class<?> storageVolumeClazz = null;
try {
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
Method getPath = storageVolumeClazz.getMethod("getPath");
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
Object result = getVolumeList.invoke(mStorageManager);
final int length = Array.getLength(result);
for (int i = 0; i < length; i++) {
Object storageVolumeElement = Array.get(result, i);
String path = (String) getPath.invoke(storageVolumeElement);
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
if (isSDcard == removable) {
File file = new File(path);
if (file.exists()) {
return file;
}else {
if (!isSDcard) {
return Environment.getExternalStorageDirectory();
} else {
File file1 = new File("root/storage/sdcard1");
if (file1.exists()){
return file1;
}else {
File file2 = new File("storage/sdcard1");
if (file2.exists()){
return file2;
}else {
File file3 = new File("/storage/emulated/0");
if (file3.exists()){
return file3;
}else {
return null;
}
}
}
}
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static String getFileCache(Context context, String s) {
return getExternalFilesDir(context, s).getAbsolutePath();
}
public static String getFileRoot(Context context) {
return getExternalFilesDir(context, "Download").getAbsolutePath();
}
public static File getExternalFilesDir(Context context, String s) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
File path = context.getExternalFilesDir(s);
if (path != null) {
return path;
}
}
final String cacheDir = "/Android/data/" + context.getPackageName() + "/files/" + s;
return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
}
// 检测文件是否存在
public static boolean isFileIsExists(String filePath){
try{
File f=new File(filePath);
if(!f.exists()){
return false;
}
}catch (Exception e) {
return false;
}
return true;
}
public static String size(long size) {
if (size / (1024 * 1024) > 0) {
float tmpSize = (float) (size) / (float) (1024 * 1024 );
DecimalFormat df = new DecimalFormat("#.##");
return "" + df.format(tmpSize) + "GB";
} else if (size / 1024 > 0) {
float tmpSize = (float) (size) / (float) 1024 ;
DecimalFormat df = new DecimalFormat("#.##");
return "" + df.format(tmpSize) + "MB";
} else if (size > 0) {
return "" + (size ) + "KB";
} else {
return "" + (size) + "KB";
}
}
}
}

View File

@@ -0,0 +1,577 @@
package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.bean.Appground;
import com.mjsheng.myappstore.bean.BaseResponse;
import com.mjsheng.myappstore.bean.ForceDownloadData;
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
import com.mjsheng.myappstore.bean.NetAndLaunchData;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.server.InitJpushServer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class JGYUtils {
private static final String TAG = JGYUtils.class.getSimpleName();
private static JGYUtils sInstance;
private Context mContext;
public static final String ROOT_URL = BuildConfig.ROOT_URL;
private JGYUtils(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new JGYUtils(context);
}
}
public static JGYUtils getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init JGYUtils first");
}
return sInstance;
}
public void resetDevice() {
boolean isReset = MySQLData.GetBooleanData(mContext, CommonDatas.IS_RESET);
int batteryLevel = getBatteryLevel();
Log.e(TAG, "batteryLevel:" + batteryLevel + " isReset" + isReset);
if (isReset && batteryLevel >= CommonDatas.MIN_POWER) {
Utils.doMasterClear(mContext);
}
}
private int getBatteryLevel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BatteryManager batteryManager = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} else {
Intent intent = new ContextWrapper(mContext).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) /
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
}
}
private PowerManager.WakeLock wakeLock = null;
private static final String mWakeLockName = "BackupService";
/**
* 获取电源锁保持该服务在屏幕熄灭时仍然获取CPU时保持运行
*/
@SuppressLint("InvalidWakeLockTag")
private synchronized void acquireWakeLock() {
if (null == wakeLock) {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE, mWakeLockName);
if (null != wakeLock) {
Log.e("fht", "acquireWakeLock!");
wakeLock.acquire();
}
}
}
/**
* 释放设备电源锁
*/
private synchronized void releaseWakeLock() {
if (null != wakeLock) {
Log.e("fht", "releaseWakeLock!");
wakeLock.release();
wakeLock = null;
}
}
/**
* 应用自启升级和网络权限管理
*
* @param netAndLaunchBean
*/
public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) {
Log.e(TAG, "setNetAndlaunch: ");
String net_ok = "";
String net_not = "";
String launch = "";
String camera_ok = "";
String camera_not = "";
String upgrade_ok = "";
String upgrade_not = "";
String slide_ok = "";
String slide_not = "";
List<NetAndLaunchData> data = netAndLaunchBean.getData();
for (int i = 0; i < data.size(); i++) {
NetAndLaunchData netAndLaunchData = data.get(i);
String app_package = netAndLaunchData.getApp_package();
int is_auto = netAndLaunchData.getIs_auto();
int is_network = netAndLaunchData.getIs_network();
int is_camera = netAndLaunchData.getIs_camera();
int is_upgrade = netAndLaunchData.getIs_upgrade();
int is_slide = netAndLaunchData.getIs_slide();
if (is_auto == 1) {
launch += app_package + ",";
}
if (is_network == 1) {
net_ok += app_package + ",";
} else {
net_not += app_package + ",";
}
if (is_camera == 1) {
camera_ok += app_package + ",";
} else {
camera_not += app_package + ",";
}
if (is_upgrade == 1) {
upgrade_ok += app_package + ",";
} else {
upgrade_not += app_package + ",";
}
if (is_slide == 1) {
slide_ok += app_package + ",";
} else {
slide_not += app_package + ",";
}
}
if (!TextUtils.isEmpty(launch)) {
launch = launch.substring(0, launch.length() - 1);
}
if (!TextUtils.isEmpty(net_ok)) {
net_ok = net_ok.substring(0, net_ok.length() - 1);
}
if (!TextUtils.isEmpty(net_not)) {
net_not = net_not.substring(0, net_not.length() - 1);
}
if (!TextUtils.isEmpty(camera_ok)) {
camera_ok = camera_ok.substring(0, camera_ok.length() - 1);
}
if (!TextUtils.isEmpty(camera_not)) {
camera_not = camera_not.substring(0, camera_not.length() - 1);
}
if (!TextUtils.isEmpty(upgrade_ok)) {
upgrade_ok = upgrade_ok.substring(0, upgrade_ok.length() - 1);
}
if (!TextUtils.isEmpty(upgrade_not)) {
upgrade_not = upgrade_not.substring(0, upgrade_not.length() - 1);
}
if (!TextUtils.isEmpty(slide_ok)) {
slide_ok = slide_ok.substring(0, slide_ok.length() - 1);
}
if (!TextUtils.isEmpty(slide_not)) {
slide_not = slide_not.substring(0, slide_not.length() - 1);
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", slide_not);
Log.e("fht", "qch_disable_slide=" + writeSucceed + ":" + slide_not);
} else {
boolean writeSucceed = Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
Log.e("fht", "qch_disable_slide ok=" + writeSucceed + ":" + slide_ok);
}
Utils.writeDisableUpdateList(mContext, upgrade_not.split(","), upgrade_ok.split(","));
boolean qch_app_power_on = Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", launch);
// Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
// netControlIntent.putExtra("package_name", net_not);
// sendBroadcast(netControlIntent);
//
// Intent netControlNotIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY);
// netControlNotIntent.putExtra("package_name", net_ok);
// sendBroadcast(netControlNotIntent);
if (!net_not.equals("")) {
String[] bans = net_not.split(",");
Settings.System.putString(mContext.getContentResolver(), "qch_jgy_network_disallow", net_not);
Log.e("fht", "ban::" + net_not);
}
BaseApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(mContext.getContentResolver(), "qch_jgy_network_allow", net_ok);
Log.e("fht", "not::" + net_ok);
}
// Intent intent2 = new Intent("qch_camera_forbid");
// intent2.putExtra("camera_package_name", camera_not).setPackage("com.android.settings");
// sendBroadcast(intent2);
// Intent intent1 = new Intent("qch_camera_open");
// intent1.putExtra("camera_package_name", camera_ok).setPackage("com.android.settings");
// sendBroadcast(intent1);
}
/**
* @param s1 需要管控的ID
* @param result 应用程序包名
*/
public void writeDeselectIDtoSystem(String s1, String result) {
if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) {
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
Log.e("writeDeselectIDtoSystem", "result: " + result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
if (!result.contains(store)) {
result = result + "," + store;
}
String olddeselectViewArray = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid_id");
Log.e("writeDeselectIDtoSystem", "olddeselectViewArray" + olddeselectViewArray);
Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid_id", result);
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", s1);
Log.e("writeDeselectIDtoSystem", "qch_app_forbid_id" + result);
Log.e("writeDeselectIDtoSystem", "deselectViewArray" + s1);
} else {
Log.e("writeDeselectIDtoSystem", "writeDeselectIDtoSystem is null:");
Settings.System.putString(mContext.getContentResolver(), "DeselectViewArray", "Invalid");
}
}
public void setAppinsideWeb(BaseResponse<List<Appground>> response) {
if (response.code == 200) {
List<Appground> appgrounds = response.data;
if (appgrounds != null && appgrounds.size() > 0) {
String strings = "";
String packageList = "";//单条管控名单
for (Appground appground : appgrounds) {
if (appground.getAddress().equals("")) {
packageList += appground.getPackages() + ",";
} else {
strings += appground.toString() + ";";
}
}
if (packageList.length() > 0) {
//app内所有的网页禁止
//packageList = packageList.substring(0, packageList.length() - 1);
//去掉多余的,
Log.e("setAppinsideWeb ", "packageList:" + packageList);
Intent qch_app_website = new Intent("qch_app_website")
.setPackage("com.android.settings");
qch_app_website.putExtra("package_name", packageList);
mContext.sendBroadcast(qch_app_website);
} else {
sendAllweb(mContext);
}
if (strings.length() > 0) {
//app内单个网页地址禁止打开
//strings = strings.substring(0, strings.length() - 1);
//去掉多余的;
Log.e("setAppinsideWeb ", "strings:" + strings);
Intent intent = new Intent("qch_app_inside_website")
.setPackage("com.android.settings");
intent.putExtra("websitelist", strings);
mContext.sendBroadcast(intent);
} else {
sendwebUrl(mContext);
}
}
} else if (response.code == 400) {
//列表为空的情况
sendAllweb(mContext);
sendwebUrl(mContext);
//ToastUtil.show(msg);
Log.e("setAppinsideWeb", "setAppinsideWeb: " + response.msg);
}
}
private static void sendAllweb(Context context) {
Intent intent = new Intent("qch_app_website")
.setPackage("com.android.settings");
intent.putExtra("package_name", "Invalid");
context.sendBroadcast(intent);
}
private static void sendwebUrl(Context context) {
Intent intent = new Intent("qch_app_inside_website")
.setPackage("com.android.settings");
intent.putExtra("websitelist", "Invalid");
context.sendBroadcast(intent);
}
public void SettingSysData(String data) {
SPUtils.put(mContext, "first_connect", 1);
SysSettingUtils.setSystemSetting(mContext, data);
}
public void writeAppPackageList(String result) {
String appstore = "com.jiaoguanyi.appstore";
String store = "com.jiaoguanyi.store";
String info = "com.info.sn";
// String iflytek = "com.estrongs.android.pop";
String jgy1 = "com.uiuios.jgy1";
String jgy2 = "com.uiuios.jgy2";
if (!TextUtils.isEmpty(result)) {
Log.e("writeAppPackageList", "result: " + result);
if (!result.contains(appstore)) {
result = result + "," + appstore;
}
if (!result.contains(store)) {
result = result + "," + store;
}
if (!result.contains(jgy1)) {
result = result + "," + jgy1;
}
if (!result.contains(jgy2)) {
result = result + "," + jgy2;
}
if (!result.contains(info)) {
result = result + "," + info;
}
boolean b = Settings.System.putString(mContext.getContentResolver(), "qch_app_forbid", result);
Log.e("mjsheng", "qch_app_forbid is :" + b + Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid"));
} else {
Log.e("mjsheng", "writeAppPackageList is null:");
}
}
public void forceDownload(List<ForceDownloadData> data) {
if (data == null || data.size() <= 0) {
return;
}
getSelfDownload(data);
List<String> list = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
ForceDownloadData forceDownloadData = data.get(i);
String app_name = forceDownloadData.getApp_name();
String app_package = forceDownloadData.getApp_package();
String app_url = forceDownloadData.getApp_url();
JSONObject jsonObject = new JSONObject();
jsonObject.put("app_name", app_name);
jsonObject.put("app_package", app_package);
int app_version_code = forceDownloadData.getApp_version_code();
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code);
if (data.get(i).getApp_package().equals("com.jiaoguanyi.appstore")) {
continue;//为自身的跳过下载
}
if (!list.contains(app_package)) {
list.add(app_package);
}
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(app_package, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e("fht", "forceDownload=" + e.getMessage());
}
if (packageInfo != null) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = packageInfo.getLongVersionCode();
} else {
appVersionCode = packageInfo.versionCode;
}
if (app_version_code > appVersionCode) {
Log.e("fht ", "download URL " + app_url);
// Aria.download(this)
// .load(app_url) //读取下载地址
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
// .setExtendField(jsonObject.toJSONString())
// .create(); //启动下载}
Utils.ariaDownload(mContext, app_url, jsonObject);
}
} else {
Log.e("fht ", "download URL " + app_url);
// if (!SaveListUtils.isDownLoading(app_package)) {
// Aria.download(this)
// .load(app_url) //读取下载地址
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
// .setExtendField(jsonObject.toJSONString())
// .create(); //启动下载}
Utils.ariaDownload(mContext, app_url, jsonObject);
// SaveListUtils.addDownLoadList(app_package);
// }
}
}
SaveListUtils.setList(list);
SaveListUtils.sendForceAPP(mContext);
}
private void getSelfDownload(List<ForceDownloadData> forceDownloadDataList) {
for (ForceDownloadData forceDownloadData : forceDownloadDataList) {
if ("com.jiaoguanyi.store".equals(forceDownloadData.getApp_package())) {
if (!ApkUtils.isAvailable(mContext, "com.jiaoguanyi.store")) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("app_name", forceDownloadData.getApp_name());
jsonObject.put("app_package", forceDownloadData.getApp_package());
// Aria.download(this)
// .load(forceDownloadData.getApp_url()) //读取下载地址
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true)
// .setExtendField(jsonObject.toJSONString())
// .create(); //启动下载}
Utils.ariaDownload(mContext, forceDownloadData.getApp_url(), jsonObject);
}
} else {
// Log.e("fht", "未上传应用");
}
}
}
/**
* @param jsonObject 安装应用
*/
public void installAPK(JsonObject jsonObject) {
final String url = jsonObject.get("url").getAsString();
int versionCode = jsonObject.get("version_code").getAsInt();
final String packageName = jsonObject.get("package").getAsString();
String app_name = jsonObject.get("app_name").getAsString();
final JSONObject object = new JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.versionCode < versionCode) {
Utils.ariaDownload(mContext, url, object);
} else {
Log.e("installAPK", "已是最新版本");
}
}
public void installTestAPK(JsonObject jsonObject) {
final String url = jsonObject.get("app_url").getAsString();
int versionCode = jsonObject.get("app_version_code").getAsInt();
final String packageName = jsonObject.get("app_package").getAsString();
String app_name = jsonObject.get("app_name").getAsString();
final JSONObject object = new JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.versionCode < versionCode) {
Utils.ariaDownload(mContext, url, object);
} else {
Log.e("installTestAPK", "TestAPK: " + "无更新");
}
}
public void installDesktop(JSONObject jsonObject) {
String app_name = jsonObject.getString("app_name");
String app_url = jsonObject.getString("app_url");
String app_package = jsonObject.getString("app_package");
int app_version_code = jsonObject.getInteger("app_version_code");
PackageInfo info = null;
PackageManager packageManager = mContext.getPackageManager();
if (null != packageManager) {
try {
info = packageManager.getPackageInfo(app_package, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e("fht", "installDesktop: " + e.getMessage());
}
if (null != info) {
long versionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
versionCode = info.getLongVersionCode();
} else {
versionCode = info.versionCode;
}
if (app_version_code > versionCode) {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(mContext, app_url, jsonObject);
}
}
} else {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(mContext, app_url, jsonObject);
}
}
}
}
//删除用户除了在应用市场的其他应用
public void deleteOtherApp(String packageList) {
Log.e("deleteOtherApp", "packageList:" + packageList);
String[] result = packageList.split(",");
List<String> resultList = new ArrayList<>(Arrays.asList(result));
List<String> packageLists = ApkUtils.queryFilterAppInfo(mContext);
Log.e("deleteOtherApp", "packageLists:" + packageLists.toString());
if (resultList.size() > 0) {
for (final String packageName : packageLists) {
if (Utils.isSystemApp(mContext, packageName)) {
Log.e("deleteOtherApp", "is systemApp:" + packageName);
continue;
}
if (ApkUtils.canremove_systemapp.contains(packageName)) {
continue;
}
if (!resultList.contains(packageName)) {
new Thread(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(mContext, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
}
}
}).start();
Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
}
}
}
}
/**
* 从Manifest中获取meta-data值
* https://blog.csdn.net/yue_233/article/details/91453451
*
* @return
*/
public String getStringMetaData() {
ApplicationInfo appInfo = null;
try {
appInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
String value = appInfo.metaData.getString("CHANNEL_VALUE");
return value;
}
}

View File

@@ -4,8 +4,6 @@ import android.app.ActivityManager;
import android.content.Context;
import android.util.Log;
import com.mjsheng.myappstore.MyApplication;
public class ServiceAliveUtils {
public static boolean isServiceAlice(Context mContext) {
boolean isServiceRunning = false;

View File

@@ -6,7 +6,7 @@ import androidx.annotation.NonNull;
import android.text.TextUtils;
import com.mjsheng.myappstore.server.InitJpushServer;
import com.mjsheng.myappstore.server.MainService;
import java.text.DateFormat;
import java.text.ParseException;
@@ -82,7 +82,7 @@ public class TimeUtils {
SPUtils.put(context, START_TIME_KEY, "00:00");
SPUtils.put(context, END_TIME_KEY, "00:00");
Intent intent = new Intent();
intent.setAction(InitJpushServer.TimeChangedReceiver.ACTION_UPDATE);
intent.setAction(MainService.TimeChangedReceiver.ACTION_UPDATE);
context.sendBroadcast(intent);
}

View File

@@ -37,8 +37,8 @@ public class ToastUtil {
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
time2 = System.currentTimeMillis();
if ((time2 - time1) > 3499) {
showToast(mContext, msg, Toast.LENGTH_LONG);
if ((time2 - time1) > 3500) {
showToast(mContext, msg, Toast.LENGTH_SHORT);
Log.e("fht", "LENGTH_LONG");
time1 = time2;
}

View File

@@ -32,7 +32,9 @@ import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.provider.Settings;
import androidx.annotation.RequiresApi;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.Formatter;
@@ -57,7 +59,7 @@ import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.base.BaseApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import java.io.BufferedReader;
@@ -441,14 +443,14 @@ public class Utils {
public static void unInstallAPP(Context context, String packageName) {
if (!TextUtils.isEmpty(packageName) && !AppsManagerUtils.isSystemApp(context, packageName)) {
if (AppsManagerUtils.isSystemApp(context, packageName)) {
Toast.makeText(MyApplication.getAppContext(), R.string.system_unistall_error, Toast.LENGTH_SHORT).show();
Toast.makeText(BaseApplication.getAppContext(), R.string.system_unistall_error, Toast.LENGTH_SHORT).show();
} else {
Uri packageURI = Uri.parse("package:" + packageName);
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
context.startActivity(intent);
}
} else {
Toast.makeText(MyApplication.getAppContext(), R.string.unistall_error, Toast.LENGTH_SHORT).show();
Toast.makeText(BaseApplication.getAppContext(), R.string.unistall_error, Toast.LENGTH_SHORT).show();
}
}
@@ -672,6 +674,20 @@ public class Utils {
return "";
}
//获取教管易版本号
public static synchronized String getAPPVersionName(Context context) {
PackageManager pm = context.getPackageManager();
String versionName;
try {
PackageInfo packageInfo = pm.getPackageInfo("com.jiaoguanyi.store", 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
versionName = "0";
}
return versionName;
}
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)