version:1.7.0
fix:在线状态,黑白名单失效 add:
This commit is contained in:
@@ -18,8 +18,8 @@ android {
|
||||
applicationId "com.info.sn"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 29
|
||||
versionCode 69
|
||||
versionName "1.6.9"
|
||||
versionCode 70
|
||||
versionName "1.7.0"
|
||||
multiDexEnabled true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
ndk {
|
||||
@@ -37,6 +37,8 @@ android {
|
||||
includeCompileClasspath true
|
||||
}
|
||||
}
|
||||
buildConfigField "String", "SCREEN_URL", '"https://homework.uiuios.com:3018/wm/is_online"'
|
||||
buildConfigField "String", "WEBSOCKET_URL", '"wss://homework.uiuios.com:3018"'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
@@ -93,7 +95,6 @@ android {
|
||||
manifestPlaceholders = [
|
||||
AMAP_KEY: "8c4e1d478cb91e6b5713562bc424efba"
|
||||
]
|
||||
buildConfigField "String", "SCREEN_URL", '"https://homework.uiuios.com:3018/wm/is_online"'
|
||||
}
|
||||
|
||||
zhanRuiDebug.initWith(debug)
|
||||
@@ -105,7 +106,6 @@ android {
|
||||
manifestPlaceholders = [
|
||||
AMAP_KEY: "8c4e1d478cb91e6b5713562bc424efba"
|
||||
]
|
||||
buildConfigField "String", "SCREEN_URL", '"https://homework.uiuios.com:3018/wm/is_online"'
|
||||
}
|
||||
|
||||
debug {
|
||||
@@ -126,7 +126,6 @@ android {
|
||||
manifestPlaceholders = [
|
||||
AMAP_KEY: "83869aed8624eb00615c2b6d3d15d777"
|
||||
]
|
||||
buildConfigField "String", "SCREEN_URL", '"https://homework.uiuios.com:3018/wm/is_online"'
|
||||
}
|
||||
|
||||
release {
|
||||
@@ -152,7 +151,6 @@ android {
|
||||
manifestPlaceholders = [
|
||||
AMAP_KEY: "83869aed8624eb00615c2b6d3d15d777"
|
||||
]
|
||||
buildConfigField "String", "SCREEN_URL", '"https://homework.uiuios.com:3018/wm/is_online"'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,21 @@
|
||||
android:exported="true" />
|
||||
<service android:name=".service.GuardService" />
|
||||
<service android:name=".service.MyDownloadService" />
|
||||
<service android:name=".service.StepService" />
|
||||
<service
|
||||
android:name=".service.StepService"
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.SCREEN_OFF" />
|
||||
<action android:name="android.intent.action.SCREEN_ON" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
|
||||
<action android:name="android.intent.action.FACTORY_RESET" />
|
||||
<action android:name="android.intent.action.MASTER_CLEAR" />
|
||||
|
||||
<data android:scheme="package" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name=".service.ManagerService">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
|
||||
@@ -923,6 +923,9 @@ public class MainPresenter implements MainContact.Presenter {
|
||||
} else {
|
||||
JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
}else {
|
||||
JGYUtils.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
|
||||
JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ public class SelecteGradePresenter implements SelecteGradeContact.Presenter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeUser(AvailableProduct product,int grade) {
|
||||
public void activeUser(AvailableProduct product, int grade) {
|
||||
String specification_id = product.getSpecification_id();
|
||||
Log.e(TAG, "activeUser: specification_id: " + specification_id);
|
||||
String appid = Scheme.partner_id;
|
||||
@@ -251,13 +251,13 @@ public class SelecteGradePresenter implements SelecteGradeContact.Presenter {
|
||||
Settings.System.putInt(mContext.getContentResolver(), MainActivity.activation, 0);
|
||||
break;
|
||||
}
|
||||
mView.activeUserFinish(gankaoBaseResponse.code,grade);
|
||||
mView.activeUserFinish(gankaoBaseResponse.code, grade);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG + "activeUser", "onError: ");
|
||||
mView.activeUserFinish(0,grade);
|
||||
mView.activeUserFinish(0, grade);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -299,7 +299,7 @@ public class SelecteGradePresenter implements SelecteGradeContact.Presenter {
|
||||
JsonObject jsonObject = JsonParser.parseString(gson.toJson(gankaoBaseResponse.data)).getAsJsonObject();
|
||||
JsonArray jsonArray = jsonObject.getAsJsonArray("powerlist");
|
||||
List<PowerUser> powerUserList = gson.fromJson(gson.toJson(jsonArray), type);
|
||||
mView. queryPowerUserListFinish(powerUserList,grade);
|
||||
mView.queryPowerUserListFinish(powerUserList, grade);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.info.sn.bean.gankao;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CancelUserPower implements Serializable {
|
||||
private static final long serialVersionUID = 6582192006004247173L;
|
||||
|
||||
boolean success;
|
||||
String user_power_id;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getUser_power_id() {
|
||||
return user_power_id;
|
||||
}
|
||||
|
||||
public void setUser_power_id(String user_power_id) {
|
||||
this.user_power_id = user_power_id;
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,9 @@ public class HTTPInterface {
|
||||
} else {
|
||||
JGYUtils.putString(context.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
}else {
|
||||
JGYUtils.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
|
||||
JGYUtils.putString(context.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class UrlAddress {
|
||||
//浏览器网址管控
|
||||
public final static String SET_BROWSER_URL = ROOT_URL + "control/getBrowser";
|
||||
//浏览器书签管控
|
||||
public final static String SET_BROWSER_Label = ROOT_URL + "control/getLabel";
|
||||
public final static String SET_BROWSER_LABEL = ROOT_URL + "control/getLabel";
|
||||
//获取强制下载
|
||||
public final static String GET_FORCE_INSTALL = ROOT_URL + "app/getForceDownload";
|
||||
//获取app管控
|
||||
|
||||
@@ -8,7 +8,7 @@ import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface BrowserLabel {
|
||||
@GET(UrlAddress.SET_BROWSER_Label)
|
||||
@GET(UrlAddress.SET_BROWSER_LABEL)
|
||||
Observable<BaseResponse> getLabel(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.info.sn.network.api;
|
||||
|
||||
import com.info.sn.bean.zuoye.AppInfo;
|
||||
import com.info.sn.bean.zuoye.BaseResponse;
|
||||
import com.info.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface NewestAppUpdate {
|
||||
@GET(UrlAddress.GET_NEWESTAPPUPDATE)
|
||||
Observable<BaseResponse<AppInfo>> getAppUpdate(
|
||||
@Query("packageName") String packageName,
|
||||
@Query("versionCode") String versionCode,
|
||||
@Query("type") int type
|
||||
);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.info.sn.network.api
|
||||
|
||||
import com.info.sn.bean.zuoye.AppInfo
|
||||
import com.info.sn.bean.zuoye.BaseResponse
|
||||
import com.info.sn.network.UrlAddress
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface NewestAppUpdate {
|
||||
@GET(UrlAddress.GET_NEWESTAPPUPDATE)
|
||||
fun getAppUpdate(
|
||||
@Query("packageName") packageName: String?,
|
||||
@Query("versionCode") versionCode: String?,
|
||||
@Query("type") type: Int
|
||||
): Observable<BaseResponse<AppInfo?>?>?
|
||||
}
|
||||
18
app/src/main/java/com/info/sn/network/api/QueryAllApp.java
Normal file
18
app/src/main/java/com/info/sn/network/api/QueryAllApp.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.info.sn.network.api;
|
||||
|
||||
import com.info.sn.bean.zuoye.AppInfo;
|
||||
import com.info.sn.bean.zuoye.BaseResponse;
|
||||
import com.info.sn.network.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface QueryAllApp {
|
||||
@GET(UrlAddress.GET_ALL_PACKAGE)
|
||||
Observable<BaseResponse<List<AppInfo>>> getAllApp(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.info.sn.network.api
|
||||
|
||||
import com.info.sn.bean.zuoye.AppInfo
|
||||
import com.info.sn.bean.zuoye.BaseResponse
|
||||
import com.info.sn.network.UrlAddress
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface QueryAllApp {
|
||||
@GET(UrlAddress.GET_ALL_PACKAGE)
|
||||
fun getAllApp(
|
||||
@Query("sn") sn: String?
|
||||
): Observable<BaseResponse<List<AppInfo?>?>?>?
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.info.sn.network.api.gankao;
|
||||
|
||||
import com.info.sn.bean.gankao.GankaoBaseResponse;
|
||||
import com.info.sn.bean.gankao.CancelUserPower;
|
||||
import com.info.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@@ -9,7 +10,7 @@ import retrofit2.http.Query;
|
||||
|
||||
public interface CancelUserPowerApi {
|
||||
@GET(UrlAddress.CANCEL_USER_POWER)
|
||||
Observable<GankaoBaseResponse> cancelUserPower(
|
||||
Observable<GankaoBaseResponse<CancelUserPower>> cancelUserPower(
|
||||
@Query("app_id") String app_id,
|
||||
@Query("timestamp") String timestamp,
|
||||
@Query("token") String token,
|
||||
|
||||
@@ -14,6 +14,6 @@ public interface UpgradeUserPowerApi {
|
||||
@Query("timestamp") String timestamp,
|
||||
@Query("token") String token,
|
||||
@Query("uid") String uid,
|
||||
@Query("user_power_id") int user_power_id
|
||||
@Query("user_power_id") String user_power_id
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,17 +18,24 @@ import android.view.Gravity;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.info.sn.activity.main.MainActivity;
|
||||
import com.info.sn.bean.gankao.AvailableProduct;
|
||||
import com.info.sn.bean.gankao.CancelUserPower;
|
||||
import com.info.sn.bean.gankao.GankaoBaseResponse;
|
||||
import com.info.sn.bean.gankao.PowerUser;
|
||||
import com.info.sn.bean.gankao.UserProduct;
|
||||
import com.info.sn.bean.gankao.UserProductCards;
|
||||
import com.info.sn.bean.zuoye.BaseResponse;
|
||||
import com.info.sn.bean.zuoye.Response;
|
||||
import com.info.sn.bean.zuoye.SNUidBean;
|
||||
import com.info.sn.config.Scheme;
|
||||
import com.info.sn.jpush.Logger;
|
||||
import com.info.sn.manager.ControlManager;
|
||||
@@ -48,7 +55,6 @@ import com.info.sn.utils.ServiceAliveUtils;
|
||||
import com.info.sn.utils.ToastUtil;
|
||||
import com.info.sn.utils.Utils;
|
||||
import com.info.sn.dialog.CustomDialog;
|
||||
import com.trello.rxlifecycle2.android.ActivityEvent;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -159,7 +165,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
private static final String JIGUANG_CHANGE_COMBO = "41";
|
||||
//取消所有套餐
|
||||
private static final String JIGUANG_CANCEL_COMBO = "42";
|
||||
|
||||
//升级套餐
|
||||
private static final String JIGUANG_UPGRADE_COMBO = "43";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -369,6 +376,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
case JIGUANG_CANCEL_COMBO:
|
||||
cancleCombo(context, extras);
|
||||
break;
|
||||
case JIGUANG_UPGRADE_COMBO:
|
||||
upgradeCombo(context, extras);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -937,11 +947,12 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
private void changeCombo(Context context, String jsonString) {
|
||||
Log.e(TAG, "changeCombo: " + jsonString);
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
String card_info = jsonObject.getString("card_info");
|
||||
if (TextUtils.isEmpty(card_info)) {
|
||||
JSONObject edit_card_info = jsonObject.getJSONObject("edit_card_info");
|
||||
String taocan = edit_card_info.getString("taocan");
|
||||
if (TextUtils.isEmpty(taocan)) {
|
||||
ToastUtil.show("要修改的套餐名为空");
|
||||
} else {
|
||||
HashSet<String> infoSet = new HashSet<>(Arrays.asList(card_info.split(",")));
|
||||
HashSet<String> infoSet = new HashSet<>(Arrays.asList(taocan.split(",")));
|
||||
for (String cardInfo : infoSet) {
|
||||
queryAvailableProduct(cardInfo);
|
||||
}
|
||||
@@ -1109,31 +1120,252 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
private void cancleCombo(Context context, String jsonString) {
|
||||
Log.e(TAG, "cancleCombo: " + jsonString);
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
cancelUserPower(jsonObject);
|
||||
|
||||
List<SNUidBean> snUidBeans = JSON.parseArray(jsonObject.getJSONArray("delete_card_info").toJSONString(), SNUidBean.class);
|
||||
for (SNUidBean snUidBean : snUidBeans) {
|
||||
cancelUserPower(context, snUidBean);
|
||||
try {
|
||||
wait(1500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelUserPower(JSONObject jsonObject) {
|
||||
String appid = Scheme.partner_id;
|
||||
private void cancelUserPower(Context context, SNUidBean snUidBean) {
|
||||
String app_id = Scheme.partner_id;
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String uid = Utils.getSerial();
|
||||
String user_power_id = jsonObject.getString("user_power_id");
|
||||
String specification_id = jsonObject.getString("specification_id");
|
||||
String user_power_id = snUidBean.getUser_power_id();
|
||||
String specification_id = snUidBean.getSpecification_id();
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("appid", appid);
|
||||
params.put("app_id", app_id);
|
||||
params.put("timestamp", timestamp);
|
||||
params.put("uid", uid);
|
||||
params.put("user_power_id", user_power_id);
|
||||
params.put("specification_id", specification_id);
|
||||
|
||||
NetInterfaceManager.getInstance()
|
||||
.getCancelUserPowerControl()
|
||||
.cancelUserPower(appid, timestamp, LaunchTools.getToken(params), user_power_id, specification_id)
|
||||
.cancelUserPower(app_id, timestamp, LaunchTools.getToken(params), user_power_id, specification_id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe();
|
||||
.subscribe(new Observer<GankaoBaseResponse<CancelUserPower>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("cancelUserPower", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GankaoBaseResponse<CancelUserPower> cancelUserPowerGankaoBaseResponse) {
|
||||
Log.e("cancelUserPower", "onNext: " + JSONObject.toJSONString(cancelUserPowerGankaoBaseResponse));
|
||||
switch (cancelUserPowerGankaoBaseResponse.code) {
|
||||
default:
|
||||
break;
|
||||
case 10000:
|
||||
|
||||
break;
|
||||
case 50000:
|
||||
|
||||
break;
|
||||
}
|
||||
queryAvailableProduct(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("cancelUserPower", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("cancelUserPower", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void queryAvailableProduct(Context context) {
|
||||
String appid = Scheme.partner_id;
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("appid", appid);
|
||||
params.put("timestamp", timestamp);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQueryProductControl()
|
||||
.activeUser(appid, timestamp, LaunchTools.getToken(params))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<GankaoBaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e(TAG + "queryAvailableProduct", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GankaoBaseResponse gankaoBaseResponse) {
|
||||
Log.e(TAG + "queryAvailableProduct", "onNext: " + JSONObject.toJSONString(gankaoBaseResponse));
|
||||
if (gankaoBaseResponse.code == 10000) {
|
||||
Type type = new TypeToken<List<AvailableProduct>>() {
|
||||
}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<AvailableProduct> availableProductList = gson.fromJson(gson.toJson(gankaoBaseResponse.data), type);
|
||||
for (AvailableProduct product : availableProductList) {
|
||||
mAvailableProductHashMap.put(product.getDuration(), product.getSpecification_id());
|
||||
}
|
||||
queryPowerUserList(context);
|
||||
} else {
|
||||
ToastUtil.show("获取激活套餐失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG + "queryAvailableProduct", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG + "queryAvailableProduct", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private HashMap<String, String> mAvailableProductHashMap = new HashMap<>();
|
||||
|
||||
public void queryPowerUserList(Context context) {
|
||||
String appid = Scheme.partner_id;
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("appid", appid);
|
||||
params.put("timestamp", timestamp);
|
||||
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQueryPowerUserListControl()
|
||||
.queryPowerUserList(appid, timestamp, LaunchTools.getToken(params))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<GankaoBaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("queryPowerUserList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GankaoBaseResponse gankaoBaseResponse) {
|
||||
Log.e("queryPowerUserList", "onNext: ");
|
||||
// Log.e("queryPowerUserList", "onNext: " + JSONObject.toJSONString(gankaoBaseResponse));
|
||||
int code = gankaoBaseResponse.code;
|
||||
if (code == 10000) {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<PowerUser>>() {
|
||||
}.getType();
|
||||
JsonObject data = JsonParser.parseString(gson.toJson(gankaoBaseResponse.data)).getAsJsonObject();
|
||||
JsonArray powerlist = data.getAsJsonArray("powerlist");
|
||||
List<PowerUser> powerUserList = gson.fromJson(gson.toJson(powerlist), type);
|
||||
Log.e("queryPowerUserList", "onNext: " + JSONObject.toJSONString(powerUserList));
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
if (powerUserList != null && powerUserList.size() != 0) {
|
||||
for (PowerUser powerUser : powerUserList) {
|
||||
if (powerUser.getUserID().equals(Utils.getSerial())) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("card_info", powerUser.getAuthorityName());
|
||||
jsonObject.put("grade", powerUser.getGrade());
|
||||
jsonObject.put("activate_time", powerUser.getAuthorizationDate());
|
||||
jsonObject.put("user_power_id", powerUser.getAuthorizationNumber());
|
||||
jsonObject.put("specification_id", mAvailableProductHashMap.get(powerUser.getAuthorityName()));
|
||||
jsonArray.add(jsonObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
sendUid(context, jsonArray.toJSONString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("queryPowerUserList", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("queryPowerUserList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendUid(Context context, String jsonString) {
|
||||
int grade = (int) SPUtils.get(context, "int_grade", 0);
|
||||
|
||||
String gankaoUID = Settings.System.getString(context.getContentResolver(), "gankaoUID");
|
||||
if (TextUtils.isEmpty(gankaoUID)) {
|
||||
ToastUtil.show("获取设备UID失败,请重新激活");
|
||||
}
|
||||
Log.e(TAG, "sendUid: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSaveSnUidApiControl()
|
||||
.saveSnUid(Utils.getSerial(), gankaoUID, grade, jsonString)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<Response>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e(TAG + "sendUid", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Response response) {
|
||||
Log.e(TAG + "sendUid", "onNext: " + JSONObject.toJSONString(response));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG + "sendUid", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG + "sendUid", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void upgradeCombo(Context context, String jsonString) {
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
String appid = Scheme.partner_id;
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String uid = Utils.getSerial();
|
||||
String user_power_id = jsonObject.getString("user_power_id");
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("app_id", appid);
|
||||
params.put("timestamp", timestamp);
|
||||
params.put("uid", uid);
|
||||
params.put("user_power_id", user_power_id);
|
||||
|
||||
NetInterfaceManager.getInstance()
|
||||
.getUpgradeUserPowerControl()
|
||||
.upgradeUserPower(appid, timestamp, LaunchTools.getToken(params), uid, user_power_id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<GankaoBaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("upgradeCombo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GankaoBaseResponse gankaoBaseResponse) {
|
||||
Log.e("upgradeCombo", "onNext: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("upgradeCombo", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("upgradeCombo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,37 +8,55 @@ package com.info.sn.service;
|
||||
*/
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.info.sn.BuildConfig;
|
||||
import com.info.sn.KeepAliveConnection;
|
||||
import com.info.sn.websocket.JWebSocketClient;
|
||||
import com.info.sn.utils.ServiceAliveUtils;
|
||||
import com.info.sn.utils.Utils;
|
||||
import com.info.sn.websocket.JWebSocketClient;
|
||||
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
||||
/**
|
||||
* 主进程 双进程通讯
|
||||
*
|
||||
* @author LiGuangMin
|
||||
* @time Created by 2018/8/17 11:26
|
||||
*/
|
||||
public class StepService extends Service {
|
||||
public class StepService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||
private final static String TAG = StepService.class.getSimpleName();
|
||||
|
||||
public JWebSocketClient client;
|
||||
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
|
||||
private final static String TAG = StepService.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
Log.i("JWebSocketClientService", "网络断开连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
Log.i("JWebSocketClientService", "网络已连接");
|
||||
connect();
|
||||
}
|
||||
|
||||
//用于Activity和service通讯
|
||||
public class JWebSocketClientBinder extends Binder {
|
||||
@@ -50,10 +68,10 @@ public class StepService extends Service {
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
Log.e(TAG, "StepService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this, getClass().getName());
|
||||
Log.w(TAG, "StepService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this, GuardService.class.getName());
|
||||
if (!isServiceRunning) {
|
||||
Intent i = new Intent(StepService.this, MyDownloadService.class);
|
||||
Intent i = new Intent(StepService.this, GuardService.class);
|
||||
startService(i);
|
||||
}
|
||||
}
|
||||
@@ -75,33 +93,116 @@ public class StepService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
registerScreenLockReceiver();
|
||||
//初始化websocket
|
||||
initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// 绑定建立链接
|
||||
Log.e("JWebSocketClientService", "onStartCommand: ");
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
private ScreenLockReceiver screenLockReceiver;
|
||||
|
||||
private void registerScreenLockReceiver() {
|
||||
if (null == screenLockReceiver) {
|
||||
screenLockReceiver = new ScreenLockReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
|
||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN);
|
||||
filter.addAction(Intent.ACTION_FACTORY_RESET);
|
||||
filter.addAction(Intent.ACTION_MASTER_CLEAR);
|
||||
registerReceiver(screenLockReceiver, filter);
|
||||
}
|
||||
|
||||
private class ScreenLockReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive:" + action);
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
Log.e(TAG, "onReceive: is NULL");
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case Intent.ACTION_BOOT_COMPLETED:
|
||||
case Intent.ACTION_USER_PRESENT:
|
||||
case Intent.ACTION_SCREEN_ON:
|
||||
sendMsg(1);
|
||||
break;
|
||||
case Intent.ACTION_SCREEN_OFF:
|
||||
case Intent.ACTION_SHUTDOWN:
|
||||
case Intent.ACTION_FACTORY_RESET:
|
||||
case Intent.ACTION_MASTER_CLEAR:
|
||||
sendMsg(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||
closeConnect();
|
||||
if (screenLockReceiver != null) {
|
||||
unregisterReceiver(screenLockReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化websocket连接
|
||||
*/
|
||||
private void initSocketClient() {
|
||||
URI uri = URI.create("ws://39.108.116.195:2346");
|
||||
URI uri = URI.create(BuildConfig.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) {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Log.i("JWebSocketClientService", "收到服务器发来的消息:" + message + "?");
|
||||
Log.i("JWebSocketClientService", "收到服务器发来的消息:" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
super.onOpen(handshakedata);
|
||||
Log.i("JWebSocketClientService", "websocket连接成功");
|
||||
sendMsg(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
super.onClose(code, reason, remote);
|
||||
Log.i("JWebSocketClientService", "websocket连接关闭:" + reason);
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
super.onError(ex);
|
||||
Log.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage());
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
|
||||
}
|
||||
};
|
||||
connect();
|
||||
@@ -118,7 +219,7 @@ public class StepService extends Service {
|
||||
//connectBlocking多出一个等待操作,会先连接再发送,否则未连接发送会报错
|
||||
Log.i("JWebSocketClientService", "websocket链接中");
|
||||
client.connectBlocking();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (Exception e) {
|
||||
Log.i("JWebSocketClientService", e.getMessage());
|
||||
// e.printStackTrace();
|
||||
}
|
||||
@@ -129,13 +230,32 @@ public class StepService extends Service {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void sendMsg(String msg) {
|
||||
public void sendMsg() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("sn", Utils.getSerial());
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (!pm.isScreenOn()) {
|
||||
jsonObject.put("online", 0);
|
||||
//熄屏状态
|
||||
} else {
|
||||
jsonObject.put("online", 1);
|
||||
}
|
||||
if (null != client) {
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + msg);
|
||||
client.send(msg);
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
client.send(jsonObject.toJSONString());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMsg(int state) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("sn", Utils.getSerial());
|
||||
jsonObject.put("online", state);
|
||||
if (null != client) {
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
client.send(jsonObject.toJSONString());
|
||||
} else {
|
||||
Log.i("JWebSocketClientService", "未连接");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +275,7 @@ public class StepService extends Service {
|
||||
}
|
||||
|
||||
// -------------------------------------websocket心跳检测------------------------------------------------
|
||||
private static final long HEART_BEAT_RATE = 50 * 1000;//每隔55秒进行一次对长连接的心跳检测
|
||||
private static final long HEART_BEAT_RATE = 30 * 1000;//每隔50秒进行一次对长连接的心跳检测
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable heartBeatRunnable = new Runnable() {
|
||||
@Override
|
||||
@@ -164,7 +284,7 @@ public class StepService extends Service {
|
||||
if (client != null) {
|
||||
if (client.isOpen()) {
|
||||
Log.i("JWebSocketClientService", "websocket已连接");
|
||||
sendMsg(Utils.getSerial());
|
||||
sendMsg();
|
||||
} else if (client.isClosed()) {
|
||||
Log.i("JWebSocketClientService", "websocket重连中");
|
||||
reconnectWs();
|
||||
@@ -196,10 +316,4 @@ public class StepService extends Service {
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
closeConnect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user