From cce093aca90a05651377d9b02867c91e340a2ae3 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Tue, 16 Dec 2025 17:57:11 +0800 Subject: [PATCH] =?UTF-8?q?version:3.4.7=20fix:=20update:=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 6 +- app/src/main/AndroidManifest.xml | 37 +- .../com/fuying/sn/base/BaseApplication.java | 91 ++- .../fuying/sn/desktop/RunningAppManager.java | 17 +- .../sn/network/NetInterfaceManager.java | 35 ++ .../PushManager.java} | 595 +++++------------- .../push/alipush/AliMessageIntentService.java | 99 +++ .../push/alipush/AliyunMessageReceiver.java | 116 ++++ .../fuying/sn/{ => push}/tpush/Constants.java | 2 +- .../fuying/sn/push/tpush/MessageReceiver.java | 297 +++++++++ .../{ => push}/tpush/common/DBOpenHelper.java | 2 +- .../tpush/common/NotificationService.java | 4 +- .../{ => push}/tpush/po/XGNotification.java | 2 +- .../fuying/sn/service/main/MainService.java | 25 +- 14 files changed, 861 insertions(+), 467 deletions(-) rename app/src/main/java/com/fuying/sn/{tpush/MessageReceiver.java => push/PushManager.java} (71%) create mode 100644 app/src/main/java/com/fuying/sn/push/alipush/AliMessageIntentService.java create mode 100644 app/src/main/java/com/fuying/sn/push/alipush/AliyunMessageReceiver.java rename app/src/main/java/com/fuying/sn/{ => push}/tpush/Constants.java (93%) create mode 100644 app/src/main/java/com/fuying/sn/push/tpush/MessageReceiver.java rename app/src/main/java/com/fuying/sn/{ => push}/tpush/common/DBOpenHelper.java (93%) rename app/src/main/java/com/fuying/sn/{ => push}/tpush/common/NotificationService.java (98%) rename app/src/main/java/com/fuying/sn/{ => push}/tpush/po/XGNotification.java (97%) diff --git a/app/build.gradle b/app/build.gradle index 257e979..909c54d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,8 +78,8 @@ android { official { flavorDimensions "default" - versionCode 86 - versionName "3.4.6" + versionCode 87 + versionName "3.4.7" } } @@ -543,6 +543,8 @@ dependencies { implementation 'com.tencent.bugly:crashreport:4.1.9.2' //腾讯移动推送 TPNS implementation 'com.tencent.tpns:tpns:1.4.4.2-release' + //阿里云推送 + implementation 'com.aliyun.ams:alicloud-android-push:3.8.0' //百度地图 implementation 'com.baidu.lbsyun:BaiduMapSDK_Location:9.1.8' //工具类 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 57e4b45..a6aabb9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -227,7 +227,7 @@ - + @@ -238,7 +238,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/fuying/sn/base/BaseApplication.java b/app/src/main/java/com/fuying/sn/base/BaseApplication.java index f37e85a..e2bf372 100644 --- a/app/src/main/java/com/fuying/sn/base/BaseApplication.java +++ b/app/src/main/java/com/fuying/sn/base/BaseApplication.java @@ -7,20 +7,13 @@ import android.media.AudioManager; import android.os.Environment; import android.os.Handler; import android.os.Looper; +import android.text.TextUtils; import android.util.Log; +import com.alibaba.sdk.android.push.CloudPushService; +import com.alibaba.sdk.android.push.CommonCallback; +import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory; import com.arialyy.aria.core.Aria; -import com.fuying.sn.service.ControlPanelService; -import com.fuying.sn.service.DownloadService; -import com.fuying.sn.service.GuardService; -import com.fuying.sn.service.ManagerService; -import com.fuying.sn.service.StepService; -import com.fuying.sn.service.main.MainService; -import com.tencent.android.tpush.XGIOperateCallback; -import com.tencent.android.tpush.XGPushConfig; -import com.tencent.android.tpush.XGPushManager; -import com.tencent.bugly.crashreport.CrashReport; -import com.tencent.mmkv.MMKV; import com.fuying.sn.BuildConfig; import com.fuying.sn.desktop.RunningAppManager; import com.fuying.sn.desktop.TimeControlManager; @@ -29,11 +22,23 @@ import com.fuying.sn.manager.ConnectManager; import com.fuying.sn.manager.ControlManager; import com.fuying.sn.manager.DeviceManager; import com.fuying.sn.network.NetInterfaceManager; +import com.fuying.sn.push.PushManager; import com.fuying.sn.rlog.LogDBManager; +import com.fuying.sn.service.ControlPanelService; +import com.fuying.sn.service.DownloadService; +import com.fuying.sn.service.GuardService; +import com.fuying.sn.service.ManagerService; +import com.fuying.sn.service.StepService; +import com.fuying.sn.service.main.MainService; import com.fuying.sn.utils.AppUsedTimeUtils; import com.fuying.sn.utils.JGYUtils; import com.fuying.sn.utils.SystemUtils; import com.fuying.sn.utils.Utils; +import com.tencent.android.tpush.XGIOperateCallback; +import com.tencent.android.tpush.XGPushConfig; +import com.tencent.android.tpush.XGPushManager; +import com.tencent.bugly.crashreport.CrashReport; +import com.tencent.mmkv.MMKV; import java.util.ArrayList; import java.util.List; @@ -69,10 +74,13 @@ public class BaseApplication extends Application { if (!BuildConfig.DEBUG) { catchException(); } - tPushInit(); String rootDir = MMKV.initialize(this); Log.i(TAG, "mmkv root: " + rootDir); + PushManager.init(this); + aliyunPushInit(); + tPushInit(); + JGYUtils.init(this); CrashReport.initCrashReport(getApplicationContext(), "e5f026c8d5", false); CrashReport.setDeviceId(this, Utils.getSerial()); @@ -129,6 +137,65 @@ public class BaseApplication extends Application { }); } + private void aliyunPushInit() { + PushServiceFactory.init(this); + CloudPushService pushService = PushServiceFactory.getCloudPushService(); + pushService.setLogLevel(CloudPushService.LOG_DEBUG); + pushService.register(this, new CommonCallback() { + @Override + public void onSuccess(String response) { + Log.e("AliyunPush", "init cloudchannel success"); + Log.e("AliyunPush", "init cloudchannel success " + pushService.getDeviceId()); + String sn = Utils.getSerial(); + Log.e(TAG, "AliyunPush: sn=" + sn); + if (TextUtils.isEmpty(sn)) { + return; + } + pushService.bindAccount(sn, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "bind account " + sn + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "bind account " + sn + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg); + } + }); + pushService.addAlias(sn, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "add alias " + sn + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "add alias " + sn + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n"); + } + }); + pushService.bindTag(CloudPushService.DEVICE_TARGET, new String[]{BuildConfig.platform}, null, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "add tag " + sn + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "add tag " + sn + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n"); + } + }); + } + + @Override + public void onFailed(String errorCode, String errorMessage) { + Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage); + } + }); + } + private void tPushInit() { XGPushConfig.enableDebug(this, true); XGPushConfig.enablePullUpOtherApp(this, false); diff --git a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java index 1f59087..5a40ad2 100644 --- a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java +++ b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java @@ -195,14 +195,17 @@ public class RunningAppManager { Log.d(TAG, "checkForegroundAppName: appPackageName = " + appPackageName); if (!JGYUtils.getInstance().isScreenOn()) { + Log.d(TAG, "checkForegroundAppName: isScreenOn = false"); if (!TextUtils.isEmpty(appPackageName)) { - NetInterfaceManager.getInstance().sendCloseApp(appPackageName, new NetInterfaceManager.CompleteCallback() { - @Override - public void onComplete() { - NetInterfaceManager.getInstance().getAppTimeControl(); - NetInterfaceManager.getInstance().getSnTimeControl(); - } - }); + Log.d(TAG, "checkForegroundAppName: isEmpty = false"); + // TODO: 2025/11/11 不确定是否因为这里导致网络请求频繁 +// NetInterfaceManager.getInstance().sendCloseApp(appPackageName, new NetInterfaceManager.CompleteCallback() { +// @Override +// public void onComplete() { +// NetInterfaceManager.getInstance().getAppTimeControl(); +// NetInterfaceManager.getInstance().getSnTimeControl(); +// } +// }); } mMMKV.encode(RUNNING_APP_PACKAGENAME, ""); AppUsedTimeUtils.getInstance().setApp_package(""); diff --git a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java index e0a8940..6ab1d44 100644 --- a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java @@ -17,6 +17,9 @@ import android.util.Log; import androidx.core.content.ContextCompat; +import com.alibaba.sdk.android.push.CloudPushService; +import com.alibaba.sdk.android.push.CommonCallback; +import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory; import com.fuying.sn.BuildConfig; import com.fuying.sn.bean.AppAndWhiteBean; import com.fuying.sn.bean.AppInfo; @@ -115,6 +118,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -763,6 +767,22 @@ public class NetInterfaceManager { Log.e("clearAndAppendTags", "onFail: " + o); } }); + + String[] tagSets = new ArrayList<>(set).toArray(new String[set.size()]); + CloudPushService pushService = PushServiceFactory.getCloudPushService(); + pushService.bindTag(CloudPushService.DEVICE_TARGET, tagSets, null, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(tagSets) + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(tagSets) + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n"); + } + }); + } private void clearAndAppendTags(Set tagSets) { @@ -783,6 +803,21 @@ public class NetInterfaceManager { Log.e("clearAndAppendTags", "onFail: " + o); } }); + + String[] set = new ArrayList<>(tagSets).toArray(new String[tagSets.size()]); + CloudPushService pushService = PushServiceFactory.getCloudPushService(); + pushService.bindTag(CloudPushService.DEVICE_TARGET, set, null, new CommonCallback() { + @Override + public void onSuccess(String s) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(set) + " success\n"); + } + + @Override + public void onFailed(String errorCode, String errorMsg) { + Log.e("AliyunPush", "bind tag " + Arrays.toString(set) + " failed." + + "errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n"); + } + }); } }); } diff --git a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java b/app/src/main/java/com/fuying/sn/push/PushManager.java similarity index 71% rename from app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java rename to app/src/main/java/com/fuying/sn/push/PushManager.java index 120cc44..dff7c9f 100644 --- a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java +++ b/app/src/main/java/com/fuying/sn/push/PushManager.java @@ -1,9 +1,8 @@ -package com.fuying.sn.tpush; +package com.fuying.sn.push; import android.annotation.SuppressLint; import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -20,7 +19,6 @@ import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.WindowManager; -import android.widget.Toast; import com.android.internal.view.RotationPolicy; import com.fuying.sn.R; @@ -35,8 +33,6 @@ import com.fuying.sn.network.NetInterfaceManager; import com.fuying.sn.receiver.BootReceiver; import com.fuying.sn.service.LogcatService; import com.fuying.sn.service.ManagerService; -import com.fuying.sn.tpush.common.NotificationService; -import com.fuying.sn.tpush.po.XGNotification; import com.fuying.sn.utils.ApkUtils; import com.fuying.sn.utils.CacheUtils; import com.fuying.sn.utils.CmdUtil; @@ -48,22 +44,14 @@ import com.fuying.sn.utils.ToastUtil; import com.fuying.sn.utils.Utils; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -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 com.tencent.mmkv.MMKV; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.HashSet; import java.util.List; import java.util.Random; @@ -87,273 +75,37 @@ import okhttp3.RequestBody; import static com.fuying.sn.service.ManagerService.LOCK_STATE; -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"; +public class PushManager { + private static final String TAG = "PushManager"; - private static final String TAG = "MessageReceiver"; + private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE); + @SuppressLint("StaticFieldLeak") + private static PushManager sInstance; private Context mContext; - private ContentResolver mResolver; - private PackageManager mPackageManager; private CacheHelper mCacheHelper; - /** - * 消息透传处理 - * - * @param context - * @param message 解析自定义的 JSON - */ - @Override - public void onTextMessage(Context context, XGPushTextMessage message) { - this.mContext = context; - this.mResolver = context.getContentResolver(); - this.mPackageManager = context.getPackageManager(); + private PushManager(Context context) { + if (context == null) { + throw new RuntimeException("Context is NULL"); + } + this.mContext = context.getApplicationContext(); this.mCacheHelper = new CacheHelper(context); - - 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; + public static void init(Context context) { + if (sInstance == null) { + sInstance = new PushManager(context); } - XGNotification notific = new XGNotification(); - notific.setMsg_id(notifiShowedRlt.getMsgId()); - notific.setTitle(notifiShowedRlt.getTitle()); - notific.setContent(notifiShowedRlt.getContent()); - // notificationActionType==1为Activity,2为url,3为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; + public static PushManager getInstance() { + if (sInstance == null) { + throw new IllegalStateException("You must be init PushManager first"); } - 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); + return sInstance; } - /** - * 反注册回调 - * - * @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(); - } - - //定义接收极光推送消息的类型。 //1.获取设备在线信息 private static final String JIGUANG_GET_DRIVELINE = "1"; // 2.获取当前正在运行得应用和电量 @@ -495,21 +247,7 @@ public class MessageReceiver extends XGPushBaseReceiver { /*添加应用*/ private static final String ADD_APK = "89"; - - private void processCustomMessage(Context context, XGPushTextMessage message) { - if (context == null || message == null) { - return; - } - - 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(); - } - + public void setPushContent(String title, String extras) { switch (title) { case JIGUANG_GET_DRIVELINE: ToastUtil.debugShow("收到推送消息: 获取在线信息"); @@ -517,25 +255,25 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_GET_STARTTIME: ToastUtil.debugShow("收到推送消息: 获取运行应用"); - sendStartTime(context, extras); + sendStartTime(extras); break; case JIGUANG_USB_STATE: ToastUtil.debugShow("收到推送消息: USB连接模式管控"); - setUsbStatus(context, extras); + setUsbStatus(extras); break; case JIGUANG_TFCARD_STATE: ToastUtil.debugShow("收到推送消息: TF卡管控"); - setTfcardState(context, extras); + setTfcardState(extras); break; case JIGUANG_BLUETOOTH_STATE: ToastUtil.debugShow("收到推送消息: 蓝牙管控"); - setBluetoothState(context, extras); + setBluetoothState(extras); break; case JIGUANG_BROWSER_URLPATH: ToastUtil.debugShow("收到推送消息: 浏览器上网管控"); -// setBrowserUrlpath(context, extras); +// setBrowserUrlpath( extras); try { - new CacheUtils().cleanApplicationUserData(context, "com.android.browser"); + new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); } @@ -548,7 +286,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_APP_NETWORKSTATE: ToastUtil.debugShow("收到推送消息: 应用联网管控"); - setAppNetworkstate(context, extras); + setAppNetworkstate(extras); new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { @@ -558,29 +296,29 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_APP_LOCKEDSTATE: ToastUtil.debugShow("收到推送消息: 应用锁管控"); - setAppLockedstate(context, extras); + setAppLockedstate(extras); break; case JIGUANG_FORCE_INSTALLAPK: ToastUtil.debugShow("收到推送消息: 强制安装应用"); // NetInterfaceManager.getInstance().getAllappPackage(); // NetInterfaceManager.getInstance().getOverallApp(); - intallApk(context, extras); + intallApk(extras); break; case JIGUANG_FORCE_UNINSTALLAPK: ToastUtil.debugShow("收到推送消息: 强制卸载应用"); - unintallApk(context, extras); + unintallApk(extras); break; case JIGUANG_BIND_DEVIVES: ToastUtil.debugShow("收到推送消息: 绑定设备"); - bindService(context, extras); + bindService(extras); break; case JIGUANG_TFMEDIA: ToastUtil.debugShow("收到推送消息: 影音格式管控"); - setTFmedia(context, extras); + setTFmedia(extras); break; case JIGUANG_CAMRERA: ToastUtil.debugShow("收到推送消息: 摄像头管控"); - setCameta(context, extras); + setCameta(extras); JGYUtils.getInstance().updateForbidList(); break; case JIGUANG_PHONE: @@ -589,11 +327,11 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_DISABLE_UPDATAE: ToastUtil.debugShow("收到推送消息: 禁止升级"); - setAppUpdate(context, extras); + setAppUpdate(extras); break; case JIGUANG_APP_WEBSITE: ToastUtil.debugShow("收到推送消息: app内部网址管控"); - setAppInsideNetwork(context, extras); + setAppInsideNetwork(extras); break; case JIGUANG_REBOOT_DEVICES: ToastUtil.debugShow("收到推送消息: 重启"); @@ -606,7 +344,7 @@ public class MessageReceiver extends XGPushBaseReceiver { case JIGUANG_BROWSER_LABEL: ToastUtil.debugShow("收到推送消息: 浏览器书签"); try { - new CacheUtils().cleanApplicationUserData(context, "com.android.browser"); + new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser"); } catch (Exception e) { e.printStackTrace(); } @@ -623,12 +361,12 @@ public class MessageReceiver extends XGPushBaseReceiver { ToastUtil.debugShow("收到推送消息: 系统管控"); // ControlManager.getInstance().setSystemSetting(extras); // if ("com.jiaoguanyi.os".equals(ForegroundAppUtil.getForegroundPackageName(context))) { -// JGYUtils.getInstance().killBackgroundProcesses(context, "com.jiaoguanyi.os"); +// JGYUtils.getInstance().killBackgroundProcesses( "com.jiaoguanyi.os"); // Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.jiaoguanyi.os"); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(intent); // } else { -// JGYUtils.getInstance().killBackgroundProcesses(context, "com.jiaoguanyi.os"); +// JGYUtils.getInstance().killBackgroundProcesses( "com.jiaoguanyi.os"); // } updateUserSettings(); @@ -656,29 +394,29 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_LOCK_SCREEN: ToastUtil.debugShow("收到推送消息: 锁屏"); - setLock_screen(context, extras); + setLock_screen(extras); Log.e(TAG, extras); break; case JIGUANG_SNAPSHOT: ToastUtil.debugShow("收到推送消息: 截图"); - doscreenshot(context); + doscreenshot(mContext); Log.e(TAG, extras); break; case JIGUANG_TIME_CONTROL: ToastUtil.debugShow("收到推送消息: 时间管控"); - timeControl(context, extras); + timeControl(extras); break; case JIGUANG_HOTSPOT_CONTROL: ToastUtil.debugShow("收到推送消息: 热点管控"); - setHotspot(context, extras); + setHotspot(extras); break; case JIGUANG_RESTORE_CONTROL: ToastUtil.debugShow("收到推送消息: 恢复出厂设置管控"); - setRestore(context, extras); + setRestore(extras); break; case JIGUANG_BROWSER_CONTROL: ToastUtil.debugShow("收到推送消息: 浏览器禁止输入"); - setBrowserInput(context, extras); + setBrowserInput(extras); break; case JIGUANG_DEVELOPER_CONTROL: ToastUtil.debugShow("收到推送消息: 开发人员选项"); @@ -686,7 +424,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_CLEAN_APP_CACHE: ToastUtil.debugShow("收到推送消息: 清除应用缓存"); - cleanAppCache(context, extras); + cleanAppCache(extras); break; case JIGUANG_APP_RECORDER: case JIGUANG_APP_FILE_MANAGER: @@ -697,7 +435,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_SEARCH_TOPIC: ToastUtil.debugShow("收到推送消息: 搜题开关"); - searchTopic(context, extras); + searchTopic(extras); break; case JIGUANG_PHONE_LIST: ToastUtil.debugShow("收到推送消息: 电话白名单管控"); @@ -731,7 +469,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_NOTDISTURB_MODE: ToastUtil.debugShow("收到推送消息: 设置勿扰模式"); - setZenMode(context, extras); + setZenMode(extras); break; case JIGUANG_LOCATION: ToastUtil.debugShow("收到推送消息: 定位设置"); @@ -740,24 +478,24 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_VOLUME: ToastUtil.debugShow("收到推送消息: 设置音量"); - setVolume(context, extras); + setVolume(extras); break; case JIGUANG_LUMINANCE: ToastUtil.debugShow("收到推送消息: 设置屏幕亮度"); - setScreenBrightness(context, extras); + setScreenBrightness(extras); break; case JIGUANG_TYPEFACE: ToastUtil.debugShow("收到推送消息: 设置字体大小"); - setFontSize(context, extras); + setFontSize(extras); break; case JIGUANG_SCREEN_ROTATION: ToastUtil.debugShow("收到推送消息: 设置自动旋转"); - setRotationLock(context, extras); + setRotationLock(extras); break; case JIGUANG_WIFI_SET: break; case JIGUANG_ALARM_CLOCK: - setAlarmCLock(context, extras); + setAlarmCLock(extras); break; case JIGUANG_APP_WHITELIST: break; @@ -765,33 +503,33 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case JIGUANG_KILL_APP: ToastUtil.debugShow("收到推送消息: 内存优化"); - Utils.killBackgroundApp(context); + Utils.killBackgroundApp(mContext); break; case JIGUANG_SOS_PHONENUM: - setSOSPhoneNumber(context, extras); + setSOSPhoneNumber(extras); break; case JIGUANG_REINSTALL_APP: - reinstallApp(context, extras); + reinstallApp(extras); break; case JIGUANG_ADMIN_APP: - setAdminApp(context, extras); + setAdminApp(extras); break; case SCREEN_SHARED: ToastUtil.debugShow("收到推送消息: 投屏开关"); - setScreenShared(context, extras); + setScreenShared(extras); break; case HOT_SPOT: ToastUtil.debugShow("收到推送消息: 热点开关"); - setHotPoint(context, extras); + setHotPoint(extras); break; case ACTION_DEFAULT_DESKTOP: - setDefaultDesktop(context, extras); + setDefaultDesktop(extras); break; case ACTION_DEFAULT_BRPWSER: - setDefaultBrowser(context, extras); + setDefaultBrowser(extras); break; case ACTION_DEFAULT_INPUT_METHOD: - setDefaultInputMethod(context, extras); + setDefaultInputMethod(extras); break; case ACTION_PARENTAL_CONTROL: ToastUtil.debugShow("收到推送消息: 家长管控"); @@ -814,7 +552,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; case ACTION_DISABLE_NETWORK: ToastUtil.debugShow("收到推送消息: 一键断网"); - oneKeyNetwork(context, extras); + oneKeyNetwork(extras); break; case SN_ADD_TAG: addTag(extras); @@ -827,6 +565,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; default: } + } private void updateUserSettings() { @@ -878,29 +617,29 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void setAdminApp(Context context, String extras) { + private void setAdminApp(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int setting_admin_app = jsonObject.get("setting_admin_app").getAsInt(); - Settings.System.putInt(context.getContentResolver(), "setting_admin_app", setting_admin_app); + Settings.System.putInt(mContext.getContentResolver(), "setting_admin_app", setting_admin_app); } - private void setZenMode(Context context, String extras) { + private void setZenMode(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int setting_disturbance = jsonObject.get("setting_disturbance").getAsInt(); } - private void setRotationLock(Context context, String extras) { + private void setRotationLock(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int setting_rotation = jsonObject.get("setting_rotation").getAsInt(); - RotationPolicy.setRotationLock(context, setting_rotation == 0); + RotationPolicy.setRotationLock(mContext, setting_rotation == 0); } - private void setScreenBrightness(Context context, String extras) { + private void setScreenBrightness(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int setting_luminance = jsonObject.get("setting_luminance").getAsInt(); - Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); + Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); int Scrern_brightness = (int) ((1.0 * 255 / 100) * setting_luminance); - Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness); + Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness); } private float[] mValues; @@ -913,10 +652,10 @@ public class MessageReceiver extends XGPushBaseReceiver { */ protected List mEntries; - private void setFontSize(Context context, String extras) { + private void setFontSize(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); String setting_typeface = jsonObject.get("setting_typeface").getAsString(); - final Resources res = context.getResources(); + final Resources res = mContext.getResources(); mEntries = Arrays.asList(res.getStringArray(R.array.entries_font_size)); final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size); mValues = new float[strEntryValues.length]; @@ -927,14 +666,14 @@ public class MessageReceiver extends XGPushBaseReceiver { if (mCurrentIndex == -1) { return; } - Settings.System.putFloat(context.getContentResolver(), Settings.System.FONT_SCALE, mValues[mCurrentIndex]); + Settings.System.putFloat(mContext.getContentResolver(), Settings.System.FONT_SCALE, mValues[mCurrentIndex]); } - private void setVolume(Context context, String extras) { + private void setVolume(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int setting_volume = jsonObject.get("setting_volume").getAsInt(); //获取系统的Audio管理者 - AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); //最大音量 int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); //当前音量 @@ -947,7 +686,7 @@ public class MessageReceiver extends XGPushBaseReceiver { return paramInt == 1 ? 0 : 1; } - synchronized private void sendStartTime(Context context, String jsonString) { + synchronized private void sendStartTime(String jsonString) { // NetInterfaceManager.getInstance().sendRunningApp(); NetInterfaceManager.getInstance().updateAdminInfo(); NetInterfaceManager.getInstance().SendAppInstallInfo(); @@ -958,7 +697,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - synchronized private void setUsbStatus(Context context, String jsonString) { + synchronized private void setUsbStatus(String jsonString) { if (!TextUtils.isEmpty(jsonString)) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); String setting_usb = jsonObject.get("setting_usb").getAsString(); @@ -968,13 +707,13 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - synchronized private void setTfcardState(Context context, String jsonString) { + synchronized private void setTfcardState(String jsonString) { if (!TextUtils.isEmpty(jsonString)) { JsonObject extra = GsonUtils.getJsonObject(jsonString); int is_tf = extra.get("setting_memory").getAsInt(); - boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, changeNum(is_tf)); + boolean aole_sdcard_forbid_on = Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, changeNum(is_tf)); if (aole_sdcard_forbid_on) { - Log.e("setTfcardState:", Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON)); + Log.e("setTfcardState:", Settings.System.getString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON)); } else { ToastUtil.debugShow("setTfcardState failed,state:" + is_tf); } @@ -985,7 +724,7 @@ public class MessageReceiver extends XGPushBaseReceiver { private BluetoothAdapter mBluetoothAdapter; - synchronized private void setBluetoothState(Context context, String jsonString) { + synchronized private void setBluetoothState(String jsonString) { if (!TextUtils.isEmpty(jsonString)) { if (null == mBluetoothAdapter) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//获取默认蓝牙适配器 @@ -995,7 +734,7 @@ public class MessageReceiver extends XGPushBaseReceiver { Log.e(TAG, "aole_bht_forbid_on: " + is_bluetooth); try { //写入系统数据库 - boolean aole_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, is_bluetooth); + boolean aole_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, is_bluetooth); Log.e(TAG, "aole_bht_forbid_on: " + aole_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (aole_bht_forbid_on) { @@ -1005,8 +744,8 @@ public class MessageReceiver extends XGPushBaseReceiver { //获取默认蓝牙适配器 } //蓝牙总开关开启 - Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty"); - Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, is_bluetooth); + Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty"); + Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, is_bluetooth); //设置关闭时关闭蓝牙 mBluetoothAdapter.disable(); } @@ -1018,7 +757,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - synchronized private void setAppNetworkstate(Context context, String jsonString) { + synchronized private void setAppNetworkstate(String jsonString) { // if (!TextUtils.isEmpty(jsonString)) { // JsonObject extra = GsonUtils.getJsonObject(jsonString); // String package0 = extra.get("package0").getAsString(); @@ -1042,13 +781,13 @@ public class MessageReceiver extends XGPushBaseReceiver { // } } - synchronized private void setAppLockedstate(Context context, String jsonString) { + synchronized private void setAppLockedstate(String jsonString) { if (!TextUtils.isEmpty(jsonString)) { JsonObject extra = GsonUtils.getJsonObject(jsonString); String packageName = extra.get("package").getAsString(); int is_lock = extra.get("is_lock").getAsInt(); ToastUtil.debugShow("收到应用锁管控消息:包名" + packageName + "is_lock_state:" + is_lock); - PackageManager pm = context.getPackageManager(); + PackageManager pm = mContext.getPackageManager(); //后台为0可能传过来null if (is_lock == 1) { pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); @@ -1060,7 +799,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void intallApk(Context context, String jsonString) { + private void intallApk(String jsonString) { if (TextUtils.isEmpty(jsonString)) { return; } @@ -1074,7 +813,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } long app_version_code = extra.get("app_version_code").getAsLong(); PackageInfo info = null; - PackageManager pm = context.getPackageManager(); + PackageManager pm = mContext.getPackageManager(); try { info = pm.getPackageInfo(packages, 0); } catch (PackageManager.NameNotFoundException e) { @@ -1089,36 +828,36 @@ public class MessageReceiver extends XGPushBaseReceiver { } if (appVersionCode < app_version_code) { Log.e(TAG, "intallApk: " + "need to upgrade"); - FileUtils.ariaDownload(context, url, extra); + FileUtils.ariaDownload(mContext, url, extra); } else Log.e(TAG, "intallApk: " + "it's up to date , no need upgrade"); } else { Log.e(TAG, "intallApk: " + "not installed , upgrade"); - FileUtils.ariaDownload(context, url, extra); + FileUtils.ariaDownload(mContext, url, extra); } } - synchronized private void unintallApk(Context context, String jsonString) { + synchronized private void unintallApk(String jsonString) { JsonObject object = GsonUtils.getJsonObject(jsonString); String packageName = object.get("app_package").getAsString(); // 台电设备不删除无法静默卸载 - removeForceSettings(context, packageName); + removeForceSettings(packageName); ToastUtil.debugShow("收到应用卸载消息:包名" + packageName); - if (!"".equals(packageName) && !packageName.equals(context.getApplicationContext().getPackageName())) { - if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) { + if (!"".equals(packageName) && !packageName.equals(mContext.getApplicationContext().getPackageName())) { + if (!ApkUtils.isAvailable(mContext.getApplicationContext(), packageName)) { } else { - ApkUtils.uninstallApp(context, packageName); + ApkUtils.uninstallApp(mContext, packageName); } } } - private boolean removeForceSettings(Context context, String pkg) { - String force_app = Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP); + private boolean removeForceSettings(String pkg) { + String force_app = Settings.System.getString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP); if (!TextUtils.isEmpty(force_app)) { Set appSet = new HashSet<>(new ArrayList<>(Arrays.asList(force_app.split(",")))); appSet.remove(pkg); - return Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, String.join(",", appSet)); + return Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, String.join(",", appSet)); } return true; } @@ -1127,13 +866,13 @@ public class MessageReceiver extends XGPushBaseReceiver { private long cutdownTime = 30; private CustomDialog dialog; - synchronized void bindService(final Context context, String jsonString) { + synchronized void bindService(final String jsonString) { ToastUtil.debugShow("收到绑定设备请求"); JsonObject object = GsonUtils.getJsonObject(jsonString); String userName = object.get("member_name").getAsString(); final String id = object.get("id").getAsString(); String phoneNum = object.get("member_phone").getAsString(); - dialog = new CustomDialog(context); + dialog = new CustomDialog(mContext); subscribe = Observable.interval(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -1144,7 +883,7 @@ public class MessageReceiver extends XGPushBaseReceiver { if (aLong < cutdownTime && !subscribe.isDisposed()) { dialog.setNegtiveText("拒绝" + "(" + (cutdownTime - aLong) + ")"); } else { - bind(context, id, 0); + bind(id, 0); dialog.dismiss(); subscribe.dispose(); subscribe = null; @@ -1159,7 +898,7 @@ public class MessageReceiver extends XGPushBaseReceiver { .setOnClickBottomListener(new CustomDialog.OnClickBottomListener() { @Override public void onPositiveClick() { - bind(context, id, 1); + bind(id, 1); dialog.dismiss(); subscribe.dispose(); subscribe = null; @@ -1167,7 +906,7 @@ public class MessageReceiver extends XGPushBaseReceiver { @Override public void onNegtiveClick() { - bind(context, id, 0); + bind(id, 0); ToastUtil.show("设备取消绑定"); dialog.dismiss(); subscribe.dispose(); @@ -1189,13 +928,13 @@ public class MessageReceiver extends XGPushBaseReceiver { // // @Override // public void onFinish() { -// bind(context, id, 0); +// bind( id, 0); // dialog.dismiss(); // } // }.start(); } - synchronized private void bind(final Context context, String id, int type) { + synchronized private void bind(final String id, int type) { NetInterfaceManager.getInstance() .getbindDevicesControl() .getBindDevices(Utils.getSerial(), id, type) @@ -1237,32 +976,32 @@ public class MessageReceiver extends XGPushBaseReceiver { String tftype = ".png,.bmp,.jpg,.mpo,.jpeg,.gif,.tif,.tiff,.dib,.jpe,.jfif,.psd,.pdd,.rle,.dcm,.dic,.dc3,.eps,.iff,.tdi,.jpf,.jpx,.jp2,.j2c,.jpc,.jps,.j2k,.pcx,.pdp,.raw,.pns,.aac,.ac3,.aiff,.amr,.ape,.au,.fla,.flac,.imy,.m4r,.mid,.mka,.mmf,.mp2,.mp3,.mxmf,.ogg,.ra,.ts,.wma,.wv,.xmf,.m4a,.wav,.3gpp,.mp4,.3gp,.as,.asf,.avi,.dat,.f4v,.flv,.mkv,.mov,.mpg,.rmvb,.swf,.trp,.vob,.webm,.wmv,.navi,.video,.ram,.qsv,.xv,.rm,.vcd,.svcd,.mlv,.mpe,.mpeg,.m2v,.iso,.html,.htm,.txt,.xls,.doc,.docx,.docm,.pdf,.xps,.dot,.dotx,.dotm,.mht,.mhtml,.rft,.xml,.xlsx,.xlsm,.xlsb,.xltx,.xltm,.xlt,.wps,.wpt,.rtf,.et,.ett,.dps,.dpt,.wpp,.ppt,.pptx,.pptm,.pps,.pot,.potm,.ppsx,.ppsm,.odp"; @SuppressLint("NewApi") - private void setTFmedia(Context context, String jsonString) { + private void setTFmedia(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); //影音管控开关 int setting_tfmedia = jsonObject.get("setting_tfmedia").getAsInt(); Log.e("SystemSetting", "qch_tfmedia_forbid---------" + setting_tfmedia); if (setting_tfmedia == 1) { - Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); + Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0); } else { - String s = Settings.System.getString(context.getContentResolver(), "qch_tfmedia_filetypes");//影音管控 + String s = Settings.System.getString(mContext.getContentResolver(), "qch_tfmedia_filetypes");//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes old" + s); - Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 1); + Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 1); String setting_tfmedia_format = jsonObject.get("setting_tfmedia_format").getAsString(); HashSet types = new HashSet<>(Arrays.asList(setting_tfmedia_format.split(","))); types.removeIf(TextUtils::isEmpty); - boolean b = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", String.join(",", types));//影音管控 + boolean b = Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", String.join(",", types));//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + b + ":" + types); } } - private void setCameta(Context context, String jsonString) { + private void setCameta(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); //摄像头开关 int setting_camera = changeNum(jsonObject.get("setting_camera").getAsInt()); - Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera); - ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); + Settings.System.putInt(mContext.getContentResolver(), "qch_app_camera", setting_camera); + ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera"); Log.e("SystemSetting", "setting_camera---------" + setting_camera); String cameraStatus = ""; switch (setting_camera) { @@ -1277,7 +1016,7 @@ public class MessageReceiver extends XGPushBaseReceiver { break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); - context.sendBroadcast(cameraIntent); + mContext.sendBroadcast(cameraIntent); } private void setPhone(String jsonString) { @@ -1285,11 +1024,11 @@ public class MessageReceiver extends XGPushBaseReceiver { } @SuppressLint("NewApi") - private void setAppUpdate(Context context, String jsonString) { + private void setAppUpdate(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); String is_upgrade = jsonObject.get("is_upgrade").getAsString(); String packageName = jsonObject.get("package").getAsString(); - String nowApplist = Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID); + String nowApplist = Settings.System.getString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID); List applist = new ArrayList<>(Arrays.asList(nowApplist.split(","))); if ("0".equals(is_upgrade)) { if (applist.contains(packageName)) { @@ -1302,42 +1041,42 @@ public class MessageReceiver extends XGPushBaseReceiver { applist.add(packageName); } } - Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, String.join(",", applist)); - Log.e("setAppUpdate", Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID)); + Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, String.join(",", applist)); + Log.e("setAppUpdate", Settings.System.getString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID)); } - private void setAppInsideNetwork(Context context, String extras) { + private void setAppInsideNetwork(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int is_ground = jsonObject.get("is_ground").getAsInt(); if (is_ground == 0) { - boolean putString = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_APP_WEB_BLACK_LIST, ""); + boolean putString = Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_APP_WEB_BLACK_LIST, ""); Log.e(TAG, "setAppInsideNetwork: " + putString); } else if (is_ground == 1) { NetInterfaceManager.getInstance().getAppJump(); } } - private void setLock_screen(Context context, String jsonString) { + private void setLock_screen(String jsonString) { int type = 0; JsonObject jSONObject = GsonUtils.getJsonObject(jsonString); type = jSONObject.get("type").getAsInt(); - if (!ServiceAliveUtils.isServiceAlive(context, ManagerService.class.getName())) { - context.startService(new Intent(context, ManagerService.class)); + if (!ServiceAliveUtils.isServiceAlive(mContext, ManagerService.class.getName())) { + mContext.startService(new Intent(mContext, ManagerService.class)); } Intent intent = new Intent(); // intent.putExtra("name", name); - SPUtils.put(context, LOCK_STATE, type); + SPUtils.put(mContext, LOCK_STATE, type); if (1 == type) { intent.setAction(ManagerService.ACTION_LOCK); } else if (0 == type) { intent.setAction(ManagerService.ACTION_UNLOCK); } - context.sendBroadcast(intent); + mContext.sendBroadcast(intent); NetInterfaceManager.getInstance().getLockScreenPwd(); } - private static Observable getScreenshot(Context context, String filePath) { + private static Observable getScreenshot(String filePath) { Observable screenshotObservable = Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter e) { @@ -1361,7 +1100,7 @@ public class MessageReceiver extends XGPushBaseReceiver { public static void doscreenshot(Context context) { String path = context.getExternalFilesDir("db").getAbsolutePath(); String filePath = path + File.separator + Utils.getSerial() + ".png"; - getScreenshot(context, filePath).concatMap(new Function>() { + getScreenshot(filePath).concatMap(new Function>() { @Override public ObservableSource apply(Integer integer) throws Exception { if (integer != 0) { @@ -1433,32 +1172,32 @@ public class MessageReceiver extends XGPushBaseReceiver { return percentBattery; } - synchronized private void setBrowserUrlpath(Context context, String jsonString) { + synchronized private void setBrowserUrlpath(String jsonString) { if (!TextUtils.isEmpty(jsonString)) { JsonObject extra = GsonUtils.getJsonObject(jsonString); String white = extra.get("white").getAsString(); if (white != null && !"".equals(white)) { - boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white); + boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white); Log.e("SystemSetting", "setBrowserList-whiteList" + whiteList + ":" + white); } else { - Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " "); + Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " "); } - Log.e("whiteList", Settings.System.getString(context.getContentResolver(), "DeselectBrowserArray")); + Log.e("whiteList", Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray")); String black = extra.get("black").getAsString(); if (black != null && !"".equals(black)) { - boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black); + boolean blackList = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", black); Log.e("SystemSetting", "setBrowserList-blackList" + blackList + ":" + black); } else { - Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " "); + Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", " "); } - Log.e("blackList", Settings.System.getString(context.getContentResolver(), "qch_webblack_url")); + Log.e("blackList", Settings.System.getString(mContext.getContentResolver(), "qch_webblack_url")); } else { - boolean setBrowserUrlpath = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", ""); + boolean setBrowserUrlpath = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", ""); ToastUtil.debugShow("setBrowserUrlpath jsonString is NULL,set default: " + setBrowserUrlpath); } } - private void timeControl(Context context, String jsonString) { + private void timeControl(String jsonString) { NetInterfaceManager.getInstance().getTimeControl(); } @@ -1466,7 +1205,7 @@ public class MessageReceiver extends XGPushBaseReceiver { * @param context * @param jsonString 设置热点开关 */ - private void setHotspot(Context context, String jsonString) { + private void setHotspot(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int setting_hotspot = changeNum(jsonObject.get("setting_hotspot").getAsInt());//热点 try { @@ -1474,9 +1213,9 @@ public class MessageReceiver extends XGPushBaseReceiver { Intent intent = new Intent(); intent.setAction("qch_hotspot_close"); intent.setPackage("com.android.settings"); - context.sendStickyBroadcast(intent); + mContext.sendStickyBroadcast(intent); } - boolean aole_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot); + boolean aole_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot); Log.e("SystemSetting", "aole_hotspot_forbid_on---------" + setting_hotspot); Log.e("SystemSetting", "aole_hotspot_forbid_on---------" + aole_hotspot_forbid_on); } catch (Exception e) { @@ -1484,30 +1223,30 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void setRestore(Context context, String jsonString) { + private void setRestore(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int mode = jsonObject.get("qch_restore").getAsInt(); - boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, changeNum(mode)); + boolean aole_restore_forbid_on = Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, changeNum(mode)); Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on); } - private void setBrowserInput(Context context, String jsonString) { + private void setBrowserInput(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int setting_browserInput = changeNum(jsonObject.get("setting_browserInput").getAsInt()); - Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", setting_browserInput); + Settings.System.putInt(mContext.getContentResolver(), "qch_Browser_input", setting_browserInput); } - private void setDeveloper(Context context, String jsonString) { + private void setDeveloper(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt()); Log.e(TAG, "getDeveloper: " + dev_mode); if (!DeviceManager.isDebugMode()) { - Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode); + Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode); if (dev_mode == 1) { Intent intent = new Intent(); intent.setAction("qch_developeroptions_close"); intent.setPackage("com.android.settings"); - context.sendBroadcast(intent); + mContext.sendBroadcast(intent); Log.e(TAG, "getDeveloper: " + "关闭开发者模式"); ToastUtil.debugShow("关闭开发者模式"); } else { @@ -1517,7 +1256,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void cleanAppCache(Context context, String jsonString) { + private void cleanAppCache(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); String pkg = jsonObject.get("package").getAsString(); if (TextUtils.isEmpty(pkg)) { @@ -1525,7 +1264,7 @@ public class MessageReceiver extends XGPushBaseReceiver { return; } try { - new CacheUtils().cleanApplicationUserData(context, pkg); + new CacheUtils().cleanApplicationUserData(mContext, pkg); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "cleanAppCache: " + e.getMessage()); @@ -1536,37 +1275,37 @@ public class MessageReceiver extends XGPushBaseReceiver { NetInterfaceManager.getInstance().getSystemSettings(); } - private void searchTopic(Context context, String jsonString) { + private void searchTopic(String jsonString) { Log.e(TAG, "searchTopic: " + jsonString); JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int search_topic = jsonObject.get("search_topic").getAsInt(); - Log.e(TAG, "searchTopic: put = " + SPUtils.put(context, "search_topic", search_topic)); + Log.e(TAG, "searchTopic: put = " + SPUtils.put(mContext, "search_topic", search_topic)); JGYUtils.getInstance().updateForbidList(); } - private void setAlarmCLock(Context context, String ex) { + private void setAlarmCLock(String ex) { Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED); bootIntent.setComponent(new ComponentName("com.uiui.os", "com.uiui.os.receiver.BootReceiver")); - context.sendBroadcast(bootIntent); + mContext.sendBroadcast(bootIntent); } - private void setSOSPhoneNumber(Context context, String extras) { + private void setSOSPhoneNumber(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); String setting_sos = jsonObject.get("setting_sos").getAsString(); - Settings.System.putString(context.getContentResolver(), "setting_sos", setting_sos); + Settings.System.putString(mContext.getContentResolver(), "setting_sos", setting_sos); Intent intent = new Intent("setting_sos"); intent.putExtra("setting_sos", setting_sos); intent.setPackage("com.uiui.os"); - context.sendBroadcast(intent); + mContext.sendBroadcast(intent); } - private void reinstallApp(Context context, String extras) { + private void reinstallApp(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); String packages = jsonObject.get("package").getAsString(); String app_url = jsonObject.get("app_url").getAsString(); } - private void setScreenShared(Context context, String extras) { + private void setScreenShared(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int projection_screen = jsonObject.get("projection_screen").getAsInt(); ControlManager.getInstance().setScreenShared(changeNum(projection_screen)); @@ -1576,7 +1315,7 @@ public class MessageReceiver extends XGPushBaseReceiver { * @param context * @param jsonString 设置热点开关 */ - private void setHotPoint(Context context, String jsonString) { + private void setHotPoint(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int setting_hotspot = changeNum(jsonObject.get("hot_point").getAsInt());//热点 try { @@ -1584,11 +1323,11 @@ public class MessageReceiver extends XGPushBaseReceiver { Intent intent = new Intent(); intent.setAction("aole_hotspot_close"); intent.setPackage("com.android.settings"); - context.sendStickyBroadcast(intent); - stopTethering(context); + mContext.sendStickyBroadcast(intent); + stopTethering(mContext); } - boolean aole_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot); + boolean aole_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot); Log.e("setHotPoint", "aole_hotspot_forbid_on: " + setting_hotspot); Log.e("setHotPoint", "aole_hotspot_forbid_on: " + aole_hotspot_forbid_on); } catch (Exception e) { @@ -1610,7 +1349,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void setDefaultDesktop(Context context, String extras) { + private void setDefaultDesktop(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); JsonElement jsonElement = jsonObject.get("desktop_app"); if (jsonElement != null) { @@ -1621,7 +1360,7 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void setDefaultBrowser(Context context, String extras) { + private void setDefaultBrowser(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); JsonElement jsonElement = jsonObject.get("browser_app"); if (jsonElement != null) { @@ -1632,13 +1371,13 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - private void setDefaultInputMethod(Context context, String extras) { + private void setDefaultInputMethod(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); String packeges = jsonObject.get("typewriting_app").getAsString(); JGYUtils.getInstance().setDefaultInputMethod(packeges); } - private void oneKeyNetwork(Context context, String extras) { + private void oneKeyNetwork(String extras) { JsonObject jsonObject = GsonUtils.getJsonObject(extras); int is_network = jsonObject.get("is_network").getAsInt(); if (is_network == 1) { diff --git a/app/src/main/java/com/fuying/sn/push/alipush/AliMessageIntentService.java b/app/src/main/java/com/fuying/sn/push/alipush/AliMessageIntentService.java new file mode 100644 index 0000000..3327582 --- /dev/null +++ b/app/src/main/java/com/fuying/sn/push/alipush/AliMessageIntentService.java @@ -0,0 +1,99 @@ +package com.fuying.sn.push.alipush; + +import android.content.Context; +import android.util.Log; + +import com.alibaba.sdk.android.push.AliyunMessageIntentService; +import com.alibaba.sdk.android.push.notification.CPushMessage; + +import java.util.Map; + +/** + * Created by liyazhou on 17/8/22. + * 为避免推送广播被系统拦截的小概率事件,我们推荐用户通过IntentService处理消息互调,接入步骤: + * 1. 创建IntentService并继承AliyunMessageIntentService + * 2. 覆写相关方法,并在Manifest的注册该Service + * 3. 调用接口CloudPushService.setPushIntentService + * 详细用户可参考:https://help.aliyun.com/document_detail/30066.html#h2-2-messagereceiver-aliyunmessageintentservice + */ + +public class AliMessageIntentService extends AliyunMessageIntentService { + private static final String TAG = "AliyunMessageIntentService"; + + /** + * 推送通知的回调方法 + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + protected void onNotification(Context context, String title, String summary, Map extraMap) { + Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary); + } + + /** + * 推送消息的回调方法 + * + * @param context + * @param cPushMessage + */ + @Override + protected void onMessage(Context context, CPushMessage cPushMessage) { + Log.i(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent()); + } + + /** + * 从通知栏打开通知的扩展处理 + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + protected void onNotificationOpened(Context context, String title, String summary, String extraMap) { + Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap); + } + + /** + * 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) { + Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap); + } + + /** + * 通知删除回调 + * + * @param context + * @param messageId + */ + @Override + protected void onNotificationRemoved(Context context, String messageId) { + Log.i(TAG, "onNotificationRemoved : " + messageId); + } + + /** + * 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html#h3-3-4-basiccustompushnotification-api + * + * @param context + * @param title + * @param summary + * @param extraMap + * @param openType + * @param openActivity + * @param openUrl + */ + @Override + protected void onNotificationReceivedInApp(Context context, String title, String summary, Map extraMap, int openType, String openActivity, String openUrl) { + Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl); + } +} diff --git a/app/src/main/java/com/fuying/sn/push/alipush/AliyunMessageReceiver.java b/app/src/main/java/com/fuying/sn/push/alipush/AliyunMessageReceiver.java new file mode 100644 index 0000000..b37179d --- /dev/null +++ b/app/src/main/java/com/fuying/sn/push/alipush/AliyunMessageReceiver.java @@ -0,0 +1,116 @@ +package com.fuying.sn.push.alipush; + +import android.content.Context; +import android.util.Log; + +import com.alibaba.sdk.android.push.MessageReceiver; +import com.alibaba.sdk.android.push.notification.CPushMessage; +import com.fuying.sn.push.PushManager; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.util.Map; + +/** + * @author: 正纬 + * @since: 15/4/9 + * @version: 1.1 + * @feature: 用于接收推送的通知和消息 + */ +public class AliyunMessageReceiver extends MessageReceiver { + // 消息接收部分的LOG_TAG + public static final String TAG = "AliyunMessageReceiver"; + + /** + * 推送通知的回调方法 + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + public void onNotification(Context context, String title, String summary, Map extraMap) { + // TODO 处理推送通知 + if (null != extraMap) { + for (Map.Entry entry : extraMap.entrySet()) { + Log.i(TAG, "@Get diy param : Key=" + entry.getKey() + " , Value=" + entry.getValue()); + } + } else { + Log.i(TAG, "@收到通知 && 自定义消息为空"); + } + Log.i(TAG, "收到一条推送通知 : " + title + ", summary:" + summary); + } + + /** + * 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html?spm=5176.product30047.6.620.wjcC87#h3-3-4-basiccustompushnotification-api + * + * @param context + * @param title + * @param summary + * @param extraMap + * @param openType + * @param openActivity + * @param openUrl + */ + @Override + protected void onNotificationReceivedInApp(Context context, String title, String summary, Map extraMap, int openType, String openActivity, String openUrl) { + Log.i(TAG, "onNotificationReceivedInApp : " + " : " + title + " : " + summary + " " + extraMap + " : " + openType + " : " + openActivity + " : " + openUrl); + } + + /** + * 推送消息的回调方法 + * + * @param context + * @param cPushMessage + */ + @Override + public void onMessage(Context context, CPushMessage cPushMessage) { + Log.e(TAG, "收到一条推送消息 : " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent()); + String title = cPushMessage.getTitle(); + String content = cPushMessage.getContent(); + JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject(); + String extras = ""; + if (extrasJson.get("extras") != null) { + extras = extrasJson.get("extras").toString(); + } + PushManager.getInstance().setPushContent(title, extras); + } + + /** + * 从通知栏打开通知的扩展处理 + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + public void onNotificationOpened(Context context, String title, String summary, String extraMap) { + Log.i(TAG, "onNotificationOpened : " + " : " + title + " : " + summary + " : " + extraMap); + } + + /** + * 通知删除回调 + * + * @param context + * @param messageId + */ + @Override + public void onNotificationRemoved(Context context, String messageId) { + Log.i(TAG, "onNotificationRemoved : " + messageId); + } + + /** + * 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened + * + * @param context + * @param title + * @param summary + * @param extraMap + */ + @Override + protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) { + Log.i(TAG, "onNotificationClickedWithNoAction : " + " : " + title + " : " + summary + " : " + extraMap); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fuying/sn/tpush/Constants.java b/app/src/main/java/com/fuying/sn/push/tpush/Constants.java similarity index 93% rename from app/src/main/java/com/fuying/sn/tpush/Constants.java rename to app/src/main/java/com/fuying/sn/push/tpush/Constants.java index f327eae..ea76bd0 100644 --- a/app/src/main/java/com/fuying/sn/tpush/Constants.java +++ b/app/src/main/java/com/fuying/sn/push/tpush/Constants.java @@ -1,4 +1,4 @@ -package com.fuying.sn.tpush; +package com.fuying.sn.push.tpush; /** * Created by chacewang on 2019/7/5. diff --git a/app/src/main/java/com/fuying/sn/push/tpush/MessageReceiver.java b/app/src/main/java/com/fuying/sn/push/tpush/MessageReceiver.java new file mode 100644 index 0000000..d3aa2ed --- /dev/null +++ b/app/src/main/java/com/fuying/sn/push/tpush/MessageReceiver.java @@ -0,0 +1,297 @@ +package com.fuying.sn.push.tpush; + +import android.content.Context; +import android.content.Intent; +import android.text.TextUtils; +import android.util.Log; +import android.widget.Toast; + +import com.fuying.sn.push.tpush.common.NotificationService; +import com.fuying.sn.push.tpush.po.XGNotification; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +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.text.SimpleDateFormat; +import java.util.Calendar; + +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"; + + /** + * 消息透传处理 + * + * @param context + * @param message 解析自定义的 JSON + */ + @Override + public void onTextMessage(Context context, XGPushTextMessage message) { + + 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为Activity,2为url,3为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 void processCustomMessage(Context context, XGPushTextMessage message) { + if (context == null || message == null) { + return; + } + + 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(); + } + +// PushManager.getInstance().setPushContent(title, extras); + } + +} diff --git a/app/src/main/java/com/fuying/sn/tpush/common/DBOpenHelper.java b/app/src/main/java/com/fuying/sn/push/tpush/common/DBOpenHelper.java similarity index 93% rename from app/src/main/java/com/fuying/sn/tpush/common/DBOpenHelper.java rename to app/src/main/java/com/fuying/sn/push/tpush/common/DBOpenHelper.java index 41ef1cc..1504e27 100644 --- a/app/src/main/java/com/fuying/sn/tpush/common/DBOpenHelper.java +++ b/app/src/main/java/com/fuying/sn/push/tpush/common/DBOpenHelper.java @@ -1,4 +1,4 @@ -package com.fuying.sn.tpush.common; +package com.fuying.sn.push.tpush.common; import android.content.Context; import android.database.sqlite.SQLiteDatabase; diff --git a/app/src/main/java/com/fuying/sn/tpush/common/NotificationService.java b/app/src/main/java/com/fuying/sn/push/tpush/common/NotificationService.java similarity index 98% rename from app/src/main/java/com/fuying/sn/tpush/common/NotificationService.java rename to app/src/main/java/com/fuying/sn/push/tpush/common/NotificationService.java index a7204b7..4cda4dc 100644 --- a/app/src/main/java/com/fuying/sn/tpush/common/NotificationService.java +++ b/app/src/main/java/com/fuying/sn/push/tpush/common/NotificationService.java @@ -1,11 +1,11 @@ -package com.fuying.sn.tpush.common; +package com.fuying.sn.push.tpush.common; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import com.fuying.sn.tpush.po.XGNotification; +import com.fuying.sn.push.tpush.po.XGNotification; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/fuying/sn/tpush/po/XGNotification.java b/app/src/main/java/com/fuying/sn/push/tpush/po/XGNotification.java similarity index 97% rename from app/src/main/java/com/fuying/sn/tpush/po/XGNotification.java rename to app/src/main/java/com/fuying/sn/push/tpush/po/XGNotification.java index 03240ae..438d06b 100644 --- a/app/src/main/java/com/fuying/sn/tpush/po/XGNotification.java +++ b/app/src/main/java/com/fuying/sn/push/tpush/po/XGNotification.java @@ -1,4 +1,4 @@ -package com.fuying.sn.tpush.po; +package com.fuying.sn.push.tpush.po; public class XGNotification { private Integer id; diff --git a/app/src/main/java/com/fuying/sn/service/main/MainService.java b/app/src/main/java/com/fuying/sn/service/main/MainService.java index d1bfe75..603e7dc 100644 --- a/app/src/main/java/com/fuying/sn/service/main/MainService.java +++ b/app/src/main/java/com/fuying/sn/service/main/MainService.java @@ -98,18 +98,19 @@ public class MainService extends BaseRxService implements MainSContact.MainView, new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { -// if (JGYUtils.getInstance().isScreenOn()) { - Log.e(TAG, "getSnInfo1"); - NetInterfaceManager.getInstance().getAppWhiteList(() -> { - Log.e("onConnected", "onNext: getAppWhiteList"); - }); - mPresenter.getSnInfo(); - mPresenter.getAppAndWhite(); - NetInterfaceManager.getInstance().updateAdminInfo(); - NetInterfaceManager.getInstance().SendAppInstallInfo(); - SPUtils.put(MainService.this, CommonConfig.JGY_FIRST_BOOT, 1); - tPushInit(); -// } + // TODO: 2025/11/11 不确定某些机型状态获取是否正常 + if (JGYUtils.getInstance().isScreenOn()) { + Log.e(TAG, "getSnInfo1"); + NetInterfaceManager.getInstance().getAppWhiteList(() -> { + Log.e("onConnected", "onNext: getAppWhiteList"); + }); + mPresenter.getSnInfo(); + mPresenter.getAppAndWhite(); + NetInterfaceManager.getInstance().updateAdminInfo(); + NetInterfaceManager.getInstance().SendAppInstallInfo(); + SPUtils.put(MainService.this, CommonConfig.JGY_FIRST_BOOT, 1); + tPushInit(); + } } }, 15000); mMMKV.encode(CommonConfig.DEVICES_REBOOT, false);