version:2.4 beta

fix:
add:优化接口请求,修复一下报错,删除极光推送和高德地图sdk
This commit is contained in:
2022-06-29 19:59:19 +08:00
parent ace28e65b5
commit 657d45ab33
67 changed files with 13003 additions and 2963 deletions

View File

@@ -4,14 +4,11 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.uiui.sn.bean.AppInfo;
import com.uiui.sn.bean.AppletQRCode;
import com.uiui.sn.bean.BaseResponse;
import com.uiui.sn.bean.SnInfo;
import com.uiui.sn.config.CommonConfig;
@@ -108,8 +105,13 @@ public class MainAPresenter implements MainAContact.Presenter {
}
@Override
public void onComplete() {
public void onError(Object o) {
Log.e("getAppletQRCode", "onError: " + o);
mView.setAppletQRCode(null);
}
@Override
public void onComplete() {
Log.e("getAppletQRCode", "onComplete: ");
}
});

View File

@@ -20,7 +20,6 @@ import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.NetworkUtils;
import com.bumptech.glide.Glide;
import com.uiui.sn.BuildConfig;
@@ -42,7 +41,7 @@ import com.uiui.sn.service.GuardService;
import com.uiui.sn.service.ManagerService;
import com.uiui.sn.service.StepService;
import com.uiui.sn.service.main.MainService;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.TimeUtils;
@@ -56,7 +55,6 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.jpush.android.api.JPushInterface;
public class MainActivity extends BaseActivity implements MainAContact.MainView, NetworkUtils.OnNetworkStatusChangedListener {
private static final String TAG = MainActivity.class.getSimpleName();
@@ -84,11 +82,13 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
@Override
public void onDisconnected() {
Log.e(TAG, "onDisconnected: ");
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
Log.e(TAG, "onConnected: ");
timeMillis = System.currentTimeMillis();
mPresenter.getSnInfo();
}
@@ -156,21 +156,24 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
}
}
//执行所有接口耗时
long timeMillis;
@Override
public void initData() {
if (DeviceManager.isDebugMode()) {
Log.e(TAG, "getAllSPUtils: " + JSONObject.toJSONString(SPUtils.getAll(this)));
Log.e(TAG, "getAllSPUtils: " + GsonUtils.toJSONString(SPUtils.getAll(this)));
Log.e(TAG, "getWeekDay: " + TimeUtils.inWeekDay());
Log.e(TAG, "getWeekDay: " + TimeUtils.inWeekDay(1627702095000L));
Log.e(TAG, "getWeekDayString: " + new TimeUtils().getWeekDayString());
Log.e(TAG, "getWeekDayString: " + new TimeUtils().getWeekDayString(1627702095000L));
}
JPushInterface.init(this);
if (DeviceManager.isDebugMode()) {
JGYUtils.putInt(getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, 0);
}
startService();
registerReceiver();
timeMillis = System.currentTimeMillis();
}
@Override
@@ -393,6 +396,6 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
@Override
public void setForceInstall() {
Log.e(TAG, "SettingFinish: " + (System.currentTimeMillis() - timeMillis) + " ms");
}
}

View File

@@ -1,8 +1,6 @@
package com.uiui.sn.base;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
@@ -13,69 +11,29 @@ import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.jpush.TagAliasOperatorHelper;
import com.uiui.sn.manager.AmapManager;
import com.uiui.sn.manager.ConnectManager;
import com.uiui.sn.manager.ControlPanelManager;
import com.uiui.sn.network.NetInterfaceManager;
import com.uiui.sn.manager.ControlManager;
import com.uiui.sn.manager.ControlPanelManager;
import com.uiui.sn.manager.DeviceManager;
import com.uiui.sn.network.UrlAddress;
import com.uiui.sn.network.NetInterfaceManager;
import com.uiui.sn.rlog.LogDBManager;
import com.uiui.sn.utils.AppUsedTimeUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.ToastUtil;
import com.uiui.sn.utils.SystemUtils;
import com.uiui.sn.utils.Utils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class BaseApplication extends Application {
private static final String TAG = BaseApplication.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
public static Context context;
@SuppressLint("StaticFieldLeak")
private static BaseApplication instance;
public static Context getAppContext() {
return context;
}
// 单例模式中获取唯一的ExitApplication实例
public static BaseApplication getInstance() {
if (null == instance) {
instance = new BaseApplication();
}
return instance;
}
@Override
public void onCreate() {
super.onCreate();
// if (!getPackageName().equals(ProcessUtils.getCurrentProcessName())) {
// return;
// }
context = this;
instance = this;
// if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
//非主进程不初始化
// if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
utilsInint();
// }
}
@@ -85,11 +43,9 @@ public class BaseApplication extends Application {
catchException();
}
tPushInit();
// 设置开启日志,发布时请关闭日志
JPushInterface.setDebugMode(true);
JPushInterface.requestPermission(this);
String rootDir = MMKV.initialize(this);
Log.i(TAG, "mmkv root: " + rootDir);
LogDBManager.init(this);
ConnectManager.init(this);
Aria.init(this);
@@ -102,8 +58,6 @@ public class BaseApplication extends Application {
NetInterfaceManager.init(this);
AppUsedTimeUtils.init(this);
JGYUtils.hookWebView();
initAliasObservable();
initTagObservable();
}
private void catchException() {
@@ -142,7 +96,7 @@ public class BaseApplication extends Application {
Log.e("TPush", "注册成功设备token为" + data);
List<XGPushManager.AccountInfo> accountInfoList = new ArrayList<>();
accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial()));
XGPushManager.upsertAccounts(getAppContext(), accountInfoList, new XGIOperateCallback() {
XGPushManager.upsertAccounts(getApplicationContext(), accountInfoList, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag);
@@ -161,265 +115,4 @@ public class BaseApplication extends Application {
}
});
}
public void onAliasOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onAliasResult.onResult(errorCode);
}
public static void setJpushAlias() {
Log.e("jiguangInterface", "30s后重新设置alias");
JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
}
public void onTagOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onTagResult.onResult(errorCode);
}
public static void setJpushTags() {
Log.e(TAG, "30s后重新设置tags");
}
private static OnAliasResult onAliasResult;
interface OnAliasResult {
void onResult(int code);
}
private static OnTagResult onTagResult;
interface OnTagResult {
void onResult(int code);
}
private static void initTagObservable() {
Log.e(TAG, "initTagObservable: ");
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) {
onTagResult = new OnTagResult() {
@Override
public void onResult(int code) {
Log.e("initTagObservable", "onResult: " + code);
emitter.onNext(code);
}
};
}
}).throttleLast(1, TimeUnit.MINUTES)
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Integer integer) {
Log.e("initTagObservable", "onNext: " + integer);
String s = "tags:\t";
switch (integer) {
case 0:
Log.e("jiguangInterface", s + "Tag绑定成功");
break;
case 6001:
Log.e("jiguangInterface", s + "无效的设置");
break;
case 6005:
Log.e("jiguangInterface", s + "某一个 tag 字符串不合法");
ToastUtil.show("设备标签不合法,联系管理员修改\t" + "code:6005");
break;
case 6006:
Log.e("jiguangInterface", s + "某一个 tag 超长");
ToastUtil.show("设备标签过长,联系管理员修改\t" + "code:6006");
break;
case 6007:
Log.e("jiguangInterface", s + "tags 数量超出限制");
ToastUtil.show("设备标签数量超出限制,联系管理员修改\t" + "code:6007");
break;
case 6008:
Log.e("jiguangInterface", s + "tag 超出总长度限制");
ToastUtil.show("设备标签超出总长度限制,联系管理员修改\t" + "code:6008");
break;
case 6011:
Log.e("jiguangInterface", s + "短时间内操作过于频繁");
break;
case 6013:
Log.e("jiguangInterface", s + "用户设备时间轴异常");
ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + "code:6013");
break;
case 6018:
Log.e("jiguangInterface", s + "Tags 过多");
cleanJpushTag();
ToastUtil.show("设备标签数量超出限制,联系管理员修改\t" + "code:6018");
break;
case 6021:
Log.e("jiguangInterface", s + "tags 操作正在进行中");
break;
//需要重新设置
case 6002:
Log.e("jiguangInterface", s + "设置超时,请重试");
setJpushTags();
break;
case 6014:
Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
setJpushTags();
break;
case 6020:
Log.e("jiguangInterface", s + "建议过一段时间再设置");
setJpushTags();
break;
case 6024:
Log.e("jiguangInterface", s + "服务器内部错误");
setJpushTags();
break;
default:
break;
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
private static void initAliasObservable() {
Log.e(TAG, "initAliasObservable: ");
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
onAliasResult = new OnAliasResult() {
@Override
public void onResult(int code) {
Log.e("initAliasObservable", "onResult: " + code);
emitter.onNext(code);
}
};
}
}).throttleLast(1, TimeUnit.MINUTES)
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Integer integer) {
Log.e("initAliasObservable", "onNext: " + integer);
String s = "alias:\t";
switch (integer) {
case 0:
Log.e("jiguangInterface", s + "Alias绑定成功");
break;
case 6001:
Log.e("jiguangInterface", s + "无效的设置");
break;
case 6011:
Log.e("jiguangInterface", s + "短时间内操作过于频繁");
break;
case 6013:
Log.e("jiguangInterface", s + "用户设备时间轴异常");
ToastUtil.show("用户设备时间轴异常,修改后重新登陆\t" + s + "code:6013");
break;
case 6022:
Log.e("jiguangInterface", s + "alias 操作正在进行中");
break;
//需要重新设置
case 6002:
Log.e("jiguangInterface", s + "设置超时,请重试");
setJpushAlias();
break;
case 6014:
Log.e("jiguangInterface", s + "服务器繁忙,建议重试");
setJpushAlias();
break;
case 6020:
Log.e("jiguangInterface", s + "建议过一段时间再设置");
setJpushAlias();
break;
case 6024:
Log.e("jiguangInterface", s + "服务器内部错误");
setJpushAlias();
break;
case 6017:
case 6027:
Log.e("jiguangInterface", s + "别名绑定的设备数超过限制");
cleanJpushAlias();
setJpushAlias();
break;
default:
break;
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
synchronized public static void cleanJpushAlias() {
//alias的绑定的设备超过10个但是alias应该是一个设备对应一个在重置设备后jpush的regid会变动所以需要清除
//https://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/#_5
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(UrlAddress.DELETE_JPUSH_ALIAS + Utils.getSerial())
.header("Authorization", JGYUtils.getAuthorization())
.delete()
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
Log.e("cleanJpushAlias", "onFailure: " + e.getMessage());
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.e("cleanJpushAlias", "onResponse: " + response.toString());
Log.e(TAG, "onResponse: " + "清除Alias成功");
}
});
}
synchronized public static void cleanJpushTag() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(UrlAddress.DELETE_JPUSH_TAG + Utils.getSerial())
.header("Authorization", JGYUtils.getAuthorization())
.delete()
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
Log.e("cleanJpushTag", "onFailure: " + e.getMessage());
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.e("cleanJpushTag", "onResponse: " + response.toString());
Log.e(TAG, "onResponse: " + "清除Tag成功");
}
});
}
}

View File

@@ -1,26 +1,14 @@
package com.uiui.sn.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import androidx.fragment.app.Fragment;
import com.uiui.sn.R;
import com.uiui.sn.bean.BaseResponse;
import com.uiui.sn.network.NetInterfaceManager;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
/**
* A simple {@link Fragment} subclass.

View File

@@ -0,0 +1,151 @@
package com.uiui.sn.gson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class GsonUtils {
//https://blog.csdn.net/zte1055889498/article/details/122400299
public static JsonObject getJsonObject(String jsonString) {
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
return jsonObject;
}
private static final Gson gson;
static {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapterFactory(new NullStringToEmptyAdapterFactory());
builder.registerTypeAdapter(Integer.class, new IntegerDefault0Adapter());
builder.registerTypeAdapter(int.class, new IntegerDefault0Adapter());
builder.disableHtmlEscaping();
builder.enableComplexMapKeySerialization();
// builder.excludeFieldsWithoutExposeAnnotation();
builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
gson = builder.create();
}
public static Type makeJavaType(Type rawType, Type... typeArguments) {
return TypeToken.getParameterized(rawType, typeArguments).getType();
}
public static String toString(Object value) {
if (Objects.isNull(value)) {
return null;
}
if (value instanceof String) {
return (String) value;
}
return toJSONString(value);
}
public static String toJSONString(Object value) {
return gson.toJson(value);
}
public static String toPrettyString(Object value) {
return gson.newBuilder().setPrettyPrinting().create().toJson(value);
}
public static JsonElement fromJavaObject(Object value) {
JsonElement result = null;
if (Objects.nonNull(value) && (value instanceof String)) {
result = parseObject((String) value);
} else {
result = gson.toJsonTree(value);
}
return result;
}
public static JsonElement parseObject(String content) {
return JsonParser.parseString(content);
}
public static JsonElement getJsonElement(JsonObject node, String name) {
return node.get(name);
}
public static JsonElement getJsonElement(JsonArray node, int index) {
return node.get(index);
}
public static <T> T toJavaObject(JsonElement node, Class<T> clazz) {
return gson.fromJson(node, clazz);
}
public static <T> T toJavaObject(JsonElement node, Type type) {
return gson.fromJson(node, type);
}
public static <T> T toJavaObject(JsonElement node, TypeToken<?> typeToken) {
return toJavaObject(node, typeToken.getType());
}
public static <E> List<E> toJavaList(JsonElement node, Class<E> clazz) {
return toJavaObject(node, makeJavaType(List.class, clazz));
}
public static List<Object> toJavaList(JsonElement node) {
return toJavaObject(node, new TypeToken<List<Object>>() {
}.getType());
}
public static <V> Map<String, V> toJavaMap(JsonElement node, Class<V> clazz) {
return toJavaObject(node, makeJavaType(Map.class, String.class, clazz));
}
public static Map<String, Object> toJavaMap(JsonElement node) {
return toJavaObject(node, new TypeToken<Map<String, Object>>() {
}.getType());
}
public static <T> T toJavaObject(String content, Class<T> clazz) {
JsonObject jsonObject = getJsonObject(content);
String jsonString = jsonObject.toString();
return gson.fromJson(jsonString, clazz);
}
public static <T> T toJavaObject(String content, Type type) {
return gson.fromJson(content, type);
}
public static <T> T toJavaObject(String content, TypeToken<?> typeToken) {
return toJavaObject(content, typeToken.getType());
}
public static <E> List<E> toJavaList(String content, Class<E> clazz) {
return toJavaObject(content, makeJavaType(List.class, clazz));
}
public static List<Object> toJavaList(String content) {
return toJavaObject(content, new TypeToken<List<Object>>() {
}.getType());
}
public static <V> Map<String, V> toJavaMap(String content, Class<V> clazz) {
return toJavaObject(content, makeJavaType(Map.class, String.class, clazz));
}
public static Map<String, Object> toJavaMap(String content) {
return toJavaObject(content, new TypeToken<Map<String, Object>>() {
}.getType());
}
}

View File

@@ -0,0 +1,35 @@
package com.uiui.sn.gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import java.lang.reflect.Type;
public class IntegerDefault0Adapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
try {
if (json.getAsString().equals("")) {
return 0;
}
} catch (Exception ignore) {
}
try {
return json.getAsInt();
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
}
}
@Override
public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src);
}
}

View File

@@ -0,0 +1,45 @@
package com.uiui.sn.gson;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
public class NullStringToEmptyAdapterFactory<T> implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<T> rawType = (Class<T>) type.getRawType();
if (rawType != String.class) {
return null;
}
return (TypeAdapter<T>) new StringAdapter();
}
public static class StringAdapter extends TypeAdapter<String> {
@Override
public String read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return "";
}
return reader.nextString();
}
@Override
public void write(JsonWriter writer, String value) throws IOException {
if (value == null) {
writer.nullValue();
return;
}
writer.value(value);
}
}
}

View File

@@ -1,25 +0,0 @@
package com.uiui.sn.jpush;
import android.app.Application;
import com.uiui.sn.BuildConfig;
import cn.jpush.android.api.JPushInterface;
/**
* For developer startup JPush SDK
*
* 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
*/
public class ExampleApplication extends Application {
private static final String TAG = "JIGUANG-Example";
@Override
public void onCreate() {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(BuildConfig.DEBUG); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
}
}

View File

@@ -1,131 +0,0 @@
package com.uiui.sn.jpush;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.jpush.android.api.JPushInterface;
public class ExampleUtil {
public static final String PREFS_NAME = "JPUSH_EXAMPLE";
public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS";
public static final String PREFS_START_TIME = "PREFS_START_TIME";
public static final String PREFS_END_TIME = "PREFS_END_TIME";
public static final String KEY_APP_KEY = "JPUSH_APPKEY";
public static boolean isEmpty(String s) {
if (null == s)
return true;
if (s.length() == 0)
return true;
if (s.trim().length() == 0)
return true;
return false;
}
/**
* 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。
* */
private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$";
public static boolean isValidMobileNumber(String s) {
if(TextUtils.isEmpty(s)) return true;
Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS);
Matcher m = p.matcher(s);
return m.matches();
}
// 校验Tag Alias 只能是数字,英文字母和中文
public static boolean isValidTagAndAlias(String s) {
Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$");
Matcher m = p.matcher(s);
return m.matches();
}
// 取得AppKey
public static String getAppKey(Context context) {
Bundle metaData = null;
String appKey = null;
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
if (null != ai)
metaData = ai.metaData;
if (null != metaData) {
appKey = metaData.getString(KEY_APP_KEY);
if ((null == appKey) || appKey.length() != 24) {
appKey = null;
}
}
} catch (NameNotFoundException e) {
}
return appKey;
}
// 取得版本号
public static String GetVersion(Context context) {
try {
PackageInfo manager = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0);
return manager.versionName;
} catch (NameNotFoundException e) {
return "Unknown";
}
}
public static void showToast(final String toast, final Context context)
{
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// Looper.prepare();
//// Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
// Looper.loop();
// }
// }).start();
}
public static boolean isConnected(Context context) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
}
public static String getImei(Context context, String imei) {
String ret = null;
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
ret = telephonyManager.getDeviceId();
} catch (Exception e) {
Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage());
}
if (isReadableASCII(ret)){
return ret;
} else {
return imei;
}
}
private static boolean isReadableASCII(CharSequence string){
if (TextUtils.isEmpty(string)) return false;
try {
Pattern p = Pattern.compile("[\\x20-\\x7E]+");
return p.matcher(string).matches();
} catch (Throwable e){
return true;
}
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
}

View File

@@ -1,263 +0,0 @@
package com.uiui.sn.jpush;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
/**
* Created by efan on 2017/4/14.
*/
public final class LocalBroadcastManager {
private static final String TAG = "JIGUANG-Example";
private static final boolean DEBUG = false;
private final Context mAppContext;
private final HashMap<BroadcastReceiver, ArrayList<IntentFilter>> mReceivers = new HashMap<BroadcastReceiver, ArrayList<IntentFilter>>();
private final HashMap<String, ArrayList<ReceiverRecord>> mActions = new HashMap<String, ArrayList<ReceiverRecord>> ();
private final ArrayList<BroadcastRecord> mPendingBroadcasts = new ArrayList<BroadcastRecord>();
static final int MSG_EXEC_PENDING_BROADCASTS = 1;
private final Handler mHandler;
private static final Object mLock = new Object();
private static LocalBroadcastManager mInstance;
public static LocalBroadcastManager getInstance(Context context) {
Object var1 = mLock;
synchronized (mLock) {
if (mInstance == null) {
mInstance = new LocalBroadcastManager(context.getApplicationContext());
}
return mInstance;
}
}
private LocalBroadcastManager(Context context) {
this.mAppContext = context;
this.mHandler = new Handler(context.getMainLooper()) {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
LocalBroadcastManager.this.executePendingBroadcasts();
break;
default:
super.handleMessage(msg);
}
}
};
}
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
HashMap var3 = this.mReceivers;
synchronized (this.mReceivers) {
ReceiverRecord entry = new ReceiverRecord(filter, receiver);
ArrayList filters = (ArrayList) this.mReceivers.get(receiver);
if (filters == null) {
filters = new ArrayList(1);
this.mReceivers.put(receiver, filters);
}
filters.add(filter);
for (int i = 0; i < filter.countActions(); ++i) {
String action = filter.getAction(i);
ArrayList entries = (ArrayList) this.mActions.get(action);
if (entries == null) {
entries = new ArrayList(1);
this.mActions.put(action, entries);
}
entries.add(entry);
}
}
}
public void unregisterReceiver(BroadcastReceiver receiver) {
HashMap var2 = this.mReceivers;
synchronized (this.mReceivers) {
ArrayList filters = (ArrayList) this.mReceivers.remove(receiver);
if (filters != null) {
for (int i = 0; i < filters.size(); ++i) {
IntentFilter filter = (IntentFilter) filters.get(i);
for (int j = 0; j < filter.countActions(); ++j) {
String action = filter.getAction(j);
ArrayList receivers = (ArrayList) this.mActions.get(action);
if (receivers != null) {
for (int k = 0; k < receivers.size(); ++k) {
if (((ReceiverRecord) receivers.get(k)).receiver == receiver) {
receivers.remove(k);
--k;
}
}
if (receivers.size() <= 0) {
this.mActions.remove(action);
}
}
}
}
}
}
}
public boolean sendBroadcast(Intent intent) {
HashMap var2 = this.mReceivers;
synchronized (this.mReceivers) {
String action = intent.getAction();
String type = intent.resolveTypeIfNeeded(this.mAppContext.getContentResolver());
Uri data = intent.getData();
String scheme = intent.getScheme();
Set categories = intent.getCategories();
boolean debug = (intent.getFlags() & 8) != 0;
if (debug) {
Logger.v("LocalBroadcastManager", "Resolving type " + type + " scheme " + scheme + " of intent " + intent);
}
ArrayList entries = (ArrayList) this.mActions.get(intent.getAction());
if (entries != null) {
if (debug) {
Logger.v("LocalBroadcastManager", "Action list: " + entries);
}
ArrayList receivers = null;
int i;
for (i = 0; i < entries.size(); ++i) {
ReceiverRecord receiver = (ReceiverRecord) entries.get(i);
if (debug) {
Logger.v("LocalBroadcastManager", "Matching against filter " + receiver.filter);
}
if (receiver.broadcasting) {
if (debug) {
Logger.v("LocalBroadcastManager", " Filter\'s target already added");
}
} else {
int match = receiver.filter.match(action, type, scheme, data, categories, "LocalBroadcastManager");
if (match >= 0) {
if (debug) {
Logger.v("LocalBroadcastManager", " Filter matched! match=0x" + Integer.toHexString(match));
}
if (receivers == null) {
receivers = new ArrayList();
}
receivers.add(receiver);
receiver.broadcasting = true;
} else if (debug) {
String reason;
switch (match) {
case -4:
reason = "category";
break;
case -3:
reason = "action";
break;
case -2:
reason = "data";
break;
case -1:
reason = "type";
break;
default:
reason = "unknown reason";
}
Logger.v("LocalBroadcastManager", " Filter did not match: " + reason);
}
}
}
if (receivers != null) {
for (i = 0; i < receivers.size(); ++i) {
((ReceiverRecord) receivers.get(i)).broadcasting = false;
}
this.mPendingBroadcasts.add(new BroadcastRecord(intent, receivers));
if (!this.mHandler.hasMessages(1)) {
this.mHandler.sendEmptyMessage(1);
}
return true;
}
}
return false;
}
}
public void sendBroadcastSync(Intent intent) {
if (this.sendBroadcast(intent)) {
this.executePendingBroadcasts();
}
}
private void executePendingBroadcasts() {
while (true) {
BroadcastRecord[] brs = null;
HashMap i = this.mReceivers;
synchronized (this.mReceivers) {
int br = this.mPendingBroadcasts.size();
if (br <= 0) {
return;
}
brs = new BroadcastRecord[br];
this.mPendingBroadcasts.toArray(brs);
this.mPendingBroadcasts.clear();
}
for (int var6 = 0; var6 < brs.length; ++var6) {
BroadcastRecord var7 = brs[var6];
for (int j = 0; j < var7.receivers.size(); ++j) {
((ReceiverRecord) var7.receivers.get(j)).receiver.onReceive(this.mAppContext, var7.intent);
}
}
}
}
private static class BroadcastRecord {
final Intent intent;
final ArrayList<ReceiverRecord> receivers;
BroadcastRecord(Intent _intent, ArrayList<ReceiverRecord> _receivers) {
this.intent = _intent;
this.receivers = _receivers;
}
}
private static class ReceiverRecord {
final IntentFilter filter;
final BroadcastReceiver receiver;
boolean broadcasting;
ReceiverRecord(IntentFilter _filter, BroadcastReceiver _receiver) {
this.filter = _filter;
this.receiver = _receiver;
}
public String toString() {
StringBuilder builder = new StringBuilder(128);
builder.append("Receiver{");
builder.append(this.receiver);
builder.append(" filter=");
builder.append(this.filter);
builder.append("}");
return builder.toString();
}
}
}

View File

@@ -1,40 +0,0 @@
package com.uiui.sn.jpush;
import android.util.Log;
/**
* Created by efan on 2017/4/13.
*/
public class Logger {
//设为false关闭日志
private static final boolean LOG_ENABLE = true;
public static void i(String tag, String msg){
if (LOG_ENABLE){
Log.i(tag, msg);
}
}
public static void v(String tag, String msg){
if (LOG_ENABLE){
Log.v(tag, msg);
}
}
public static void d(String tag, String msg){
if (LOG_ENABLE){
Log.d(tag, msg);
}
}
public static void w(String tag, String msg){
if (LOG_ENABLE){
Log.w(tag, msg);
}
}
public static void e(String tag, String msg){
if (LOG_ENABLE){
Log.e(tag, msg);
}
}
}

View File

@@ -1,46 +0,0 @@
package com.uiui.sn.jpush;
import android.content.Context;
import com.uiui.sn.base.BaseApplication;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.service.JPushMessageReceiver;
/**
* 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
*/
public class MyJPushMessageReceiver extends JPushMessageReceiver {
@Override
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onTagOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onTagOperatorResult(jPushMessage);
super.onTagOperatorResult(context, jPushMessage);
}
@Override
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context, jPushMessage);
super.onCheckTagOperatorResult(context, jPushMessage);
}
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onAliasOperatorResult(jPushMessage);
super.onAliasOperatorResult(context, jPushMessage);
}
@Override
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context, jPushMessage);
super.onMobileNumberOperatorResult(context, jPushMessage);
}
@Override
public void onMessage(Context context, CustomMessage customMessage) {
super.onMessage(context, customMessage);
}
}

View File

@@ -1,7 +0,0 @@
package com.uiui.sn.jpush;
import cn.jpush.android.service.JCommonService;
public class PushService extends JCommonService {
}

View File

@@ -1,345 +0,0 @@
package com.uiui.sn.jpush;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.SparseArray;
import com.uiui.sn.utils.ToastUtil;
import java.util.Locale;
import java.util.Set;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
/**
* 处理tagalias相关的逻辑
* */
public class TagAliasOperatorHelper {
private static final String TAG = "JIGUANG-TagAliasHelper";
public static int sequence = 1;
/**增加*/
public static final int ACTION_ADD = 1;
/**覆盖*/
public static final int ACTION_SET = 2;
/**删除部分*/
public static final int ACTION_DELETE = 3;
/**删除所有*/
public static final int ACTION_CLEAN = 4;
/**查询*/
public static final int ACTION_GET = 5;
public static final int ACTION_CHECK = 6;
public static final int DELAY_SEND_ACTION = 1;
public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2;
private Context context;
private static TagAliasOperatorHelper mInstance;
private TagAliasOperatorHelper(){
}
public static TagAliasOperatorHelper getInstance(){
if(mInstance == null){
synchronized (TagAliasOperatorHelper.class){
if(mInstance == null){
mInstance = new TagAliasOperatorHelper();
}
}
}
return mInstance;
}
public void init(Context context){
if(context != null) {
this.context = context.getApplicationContext();
}
}
private SparseArray<Object> setActionCache = new SparseArray<Object>();
public Object get(int sequence){
return setActionCache.get(sequence);
}
public Object remove(int sequence){
return setActionCache.get(sequence);
}
public void put(int sequence,Object tagAliasBean){
setActionCache.put(sequence,tagAliasBean);
}
private Handler delaySendHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case DELAY_SEND_ACTION:
if(msg.obj !=null && msg.obj instanceof TagAliasBean){
Logger.i(TAG,"on delay time");
sequence++;
TagAliasBean tagAliasBean = (TagAliasBean) msg.obj;
setActionCache.put(sequence, tagAliasBean);
if(context!=null) {
handleAction(context, sequence, tagAliasBean);
}else{
Logger.e(TAG,"#unexcepted - context was null");
}
}else{
Logger.w(TAG,"#unexcepted - msg obj was incorrect");
}
break;
case DELAY_SET_MOBILE_NUMBER_ACTION:
if(msg.obj !=null && msg.obj instanceof String) {
Logger.i(TAG, "retry set mobile number");
sequence++;
String mobileNumber = (String) msg.obj;
setActionCache.put(sequence, mobileNumber);
if(context !=null) {
handleAction(context, sequence, mobileNumber);
}else {
Logger.e(TAG, "#unexcepted - context was null");
}
}else{
Logger.w(TAG,"#unexcepted - msg obj was incorrect");
}
break;
}
}
};
public void handleAction(Context context,int sequence,String mobileNumber){
put(sequence,mobileNumber);
Logger.d(TAG,"sequence:"+sequence+",mobileNumber:"+mobileNumber);
JPushInterface.setMobileNumber(context,sequence,mobileNumber);
}
/**
* 处理设置tag
* */
public void handleAction(Context context,int sequence, TagAliasBean tagAliasBean){
init(context);
if(tagAliasBean == null){
Logger.w(TAG,"tagAliasBean was null");
return;
}
put(sequence,tagAliasBean);
if(tagAliasBean.isAliasAction){
switch (tagAliasBean.action){
case ACTION_GET:
JPushInterface.getAlias(context,sequence);
break;
case ACTION_DELETE:
JPushInterface.deleteAlias(context,sequence);
break;
case ACTION_SET:
JPushInterface.setAlias(context,sequence,tagAliasBean.alias);
break;
default:
Logger.w(TAG,"unsupport alias action type");
return;
}
}else {
switch (tagAliasBean.action) {
case ACTION_ADD:
JPushInterface.addTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_SET:
JPushInterface.setTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_DELETE:
JPushInterface.deleteTags(context, sequence, tagAliasBean.tags);
break;
case ACTION_CHECK:
//一次只能check一个tag
String tag = (String)tagAliasBean.tags.toArray()[0];
JPushInterface.checkTagBindState(context,sequence,tag);
break;
case ACTION_GET:
JPushInterface.getAllTags(context, sequence);
break;
case ACTION_CLEAN:
JPushInterface.cleanTags(context, sequence);
break;
default:
Logger.w(TAG,"unsupport tag action type");
return;
}
}
}
private boolean RetryActionIfNeeded(int errorCode,TagAliasBean tagAliasBean){
if(!ExampleUtil.isConnected(context)){
Logger.w(TAG,"no network");
return false;
}
//返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试
if(errorCode == 6002 || errorCode == 6014){
Logger.d(TAG,"need retry");
if(tagAliasBean!=null){
Message message = new Message();
message.what = DELAY_SEND_ACTION;
message.obj = tagAliasBean;
delaySendHandler.sendMessageDelayed(message,1000*60);
String logs =getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action,errorCode);
ExampleUtil.showToast(logs, context);
return true;
}
}
return false;
}
private boolean RetrySetMObileNumberActionIfNeeded(int errorCode,String mobileNumber){
if(!ExampleUtil.isConnected(context)){
Logger.w(TAG,"no network");
return false;
}
//返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试
if(errorCode == 6002 || errorCode == 6024){
Logger.d(TAG,"need retry");
Message message = new Message();
message.what = DELAY_SET_MOBILE_NUMBER_ACTION;
message.obj = mobileNumber;
delaySendHandler.sendMessageDelayed(message,1000*60);
String str = "Failed to set mobile number due to %s. Try again after 60s.";
str = String.format(Locale.ENGLISH,str,(errorCode == 6002 ? "timeout" : "server internal error”"));
ExampleUtil.showToast(str, context);
return true;
}
return false;
}
private String getRetryStr(boolean isAliasAction,int actionType,int errorCode){
String str = "Failed to %s %s due to %s. Try again after 60s.";
str = String.format(Locale.ENGLISH,str,getActionStr(actionType),(isAliasAction? "alias" : " tags") ,(errorCode == 6002 ? "timeout" : "server too busy"));
return str;
}
private String getActionStr(int actionType){
switch (actionType){
case ACTION_ADD:
return "add";
case ACTION_SET:
return "set";
case ACTION_DELETE:
return "delete";
case ACTION_GET:
return "get";
case ACTION_CLEAN:
return "clean";
case ACTION_CHECK:
return "check";
}
return "unkonw operation";
}
public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onTagOperatorResult, sequence:"+sequence+",tags:"+jPushMessage.getTags());
Logger.i(TAG,"tags size:"+jPushMessage.getTags().size());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - modify tag Success,sequence:"+sequence);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" tags success";
Logger.i(TAG,logs);
Log.e(TAG,"Tag绑定成功: " + jPushMessage.getTags());
ToastUtil.debugShow("Tag绑定成功: " + jPushMessage.getTags());
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags";
if(jPushMessage.getErrorCode() == 6018){
//tag数量超过限制,需要先清除一部分再add
logs += ", tags is exceed limit need to clean";
}
logs += ", errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage){
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onCheckTagOperatorResult, sequence:"+sequence+",checktag:"+jPushMessage.getCheckTag());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"tagBean:"+tagAliasBean);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" tag "+jPushMessage.getCheckTag() + " bind state success,state:"+jPushMessage.getTagCheckStateResult();
Logger.i(TAG,logs);
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" tags, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onAliasOperatorResult, sequence:"+sequence+",alias:"+jPushMessage.getAlias());
init(context);
//根据sequence从之前操作缓存中获取缓存记录
TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.get(sequence);
if(tagAliasBean == null){
ExampleUtil.showToast("获取缓存记录失败", context);
return;
}
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - modify alias Success,sequence:"+sequence);
setActionCache.remove(sequence);
String logs = getActionStr(tagAliasBean.action)+" alias success";
Logger.i(TAG,logs);
Log.e(TAG,"Alias绑定成功: "+jPushMessage.getAlias());
ToastUtil.debugShow("Alias绑定成功: "+jPushMessage.getAlias());
ExampleUtil.showToast(logs, context);
}else{
String logs = "Failed to " + getActionStr(tagAliasBean.action)+" alias, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetryActionIfNeeded(jPushMessage.getErrorCode(),tagAliasBean)) {
ExampleUtil.showToast(logs, context);
}
}
}
//设置手机号码回调
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
int sequence = jPushMessage.getSequence();
Logger.i(TAG,"action - onMobileNumberOperatorResult, sequence:"+sequence+",mobileNumber:"+jPushMessage.getMobileNumber());
init(context);
if(jPushMessage.getErrorCode() == 0){
Logger.i(TAG,"action - set mobile number Success,sequence:"+sequence);
setActionCache.remove(sequence);
}else{
String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode();
Logger.e(TAG, logs);
if(!RetrySetMObileNumberActionIfNeeded(jPushMessage.getErrorCode(),jPushMessage.getMobileNumber())){
ExampleUtil.showToast(logs, context);
}
}
}
public static class TagAliasBean{
public int action;
public Set<String> tags;
public String alias;
public boolean isAliasAction;
@Override
public String toString() {
return "TagAliasBean{" +
"action=" + action +
", tags=" + tags +
", alias='" + alias + '\'' +
", isAliasAction=" + isAliasAction +
'}';
}
}
}

View File

@@ -1,32 +0,0 @@
package com.uiui.sn.jpush;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import cn.jpush.android.api.JPushInterface;
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("用户自定义打开的Activity");
Intent intent = getIntent();
if (null != intent) {
Bundle bundle = getIntent().getExtras();
String title = null;
String content = null;
if(bundle!=null){
title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
content = bundle.getString(JPushInterface.EXTRA_ALERT);
}
tv.setText("Title : " + title + " " + "Content : " + content);
}
addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}

View File

@@ -99,15 +99,34 @@ public class AmapManager {
*/
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (null != location && location.getLocType() != BDLocation.TypeServerError) {
Log.e(TAG, "onLocationChanged: " + "定位成功");
Log.e(TAG, "onLocationChanged: " + location.getAddress());
SPUtils.put(mContext, "AmapAddress", location.getAddress());
SPUtils.put(mContext, "longitude", location.getLongitude());
SPUtils.put(mContext, "latitude", location.getLatitude());
SPUtils.put(mContext, "AmapError", "");
// int tag = 1;
if (null != location) {
switch (location.getLocType()) {
case BDLocation.TypeGpsLocation:// GPS定位结果
case BDLocation.TypeNetWorkLocation:// 网络定位结果
case BDLocation.TypeOffLineLocation:// 离线定位结果
Log.e(TAG, "onLocationChanged: " + "定位成功");
Log.e(TAG, "onLocationChanged: " + location.getAddrStr() + location.getLocationDescribe());
SPUtils.put(mContext, "AmapAddress", location.getAddrStr() + location.getLocationDescribe());
SPUtils.put(mContext, "longitude", location.getLongitude());
SPUtils.put(mContext, "latitude", location.getLatitude());
SPUtils.put(mContext, "AmapError", "-");
break;
case BDLocation.TypeServerError:
Log.e(TAG, "onReceiveLocation: " + "服务端网络定位失败");
SPUtils.put(mContext, "AmapError", "服务端网络定位失败可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com会有人追查原因");
break;
case BDLocation.TypeNetWorkException:
Log.e(TAG, "onReceiveLocation: " + "网络不同导致定位失败,请检查网络是否通畅");
SPUtils.put(mContext, "AmapError", "网络不同导致定位失败,请检查网络是否通畅");
break;
case BDLocation.TypeCriteriaException:
Log.e(TAG, "onReceiveLocation: " + "无法获取有效定位依据导致定位失败");
SPUtils.put(mContext, "AmapError", "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
break;
default:
}
}
// if (null != location && location.getLocType() != BDLocation.TypeServerError) {
// StringBuffer sb = new StringBuffer(256);
// sb.append("time : ");
// /**
@@ -213,9 +232,9 @@ public class AmapManager {
// }
//// logMsg(sb.toString(), tag);
// Log.e(TAG, "onReceiveLocation: " + sb);
}
Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-"));
Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-"));
// }
Log.e(TAG, "AmapAddress: " + (String) SPUtils.get(mContext, "AmapAddress", "-"));
Log.e(TAG, "AmapError: " + (String) SPUtils.get(mContext, "AmapError", "-"));
}
@Override

View File

@@ -10,11 +10,11 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.uiui.sn.bean.SystemSettings;
import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ToastUtil;
@@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.function.Predicate;
/**
* 系统管理处理
* 所有数据 后台1是0否底层0是1否
@@ -67,7 +66,7 @@ public class ControlManager {
if (TextUtils.isEmpty(jsonString)) {
return;
}
SystemSettings settings = JSON.parseObject(jsonString, SystemSettings.class);
SystemSettings settings = GsonUtils.toJavaObject(jsonString, SystemSettings.class);
if (null != settings) {
setUSBstate(settings);
setPhoneList(settings);
@@ -578,8 +577,8 @@ public class ControlManager {
}
public void setDeveloperOptions(String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int dev_mode = changeNum(jsonObject.getIntValue("dev_mode"));
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt());
Log.e(TAG, "getDeveloper: " + dev_mode);
if (!DeviceManager.isDebugMode()) {
JGYUtils.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode);
@@ -615,8 +614,9 @@ public class ControlManager {
}
public void setSearchTopic(String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int mode = jsonObject.getIntValue("search_topic");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
if (jsonObject.get("search_topic") == null) return;
int mode = jsonObject.get("search_topic").getAsInt();
SPUtils.put(mContext, "search_topic", mode);
Log.e(TAG, "search_topic:" + mode);
}
@@ -715,5 +715,4 @@ public class ControlManager {
}
}

View File

@@ -71,10 +71,9 @@ import com.uiui.sn.network.interceptor.RepeatRequestInterceptor;
import com.uiui.sn.service.ManagerService;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.AppUsedTimeUtils;
import com.uiui.sn.utils.CacheUtils;
import com.uiui.sn.utils.CmdUtil;
import com.uiui.sn.utils.FileUtils;
import com.uiui.sn.utils.GsonUtils;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.MD5Util;
import com.uiui.sn.utils.SPUtils;
@@ -98,7 +97,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
@@ -494,6 +492,8 @@ public class NetInterfaceManager {
public interface onNextCallback {
void onNext(Object o);
void onError(Object o);
void onComplete();
}
@@ -535,7 +535,7 @@ public class NetInterfaceManager {
Log.e("getSnInfo", "onNext: " + userInfoBaseResponse);
SPUtils.put(mContext, CommonConfig.JGY_FIRST_CONNECT, 1);
callback.onNext(userInfoBaseResponse);
cacheHelper.put(UrlAddress.SNINFO, GsonUtils.toJsonString(userInfoBaseResponse));
cacheHelper.put(UrlAddress.SNINFO, GsonUtils.toJSONString(userInfoBaseResponse));
int code = userInfoBaseResponse.code;
if (userInfoBaseResponse.code == 200) {
SPUtils.put(mContext, CommonConfig.isLogined, 1);
@@ -632,7 +632,7 @@ public class NetInterfaceManager {
} else {
Log.e("setPushTags", "onNext: " + "batch empty");
}
cacheHelper.put(UrlAddress.GET_BATCH, GsonUtils.toJsonString(response.data));
cacheHelper.put(UrlAddress.GET_BATCH, GsonUtils.toJSONString(response.data));
} else {
cacheHelper.put(UrlAddress.GET_BATCH, "");
}
@@ -731,7 +731,7 @@ public class NetInterfaceManager {
uploadInfo.setApp_size(getPackageSize(mContext, info.applicationInfo.publicSourceDir));
uploadInfos.add(uploadInfo);
}
String json = GsonUtils.toJsonString(uploadInfos);
String json = GsonUtils.toJSONString(uploadInfos);
emitter.onNext(json);
}
})
@@ -807,7 +807,7 @@ public class NetInterfaceManager {
@Override
public void onNext(@NonNull List<AppInfo> appInfos) {
cacheHelper.put(UrlAddress.GET_NEWESTAPPUPDATE, GsonUtils.toJsonString(appInfos));
cacheHelper.put(UrlAddress.GET_NEWESTAPPUPDATE, GsonUtils.toJSONString(appInfos));
getAllAppUpdate(appInfos);
Log.e("getElderlyUsersApp", "onNext: " + appInfos);
}
@@ -920,7 +920,7 @@ public class NetInterfaceManager {
@Override
public void onNext(@NonNull List<AppInfo> appInfos) {
cacheHelper.put(UrlAddress.GET_NEWESTAPPUPDATE, GsonUtils.toJsonString(appInfos));
cacheHelper.put(UrlAddress.GET_NEWESTAPPUPDATE, GsonUtils.toJSONString(appInfos));
getAllAppUpdate(appInfos);
Log.e("checkAllAppUpdate", "onNext: " + appInfos);
}
@@ -1081,7 +1081,7 @@ public class NetInterfaceManager {
Log.e("getQRCodeURL", "onNext: ");
if (baseResponse.code == 200) {
AppletQRCode appletQRCode = baseResponse.data;
cacheHelper.put(UrlAddress.GET_APPLET_QRCODE, GsonUtils.toJsonString(appletQRCode));
cacheHelper.put(UrlAddress.GET_APPLET_QRCODE, GsonUtils.toJSONString(appletQRCode));
String url = appletQRCode.getFile();
callback.onNext(url);
} else {
@@ -1093,7 +1093,7 @@ public class NetInterfaceManager {
@Override
public void onError(Throwable e) {
Log.e("getQRCodeURL", "onError: " + e.getMessage());
callback.onNext("");
callback.onError("");
onComplete();
}
@@ -1153,43 +1153,6 @@ public class NetInterfaceManager {
new URLUtils(mContext).setBrowserList();
}
});
// getLabelControl().getLabel(Utils.getSerial())
// .flatMap(new Function<BaseResponse, ObservableSource<BaseResponse<BrowserApiData>>>() {
// @Override
// public ObservableSource<BaseResponse<BrowserApiData>> apply(BaseResponse baseResponse) throws Exception {
// return getBrowserControl().getBrowser(Utils.getSerial());
// }
// })
// .map(new Function<BaseResponse, String>() {
// @Override
// public String apply(BaseResponse baseResponse) throws Exception {
// return null;
// }
// })
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Observer<String>() {
// @Override
// public void onSubscribe(Disposable d) {
// Log.e("setBrowserWhiteList", "onSubscribe: ");
// }
//
// @Override
// public void onNext(String s) {
// Log.e("setBrowserWhiteList", "onNext: ");
// }
//
// @Override
// public void onError(Throwable e) {
// Log.e("setBrowserWhiteList", "onError: ");
// }
//
// @Override
// public void onComplete() {
// Log.e("setBrowserWhiteList", "onComplete: ");
// }
// });
}
/**
@@ -1552,7 +1515,7 @@ public class NetInterfaceManager {
Log.e("setAppHide", "setAppHide: " + e.getMessage());
}
}
String jsonString = GsonUtils.toJsonString(hideAPPList);
String jsonString = GsonUtils.toJSONString(hideAPPList);
SPUtils.put(mContext, "Hide_APP_List", String.join(",", jsonString));
JGYUtils.getInstance().updateHideList();
Log.e(TAG, "Hide_APP_List: " + jsonString);
@@ -1657,7 +1620,8 @@ public class NetInterfaceManager {
softwareJson.addProperty("gankao_version", ApkUtils.getAPPVersionName(mContext, "com.gankao.gkwxhd"));
softwareJson.addProperty("learning_version", ApkUtils.getAPPVersionName(mContext, "com.info.learning"));
softwareJson.addProperty("chat_version", ApkUtils.getAPPVersionName(mContext, "com.info.chat"));
softwareJson.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext));
// TODO: 2022/6/29
softwareJson.addProperty("jpush_id", "");
softwareJson.addProperty("notice_version", ApkUtils.getAPPVersionName(mContext, "com.uiui.info"));
softwareJson.addProperty("browser_version", ApkUtils.getAPPVersionName(mContext, "com.uiui.browser"));
softwareJson.addProperty("desktop_version", ApkUtils.getAPPVersionName(mContext, "com.uiui.os"));
@@ -1952,7 +1916,7 @@ public class NetInterfaceManager {
@Override
public void onNext(BaseResponse baseResponse) {
String jsonString = GsonUtils.toJsonString(baseResponse.data);
String jsonString = GsonUtils.toJSONString(baseResponse.data);
Log.e("getAppInside", "onNext: " + jsonString);
if (baseResponse.code == 200) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);

View File

@@ -64,11 +64,4 @@ public class UrlAddress {
/*获取公网IP*/
public static final String SHOUHU_CITYJSON = "http://pv.sohu.com/cityjson/";
/*
* 极光
* */
/*删除alias*/
public static final String DELETE_JPUSH_ALIAS = "https://device.jpush.cn/v3/aliases/";
/*删除tags*/
public static final String DELETE_JPUSH_TAG = "https://device.jpush.cn/v3/tags/";
}

View File

@@ -30,8 +30,9 @@ public class RepeatRequestInterceptor implements Interceptor {
Response response = chain.proceed(chain.request());
String content = response.body().string();
if (BuildConfig.DEBUG)
Log.e(TAG, "请求体返回:| Response:" + content);
if (BuildConfig.DEBUG) {
// Log.e(TAG, "请求体返回:| Response:" + content);
}
//相同的请求
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + request.body());
long time = System.currentTimeMillis();//请求时间

View File

@@ -41,8 +41,6 @@ public class BootReceiver extends BroadcastReceiver {
|| BOOT_COMPLETED.equals(action)
|| "android.intent.action.BATTERY_LEVEL_CHANGED".equals(action)
) {
// Intent i = new Intent(context, InitJpushServer.class);
// context.startService(i);
context.startService(new Intent(context, MainService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, StepService.class));

File diff suppressed because it is too large Load Diff

View File

@@ -13,17 +13,16 @@ import android.view.WindowManager;
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.task.DownloadTask;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.JsonObject;
import com.uiui.sn.KeepAliveConnection;
import com.uiui.sn.R;
import com.uiui.sn.service.main.MainService;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.gson.GsonUtils;
import java.io.File;
@@ -127,9 +126,9 @@ public class DownloadService extends Service {
String appName = "";
try {
String jsonString = task.getExtendField();
JSONObject jsonObject = JSON.parseObject(jsonString);
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
if (!TextUtils.isEmpty(jsonString) && jsonObject != null) {
appName = jsonObject.getString("app_name");
appName = jsonObject.get("app_name").getAsString();
}
} catch (Exception e) {
Log.e("running", "running: " + e.getMessage());

View File

@@ -19,9 +19,8 @@ import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.NetworkUtils;
import com.google.gson.JsonObject;
import com.uiui.sn.R;
import com.uiui.sn.bean.BaseResponse;
import com.uiui.sn.config.CommonConfig;
@@ -29,6 +28,7 @@ import com.uiui.sn.manager.ControlManager;
import com.uiui.sn.network.NetInterfaceManager;
import com.uiui.sn.receiver.APKinstallReceiver;
import com.uiui.sn.receiver.BootReceiver;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.TimeUtils;
import com.uiui.sn.utils.Utils;
@@ -157,8 +157,8 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta
Log.e("getScreenLockState", "onNext: ");
int code = baseResponse.code;
if (code == 200) {
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(baseResponse.data));
int is_screen_lock = jsonObject.getIntValue("is_screen_lock");
JsonObject jsonObject = GsonUtils.getJsonObject(GsonUtils.toJSONString(baseResponse.data));
int is_screen_lock = jsonObject.get("is_screen_lock").getAsInt();
setLockedState(is_screen_lock);
} else {
if (!timelocked) {

View File

@@ -23,8 +23,8 @@ import android.util.Log;
import androidx.annotation.Nullable;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.NetworkUtils;
import com.google.gson.JsonObject;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.KeepAliveConnection;
import com.uiui.sn.utils.ServiceAliveUtils;
@@ -232,29 +232,29 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
* 发送消息
*/
public void sendMsg() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("sn", Utils.getSerial());
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial());
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (!pm.isScreenOn()) {
jsonObject.put("online", 0);
jsonObject.addProperty("online", 0);
//熄屏状态
} else {
jsonObject.put("online", 1);
jsonObject.addProperty("online", 1);
}
if (null != client) {
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
client.send(jsonObject.toJSONString());
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toString());
client.send(jsonObject.toString());
}
}
public void sendMsg(int state) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("sn", Utils.getSerial());
jsonObject.put("online", state);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial());
jsonObject.addProperty("online", state);
if (null != client) {
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toString());
try {
client.send(jsonObject.toJSONString());
client.send(jsonObject.toString());
} catch (Exception e) {
Log.i(TAG, "sendMsg :" + e.getLocalizedMessage());
}

View File

@@ -1,6 +1,5 @@
package com.uiui.sn.service.main;
import com.alibaba.fastjson.JSONObject;
import com.uiui.sn.base.BasePresenter;
import com.uiui.sn.base.BaseView;
import com.uiui.sn.bean.BaseResponse;

View File

@@ -8,9 +8,8 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.uiui.sn.bean.AppInfo;
@@ -24,6 +23,7 @@ import com.uiui.sn.manager.ControlManager;
import com.uiui.sn.network.NetInterfaceManager;
import com.uiui.sn.service.ManagerService;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ServiceAliveUtils;
@@ -138,7 +138,7 @@ public class MainSPresenter implements MainSContact.Presenter {
if (code == 200) {
List<AppInfo> appInfoList = listBaseResponse.data;
if (appInfoList == null || appInfoList.size() == 0) {
ApkUtils.writeAppPackageList(mContext, "Invalid");
ApkUtils.writeAppPackageList(mContext, "");
} else {
HashSet allPkgSet = new HashSet<String>();
for (AppInfo pkg : appInfoList) {
@@ -181,12 +181,12 @@ public class MainSPresenter implements MainSContact.Presenter {
@Override
public void onNext(BaseResponse baseResponse) {
String jsonString = JSON.toJSONString(baseResponse.data);
String jsonString = GsonUtils.toJSONString(baseResponse.data);
Log.e("getAppInside", "onNext: " + jsonString);
if (baseResponse.code == 200) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String ids = jsonObject.getString("ids");
String packages = jsonObject.getString("package");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String ids = jsonObject.get("ids").getAsString();
String packages = jsonObject.get("package").getAsString();
JGYUtils.getInstance().writeDeselectIDtoSystem(ids, packages);
} else {
Log.e("getAppInside", "onNext: " + baseResponse.msg);
@@ -262,12 +262,11 @@ public class MainSPresenter implements MainSContact.Presenter {
@Override
public void onNext(BaseResponse systemSettingsBaseResponse) {
Log.e("getSystemSettings", "onNext: ");
Log.e("getSystemSettings", "onNext: "+systemSettingsBaseResponse);
SPUtils.put(mContext, "is_first_connection", 0);
int code = systemSettingsBaseResponse.code;
if (code == 200) {
String data = new Gson().toJson(systemSettingsBaseResponse.data);
Log.e("getSystemSettings", "onNext: " + data);
ControlManager.getInstance().setSystemSetting(data);
} else {
ControlManager.getInstance().setDisableSetting();
@@ -474,13 +473,13 @@ public class MainSPresenter implements MainSContact.Presenter {
Log.e("getTimeControlControl", "onNext: ");
int code = baseResponse.code;
if (code == 200) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
JSONObject work = jsonObject.getJSONObject("work");
String work_start_time = work.getString("start_time");
String work_end_time = work.getString("end_time");
JSONObject rest = jsonObject.getJSONObject("rest");
String rest_start_time = rest.getString("start_time");
String rest_end_time = rest.getString("end_time");
JsonObject jsonObject = GsonUtils.getJsonObject(GsonUtils.toJSONString(baseResponse.data));
JsonObject work = jsonObject.getAsJsonObject("work");
String work_start_time = work.get("start_time").getAsString();
String work_end_time = work.get("end_time").getAsString();
JsonObject rest = jsonObject.getAsJsonObject("rest");
String rest_start_time = rest.get("start_time").getAsString();
String rest_end_time = rest.get("end_time").getAsString();
TimeUtils.ContralTime workingTime = TimeUtils.String2WorkingTime(mContext, work_start_time + "-" + work_end_time);
TimeUtils.ContralTime weekTime = TimeUtils.String2WeekTime(mContext, rest_start_time + "-" + rest_end_time);
if (null != workingTime) {
@@ -538,8 +537,8 @@ public class MainSPresenter implements MainSContact.Presenter {
Log.e("getScreenLock", "onNext: " + baseResponse);
int code = baseResponse.code;
if (code == 200) {
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(baseResponse.data));
int is_screen_lock = jsonObject.getIntValue("is_screen_lock");
JsonObject jsonObject = GsonUtils.getJsonObject(GsonUtils.toJSONString(baseResponse.data));
int is_screen_lock = jsonObject.get("is_screen_lock").getAsInt();
if (!ServiceAliveUtils.isServiceAlice(mContext, ManagerService.class.getName())) {
mContext.startService(new Intent(mContext, ManagerService.class));
}

View File

@@ -13,11 +13,9 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.IBinder;
import android.provider.Settings;
import android.text.TextUtils;
import android.os.SystemClock;
import android.util.Log;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.NetworkUtils;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
@@ -52,7 +50,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
@@ -65,9 +62,16 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject;
*/
public class MainService extends Service implements MainSContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
private String TAG = MainService.class.getSimpleName();
public static MainSPresenter mPresenter;
private MMKV mMMKV = MMKV.defaultMMKV();
//执行所有请求的时间
long runningTime;
//MainService上次执行时间
long startCommandTime = 0;
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
@NotNull
@@ -112,6 +116,86 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
task.execute("ntp.aliyun.com");
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
lifecycleSubject.onNext(ActivityEvent.CREATE);
mPresenter = new MainSPresenter(this);
mPresenter.setLifecycle(lifecycleSubject);
mPresenter.attachView(this);
TimeTask task = new TimeTask();
task.execute("ntp.aliyun.com");
ApkUtils.UninstallAPP(this, "com.joytv.live");
ApkUtils.UninstallAPP(this, "com.tencent.android.qqdownloader");
try {
getPackageManager().setApplicationEnabledSetting("com.android.email", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
} catch (Exception e) {
Log.e(TAG, "onCreate: " + e.getMessage());
}
Observable.create(subscribe)
.throttleFirst(1, TimeUnit.MINUTES)
.subscribe(timeObserver);
if ((int) SPUtils.get(this, CommonConfig.JGY_FIRST_CONNECT, 0) == 0) {
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
}
int oldVersionCode = (int) SPUtils.get(this, CommonConfig.SN_VERSIONCODE, 0);
if (oldVersionCode < BuildConfig.VERSION_CODE) {
Log.e(TAG, "onCreate: " + "upgrade successful");
try {
new CacheUtils().cleanApplicationUserData(this, "com.aoleyun.os");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
} else {
if (ConnectManager.getInstance().isRebootFistConnect()) {
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
runningTime = SystemClock.elapsedRealtime();
} else {
Log.e(TAG, "onCreate: " + "Service Reboot");
// mPresenter.getLockedState();
}
}
SPUtils.put(this, CommonConfig.SN_VERSIONCODE, BuildConfig.VERSION_CODE);
registerReceivers();
NetworkUtils.registerNetworkStatusChangedListener(this);
ControlManager.getInstance().setDefaultUSBstate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand: " + System.currentTimeMillis());
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
lifecycleSubject.onNext(ActivityEvent.DESTROY);
NetworkUtils.unregisterNetworkStatusChangedListener(this);
mPresenter.detachView();
}
public static MainSPresenter getPresenter() {
return mPresenter;
}
private void startService() {
startService(new Intent(this, GuardService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, DownloadService.class));
}
private class TimeTask extends AsyncTask<String, Long, Long> {
@Override
protected Long doInBackground(String... strings) {
@@ -165,6 +249,10 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
private WifiReceiver mWifiReceiver;
private void registerReceivers() {
registerWiFiReceiver();
}
private void registerWiFiReceiver() {
if (mWifiReceiver == null) {
mWifiReceiver = new WifiReceiver();
@@ -255,6 +343,7 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void onNext(String string) {
Log.e("TimeObserver", "onNext: " + string);
startCommandTime = runningTime = SystemClock.elapsedRealtime();
mPresenter.getSnInfo();
startService();
}
@@ -270,90 +359,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
}
};
public static MainSPresenter getPresenter() {
return mPresenter;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
lifecycleSubject.onNext(ActivityEvent.CREATE);
mPresenter = new MainSPresenter(this);
mPresenter.setLifecycle(lifecycleSubject);
mPresenter.attachView(this);
TimeTask task = new TimeTask();
task.execute("ntp.aliyun.com");
ApkUtils.UninstallAPP(this, "com.joytv.live");
ApkUtils.UninstallAPP(this, "com.tencent.android.qqdownloader");
try {
getPackageManager().setApplicationEnabledSetting("com.android.email", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
} catch (Exception e) {
Log.e(TAG, "onCreate: " + e.getMessage());
}
Observable.create(subscribe)
.throttleFirst(1, TimeUnit.MINUTES)
.subscribe(timeObserver);
if ((int) SPUtils.get(this, CommonConfig.JGY_FIRST_CONNECT, 0) == 0) {
// TODO: 2021/5/26 待底层修改,临时解决办法
Log.e(TAG, "onCreate: " + "Disable All Settings");
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
}
int oldVersionCode = (int) SPUtils.get(this, CommonConfig.SN_VERSIONCODE, 0);
if (oldVersionCode < BuildConfig.VERSION_CODE) {
Log.e(TAG, "onCreate: " + "upgrade successful");
try {
new CacheUtils().cleanApplicationUserData(this, "com.aoleyun.os");
} catch (Exception e) {
Log.e(TAG, "onReceive: " + e.getMessage());
e.printStackTrace();
}
} else {
// if (ConnectManager.getInstance().isRebootFistConnect()) {
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
// }
}
SPUtils.put(this, CommonConfig.SN_VERSIONCODE, BuildConfig.VERSION_CODE);
registerReceivers();
NetworkUtils.registerNetworkStatusChangedListener(this);
ControlManager.getInstance().setDefaultUSBstate();
JPushInterface.init(this);
}
private void registerReceivers() {
registerWiFiReceiver();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand: " + System.currentTimeMillis());
mPresenter.checkUpdate();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
lifecycleSubject.onNext(ActivityEvent.DESTROY);
NetworkUtils.unregisterNetworkStatusChangedListener(this);
mPresenter.detachView();
}
private void startService() {
startService(new Intent(this, GuardService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, DownloadService.class));
}
@Override
public void setSnInfo(BaseResponse<SnInfo> response) {
if (response != null) {
@@ -438,6 +443,6 @@ public class MainService extends Service implements MainSContact.MainView, Netwo
@Override
public void setScreenLock() {
Log.e(TAG, "SettingFinish: " + (SystemClock.elapsedRealtime() - runningTime) + " ms");
}
}

View File

@@ -10,7 +10,6 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.provider.Settings;
@@ -20,8 +19,6 @@ import android.view.Gravity;
import android.view.WindowManager;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.android.internal.view.RotationPolicy;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
@@ -49,6 +46,7 @@ import com.uiui.sn.tpush.po.XGNotification;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.CacheUtils;
import com.uiui.sn.utils.CmdUtil;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ServiceAliveUtils;
@@ -608,8 +606,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
break;
case JIGUANG_FORCE_KILL:
ToastUtil.debugShow("收到推送消息: 强制停止应用");
JSONObject killJSONObject = JSON.parseObject(extras);
String packages = killJSONObject.getString("app_package");
JsonObject killJSONObject = GsonUtils.getJsonObject(extras);
String packages = killJSONObject.get("app_package").getAsString();
JGYUtils.getInstance().killBackgroundProcesses(packages);
Log.e(TAG, extras);
break;
@@ -741,27 +739,27 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setAdminApp(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_admin_app = jsonObject.getInteger("setting_admin_app");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_admin_app = jsonObject.get("setting_admin_app").getAsInt();
Settings.System.putInt(context.getContentResolver(), "setting_admin_app", setting_admin_app);
}
private void setZenMode(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_disturbance = jsonObject.getInteger("setting_disturbance");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_disturbance = jsonObject.get("setting_disturbance").getAsInt();
}
private void setRotationLock(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_rotation = jsonObject.getInteger("setting_rotation");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_rotation = jsonObject.get("setting_rotation").getAsInt();
RotationPolicy.setRotationLock(context, setting_rotation == 0);
}
private void setScreenBrightness(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_luminance = jsonObject.getInteger("setting_luminance");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_luminance = jsonObject.get("setting_luminance").getAsInt();
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
int Scrern_brightness = (int) ((1.0 * 255 / 100) * setting_luminance);
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness);
@@ -778,8 +776,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
protected List<String> mEntries;
private void setFontSize(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String setting_typeface = jsonObject.getString("setting_typeface");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String setting_typeface = jsonObject.get("setting_typeface").getAsString();
final Resources res = context.getResources();
mEntries = Arrays.asList(res.getStringArray(R.array.entries_font_size));
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
@@ -795,8 +793,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setVolume(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_volume = jsonObject.getInteger("setting_volume");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_volume = jsonObject.get("setting_volume").getAsInt();
//获取系统的Audio管理者
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//最大音量
@@ -822,11 +820,11 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void setUsbStatus(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String setting_usb = jsonObject.getString("setting_usb");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String setting_usb = jsonObject.get("setting_usb").getAsString();
ControlPanelManager.getInstance().setUsbStatus(setting_usb);
// boolean qch_usb_choose = JGYUtils.putString(context.getContentResolver(), "qch_usb_choose", setting_usb);
// Log.e("setUsbState:", JGYUtils.getString(context.getContentResolver(), "qch_usb_choose"));
// Log.e("setUsbState:", JGYUtils.get(context.getContentResolver(), "qch_usb_choose"));
// String usbStatus = "";
// switch (setting_usb) {
// case "usb_charge":
@@ -851,8 +849,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void setTfcardState(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JSONObject extra = JSON.parseObject(jsonString);
int is_tf = extra.getIntValue("setting_memory");
JsonObject extra = GsonUtils.getJsonObject(jsonString);
int is_tf = extra.get("setting_memory").getAsInt();
boolean aole_sdcard_forbid_on = JGYUtils.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, changeNum(is_tf));
if (aole_sdcard_forbid_on) {
Log.e("setTfcardState:", JGYUtils.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON));
@@ -871,8 +869,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//获取默认蓝牙适配器
}
JSONObject extra = JSON.parseObject(jsonString);
int is_bluetooth = changeNum(extra.getIntValue("setting_bht"));
JsonObject extra = GsonUtils.getJsonObject(jsonString);
int is_bluetooth = changeNum(extra.get("setting_bht").getAsInt());
Log.e(TAG, "aole_bht_forbid_on: " + is_bluetooth);
try {
//写入系统数据库
@@ -901,9 +899,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void setAppNetworkstate(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JSONObject extra = JSON.parseObject(jsonString);
String package0 = extra.getString("package0");
String package1 = extra.getString("package1");
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String package0 = extra.get("package0").getAsString();
String package1 = extra.get("package1").getAsString();
if (package0.length() != 0) {
boolean aole_network_allow = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW, package0);
Log.e("fht", "aole_network_allow::" + aole_network_allow + ":" + JGYUtils.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW));
@@ -925,9 +923,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void setAppLockedstate(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JSONObject extra = JSON.parseObject(jsonString);
String packageName = extra.getString("package");
int is_lock = extra.getIntValue("is_lock");
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String packageName = extra.get("package").getAsString();
int is_lock = extra.get("is_lock").getAsInt();
ToastUtil.debugShow("收到应用锁管控消息:包名" + packageName + "is_lock_state:" + is_lock);
PackageManager pm = context.getPackageManager();
//后台为0可能传过来null
@@ -947,10 +945,10 @@ public class MessageReceiver extends XGPushBaseReceiver {
return;
}
// NetInterfaceManager.getInstance().getAllAppPackageName(context);
JSONObject extra = JSON.parseObject(jsonString);
final String packages = extra.getString("package");
JsonObject extra = GsonUtils.getJsonObject(jsonString);
final String packages = extra.get("package").getAsString();
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
String url = extra.getString("url");
String url = extra.get("url").getAsString();
if (TextUtils.isEmpty(url)) {
return;
}
@@ -974,8 +972,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void unintallApk(Context context, String jsonString) {
int sn_id = (int) SPUtils.get(context, "sn_id", -1);
JSONObject object = JSON.parseObject(jsonString);
String packageName = object.getString("app_package");
JsonObject object = GsonUtils.getJsonObject(jsonString);
String packageName = object.get("app_package").getAsString();
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
if (!"".equals(packageName) && !packageName.equals(context.getApplicationContext().getPackageName())) {
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
@@ -992,10 +990,10 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized void bindService(final Context context, String jsonString) {
ToastUtil.debugShow("收到绑定设备请求");
JSONObject object = JSON.parseObject(jsonString);
String userName = object.getString("member_name");
final String id = object.getString("id");
String phoneNum = object.getString("member_phone");
JsonObject object = GsonUtils.getJsonObject(jsonString);
String userName = object.get("member_name").getAsString();
final String id = object.get("id").getAsString();
String phoneNum = object.get("member_phone").getAsString();
dialog = new CustomDialog(context);
subscribe = Observable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
@@ -1101,9 +1099,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
@SuppressLint("NewApi")
private void setTFmedia(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
//影音管控开关
int setting_tfmedia = jsonObject.getIntValue("setting_tfmedia");
int setting_tfmedia = jsonObject.get("setting_tfmedia").getAsInt();
Log.e("SystemSetting", "qch_tfmedia_forbid---------" + setting_tfmedia);
if (setting_tfmedia == 1) {
@@ -1112,7 +1110,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
String s = JGYUtils.getString(context.getContentResolver(), "qch_tfmedia_filetypes");//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes old" + s);
JGYUtils.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 1);
String setting_tfmedia_format = jsonObject.getString("setting_tfmedia_format");
String setting_tfmedia_format = jsonObject.get("setting_tfmedia_format").getAsString();
HashSet<String> types = new HashSet<>(Arrays.asList(setting_tfmedia_format.split(",")));
types.removeIf(TextUtils::isEmpty);
boolean b = JGYUtils.putString(context.getContentResolver(), "qch_tfmedia_filetypes", String.join(",", types));//影音管控
@@ -1121,9 +1119,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setCameta(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
//摄像头开关
int setting_camera = changeNum(jsonObject.getIntValue("setting_camera"));
int setting_camera = changeNum(jsonObject.get("setting_camera").getAsInt());
JGYUtils.putInt(context.getContentResolver(), "qch_app_camera", setting_camera);
ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera");
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
@@ -1149,9 +1147,9 @@ public class MessageReceiver extends XGPushBaseReceiver {
@SuppressLint("NewApi")
private void setAppUpdate(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String is_upgrade = jsonObject.getString("is_upgrade");
String packageName = jsonObject.getString("package");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String is_upgrade = jsonObject.get("is_upgrade").getAsString();
String packageName = jsonObject.get("package").getAsString();
String nowApplist = JGYUtils.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID);
List<String> applist = new ArrayList<>(Arrays.asList(nowApplist.split(",")));
if ("0".equals(is_upgrade)) {
@@ -1171,8 +1169,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
private void setLock_screen(Context context, String jsonString) {
int type = 0;
JSONObject jSONObject = JSON.parseObject(jsonString);
type = jSONObject.getInteger("type");
JsonObject jSONObject = GsonUtils.getJsonObject(jsonString);
type = jSONObject.get("type").getAsInt();
if (!ServiceAliveUtils.isServiceAlice(context, ManagerService.class.getName())) {
context.startService(new Intent(context, ManagerService.class));
@@ -1286,8 +1284,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
synchronized private void setBrowserUrlpath(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JSONObject extra = JSON.parseObject(jsonString);
String white = extra.getString("white");
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String white = extra.get("white").getAsString();
if (white != null && !"".equals(white)) {
boolean whiteList = JGYUtils.putString(context.getContentResolver(), "DeselectBrowserArray", white);
Log.e("SystemSetting", "setBrowserList-whiteList" + whiteList + ":" + white);
@@ -1295,7 +1293,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
JGYUtils.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
}
Log.e("whiteList", JGYUtils.getString(context.getContentResolver(), "DeselectBrowserArray"));
String black = extra.getString("black");
String black = extra.get("black").getAsString();
if (black != null && !"".equals(black)) {
boolean blackList = JGYUtils.putString(context.getContentResolver(), "qch_webblack_url", black);
Log.e("SystemSetting", "setBrowserList-blackList" + blackList + ":" + black);
@@ -1318,8 +1316,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
* @param jsonString 设置热点开关
*/
private void setHotspot(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int setting_hotspot = changeNum(jsonObject.getIntValue("setting_hotspot"));//热点
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int setting_hotspot = changeNum(jsonObject.get("setting_hotspot").getAsInt());//热点
try {
if (setting_hotspot == 1) {
Intent intent = new Intent();
@@ -1336,21 +1334,21 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setRestore(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int mode = jsonObject.getIntValue("qch_restore");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int mode = jsonObject.get("qch_restore").getAsInt();
boolean aole_restore_forbid_on = JGYUtils.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, changeNum(mode));
Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on);
}
private void setBrowserInput(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int setting_browserInput = changeNum(jsonObject.getIntValue("setting_browserInput"));
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int setting_browserInput = changeNum(jsonObject.get("setting_browserInput").getAsInt());
JGYUtils.putInt(context.getContentResolver(), "qch_Browser_input", setting_browserInput);
}
private void setDeveloper(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int dev_mode = changeNum(jsonObject.getIntValue("dev_mode"));
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt());
Log.e(TAG, "getDeveloper: " + dev_mode);
if (!DeviceManager.isDebugMode()) {
JGYUtils.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode);
@@ -1369,8 +1367,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void cleanAppCache(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String pkg = jsonObject.getString("package");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String pkg = jsonObject.get("package").getAsString();
if (TextUtils.isEmpty(pkg)) {
Log.e(TAG, "cleanAppCache: pkg is null");
return;
@@ -1389,8 +1387,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
private void searchTopic(Context context, String jsonString) {
Log.e(TAG, "searchTopic: " + jsonString);
JSONObject jsonObject = JSON.parseObject(jsonString);
int search_topic = jsonObject.getIntValue("search_topic");
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int search_topic = jsonObject.get("search_topic").getAsInt();
Log.e(TAG, "searchTopic: put = " + SPUtils.put(context, "search_topic", search_topic));
JGYUtils.getInstance().updateForbidList();
}
@@ -1402,8 +1400,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void setSOSPhoneNumber(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String setting_sos = jsonObject.getString("setting_sos");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String setting_sos = jsonObject.get("setting_sos").getAsString();
Settings.System.putString(context.getContentResolver(), "setting_sos", setting_sos);
Intent intent = new Intent("setting_sos");
intent.putExtra("setting_sos", setting_sos);
@@ -1412,8 +1410,8 @@ public class MessageReceiver extends XGPushBaseReceiver {
}
private void reinstallApp(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String packages = jsonObject.getString("package");
String app_url = jsonObject.getString("app_url");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String packages = jsonObject.get("package").getAsString();
String app_url = jsonObject.get("app_url").getAsString();
}
}

View File

@@ -528,7 +528,7 @@ public class ApkUtils {
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
Log.e("UninstallAPP", "call " + Thread.currentThread().getName());
Log.e("UninstallAPP", "pkg " + pkg);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(context, pkg);
} else {
@@ -809,9 +809,9 @@ public class ApkUtils {
writeAppSet.addAll(factoryAppList);
String pkgString = String.join(",", writeAppSet);
Log.e("fht", "aole_app_forbid: " + pkgString);
boolean aole_app_forbid = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, pkgString);
boolean aole_app_forbid = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, pkgString);
} else {
JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, String.join(",", factoryAppList));
JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, String.join(",", factoryAppList));
Log.e("fht", "writeAppPackageList is null:");
}
Utils.writeDisableUpdateList(context);

View File

@@ -1,29 +0,0 @@
package com.uiui.sn.utils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
public class GsonUtils {
public static JsonObject getJsonObject(String jsonString) {
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
return jsonObject;
}
// TODO: 2022/3/31 暂时没有实现
public static <E> E getJsonFromType(String jsonString) {
Gson gson = new Gson();
Type Type = new TypeToken<E>() {
}.getType();
E e = gson.fromJson(jsonString, Type);
return e;
}
public static String toJsonString(Object o) {
return new Gson().toJson(o);
}
}

View File

@@ -30,12 +30,12 @@ import android.util.Log;
import androidx.core.content.ContextCompat;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.android.internal.view.RotationPolicy;
import com.google.gson.JsonObject;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.R;
import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.receiver.BootReceiver;
import java.io.File;
@@ -70,6 +70,7 @@ public class JGYUtils {
HashSet<String> ownApp = new HashSet<String>() {{
this.add("com.tt.ttutils");
this.add(BuildConfig.APPLICATION_ID);
this.add("com.uiui.sn");
this.add("com.appstore.uiui");
this.add("com.alarmclock.uiui");
this.add("com.android.uiuios");
@@ -79,10 +80,11 @@ public class JGYUtils {
this.add("com.uiui.appstore");
this.add("com.uiui.browser");
this.add("com.uiui.health");
this.add("com.uiui.os");
this.add("com.uiui.aios");
this.add("com.uiui.sn");
this.add("com.uiui.videoplayer");
this.add("com.uiui.os");
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
this.add("com.uiui.aios");
this.add("com.uiuios.jgy1");
this.add("com.uiuios.jgy2");
this.add("com.info.chat");
@@ -635,7 +637,7 @@ public class JGYUtils {
ArrayList<String> disableApp = new ArrayList<>();
int search_topic = (int) SPUtils.get(mContext, "search_topic", 0);
Log.e(TAG, "getForbidList: search_topic = " + search_topic);
Log.e(TAG, "getForbidList: " + JSONObject.toJSONString(SPUtils.getAll(mContext)));
Log.e(TAG, "getForbidList: " + GsonUtils.toJSONString(SPUtils.getAll(mContext)));
if (search_topic == 0) {
disableApp.add("拍照搜题");
@@ -871,20 +873,20 @@ public class JGYUtils {
private String ZENNODETAG = "ZenModeSettingsBackend";
public void setZenMode(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_disturbance = jsonObject.getInteger("setting_disturbance");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_disturbance = jsonObject.get("setting_disturbance").getAsInt();
NotificationManager.from(mContext).setZenMode(setting_disturbance, null, ZENNODETAG);
}
public void setRotationLock(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_rotation = jsonObject.getInteger("setting_rotation");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_rotation = jsonObject.get("setting_rotation").getAsInt();
RotationPolicy.setRotationLock(mContext, setting_rotation == 0);
}
public void setScreenBrightness(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_luminance = jsonObject.getInteger("setting_luminance");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_luminance = jsonObject.get("setting_luminance").getAsInt();
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
int Scrern_brightness = (int) ((1.0 * 255 / 100) * setting_luminance);
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness);
@@ -901,8 +903,8 @@ public class JGYUtils {
protected List<String> mEntries;
public void setFontSize(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String setting_typeface = jsonObject.getString("setting_typeface");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String setting_typeface = jsonObject.get("setting_typeface").getAsString();
final Resources res = mContext.getResources();
mEntries = Arrays.asList(res.getStringArray(R.array.entries_font_size));
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
@@ -918,8 +920,8 @@ public class JGYUtils {
}
public void setVolume(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
int setting_volume = jsonObject.getInteger("setting_volume");
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_volume = jsonObject.get("setting_volume").getAsInt();
//获取系统的Audio管理者
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
//最大音量

View File

@@ -48,8 +48,7 @@ import android.widget.Toast;
import androidx.annotation.VisibleForTesting;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
@@ -62,6 +61,7 @@ import com.uiui.sn.Statistics.AppInformation;
import com.uiui.sn.Statistics.StatisticsInfo;
import com.uiui.sn.bean.AppUsed;
import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.network.NetInterfaceManager;
import java.io.BufferedReader;
@@ -914,7 +914,7 @@ public class Utils {
writeSucceed = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, list);
Log.e("writeDisableUpdateList", "aole_app_forbid: " + list);
} else {
writeSucceed = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, "Invalid");
writeSucceed = JGYUtils.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, "");
}
return writeSucceed;
/*功能和应用安装白名单一样首先会写入所有的app名单。
@@ -1201,14 +1201,14 @@ public class Utils {
String rom = JGYUtils.getCustomVersion();
String screen_rate = getAndroiodScreenProperty(context);
JSONObject jsonObject = new JSONObject();
jsonObject.put("device", device);
jsonObject.put("imei", imei);
jsonObject.put("system_version", system_version);
jsonObject.put("firmware_version", firmware_version);
jsonObject.put("rom", rom);
jsonObject.put("screen_rate", screen_rate);
return jsonObject.toJSONString();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("device", device);
jsonObject.addProperty("imei", imei);
jsonObject.addProperty("system_version", system_version);
jsonObject.addProperty("firmware_version", firmware_version);
jsonObject.addProperty("rom", rom);
jsonObject.addProperty("screen_rate", screen_rate);
return jsonObject.toString();
}
public static String getHardware(Context context) {
@@ -1229,24 +1229,24 @@ public class Utils {
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
WifiInfo info = wifiManager.getConnectionInfo();
JSONObject jsonObject = new JSONObject();
jsonObject.put("electric", electric);
jsonObject.put("charging", charging);
jsonObject.put("memory", memory);
jsonObject.put("mac", getMAC(context));
jsonObject.put("storage", storage);
jsonObject.put("is_wifi", JGYUtils.getInstance().isWifiConnect());
jsonObject.put("CPU", CPU + "");
jsonObject.put("use_space", use_space);
jsonObject.put("use_ram", use_ram);
jsonObject.put("wifi_ssid", getWifiSSID(context));
jsonObject.put("wifi_time", wifi_time);
jsonObject.put("boot_time", SystemClock.elapsedRealtime());
jsonObject.put("battery_capacity", getBatterymAh(context));
jsonObject.put("wifi_signal", info.getRssi());
jsonObject.put("bluetooth", getBluetoothList());
Log.e(TAG, "getHardware: " + jsonObject.toJSONString());
return jsonObject.toJSONString();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("electric", electric);
jsonObject.addProperty("charging", charging);
jsonObject.addProperty("memory", memory);
jsonObject.addProperty("mac", getMAC(context));
jsonObject.addProperty("storage", storage);
jsonObject.addProperty("is_wifi", JGYUtils.getInstance().isWifiConnect());
jsonObject.addProperty("CPU", CPU + "");
jsonObject.addProperty("use_space", use_space);
jsonObject.addProperty("use_ram", use_ram);
jsonObject.addProperty("wifi_ssid", getWifiSSID(context));
jsonObject.addProperty("wifi_time", wifi_time);
jsonObject.addProperty("boot_time", SystemClock.elapsedRealtime());
jsonObject.addProperty("battery_capacity", getBatterymAh(context));
jsonObject.addProperty("wifi_signal", info.getRssi());
jsonObject.addProperty("bluetooth", getBluetoothList());
Log.e(TAG, "getHardware: " + jsonObject.toString());
return jsonObject.toString();
}
public static String getWifiSSID(Context context) {
@@ -1297,7 +1297,7 @@ public class Utils {
appUsedList.add(used);
}
appUsedList.removeIf(appUsed -> appUsed.getUseTime() == 0);
String jsonString = JSON.toJSONString(appUsedList);
String jsonString = GsonUtils.toJSONString(appUsedList);
Log.e(TAG, "getAppUsedStatistics: " + jsonString);
return jsonString;
}