version:1.0
update:2021-10-21 10:14:40 fix: add:增加开机检测弹窗,增加常驻通知
This commit is contained in:
@@ -8,11 +8,15 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.action.JGYActions;
|
||||
import com.aoleyun.sn.network.api.newapi.GetPublicIPApi;
|
||||
import com.aoleyun.sn.network.api.newapi.SendScreenStatusApi;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -55,6 +59,10 @@ import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
|
||||
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence;
|
||||
@@ -846,4 +854,72 @@ public class HTTPInterface {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface PublicIP {
|
||||
void set(String ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备公网IP
|
||||
*
|
||||
* @param context
|
||||
* @param publicIP
|
||||
*/
|
||||
public static void getPublicIP(Context context, PublicIP publicIP) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(NetInterfaceManager.getInstance().getOkHttpClient())
|
||||
.baseUrl(UrlAddress.SHOUHU_CITYJSON)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
GetPublicIPApi getPublicIPApi = retrofit.create(GetPublicIPApi.class);
|
||||
getPublicIPApi.getJpushTags()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<ResponseBody>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getPublicIP", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(ResponseBody responseBody) {
|
||||
try {
|
||||
String s = responseBody.string();
|
||||
Log.e("getPublicIP", "onNext: " + s);
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
//var returnCitySN = {"cip": "183.11.74.141", "cid": "440300", "cname": "广东省深圳市"};
|
||||
if (s.contains("{")) {
|
||||
String jsonString = s.substring(s.indexOf("{"), s.lastIndexOf("}") + 1);
|
||||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
||||
String ip = jsonObject.get("cip").getAsString();
|
||||
if (!TextUtils.isEmpty(ip)) {
|
||||
publicIP.set(ip);
|
||||
} else {
|
||||
publicIP.set("");
|
||||
}
|
||||
} else {
|
||||
publicIP.set("");
|
||||
}
|
||||
} else {
|
||||
publicIP.set("");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("getPublicIP", "IOException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getPublicIP", "onError: " + e.getMessage());
|
||||
publicIP.set("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getPublicIP", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.aoleyun.sn.network;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.bean.Appground;
|
||||
@@ -48,10 +49,15 @@ import com.aoleyun.sn.network.api.newapi.SnTimeControlApi;
|
||||
import com.aoleyun.sn.network.api.newapi.StudentsInfosApi;
|
||||
import com.aoleyun.sn.network.api.newapi.TopAppControlApi;
|
||||
import com.aoleyun.sn.network.api.newapi.UpdateDeviceInfoApi;
|
||||
import com.aoleyun.sn.utils.MD5Util;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
@@ -59,7 +65,11 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
@@ -73,6 +83,7 @@ public class NetInterfaceManager {
|
||||
private Context mContext;
|
||||
private Retrofit mRetrofit;
|
||||
private OkHttpClient okHttpClient;
|
||||
private final ConcurrentHashMap<String, Long> requestIdsMap = new ConcurrentHashMap<>();
|
||||
|
||||
//超时时间
|
||||
private static int timeOut = 5;
|
||||
@@ -80,16 +91,73 @@ public class NetInterfaceManager {
|
||||
private static long cacheSize = 1024 * 1024 * 64;
|
||||
|
||||
public static final String HTTP_KEY = "YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=";
|
||||
public static final String CUSTOM_REPEAT_REQ_PROTOCOL = "MY_CUSTOM_REPEAT_REQ_PROTOCOL";
|
||||
|
||||
private NetInterfaceManager(Context context) {
|
||||
this.mContext = context;
|
||||
if (okHttpClient == null) {
|
||||
Interceptor myHttpInterceptor = new Interceptor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Response intercept(@NotNull Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
|
||||
Response response = chain.proceed(request); //准备返回Response
|
||||
// try {
|
||||
// response.close();
|
||||
// response = chain.proceed(request);
|
||||
// } catch (Exception e) {
|
||||
// Log.e(TAG, "intercept: " + e.getMessage());
|
||||
// //异常的返回也是完成Http请求。在这里移除请求登记
|
||||
// if (!TextUtils.isEmpty(e.toString()) && e.toString().contains(NetInterfaceManager.CUSTOM_REPEAT_REQ_PROTOCOL)) {
|
||||
// Log.e("REPEAT-REQUEST", "移除请求1:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
|
||||
// } else {
|
||||
// requestIdsMap.remove(requestKey);
|
||||
// }
|
||||
// throw e;
|
||||
// }
|
||||
synchronized (requestIdsMap) {
|
||||
requestIdsMap.remove(requestKey); //在这里移除正常的请求登记
|
||||
Log.e("REPEAT-REQUEST", "移除请求2:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
};
|
||||
Interceptor mRequestInterceptor = new Interceptor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Response intercept(@NotNull Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
//拦截处理重复的HTTP 请求,类似 防止快速点击按钮去重 可以不去处理了,全局统一处理
|
||||
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
|
||||
synchronized (requestIdsMap) {
|
||||
if (requestIdsMap.get(requestKey) == null) {
|
||||
// Log.e("REPEAT-REQUEST", "intercept: " + requestIdsMap);
|
||||
requestIdsMap.put(requestKey, System.currentTimeMillis());
|
||||
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
|
||||
} else {
|
||||
//如果是重复的请求,抛出一个自定义的错误,这个错误大家根据自己的业务定义吧
|
||||
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
|
||||
return new Response.Builder()
|
||||
.protocol(Protocol.get(CUSTOM_REPEAT_REQ_PROTOCOL))
|
||||
.request(request) //multi thread
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Response originalResponse = chain.proceed(request);
|
||||
return originalResponse.newBuilder().build();
|
||||
}
|
||||
};
|
||||
|
||||
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.connectTimeout(timeOut, TimeUnit.SECONDS); // 设置连接超时时间
|
||||
builder.writeTimeout(timeOut, TimeUnit.SECONDS);// 设置写入超时时间
|
||||
builder.readTimeout(timeOut, TimeUnit.SECONDS);// 设置读取数据超时时间
|
||||
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
|
||||
builder.addInterceptor(myHttpInterceptor);
|
||||
builder.addNetworkInterceptor(mRequestInterceptor);
|
||||
|
||||
// 设置缓存文件路径
|
||||
String cacheDirectory = mContext.getExternalCacheDir().getAbsolutePath() + "/OkHttpCache";
|
||||
Cache cache = new Cache(new File(cacheDirectory), cacheSize);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class UrlAddress {
|
||||
//获取隐藏桌面图标
|
||||
public static final String GET_HIDE_DESKTOPICON = "Icon";
|
||||
//获取应用升级自启
|
||||
public final static String NET_AND_LAUNCH_API = "automatic/get";
|
||||
public static final String NET_AND_LAUNCH_API = "automatic/get";
|
||||
//通过sn获取信息
|
||||
public static final String GET_STUDENTS_INFO = "Sn/getStudent";
|
||||
//上传截图
|
||||
@@ -50,28 +50,30 @@ public class UrlAddress {
|
||||
//上传我的设备
|
||||
//public static final String UPDATE_DEVICEINFO = "Mac/getInfo";
|
||||
//获取霸屏状态
|
||||
public final static String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen";
|
||||
public static final String GET_LOCK_SCREEN_STATE = "Sn/getSnScreen";
|
||||
//获取默认桌面升级
|
||||
public final static String GET_DESKTOP = "Sn/getSnDesktop";
|
||||
public static final String GET_DESKTOP = "Sn/getSnDesktop";
|
||||
//获取时间管控
|
||||
public final static String GET_SN_TIME_CONTROL = "Sn/getSnTimeControl";
|
||||
public static final String GET_SN_TIME_CONTROL = "Sn/getSnTimeControl";
|
||||
//获取顶部app管控
|
||||
public final static String GET_TOP_APP_CONTROL = "Sn/getSnAppControl";
|
||||
public static final String GET_TOP_APP_CONTROL = "Sn/getSnAppControl";
|
||||
//获取测试app
|
||||
public final static String GET_SN_APP_TEST = "Sn/getSnAppTest";
|
||||
public static final String GET_SN_APP_TEST = "Sn/getSnAppTest";
|
||||
//开机动画
|
||||
public final static String GET_LOGO_IMG = "Sn/getLogoImg";
|
||||
public static final String GET_LOGO_IMG = "Sn/getLogoImg";
|
||||
//开发人员选项开关
|
||||
public final static String GET_DEVELOPER = "Sn/getDeveloper";
|
||||
public static final String GET_DEVELOPER = "Sn/getDeveloper";
|
||||
//通过固件名获取内置应用
|
||||
public final static String GET_ROM_APP = "And/getFirmwareApp";
|
||||
public static final String GET_ROM_APP = "And/getFirmwareApp";
|
||||
//获取全部应用
|
||||
public final static String GET_ALL_APP = "recommend/index";
|
||||
public static final String GET_ALL_APP = "recommend/index";
|
||||
//获取电子书包激活码
|
||||
public final static String GET_EBAG_CODE = "And/getEbagCode";
|
||||
public static final String GET_EBAG_CODE = "And/getEbagCode";
|
||||
//获取系统默认程序
|
||||
public final static String GET_DEFAULT_APP = "app/getDefaultApp";
|
||||
public static final String GET_DEFAULT_APP = "app/getDefaultApp";
|
||||
|
||||
//获取公网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
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.aoleyun.sn.network.api.newapi;
|
||||
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/1814:39
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public interface GetPublicIPApi {
|
||||
@GET(UrlAddress.SHOUHU_CITYJSON)
|
||||
Observable<ResponseBody> getJpushTags();
|
||||
}
|
||||
Reference in New Issue
Block a user