version:2.1

fix:完善推送
update:
This commit is contained in:
2022-01-25 16:12:36 +08:00
parent a432526311
commit edf23945b5
36 changed files with 2692 additions and 945 deletions

View File

@@ -19,6 +19,8 @@ import android.widget.Button;
import android.widget.TextView;
import com.aoleyun.sn.R;
import com.aoleyun.sn.activity.main.MainContact;
import com.aoleyun.sn.activity.main.MainPresenter;
import com.aoleyun.sn.base.BaseActivity;
import com.aoleyun.sn.service.MainService;
import com.aoleyun.sn.utils.ApkUtils;
@@ -33,7 +35,6 @@ import com.google.gson.JsonObject;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.jpush.android.api.JPushInterface;
import pl.droidsonroids.gif.GifImageView;
public class CheckNetActivity extends BaseActivity implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener {
@@ -69,12 +70,12 @@ public class CheckNetActivity extends BaseActivity implements MainContact.MainVi
@Override
public void onDisconnected() {
Log.e("OnNetworkStatusChangedListener", "onDisconnected: ");
Log.e("OnNetworkStatusChanged", "onDisconnected: ");
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
Log.e("OnNetworkStatusChangedListener", "onConnected: ");
Log.e("OnNetworkStatusChanged", "onConnected: ");
timeMillis = SystemClock.elapsedRealtime();
//直接获取数据
mPresenter.getLockedState();
@@ -167,7 +168,7 @@ public class CheckNetActivity extends BaseActivity implements MainContact.MainVi
@Override
public void initData() {
JPushInterface.init(this);
// JPushInterface.init(this);
registerMessageReceiver();
Log.e("getMacAddress", Utils.getAndroid10MAC(this));
timeMillis = SystemClock.elapsedRealtime();
@@ -219,7 +220,7 @@ public class CheckNetActivity extends BaseActivity implements MainContact.MainVi
}
SaveListUtils.getList();
//获取系统管控
mPresenter.setJpushTags();
mPresenter.setPushTags();
netWorkIsRunning = true;
} else {
netWorkIsRunning = false;

View File

@@ -10,7 +10,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.PowerManager;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
@@ -25,6 +24,7 @@ import androidx.core.content.ContextCompat;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.R;
import com.aoleyun.sn.action.JGYActions;
import com.aoleyun.sn.activity.main.MainActivity;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.comm.PackageNames;
import com.aoleyun.sn.service.LogcatService;
@@ -42,7 +42,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import cn.jpush.android.api.JPushInterface;
public class SplashActivity extends AppCompatActivity {
@@ -131,7 +130,7 @@ public class SplashActivity extends AppCompatActivity {
// Log.i(TAG, "debugTest: iptables = " + CmdUtil.execute("iptables -L -n" ).toString());
Log.i(TAG, "debugTest: " + Utils.getAndroid10MAC(this));
Log.i(TAG, "debugTest: " + JPushInterface.getRegistrationID(this));
// Log.i(TAG, "debugTest: " + JPushInterface.getRegistrationID(this));
Log.i(TAG, "debugTest: " + Utils.getCustomVersion());
Log.i(TAG, "debugTest: " + BuildConfig.VERSION_NAME);
Log.i(TAG, "debugTest: " + Utils.getAPPVersionName(PackageNames.APPSTORE, this));
@@ -145,8 +144,8 @@ public class SplashActivity extends AppCompatActivity {
// }
// ActivityManager mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// mAm.killBackgroundProcesses("com.android.documentsui");
BaseApplication.cleanJpushAlias();
BaseApplication.cleanJpushTag();
// BaseApplication.cleanJpushAlias();
// BaseApplication.cleanJpushTag();
Log.e(TAG, "debugTest: SPUtils all " + SPUtils.getAll(this));
try {
PackageManager packageManager = getPackageManager();

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.activity;
package com.aoleyun.sn.activity.main;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@@ -33,13 +33,13 @@ import com.aoleyun.sn.utils.SaveListUtils;
import com.aoleyun.sn.utils.SysSettingUtils;
import com.aoleyun.sn.utils.ToastUtil;
import com.aoleyun.sn.utils.Utils;
import com.tencent.mmkv.MMKV;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -171,7 +171,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
@Override
public void initData() {
JPushInterface.init(this);
// JPushInterface.init(this);
registerMessageReceiver();
Log.e("getMacAddress", Utils.getAndroid10MAC(this));
timeMillis = SystemClock.elapsedRealtime();
@@ -229,7 +229,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
//设置极光推送别名
mPresenter.setJpushAlias();
//设置极光推送标签
mPresenter.setJpushTags();
mPresenter.setPushTags();
Log.e(TAG, "netWorkIsRunning: " + netWorkIsRunning);
Log.e(TAG, "MainService.netWorkIsRunning: " + MainService.netWorkIsRunning);
if (loocked) {
@@ -461,8 +461,6 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
@Override
public void getDefaultDesktopFinish() {
netWorkIsRunning = false;
Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - timeMillis) + " ms");
mPresenter.getPoweroffTime();
}
@@ -473,7 +471,9 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
@Override
public void setWiFiPasswd() {
MMKV.defaultMMKV().encode(MainPresenter.GET_SETTING_FINISH_TIME, System.currentTimeMillis());
netWorkIsRunning = false;
Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - timeMillis) + " ms");
}
@Override
@@ -595,12 +595,12 @@ public class MainActivity extends BaseActivity implements MainContact.MainView,
@Override
public void onDisconnected() {
Log.e("OnNetworkStatusChangedListener", "onDisconnected: ");
Log.e("OnNetworkStatusChanged", "onDisconnected: ");
}
@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
Log.e("OnNetworkStatusChangedListener", "onConnected: ");
Log.e("OnNetworkStatusChanged", "onConnected: ");
timeMillis = SystemClock.elapsedRealtime();
//直接获取数据
mPresenter.getLockedState();

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.activity;
package com.aoleyun.sn.activity.main;
import android.graphics.Bitmap;
import android.view.View;
@@ -47,7 +47,7 @@ public class MainContact {
void checkTestUpdate();
//开始
//设置极光推送标签
void setJpushTags();
void setPushTags();
//获取开发者选项
void getDeveloper();
//获取设备后台设置

View File

@@ -1,4 +1,4 @@
package com.aoleyun.sn.activity;
package com.aoleyun.sn.activity.main;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -32,7 +32,6 @@ import com.aoleyun.sn.bean.ForceDownloadData;
import com.aoleyun.sn.bean.LogoImg;
import com.aoleyun.sn.bean.NetAndLaunchBean;
import com.aoleyun.sn.bean.StudentsInfo;
import com.aoleyun.sn.jpush.TagAliasOperatorHelper;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.service.MainService;
@@ -46,6 +45,8 @@ import com.aoleyun.sn.utils.TimeUtils;
import com.aoleyun.sn.utils.ToastUtil;
import com.aoleyun.sn.utils.URLUtils;
import com.aoleyun.sn.utils.Utils;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
@@ -55,10 +56,8 @@ import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
@@ -66,8 +65,8 @@ import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence;
//import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
//import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence;
/**
* MainActivity和MainService Presenter
@@ -79,6 +78,8 @@ public class MainPresenter implements MainContact.Presenter {
private MainContact.MainView mView;
private Context mContext;
public static final String GET_SETTING_FINISH_TIME = "GET_SETTING_FINISH_TIME";
//是否有接口请求成功
public boolean requestSucceeded = false;
private final String DEFAULT_INFO = "暂无信息";
@@ -260,12 +261,18 @@ public class MainPresenter implements MainContact.Presenter {
}
private long lastgetLockedTime;
private long one_minute = 1000 * 60;
@Override
public void getLockedState() {
// if (System.currentTimeMillis() - lastgetLockedTime < 600 * 1000) {
// return;
// }
MMKV mmkv = MMKV.defaultMMKV();
lastgetLockedTime = mmkv.decodeLong(MainPresenter.GET_SETTING_FINISH_TIME);
Log.e(TAG, "getLockedState: " + lastgetLockedTime);
if (System.currentTimeMillis() - lastgetLockedTime < one_minute) {
Log.e(TAG, "getLockedState: lastgetLockedTime = " + lastgetLockedTime);
return;
}
// lastgetLockedTime = System.currentTimeMillis();
NetInterfaceManager.getInstance()
.getDevicesLockedStateObservable()
@@ -553,34 +560,34 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void setJpushAlias() {
JPushInterface.init(mContext);
SetAlias();
String rid = JPushInterface.getRegistrationID(mContext);
if (!TextUtils.isEmpty(rid)) {
Log.e(TAG + ":" + "setJpushAlias", "RegId:" + rid);
}
JPushInterface.getAlias(mContext, new Random().nextInt(100));
// JPushInterface.init(mContext);
// SetAlias();
// String rid = JPushInterface.getRegistrationID(mContext);
// if (!TextUtils.isEmpty(rid)) {
// Log.e(TAG + ":" + "setJpushAlias", "RegId:" + rid);
// }
// JPushInterface.getAlias(mContext, new Random().nextInt(100));
mView.setAliasFinish();
}
private void SetAlias() {
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
tagAliasBean.action = ACTION_SET;
sequence++;
tagAliasBean.alias = Utils.getSerial();
tagAliasBean.isAliasAction = true;
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
}
// private void SetAlias() {
// TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
// tagAliasBean.action = ACTION_SET;
// sequence++;
// tagAliasBean.alias = Utils.getSerial();
// tagAliasBean.isAliasAction = true;
// TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
// }
@Override
public void setJpushTags() {
public void setPushTags() {
NetInterfaceManager.getInstance()
.getJpushTagsObservable()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e(TAG + ":" + "setJpushTags", "onSubscribe: ");
Log.e(TAG + ":" + "setPushTags", "onSubscribe: ");
}
@Override
@@ -589,7 +596,7 @@ public class MainPresenter implements MainContact.Presenter {
if (response.code == OK) {
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
String batch = jsonObject.get("batch").getAsString();
Log.e(TAG + ":" + "setJpushTags", "onNext: " + batch);
Log.e(TAG + ":" + "setPushTags", "onNext: " + batch);
if (!TextUtils.isEmpty(batch)) {
mView.setTagsFinish(false);
Set set = new HashSet();
@@ -604,27 +611,39 @@ public class MainPresenter implements MainContact.Presenter {
}
}
});
setTag(set);
Set<String> tagsSet = new HashSet<>(set);
XGPushManager.clearAndAppendTags(mContext, "clearAndAppendTags :" + System.currentTimeMillis(), tagsSet, new XGIOperateCallback() {
@Override
public void onSuccess(Object o, int i) {
Log.e("setPushTags", "onSuccess: " + o);
}
@Override
public void onFail(Object o, int i, String s) {
Log.e("setPushTags", "onFail: " + o);
}
});
// setTag(set);
} else {
mView.setTagsFinish(true);
Log.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty");
Log.e(TAG + ":" + "setPushTags", "onNext: " + "batch empty");
}
} else {
mView.setTagsFinish(true);
Log.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString());
Log.e(TAG + ":" + "setPushTags", "onNext: " + response.toString());
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage());
Log.e(TAG + ":" + "setPushTags", "onError: " + e.getMessage());
mView.setTagsFinish(true);
onComplete();
}
@Override
public void onComplete() {
Log.e(TAG + ":" + "setJpushTags", "onComplete: ");
Log.e(TAG + ":" + "setPushTags", "onComplete: ");
}
});
}
@@ -634,14 +653,14 @@ public class MainPresenter implements MainContact.Presenter {
mView.setJpushPlatformTagsFinish();
}
private void setTag(Set set) {
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
tagAliasBean.action = ACTION_SET;
sequence++;
tagAliasBean.tags = set;
tagAliasBean.isAliasAction = false;
TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
}
// private void setTag(Set set) {
// TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
// tagAliasBean.action = ACTION_SET;
// sequence++;
// tagAliasBean.tags = set;
// tagAliasBean.isAliasAction = false;
// TagAliasOperatorHelper.getInstance().handleAction(mContext, sequence, tagAliasBean);
// }
@Override
public void checkStoreUpdate() {
@@ -2043,6 +2062,7 @@ public class MainPresenter implements MainContact.Presenter {
public void getPoweroffTime() {
NetInterfaceManager.getInstance()
.getPoweroffTimeControl()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<List<PoweroffBean>>>() {
@Override
public void onSubscribe(Disposable d) {
@@ -2079,6 +2099,7 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void getWiFiPasswd() {
NetInterfaceManager.getInstance().getWiFiControl()
.compose(getProvider().bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<List<WiFiAlias>>>() {
@Override
public void onSubscribe(Disposable d) {
@@ -2101,11 +2122,13 @@ public class MainPresenter implements MainContact.Presenter {
@Override
public void onError(Throwable e) {
Log.e("getWiFiPasswd", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("getWiFiPasswd", "onComplete: ");
mView.setWiFiPasswd();
}
});
}

View File

@@ -16,7 +16,6 @@ import com.aoleyun.sn.utils.WiFiUtils;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.jpush.TagAliasOperatorHelper;
import com.aoleyun.sn.manager.AmapManager;
import com.aoleyun.sn.manager.FileManager;
import com.aoleyun.sn.network.NetInterfaceManager;
@@ -30,6 +29,9 @@ import com.aoleyun.sn.utils.SystemUtils;
import com.aoleyun.sn.utils.ToastUtil;
import com.aoleyun.sn.utils.Utils;
import com.aoleyun.sn.utils.XAPKUtils;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import org.jetbrains.annotations.NotNull;
@@ -39,8 +41,6 @@ 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.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -87,6 +87,8 @@ public class BaseApplication extends MultiDexApplication {
private void init() {
String rootDir = MMKV.initialize(this);
Log.e(TAG, "mmkv root: " + rootDir);
tPushInit();
ToastUtil.init(this);
NetInterfaceManager.init(this);
JGYUtils.init(this);
@@ -99,8 +101,8 @@ public class BaseApplication extends MultiDexApplication {
JGYUtils.getInstance().hookWebView();
// 设置开启日志,发布时请关闭日志
JPushInterface.setDebugMode(true);
JPushInterface.requestPermission(this);
// JPushInterface.setDebugMode(true);
// JPushInterface.requestPermission(this);
//解锁设备不需要初始化
// 初始化 JPush
//JPushInterface.init(this);
@@ -150,6 +152,37 @@ public class BaseApplication extends MultiDexApplication {
});
}
private void tPushInit() {
XGPushConfig.enableDebug(this, true);
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
//token在设备卸载重装的时候有可能会变
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() {
@Override
public void onSuccess(Object data, int flag) {
Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.e("TPush", "onFail, data:" + data + ", code:" + errCode + ", msg:" + msg);
}
});
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
private static void initAliasObservable() {
Log.e(TAG, "initAliasObservable: ");
Observable.create(new ObservableOnSubscribe<Integer>() {
@@ -232,17 +265,17 @@ public class BaseApplication extends MultiDexApplication {
});
}
public void onAliasOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onAliasResult.onResult(errorCode);
}
// 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());
// JPushInterface.setAlias(context, TagAliasOperatorHelper.sequence++, Utils.getSerial());
}
private static void initTagObservable() {
@@ -341,17 +374,17 @@ public class BaseApplication extends MultiDexApplication {
});
}
public void onTagOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
}
int errorCode = jPushMessage.getErrorCode();
onTagResult.onResult(errorCode);
}
// 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");
HTTPInterface.setJpushTags(context);
HTTPInterface.setPushTags(context);
}
private static OnAliasResult onAliasResult;

View File

@@ -15,7 +15,6 @@ 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";
@@ -126,7 +125,7 @@ public class ExampleUtil {
}
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
// public static String getDeviceId(Context context) {
// return JPushInterface.getUdid(context);
// }
}

View File

@@ -4,43 +4,40 @@ import android.content.Context;
import com.aoleyun.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);
super.onTagOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onTagOperatorResult(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);
super.onAliasOperatorResult(context, jPushMessage);
BaseApplication.getInstance().onAliasOperatorResult(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);
}
}
//public class MyJPushMessageReceiver extends JPushMessageReceiver {
//
// @Override
// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
// super.onTagOperatorResult(context, jPushMessage);
// BaseApplication.getInstance().onTagOperatorResult(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);
// super.onAliasOperatorResult(context, jPushMessage);
// BaseApplication.getInstance().onAliasOperatorResult(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);
// }
//
//
//}

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,5 @@
package com.aoleyun.sn.jpush;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.aoleyun.sn.activity.MainActivity;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import cn.jpush.android.api.JPushInterface;
/**
* 自定义接收器
@@ -22,108 +8,108 @@ import cn.jpush.android.api.JPushInterface;
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
*/
public class MyReceiver extends BroadcastReceiver {
private static final String TAG = "JIGUANG-Example";
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
// i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
// context.startActivity(i);
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
} else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Logger.w(TAG, "[MyReceiver]" + intent.getAction() +" connected state change to "+connected);
} else {
Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
} catch (Exception e){
}
}
// 打印所有的 intent extra 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
}else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){
sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
} else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Logger.i(TAG, "This message has no Extra data");
continue;
}
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
Iterator<String> it = json.keys();
while (it.hasNext()) {
String myKey = it.next();
sb.append("\nkey:" + key + ", value: [" +
myKey + " - " +json.optString(myKey) + "]");
}
} catch (JSONException e) {
Logger.e(TAG, "Get message extra JSON error!");
}
} else {
sb.append("\nkey:" + key + ", value:" + bundle.get(key));
}
}
return sb.toString();
}
//send msg to MainActivity
private void processCustomMessage(Context context, Bundle bundle) {
if (MainActivity.isForeground) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
if (!ExampleUtil.isEmpty(extras)) {
try {
JSONObject extraJson = new JSONObject(extras);
if (extraJson.length() > 0) {
msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
}
} catch (JSONException e) {
}
}
LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
}
}
}
//public class MyReceiver extends BroadcastReceiver {
// private static final String TAG = "JIGUANG-Example";
//
// @Override
// public void onReceive(Context context, Intent intent) {
// try {
// Bundle bundle = intent.getExtras();
// Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
//
// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
// String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
// Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
// //send the Registration Id to your server...
//
// } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
// processCustomMessage(context, bundle);
//
// } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
// int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
// Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
//
// } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
//
// //打开自定义的Activity
//// Intent i = new Intent(context, TestActivity.class);
//// i.putExtras(bundle);
// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
//// context.startActivity(i);
//
// } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
// Logger.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
// //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
//
// } else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
// boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
// Logger.w(TAG, "[MyReceiver]" + intent.getAction() +" connected state change to "+connected);
// } else {
// Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
// }
// } catch (Exception e){
//
// }
//
// }
//
// // 打印所有的 intent extra 数据
// private static String printBundle(Bundle bundle) {
// StringBuilder sb = new StringBuilder();
// for (String key : bundle.keySet()) {
// if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
// sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
// }else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){
// sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
// } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
// if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
// Logger.i(TAG, "This message has no Extra data");
// continue;
// }
//
// try {
// JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
// Iterator<String> it = json.keys();
//
// while (it.hasNext()) {
// String myKey = it.next();
// sb.append("\nkey:" + key + ", value: [" +
// myKey + " - " +json.optString(myKey) + "]");
// }
// } catch (JSONException e) {
// Logger.e(TAG, "Get message extra JSON error!");
// }
//
// } else {
// sb.append("\nkey:" + key + ", value:" + bundle.get(key));
// }
// }
// return sb.toString();
// }
//
// //send msg to MainActivity
// private void processCustomMessage(Context context, Bundle bundle) {
// if (MainActivity.isForeground) {
// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
// Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
// if (!ExampleUtil.isEmpty(extras)) {
// try {
// JSONObject extraJson = new JSONObject(extras);
// if (extraJson.length() > 0) {
// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
// }
// } catch (JSONException e) {
//
// }
//
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
// }
// }
//}

View File

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

View File

@@ -11,335 +11,333 @@ import com.aoleyun.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.betaShow("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.betaShow("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 +
'}';
}
}
// 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.betaShow("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.betaShow("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

@@ -4,7 +4,6 @@ import android.app.Application;
import com.aoleyun.sn.jpush.Logger;
import cn.jpush.android.api.JPushInterface;
/**
* For developer startup JPush SDK
@@ -19,7 +18,7 @@ public class ExampleApplication extends Application {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
// JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
// JPushInterface.init(this); // 初始化 JPush
}
}

View File

@@ -6,7 +6,6 @@ import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import cn.jpush.android.api.JPushInterface;
public class TestActivity extends Activity {
@@ -21,8 +20,8 @@ public class TestActivity extends Activity {
String title = null;
String content = null;
if(bundle!=null){
title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
content = bundle.getString(JPushInterface.EXTRA_ALERT);
// title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
// content = bundle.getString(JPushInterface.EXTRA_ALERT);
}
tv.setText("Title : " + title + " " + "Content : " + content);
}

View File

@@ -49,6 +49,8 @@ import com.aoleyun.sn.utils.ForegroundAppUtil;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.TimeUtils;
import com.aoleyun.sn.utils.Utils;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import java.io.IOException;
@@ -69,8 +71,8 @@ import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence;
//import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
//import static com.aoleyun.sn.jpush.TagAliasOperatorHelper.sequence;
public class HTTPInterface {
private static final String TAG = HTTPInterface.class.getSimpleName();
@@ -100,13 +102,13 @@ public class HTTPInterface {
}
}
synchronized public static void setJpushTags(final Context context) {
synchronized public static void setPushTags(final Context context) {
NetInterfaceManager.getInstance()
.getJpushTagsObservable()
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e(TAG + ":" + "setJpushTags", "onSubscribe: ");
Log.e(TAG + ":" + "setPushTags", "onSubscribe: ");
}
@Override
@@ -114,7 +116,7 @@ public class HTTPInterface {
if (response.code == 200) {
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
String batch = jsonObject.get("batch").getAsString();
Log.e(TAG + ":" + "setJpushTags", "onNext: " + batch);
Log.e(TAG + ":" + "setPushTags", "onNext: " + batch);
if (!TextUtils.isEmpty(batch)) {
Set set = new HashSet();
set.add(batch);
@@ -128,36 +130,48 @@ public class HTTPInterface {
}
}
});
setTag(context, set);
Set<String> tagsSet = new HashSet<>(set);
XGPushManager.clearAndAppendTags(context, "clearAndAppendTags :" + System.currentTimeMillis(), tagsSet, new XGIOperateCallback() {
@Override
public void onSuccess(Object o, int i) {
Log.e("setPushTags", "onSuccess: " + o);
}
@Override
public void onFail(Object o, int i, String s) {
Log.e("setPushTags", "onFail: " + o);
}
});
// setTag(context, set);
} else {
Log.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty");
Log.e(TAG + ":" + "setPushTags", "onNext: " + "batch empty");
}
} else {
Log.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString());
Log.e(TAG + ":" + "setPushTags", "onNext: " + response.toString());
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage());
Log.e(TAG + ":" + "setPushTags", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e(TAG + ":" + "setJpushTags", "onComplete: ");
Log.e(TAG + ":" + "setPushTags", "onComplete: ");
}
});
}
private static void setTag(Context context, Set set) {
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
tagAliasBean.action = ACTION_SET;
sequence++;
tagAliasBean.tags = set;
tagAliasBean.isAliasAction = false;
TagAliasOperatorHelper.getInstance().handleAction(context, sequence, tagAliasBean);
}
// private static void setTag(Context context, Set set) {
// TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
// tagAliasBean.action = ACTION_SET;
// sequence++;
// tagAliasBean.tags = set;
// tagAliasBean.isAliasAction = false;
// TagAliasOperatorHelper.getInstance().handleAction(context, sequence, tagAliasBean);
// }
public interface GetAppinsideWebCallback {
void onComplete();
@@ -802,28 +816,28 @@ public class HTTPInterface {
.subscribe(new Observer<NetAndLaunchBean>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e("getAppAutoStartUpdateAndNet", "onSubscribe: ");
Log.e("getAutoUpdateAndNet", "onSubscribe: ");
}
@Override
public void onNext(@NonNull NetAndLaunchBean netAndLaunchBean) {
Log.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString());
Log.e("getAutoUpdateAndNet", "onNext: " + netAndLaunchBean.toString());
if (netAndLaunchBean.getCode() == 200) {
JGYUtils.getInstance().setNetAndlaunch(netAndLaunchBean, appListInfos);
} else {
Log.e("getAppAutoStartUpdateAndNet", "onNext: " + netAndLaunchBean.toString());
Log.e("getAutoUpdateAndNet", "onNext: " + netAndLaunchBean.toString());
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("getAppAutoStartUpdateAndNet", "onError: " + e.getMessage());
Log.e("getAutoUpdateAndNet", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("getAppAutoStartUpdateAndNet", "onComplete: ");
Log.e("getAutoUpdateAndNet", "onComplete: ");
}
});
}

View File

@@ -58,6 +58,7 @@ 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.JGYUtils;
import com.aoleyun.sn.utils.MD5Util;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.Utils;
@@ -70,7 +71,6 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@@ -265,7 +265,8 @@ public class NetInterfaceManager {
return mRetrofit.create(MACAddressApi.class)
.sendMACaddress(Utils.getSerial(),
Utils.getAndroid10MAC(mContext),
JPushInterface.getRegistrationID(mContext),
"0000",
// JPushInterface.getRegistrationID(mContext),
Utils.getCustomVersion(),
BuildConfig.VERSION_NAME,
Utils.getAPPVersionName(PackageNames.APPSTORE, mContext),
@@ -277,7 +278,8 @@ public class NetInterfaceManager {
Utils.getBluetoothList(),
Utils.getWifiAlias(mContext),
Utils.getAPPVersionName(PackageNames.BROWSER, mContext),
Utils.getAPPVersionName(PackageNames.NOTIFICATIONS, mContext)
Utils.getAPPVersionName(PackageNames.NOTIFICATIONS, mContext),
JGYUtils.getInstance().getAppPlatform()
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());

View File

@@ -3,6 +3,8 @@ package com.aoleyun.sn.network.api.newapi;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.network.UrlAddress;
import java.io.File;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
@@ -26,6 +28,7 @@ public interface MACAddressApi {
@Field("bluetooth") String bluetooth,
@Field("wifi_name") String wifi_name,
@Field("browser_version") String browser_version,
@Field("notice_version") String notice_version
@Field("notice_version") String notice_version,
@Field("platform") String platform
);
}

View File

@@ -32,9 +32,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aoleyun.sn.R;
import com.aoleyun.sn.action.JGYActions;
import com.aoleyun.sn.activity.MainActivity;
import com.aoleyun.sn.activity.MainContact;
import com.aoleyun.sn.activity.MainPresenter;
import com.aoleyun.sn.activity.main.MainActivity;
import com.aoleyun.sn.activity.main.MainContact;
import com.aoleyun.sn.activity.main.MainPresenter;
import com.aoleyun.sn.bean.PoweroffBean;
import com.aoleyun.sn.comm.PackageNames;
import com.aoleyun.sn.receiver.BootReceiver;
@@ -64,7 +64,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -210,7 +209,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName(PackageNames.APPSTORE, PackageNames.APP_STORE_BOOTRECEIVER));
sendBroadcast(bootIntent);
JPushInterface.init(this);
// JPushInterface.init(this);
if (MainActivity.isForeground) {
Log.e(TAG, "onStartCommand: MainService: isForeground: " + MainActivity.isForeground);
} else {
@@ -649,7 +648,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
//设置极光推送别名
mPresenter.setJpushAlias();
//设置极光推送标签
mPresenter.setJpushTags();
mPresenter.setPushTags();
if (loocked) {
ToastUtil.betaShow("设备已上锁");
//上传APP信息
@@ -842,8 +841,6 @@ public class MainService extends Service implements MainContact.MainView, Networ
@Override
public void getDefaultDesktopFinish() {
netWorkIsRunning = false;
Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms");
mPresenter.getPoweroffTime();
}
@@ -854,7 +851,9 @@ public class MainService extends Service implements MainContact.MainView, Networ
@Override
public void setWiFiPasswd() {
MMKV.defaultMMKV().encode(MainPresenter.GET_SETTING_FINISH_TIME, System.currentTimeMillis());
netWorkIsRunning = false;
Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms");
}
@Override

View File

@@ -0,0 +1,17 @@
package com.aoleyun.sn.tpush;
/**
* Created by chacewang on 2019/7/5.
*/
public class Constants {
public static final int TEST_LOCAL_NOTIFICATION = 1;
public static final int TEST_NOTIFICATION = 2;
public static final int TEST_SET_TAG = 3;
public static final int TEST_DEL_TAG = 4;
public static final int TEST_SET_ACCOUNT = 5;
public static final int TEST_DEL_ACCOUNT = 6;
public static final String LOCAL_NOTIFICATION_TITLE = "localtest";
public static final String TEST_TAG_NAME = "DiagnosisTag";
}

View File

@@ -1,7 +1,7 @@
package com.aoleyun.sn.receiver;
package com.aoleyun.sn.tpush;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
@@ -17,49 +17,57 @@ import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.aoleyun.sn.R;
import com.aoleyun.sn.action.JGYActions;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.bean.TTAppground;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.PathUtils;
import com.aoleyun.sn.R;
import com.aoleyun.sn.utils.CacheUtils;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.comm.CommonDatas;
import com.aoleyun.sn.manager.AmapManager;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.service.MainService;
import com.aoleyun.sn.tpush.common.NotificationService;
import com.aoleyun.sn.tpush.po.XGNotification;
import com.aoleyun.sn.utils.ApkUtils;
import com.aoleyun.sn.utils.CacheUtils;
import com.aoleyun.sn.utils.CmdUtil;
import com.aoleyun.sn.utils.ForegroundAppUtil;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.MySQLData;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.SaveListUtils;
import com.aoleyun.sn.utils.ServiceAliveUtils;
import com.aoleyun.sn.utils.ToastUtil;
import com.aoleyun.sn.utils.Utils;
import com.arialyy.aria.core.Aria;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.tencent.android.tpush.NotificationAction;
import com.tencent.android.tpush.XGPushBaseReceiver;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushRegisterResult;
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;
import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
@@ -72,8 +80,12 @@ import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
public class MyJPushReceiver extends BroadcastReceiver {
private static final String TAG = MyJPushReceiver.class.getSimpleName();
public class MessageReceiver extends XGPushBaseReceiver {
public static final String UPDATE_LISTVIEW_ACTION = "com.qq.xgdemo.activity.UPDATE_LISTVIEW";
public static final String TEST_ACTION = "com.qq.xgdemo.activity.TEST_ACTION";
public static final String LogTag = "xg.test";
private static final String TAG = MessageReceiver.class.getSimpleName();
//删除应用
private final String MSG_DELETE = "1";
@@ -156,57 +168,281 @@ public class MyJPushReceiver extends BroadcastReceiver {
//自定义指令
private final String CUSTOM_ORDER = "44";
private Context mContext;
private ContentResolver mResolver;
private PackageManager mPackageManager;
/**
* 消息透传处理
*
* @param context
* @param message 解析自定义的 JSON
*/
@Override
public void onTextMessage(Context context, XGPushTextMessage message) {
this.mContext = context;
this.mResolver = context.getContentResolver();
this.mPackageManager = context.getPackageManager();
String text = "收到消息:" + message.toString();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
// key1为前台配置的key
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
String value = obj.get("key").getAsString();
Log.d(LogTag, "get custom value:" + value);
}
// ...
}
// APP自主处理消息的过程...
Log.e(LogTag, text);
show(context, text);
processCustomMessage(context, message);
}
/**
* 通知展示
*
* @param context
* @param notifiShowedRlt 包含通知的内容
*/
@Override
public void onNotificationShowedResult(Context context, XGPushShowedResult notifiShowedRlt) {
if (context == null || notifiShowedRlt == null) {
return;
}
XGNotification notific = new XGNotification();
notific.setMsg_id(notifiShowedRlt.getMsgId());
notific.setTitle(notifiShowedRlt.getTitle());
notific.setContent(notifiShowedRlt.getContent());
// notificationActionType==1为Activity2为url3为intent
notific.setNotificationActionType(notifiShowedRlt
.getNotificationActionType());
// Activity,url,intent都可以通过getActivity()获得
notific.setActivity(notifiShowedRlt.getActivity());
notific.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(Calendar.getInstance().getTime()));
NotificationService.getInstance(context).save(notific);
Intent testIntent = new Intent(TEST_ACTION);
if (notifiShowedRlt.getTitle().equals(Constants.LOCAL_NOTIFICATION_TITLE)) {
testIntent.putExtra("step", Constants.TEST_LOCAL_NOTIFICATION);
} else {
testIntent.putExtra("step", Constants.TEST_NOTIFICATION);
}
context.sendBroadcast(testIntent);
Intent viewIntent = new Intent(UPDATE_LISTVIEW_ACTION);
context.sendBroadcast(viewIntent);
show(context, "您有1条新消息, " + "通知被展示 " + notifiShowedRlt.toString());
Log.d(LogTag, "您有1条新消息, " + "通知被展示 " + notifiShowedRlt.toString() + ", PushChannel:" + notifiShowedRlt.getPushChannel());
}
/**
* 注册回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
*/
@Override
public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
// 在这里拿token
String token = message.getToken();
text = "注册成功1. token" + token;
} else {
text = message + "注册失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 反注册回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
*/
@Override
public void onUnregisterResult(Context context, int errorCode) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "反注册成功";
} else {
text = "反注册失败" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 设置标签回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onSetTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"设置成功";
} else {
text = "\"" + tagName + "\"设置失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_TAG);
context.sendBroadcast(testIntent);
}
/**
* 删除标签的回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onDeleteTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"删除成功";
} else {
text = "\"" + tagName + "\"删除失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_TAG);
context.sendBroadcast(testIntent);
}
/**
* 设置账号回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
* @param account 设置的账号
*/
@Override
public void onSetAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_ACCOUNT);
context.sendBroadcast(testIntent);
}
/**
* 删除账号回调
*
* @param context
* @param errorCode 0 为成功其它为错误码
* @param account 设置的账号
*/
@Override
public void onDeleteAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_ACCOUNT);
context.sendBroadcast(testIntent);
}
@Override
public void onSetAttributeResult(Context context, int i, String s) {
}
@Override
public void onDeleteAttributeResult(Context context, int i, String s) {
}
@Override
public void onQueryTagsResult(Context context, int errorCode, String data, String operateName) {
Log.i(LogTag, "action - onQueryTagsResult, errorCode:" + errorCode + ", operateName:" + operateName + ", data: " + data);
}
/**
* 通知点击回调 actionType=1为该消息被清除actionType=0为该消息被点击
*
* @param context
* @param message 包含被点击通知的内容
*/
@Override
public void onNotificationClickedResult(Context context, XGPushClickedResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (message.getActionType() == NotificationAction.clicked.getType()) {
// 通知在通知栏被点击啦
// APP自己处理点击的相关动作
// 这个动作可以在activity的onResume也能监听请看第3点相关内容
text = "通知被打开 :" + message;
} else if (message.getActionType() == NotificationAction.delete.getType()) {
// 通知被清除啦
// APP自己处理通知被清除后的相关动作
text = "通知被清除 :" + message;
}
Toast.makeText(context, "广播接收到通知被点击:" + message.toString(),
Toast.LENGTH_SHORT).show();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
// key1为前台配置的key
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
String value = obj.get("key").getAsString();
Log.d(LogTag, "get custom value:" + value);
}
// ...
}
// APP自主处理的过程
Log.d(LogTag, text);
show(context, text);
}
private void show(Context context, String text) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
private int changeNum(int paramInt) {
return paramInt == 0 ? 1 : 0;
}
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
Bundle bundle = intent.getExtras();
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Log.e(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
// ToastTool.show("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
// Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
processCustomMessage(context, bundle);//屏蔽推送
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA));
// doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA));
// Log.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] 用户点击打开了通知");
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Log.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Log.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
private void processCustomMessage(Context context, XGPushTextMessage message) {
if (context == null || message == null) {
return;
}
}
private void processCustomMessage(final Context context, Bundle bundle) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
String package_name = bundle.getString("package_name");
Log.e(TAG, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
switch (message) {
String title = message.getTitle();
String content = message.getContent();
JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject();
String extras = "";
if (extrasJson.get("extras") != null) {
extras = extrasJson.get("extras").toString();
}
switch (title) {
default:
break;
case MSG_DELETE:
@@ -218,7 +454,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
SaveListUtils.sendForceAPP(mContext);
ApkUtils.UninstallAPP(mContext, title);
}
HTTPInterface.getAppLimit(context);
HTTPInterface.getAppLimit(mContext);
HTTPInterface.getNetAndLaunchSetting(mContext);
break;
case MSG_SETTING:
@@ -249,7 +485,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
case MSG_INSTALL:
ToastUtil.betaShow("收到管控:应用安装");
HTTPInterface.getAppLimit(context);
HTTPInterface.getAppLimit(mContext);
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
break;
@@ -269,9 +505,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
case GET_APP_USEDTIME:
ToastUtil.betaShow("收到管控:获取应用使用时间");
JSONObject jsonObject = JSON.parseObject(extras);
String random = jsonObject.getString("random");
String sendType = jsonObject.getString("type");
JSONObject usedTimeJson = JSON.parseObject(extras);
String random = usedTimeJson.getString("random");
String sendType = usedTimeJson.getString("type");
BaseApplication.sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
@@ -306,7 +542,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
e.printStackTrace();
Log.e(TAG, "setHomepagtag: " + e.getMessage());
}
setHomepagtag(extras);
setHomepagtag();
ToastUtil.betaShow("收到管控:浏览器主页书签设置");
}
}, 2000);
@@ -325,7 +561,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
Handler.getMain().postDelayed(() -> {
//后台发送时数据库未改变有时候可能获取到的数据时上一次的
Log.e(TAG, "run: HIDE_DESKTOP_ICON ");
HTTPInterface.setHideDesktopIcon(context);
HTTPInterface.setHideDesktopIcon(mContext);
}, 2000);
break;
case DISABLE_APP_SLIDE:
@@ -334,7 +570,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
case UPDATE_INFO:
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(context);
HTTPInterface.getAppLimit(mContext);
break;
case SN_SCREENSHOT:
ToastUtil.betaShow("收到管控:设备截图");
@@ -384,42 +620,42 @@ public class MyJPushReceiver extends BroadcastReceiver {
ToastUtil.betaShow("收到管控:屏幕锁定");
JSONObject lockJSONObject = JSON.parseObject(extras);
String name = lockJSONObject.getString("name");
setLock_screen(1, context, name);
setLock_screen(1, name);
break;
case UNLOCK_SCREEN:
ToastUtil.betaShow("收到管控:屏幕解锁");
setLock_screen(0, context, "");
setLock_screen(0, "");
break;
case KILL_SERVER:
ToastUtil.betaShow("收到管控:停止应用");
JSONObject killJSONObject = JSON.parseObject(extras);
String packages = killJSONObject.getString("package_name");
JGYUtils.getInstance().killBackgroundProcesses(context, packages);
JGYUtils.getInstance().killBackgroundProcesses(mContext, packages);
break;
case TIME_CONTROL:
ToastUtil.betaShow("收到管控:使用时间管控");
getTimeControl(context, extras);
getTimeControl(extras);
break;
case TOP_APP:
ToastUtil.betaShow("收到管控:应用霸屏");
getTopApp(context, extras);
getTopApp(extras);
break;
case LOGO_IMG:
ToastUtil.betaShow("收到管控:开机动画设置");
setBootanimation(context, extras);
setBootanimation(extras);
Log.e(TAG, "processCustomMessage: " + extras);
break;
case DEFAULTP_APP:
ToastUtil.betaShow("收到管控:");
setDefalutApp(context, extras);
setDefalutApp(extras);
break;
case PLAY_SOUND:
ToastUtil.betaShow("收到管控:查找设备");
playSound(context, extras);
playSound(extras);
break;
case CLEAN_APP_CACHE:
ToastUtil.betaShow("收到管控:应用缓存清除");
cleanCache(context, extras);
cleanCache(extras);
break;
case DEVELOPER_OPTIONS:
ToastUtil.betaShow("收到管控:开发人员选项管控");
@@ -432,7 +668,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
case EBAG_CODE:
ToastUtil.betaShow("收到管控:电子书包激活码");
setEbagCode(extras);
JGYUtils.getInstance().killBackgroundProcesses(context, "com.jxw.launcher");
JGYUtils.getInstance().killBackgroundProcesses(mContext, "com.jxw.launcher");
break;
case UPDATE_WHITELIST:
ToastUtil.betaShow("收到管控:更新白名单");
@@ -455,24 +691,23 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
break;
case UPDATE_WIFI_PW:
HTTPInterface.getWiFiPasswd(context);
HTTPInterface.getWiFiPasswd(mContext);
break;
case DEVICES_POWEROFF:
HTTPInterface.getPoweroffTime();
break;
case SN_RUN_LOG:
recordLog(context, extras);
recordLog(extras);
break;
case CUSTOM_ORDER:
customOrder(context, extras);
customOrder(extras);
break;
}
}
private void setLock_screen(int state, Context context, String name) {
if (ServiceAliveUtils.isServiceAlive(context)) {
context.startService(new Intent(context, MainService.class));
private void setLock_screen(int state, String name) {
if (ServiceAliveUtils.isServiceAlive(mContext)) {
mContext.startService(new Intent(mContext, MainService.class));
}
Intent intent = new Intent();
intent.putExtra("name", name);
@@ -481,7 +716,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
} else if (state == 0) {
intent.setAction(MainService.LockScreenReceiver.action_unlock);
}
context.sendBroadcast(intent);
mContext.sendBroadcast(intent);
}
private void doDownloadAndInstall(String jsonString) {
@@ -509,10 +744,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
Log.e(TAG, "doDownloadAndInstall: app_url:" + app_url);
SaveListUtils.addList(app_package);
SaveListUtils.sendForceAPP(mContext);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(app_package, 0);
packageInfo = mPackageManager.getPackageInfo(app_package, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
@@ -541,9 +775,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
private int getBatteryLevel() {
if (Build.VERSION.SDK_INT >= 21) {
return ((BatteryManager) this.mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
}
Intent intent = (new ContextWrapper(this.mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
@@ -596,26 +830,26 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void setDisableSlideList(String s) {
JSONObject jSONObject = JSON.parseObject(s);
private void setDisableSlideList(String jsonString) {
JSONObject jSONObject = JSON.parseObject(jsonString);
Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString());
String strban = jSONObject.getString("ban");
String strnot = jSONObject.getString("not");
String qch_disable_slide = Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide");
String qch_disable_slide = Settings.System.getString(mResolver, "qch_disable_slide");
Log.e("fht", "qch_disable_slide::" + qch_disable_slide);
if (!TextUtils.isEmpty(strban)) {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", strban);
Settings.System.putString(mResolver, "qch_disable_slide", strban);
Log.e("fht", "sendban::" + strban);
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
Settings.System.putString(mResolver, "qch_disable_slide", "Invalid");
}
Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide"));
Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mResolver, "qch_disable_slide"));
}
private void setDisableUpdateList(String s) {
Log.e("setDisableUpdateList", s);
JSONObject jsonObject = JSON.parseObject(s);
private void setDisableUpdateList(String jsonString) {
Log.e("setDisableUpdateList", jsonString);
JSONObject jsonObject = JSON.parseObject(jsonString);
String ban = jsonObject.getString("ban");
String not = jsonObject.getString("not");
String[] banList = ban.split(",");
@@ -628,7 +862,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
if (TextUtils.isEmpty(s)) {
Intent intent = new Intent("qch_camera_forbid").setPackage("com.android.settings");
intent.putExtra("camera_package_name", "close");
this.mContext.sendBroadcast(intent);
mContext.sendBroadcast(intent);
Log.e(TAG, "settingNetControl extras is null");
return;
}
@@ -640,11 +874,11 @@ public class MyJPushReceiver extends BroadcastReceiver {
if ("0".equals(s1)) {
Intent intent2 = new Intent("qch_camera_forbid").setPackage("com.android.settings");
// intent2.putExtra("camera_package_name", s1);
this.mContext.sendBroadcast(intent2);
mContext.sendBroadcast(intent2);
} else {
Intent intent1 = new Intent("qch_camera_open").setPackage("com.android.settings");
// intent1.putExtra("camera_package_name", str);
this.mContext.sendBroadcast(intent1);
mContext.sendBroadcast(intent1);
}
}
@@ -683,20 +917,20 @@ public class MyJPushReceiver extends BroadcastReceiver {
Log.e(TAG, "settingPowerOn qch_app_power_on = " + not);
if (TextUtils.isEmpty(not)) {
// qch_app_power_on 的值为空时会造成系统所有应用断网
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", "Invalid");
Settings.System.putString(mResolver, "qch_app_power_on", "Invalid");
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", not);
Settings.System.putString(mResolver, "qch_app_power_on", not);
}
}
private void writeDeselectBrowserIDtoSystem(String s) {
boolean bool = Settings.System.putString(this.mContext.getContentResolver(), "DeselectBrowserArray", s);
boolean bool = Settings.System.putString(mResolver, "DeselectBrowserArray", s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + bool);
}
private void setHomepagtag(String s) {
private void setHomepagtag() {
HTTPInterface.getHomePageBookmarks(mContext, null);
}
@@ -723,7 +957,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
JSONObject jSONObject = JSON.parseObject(s);
int i = changeNum(jSONObject.getIntValue("lock"));
Settings.System.putInt(this.mContext.getContentResolver(), JGYActions.ACTION_QCH_UNLOCK_IPAD, i);
Settings.System.putInt(mResolver, JGYActions.ACTION_QCH_UNLOCK_IPAD, i);
Log.e("SystemSetting", "qch_unlock_ipad---------" + i);
if (getBatteryLevel() >= CommonDatas.MIN_POWER) {
@@ -826,24 +1060,24 @@ public class MyJPushReceiver extends BroadcastReceiver {
});
}
private void getTimeControl(Context context, String extras) {
HTTPInterface.getSnTimeControl(context);
private void getTimeControl(String extras) {
HTTPInterface.getSnTimeControl(mContext);
}
private void getTopApp(Context context, String extras) {
private void getTopApp(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(context, "");
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(mContext, "");
} else {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(context, packageName);
ForegroundAppUtil.openTopApp(context);
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(mContext, packageName);
ForegroundAppUtil.openTopApp(mContext);
}
}
private void setBootanimation(Context context, String extras) {
private void setBootanimation(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
int type = jsonObject.getInteger("type");
if (type == 1) {
@@ -855,7 +1089,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
}
private void setDefalutApp(Context context, String extras) {
private void setDefalutApp(String extras) {
if (TextUtils.isEmpty(extras)) {
JGYUtils.getInstance().setDefaultDesktop("");
} else {
@@ -863,18 +1097,18 @@ public class MyJPushReceiver extends BroadcastReceiver {
String default_launcher = jsonObject.getString("default_launcher");
if (TextUtils.isEmpty(default_launcher)) {
JGYUtils.getInstance().setDefaultDesktop("");
SPUtils.put(context, "default_launcher", "");
SPUtils.put(mContext, "default_launcher", "");
} else {
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
SPUtils.put(context, "default_launcher", default_launcher);
SPUtils.put(mContext, "default_launcher", default_launcher);
}
}
}
private void playSound(Context context, String extras) {
private void playSound(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
defaultCallMediaPlayer(context);
defaultCallMediaPlayer(mContext);
}
/**
@@ -885,12 +1119,12 @@ public class MyJPushReceiver extends BroadcastReceiver {
*/
MediaPlayer mediaPlayer;
public void defaultCallMediaPlayer(Context context) {
public void defaultCallMediaPlayer(Context mContext) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}
mediaPlayer = MediaPlayer.create(context, R.raw.test);
mediaPlayer = MediaPlayer.create(mContext, R.raw.test);
try {
// mediaPlayer.prepare();
mediaPlayer.setLooping(false);
@@ -908,7 +1142,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (soundCount[0] <= finalLoop) {
setMaxVolume(context);
setMaxVolume(mContext);
mediaPlayer.start();
soundCount[0] += 1;
Log.e(TAG, "onCompletion: " + "loop: " + finalLoop);
@@ -922,7 +1156,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
});
mediaPlayer.setLooping(false);
setMaxVolume(context);
setMaxVolume(mContext);
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
@@ -931,8 +1165,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void setMaxVolume(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
private void setMaxVolume(Context mContext) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int ringMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
int musicMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int voiceMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
@@ -944,14 +1178,14 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void cleanCache(Context context, String extras) {
private void cleanCache(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
Log.e(TAG, "cleanCache: " + "package is empty");
} else {
try {
if (new CacheUtils().cleanApplicationUserData(context, packageName)) {
if (new CacheUtils().cleanApplicationUserData(mContext, packageName)) {
Log.e(TAG, "cleanCache: " + packageName + " success");
} else {
Log.e(TAG, "cleanCache: " + packageName + " failed");
@@ -987,10 +1221,9 @@ public class MyJPushReceiver extends BroadcastReceiver {
@SuppressLint("NewApi")
private void checkAPPInstall(JSONObject jsonObject) {
long version_code = jsonObject.getLong("app_version_code");
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(jsonObject.getString("app_package"), 0);
packageInfo = mPackageManager.getPackageInfo(jsonObject.getString("app_package"), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
@@ -1011,15 +1244,15 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
}
private void recordLog(Context context, String jsonString) {
HTTPInterface.getRunLog(context);
private void recordLog(String jsonString) {
HTTPInterface.getRunLog(mContext);
}
private static final int ACTION_PULL = 1;
private static final int ACTION_DELETE = 2;
private static final int ACTION_UPGRADE = 3;
private void customOrder(Context context, String jsonString) {
private void customOrder(String jsonString) {
Gson gson = new Gson();
Type type = new TypeToken<RemoteDebug>() {
}.getType();
@@ -1030,19 +1263,20 @@ public class MyJPushReceiver extends BroadcastReceiver {
switch (remoteDebug.getType()) {
case ACTION_PULL:
Log.e(TAG, "customOrder: 唤起");
ApkUtils.openPackage(context, pkg);
ApkUtils.openPackage(mContext, pkg);
break;
case ACTION_DELETE:
Log.e(TAG, "customOrder: 删除");
ApkUtils.UninstallAPP(context, pkg);
ApkUtils.UninstallAPP(mContext, pkg);
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
HTTPInterface.getForceDownload(context);
HTTPInterface.getForceDownload(mContext);
break;
default:
break;
}
}
}
}

View File

@@ -0,0 +1,23 @@
package com.aoleyun.sn.tpush.common;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBOpenHelper extends SQLiteOpenHelper {
public DBOpenHelper(Context context) {
super(context, "XGExample.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE notification (id integer primary key autoincrement,msg_id varchar(64),title varchar(128),activity varchar(256),notificationActionType varchar(512),content text,update_time varchar(16))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

View File

@@ -0,0 +1,134 @@
package com.aoleyun.sn.tpush.common;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.aoleyun.sn.tpush.po.XGNotification;
import java.util.ArrayList;
import java.util.List;
public class NotificationService {
private DBOpenHelper dbOpenHelper;
private static NotificationService instance = null;
public NotificationService(Context context) {
this.dbOpenHelper = new DBOpenHelper(context);
}
public synchronized static NotificationService getInstance(Context ctx) {
if (null == instance) {
instance = new NotificationService(ctx);
}
return instance;
}
public void save(XGNotification notification) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("msg_id", notification.getMsg_id());
values.put("title", notification.getTitle());
values.put("content", notification.getContent());
values.put("activity", notification.getActivity());
values.put("notificationActionType", notification.getNotificationActionType());
values.put("update_time", notification.getUpdate_time());
db.insert("notification", null, values);
}
public void delete(Integer id) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.delete("notification", "id=?", new String[] { id.toString() });
}
public void deleteAll() {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.delete("notification", "", null);
}
public void update(XGNotification notification) {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("msg_id", notification.getMsg_id());
values.put("title", notification.getTitle());
values.put("content", notification.getContent());
values.put("activity", notification.getActivity());
values.put("notificationActionType", notification.getNotificationActionType());
values.put("update_time", notification.getUpdate_time());
db.update("notification", values, "id=?", new String[] { notification
.getId().toString() });
}
public XGNotification find(Integer id) {
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
"id=?", new String[] { id.toString() }, null, null,
null, "1");
try {
if (cursor.moveToFirst()) {
return new XGNotification(cursor.getInt(cursor
.getColumnIndex("id")), cursor.getLong(cursor
.getColumnIndex("msg_id")), cursor.getString(cursor
.getColumnIndex("title")), cursor.getString(cursor
.getColumnIndex("content")), cursor.getString(cursor
.getColumnIndex("activity")), cursor.getInt(cursor
.getColumnIndex("notificationActionType")), cursor.getString(cursor
.getColumnIndex("update_time")));
}
return null;
} finally {
cursor.close();
}
}
public List<XGNotification> getScrollData(int currentPage, int lineSize,
String msg_id) {
String firstResult = String.valueOf((currentPage - 1) * lineSize);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = null;
try {
if (msg_id == null || "".equals(msg_id)) {
cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
null, null, null, null, "update_time DESC",
firstResult + "," + lineSize);
} else {
cursor = db
.query("notification",
new String[] { "id,msg_id,title,content,activity,notificationActionType,update_time" },
"msg_id like ?", new String[] { msg_id + "%" },
null, null, "update_time DESC", firstResult
+ "," + lineSize);
}
List<XGNotification> notifications = new ArrayList<XGNotification>();
while (cursor.moveToNext()) {
notifications.add(new XGNotification(cursor.getInt(cursor
.getColumnIndex("id")), cursor.getLong(cursor
.getColumnIndex("msg_id")), cursor.getString(cursor
.getColumnIndex("title")), cursor.getString(cursor
.getColumnIndex("content")), cursor.getString(cursor
.getColumnIndex("activity")), cursor.getInt(cursor
.getColumnIndex("notificationActionType")), cursor.getString(cursor
.getColumnIndex("update_time"))));
}
return notifications;
} finally {
cursor.close();
}
}
public int getCount() {
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select count(*) from notification", null);
try {
cursor.moveToFirst();
return cursor.getInt(0);
} finally {
cursor.close();
}
}
}

View File

@@ -0,0 +1,83 @@
package com.aoleyun.sn.tpush.po;
public class XGNotification {
private Integer id;
private Long msg_id;
private String title;
private String content;
private String activity;
private int notificationActionType;
private String update_time;
public XGNotification() {
}
public XGNotification(Integer id, Long msg_id, String title,
String content, String activity, int notificationActionType, String update_time) {
super();
this.id = id;
this.msg_id = msg_id;
this.title = title;
this.content = content;
this.activity = activity;
this.notificationActionType = notificationActionType;
this.update_time = update_time;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Long getMsg_id() {
return msg_id;
}
public void setMsg_id(Long msg_id) {
this.msg_id = msg_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getUpdate_time() {
return update_time;
}
public void setUpdate_time(String update_time) {
this.update_time = update_time;
}
public String getActivity() {
return activity;
}
public void setActivity(String activity) {
this.activity = activity;
}
public int getNotificationActionType() {
return notificationActionType;
}
public void setNotificationActionType(int notificationActionType) {
this.notificationActionType = notificationActionType;
}
}

View File

@@ -23,7 +23,6 @@ import java.text.DecimalFormat;
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";
@@ -135,7 +134,8 @@ public class ExampleUtil {
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
// return JPushInterface.getUdid(context);
return "0";
}
public static class StorageUtils {

View File

@@ -89,7 +89,6 @@ import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import cn.jpush.android.api.JPushInterface;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
@@ -112,7 +111,11 @@ public class JGYUtils {
}
private JGYUtils(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
}
public static void init(Context context) {
@@ -939,6 +942,12 @@ public class JGYUtils {
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
this.add("com.aoleyun.info");
this.add("com.calculator.uiui");
this.add("com.notepad.uiui");
this.add("com.calendar.uiui");
this.add("com.alarmclock.uiui");
this.add("com.uiui.videoplayer");
}};
HashSet<String> pkgSet = new HashSet<>(Arrays.asList(packageList.split(",")));
pkgSet.addAll(packages);
@@ -1838,7 +1847,8 @@ public class JGYUtils {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial());
jsonObject.addProperty("mac", Utils.getAndroid10MAC(mContext));
jsonObject.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext));
// jsonObject.addProperty("jpush_id", JPushInterface.getRegistrationID(mContext));
jsonObject.addProperty("jpush_id", "0000");
jsonObject.addProperty("devices_version", Utils.getCustomVersion());
jsonObject.addProperty("appstore_version", BuildConfig.VERSION_NAME);
jsonObject.addProperty("store_version", Utils.getAPPVersionName(PackageNames.APPSTORE, mContext));
@@ -1849,6 +1859,7 @@ public class JGYUtils {
jsonObject.addProperty("LAN_ip", Utils.getIPAddress(mContext));
jsonObject.addProperty("bluetooth", Utils.getBluetoothList());
jsonObject.addProperty("wifi_name", Utils.getWifiAlias(mContext));
jsonObject.addProperty("platform", JGYUtils.getInstance().getAppPlatform());
return jsonObject.toString();
}