data = remoteMessage.getData();
28 | if (null == data) {
29 | return;
30 | }
31 | LogUtil.log.d("received message from: " + remoteMessage.getFrom() + ", payload: " + data.toString());
32 | try {
33 | JSONObject jsonObject = JSON.parseObject(data.get("payload"));
34 | if (null != jsonObject) {
35 | String channel = jsonObject.getString("_channel");
36 | String action = jsonObject.getString("action");
37 |
38 | AVNotificationManager.getInstance().processGcmMessage(channel, action, jsonObject.toJSONString());
39 | }
40 | } catch (Exception ex) {
41 | LogUtil.avlog.e("failed to parse push data.", ex);
42 | }
43 | }
44 |
45 | @Override
46 | public void onDeletedMessages() {
47 | super.onDeletedMessages();
48 | }
49 | }
--------------------------------------------------------------------------------
/avoscloud-sdk/src/main/java/com/avos/avoscloud/RequestEmailVerifyCallback.java:
--------------------------------------------------------------------------------
1 | package com.avos.avoscloud;
2 |
3 | /**
4 | *
5 | * RequestEmailVerifyCallback 用来验证用户的邮箱.
6 | *
7 | *
8 | * The easiest way to use a RequestEmailVerifyCallback is through an anonymous inner class. Override
9 | * the done function to specify what the callback should do after the request is complete. The done
10 | * function will be run in the UI thread, while the request happens in a background thread. This
11 | * ensures that the UI does not freeze while the request happens.
12 | *
13 | *
14 | * For example, this sample code requests an email verify for a user and calls a different function
15 | * depending on whether the request succeeded or not.
16 | *
17 | *
18 | *
19 | * AVUser.requestEmailVerfiyInBackground("forgetful@example.com",
20 | * new RequestEmailVerifyCallback() {
21 | * public void done(AVException e) {
22 | * if (e == null) {
23 | * requestedSuccessfully();
24 | * } else {
25 | * requestDidNotSucceed();
26 | * }
27 | * }
28 | * });
29 | *
30 | */
31 | public abstract class RequestEmailVerifyCallback extends AVCallback {
32 | /**
33 | * Override this function with the code you want to run after the request is complete.
34 | *
35 | * @param e The exception raised by the save, or null if no account is associated with the email
36 | * address.
37 | */
38 | public abstract void done(AVException e);
39 |
40 | @Override
41 | protected void internalDone0(Void t, AVException avException) {
42 | this.done(avException);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/avoscloud-sdk/src/main/java/com/avos/avoscloud/LogInCallback.java:
--------------------------------------------------------------------------------
1 | package com.avos.avoscloud;
2 |
3 | /**
4 | *
5 | * A LogInCallback is used to run code after logging in a user.
6 | *
7 | *
8 | * The easiest way to use a LogInCallback is through an anonymous inner class. Override the done
9 | * function to specify what the callback should do after the login is complete. The done function
10 | * will be run in the UI thread, while the login happens in a background thread. This ensures that
11 | * the UI does not freeze while the save happens.
12 | *
13 | *
14 | * For example, this sample code logs in a user and calls a different function depending on whether
15 | * the login succeeded or not.
16 | *
17 | *
18 | *
19 | * AVUser.logInInBackground("username", "password", new LogInCallback() {
20 | * public void done(AVUser user, AVException e) {
21 | * if (e == null && user != null) {
22 | * loginSuccessful();
23 | * } else if (user == null) {
24 | * usernameOrPasswordIsInvalid();
25 | * } else {
26 | * somethingWentWrong();
27 | * }
28 | * }
29 | * });
30 | *
31 | */
32 | public abstract class LogInCallback extends AVCallback {
33 | /**
34 | * Override this function with the code you want to run after the save is complete.
35 | *
36 | * @param user The user that logged in, if the username and password is valid.
37 | * @param e The exception raised by the login.
38 | */
39 | public abstract void done(T user, AVException e);
40 |
41 | protected final void internalDone0(T returnValue, AVException e) {
42 | done(returnValue, e);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/avoscloud-sdk/src/main/java/com/avos/avoscloud/AVLogger.java:
--------------------------------------------------------------------------------
1 | package com.avos.avoscloud;
2 |
3 | /**
4 | * Created by wli on 16/6/15.
5 | */
6 | public abstract class AVLogger {
7 | public static final int LOG_LEVEL_VERBOSE = 1 << 1;
8 | public static final int LOG_LEVEL_DEBUG = 1 << 2;
9 | public static final int LOG_LEVEL_INFO = 1 << 3;
10 | public static final int LOG_LEVEL_WARNING = 1 << 4;
11 | public static final int LOG_LEVEL_ERROR = 1 << 5;
12 | public static final int LOG_LEVEL_NONE = ~0;
13 | boolean enabled;
14 | int logLevel = LOG_LEVEL_NONE;
15 |
16 | public boolean isDebugEnabled() {
17 | return enabled;
18 | }
19 |
20 | public void setDebugEnabled(boolean enable) {
21 | enabled = enable;
22 | }
23 |
24 | public boolean showInternalDebugLog() {
25 | return false;
26 | }
27 |
28 | public int getLogLevel() {
29 | return logLevel;
30 | }
31 |
32 | public void setLogLevel(int logLevel) {
33 | this.logLevel = logLevel;
34 | }
35 |
36 | public abstract int v(String tag, String msg);
37 |
38 | public abstract int v(String tag, String msg, Throwable tr);
39 |
40 | public abstract int d(String tag, String msg);
41 |
42 | public abstract int d(String tag, String msg, Throwable tr);
43 |
44 | public abstract int i(String tag, String msg);
45 |
46 | public abstract int i(String tag, String msg, Throwable tr);
47 |
48 | public abstract int w(String tag, String msg);
49 |
50 | public abstract int w(String tag, String msg, Throwable tr);
51 |
52 |
53 | public abstract int w(String tag, Throwable tr);
54 |
55 | public abstract int e(String tag, String msg);
56 |
57 | public abstract int e(String tag, String msg, Throwable tr);
58 | }
--------------------------------------------------------------------------------
/hmsagent/src/main/java/com/huawei/android/hms/agent/common/ThreadUtil.java:
--------------------------------------------------------------------------------
1 | package com.huawei.android.hms.agent.common;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import java.util.concurrent.ExecutorService;
7 | import java.util.concurrent.Executors;
8 |
9 | /**
10 | * 线程工具,用于执行线程等
11 | */
12 | public final class ThreadUtil {
13 | public static final ThreadUtil INST = new ThreadUtil();
14 |
15 | private ExecutorService executors;
16 |
17 | private ThreadUtil(){
18 | }
19 |
20 | /**
21 | * 在线程中执行
22 | * @param runnable 要执行的runnable
23 | */
24 | public void excute(Runnable runnable) {
25 | ExecutorService executorService = getExecutorService();
26 | if (executorService != null) {
27 | // 优先使用线程池,提高效率
28 | executorService.execute(runnable);
29 | } else {
30 | // 线程池获取失败,则直接使用线程
31 | new Thread(runnable).start();
32 | }
33 | }
34 |
35 | /**
36 | * 在主线程中执行
37 | * @param runnable 要执行的runnable
38 | */
39 | public void excuteInMainThread(Runnable runnable){
40 | new Handler(Looper.getMainLooper()).post(runnable);
41 | }
42 |
43 | /**
44 | * 获取缓存线程池
45 | * @return 缓存线程池服务
46 | */
47 | private ExecutorService getExecutorService(){
48 | if (executors == null) {
49 | try {
50 | executors = Executors.newCachedThreadPool();
51 | } catch (Exception e) {
52 | HMSAgentLog.e("create thread service error:" + e.getMessage());
53 | }
54 | }
55 |
56 | return executors;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/avoscloud-push/src/main/java/com/avos/avoscloud/HeartBeatPolicy.java:
--------------------------------------------------------------------------------
1 | package com.avos.avoscloud;
2 |
3 | import java.util.concurrent.Future;
4 | import java.util.concurrent.ScheduledThreadPoolExecutor;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | /**
8 | * Created by wli on 2017/6/7.
9 | */
10 |
11 | abstract class HeartBeatPolicy {
12 |
13 | /**
14 | * 定时任务
15 | */
16 | private static final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
17 |
18 | private Future healthFuture;
19 |
20 | /**
21 | * 最近收到 ping 的时间
22 | */
23 | private long lastPongTS;
24 |
25 | /**
26 | * 心跳设置为 180s
27 | */
28 | private final long HEART_BEAT_INTERNAL = 180 * 1000;
29 |
30 | /**
31 | * 超时时长设置为两个心跳
32 | */
33 | private final long HEALTHY_THRESHOLD = HEART_BEAT_INTERNAL * 2;
34 |
35 | private Runnable healthMonitor = new Runnable() {
36 | @Override
37 | public void run() {
38 | if (System.currentTimeMillis() - lastPongTS > HEALTHY_THRESHOLD) {
39 | onTimeOut();
40 | } else {
41 | sendPing();
42 | }
43 | }
44 | };
45 |
46 | synchronized void onPong() {
47 | lastPongTS = System.currentTimeMillis();
48 | }
49 |
50 | synchronized void startHeartbeat() {
51 | stopHeartbeat();
52 | lastPongTS = System.currentTimeMillis();
53 | healthFuture = executor.scheduleAtFixedRate(healthMonitor, HEART_BEAT_INTERNAL, HEART_BEAT_INTERNAL,
54 | TimeUnit.MILLISECONDS);
55 | }
56 |
57 | synchronized void stopHeartbeat() {
58 | if (null != healthFuture) {
59 | healthFuture.cancel(true);
60 | }
61 | }
62 |
63 | public abstract void onTimeOut();
64 |
65 | public abstract void sendPing();
66 | }
67 |
--------------------------------------------------------------------------------
/hmsagent/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\DevApps\android\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 | -ignorewarning
27 |
28 | -keepattributes *Annotation*
29 | -keepattributes Exceptions
30 | -keepattributes InnerClasses
31 | -keepattributes Signature
32 | -keepattributes SourceFile,LineNumberTable
33 |
34 | -keep class com.hianalytics.android.**{*;}
35 | -keep class com.huawei.updatesdk.**{*;}
36 | -keep class com.huawei.hms.**{*;}
37 | -keep class com.huawei.gamebox.plugin.gameservice.**{*;}
38 | -keep public class com.huawei.android.hms.agent.** extends android.app.Activity { public *; protected *; }
39 | -keep interface com.huawei.android.hms.agent.common.INoProguard {*;}
40 | -keep class * extends com.huawei.android.hms.agent.common.INoProguard {*;}
41 |
--------------------------------------------------------------------------------
/avoscloud-push/src/main/java/com/avos/avoscloud/im/v2/AVIMConversationQueryConditions.java:
--------------------------------------------------------------------------------
1 | package com.avos.avoscloud.im.v2;
2 |
3 | import com.avos.avoscloud.QueryConditions;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Created by wli on 2016/11/1.
9 | */
10 |
11 | final class AVIMConversationQueryConditions extends QueryConditions {
12 | private boolean isWithLastMessageRefreshed = false;
13 | private boolean isCompact = false;
14 |
15 | /**
16 | * 是否携带最后一条消息
17 | *
18 | * @return
19 | */
20 | public boolean isWithLastMessagesRefreshed() {
21 | return isWithLastMessageRefreshed;
22 | }
23 |
24 | /**
25 | * 设置是否携带最后一条消息
26 | *
27 | * @param isWithLastMessageRefreshed
28 | */
29 | public void setWithLastMessagesRefreshed(boolean isWithLastMessageRefreshed) {
30 | this.isWithLastMessageRefreshed = isWithLastMessageRefreshed;
31 | }
32 |
33 | public void setCompact(boolean isCompact) {
34 | this.isCompact = isCompact;
35 | }
36 |
37 | @Override
38 | public Map assembleParameters() {
39 | Map parameters = super.assembleParameters();
40 | if (isWithLastMessageRefreshed) {
41 | parameters.put(Conversation.QUERY_PARAM_LAST_MESSAGE, Boolean.toString(isWithLastMessageRefreshed));
42 | } else if (parameters.containsKey(Conversation.QUERY_PARAM_LAST_MESSAGE)) {
43 | parameters.remove(Conversation.QUERY_PARAM_LAST_MESSAGE);
44 | }
45 |
46 | if (isCompact) {
47 | parameters.put(Conversation.QUERY_PARAM_COMPACT, Boolean.toString(isCompact));
48 | } else if (parameters.containsKey(Conversation.QUERY_PARAM_COMPACT)) {
49 | parameters.remove(Conversation.QUERY_PARAM_COMPACT);
50 | }
51 | return parameters;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------