From 4e7cb4365f0f77c5a029b0a4562daf88b37c773c Mon Sep 17 00:00:00 2001 From: thermatk Date: Fri, 25 Jan 2019 21:55:45 +0000 Subject: [PATCH] [TF][KILL] remaining GMS(GCM, Wear, etc), except for Maps (cherry picked from commit 337ab9e8e8aa966281716e6af164882184bf80c7) --- TMessagesProj/build.gradle | 20 +- .../config/debug/AndroidManifest.xml | 31 - .../config/debug/AndroidManifest_SDK23.xml | 31 - .../config/release/AndroidManifest.xml | 31 - .../config/release/AndroidManifest_SDK23.xml | 31 - TMessagesProj/src/main/AndroidManifest.xml | 15 - .../telegram/messenger/AndroidUtilities.java | 19 - .../telegram/messenger/ApplicationLoader.java | 58 - .../messenger/GcmPushListenerService.java | 993 ------------------ .../messenger/MessagesController.java | 3 - .../messenger/NotificationsController.java | 13 - .../WearDataLayerListenerService.java | 313 ------ 12 files changed, 12 insertions(+), 1546 deletions(-) delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java delete mode 100644 TMessagesProj/src/main/java/org/telegram/messenger/WearDataLayerListenerService.java diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 7f2df8503..86f1c05a7 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -13,10 +13,6 @@ configurations { compile.exclude module: 'support-v4' } -configurations.all { - exclude group: 'com.google.firebase', module: 'firebase-core' -} - dependencies { implementation 'androidx.core:core:1.1.0-beta01' implementation 'androidx.palette:palette:1.0.0' @@ -26,16 +22,24 @@ dependencies { compileOnly 'org.checkerframework:checker-qual:2.5.2' compileOnly 'org.checkerframework:checker-compat-qual:2.5.0' - implementation 'com.google.firebase:firebase-messaging:20.2.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' - implementation 'com.google.android.gms:play-services-auth:18.0.0' - implementation 'com.google.android.gms:play-services-wearable:17.0.0' implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.googlecode.mp4parser:isoparser:1.0.6' implementation 'com.stripe:stripe-android:2.0.2' implementation 'com.google.code.gson:gson:2.8.6' implementation files('libs/libgsaverification-client.aar') - implementation "com.microsoft.appcenter:appcenter-analytics:3.1.0" +} + +//return an api key from a properties file. +def getAppId(){ + Properties properties = new Properties() + properties.load(new FileInputStream("./API_KEYS")) + return properties.get("APP_ID") +} +def getAppHash(){ + Properties properties = new Properties() + properties.load(new FileInputStream("./API_KEYS")) + return "\"" + properties.get("APP_HASH") + "\"" } android { diff --git a/TMessagesProj/config/debug/AndroidManifest.xml b/TMessagesProj/config/debug/AndroidManifest.xml index 73f981fd5..e6b8c30df 100644 --- a/TMessagesProj/config/debug/AndroidManifest.xml +++ b/TMessagesProj/config/debug/AndroidManifest.xml @@ -9,9 +9,7 @@ - - @@ -28,35 +26,6 @@ android:supportsRtl="false" tools:replace="android:supportsRtl"> - - - - - - - - - - - - - - - - - - - - - diff --git a/TMessagesProj/config/debug/AndroidManifest_SDK23.xml b/TMessagesProj/config/debug/AndroidManifest_SDK23.xml index 41bfbe412..e541ab3b8 100644 --- a/TMessagesProj/config/debug/AndroidManifest_SDK23.xml +++ b/TMessagesProj/config/debug/AndroidManifest_SDK23.xml @@ -9,9 +9,7 @@ - - @@ -30,35 +28,6 @@ android:supportsRtl="false" tools:replace="android:supportsRtl"> - - - - - - - - - - - - - - - - - - - - - diff --git a/TMessagesProj/config/release/AndroidManifest.xml b/TMessagesProj/config/release/AndroidManifest.xml index 27a6a219c..190a66dea 100644 --- a/TMessagesProj/config/release/AndroidManifest.xml +++ b/TMessagesProj/config/release/AndroidManifest.xml @@ -9,9 +9,7 @@ - - @@ -28,35 +26,6 @@ android:supportsRtl="false" tools:replace="android:supportsRtl"> - - - - - - - - - - - - - - - - - - - - - diff --git a/TMessagesProj/config/release/AndroidManifest_SDK23.xml b/TMessagesProj/config/release/AndroidManifest_SDK23.xml index c497ee607..5b25c540d 100644 --- a/TMessagesProj/config/release/AndroidManifest_SDK23.xml +++ b/TMessagesProj/config/release/AndroidManifest_SDK23.xml @@ -9,9 +9,7 @@ - - @@ -29,35 +27,6 @@ android:supportsRtl="false" tools:replace="android:supportsRtl"> - - - - - - - - - - - - - - - - - - - - - diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml index 02bacd6da..ba13cf306 100644 --- a/TMessagesProj/src/main/AndroidManifest.xml +++ b/TMessagesProj/src/main/AndroidManifest.xml @@ -303,16 +303,6 @@ - - - - - - - - - - @@ -393,11 +383,6 @@ - - - - - task = client.startSmsRetriever(); - task.addOnSuccessListener(aVoid -> { - if (BuildVars.DEBUG_VERSION) { - FileLog.d("sms listener registered"); - } - }); - } - } catch (Throwable e) { - FileLog.e(e); - } - } } public static int getShadowHeight() { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java index ca81547f3..ab4975c1e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java @@ -28,10 +28,6 @@ import android.os.PowerManager; import android.telephony.TelephonyManager; import android.text.TextUtils; -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.firebase.iid.FirebaseInstanceId; - import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLRPC; import org.telegram.ui.Components.ForegroundDetector; @@ -156,7 +152,6 @@ public class ApplicationLoader extends Application { } ApplicationLoader app = (ApplicationLoader) ApplicationLoader.applicationContext; - app.initPlayServices(); if (BuildVars.LOGS_ENABLED) { FileLog.d("app initied"); } @@ -166,8 +161,6 @@ public class ApplicationLoader extends Application { ContactsController.getInstance(a).checkAppAccount(); DownloadController.getInstance(a); } - - WearDataLayerListenerService.updateWatchConnectionState(); } public ApplicationLoader() { @@ -244,57 +237,6 @@ public class ApplicationLoader extends Application { } } - private void initPlayServices() { - AndroidUtilities.runOnUIThread(() -> { - if (hasPlayServices = checkPlayServices()) { - final String currentPushString = SharedConfig.pushString; - if (!TextUtils.isEmpty(currentPushString)) { - if (BuildVars.DEBUG_PRIVATE_VERSION && BuildVars.LOGS_ENABLED) { - FileLog.d("GCM regId = " + currentPushString); - } - } else { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM Registration not found."); - } - } - Utilities.globalQueue.postRunnable(() -> { - try { - FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> { - String token = instanceIdResult.getToken(); - if (!TextUtils.isEmpty(token)) { - GcmPushListenerService.sendRegistrationToServer(token); - } - }).addOnFailureListener(e -> { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("Failed to get regid"); - FileLog.e(e); - } - SharedConfig.pushStringStatus = "__FIREBASE_FAILED__"; - GcmPushListenerService.sendRegistrationToServer(null); - }); - } catch (Throwable e) { - FileLog.e(e); - } - }); - } else { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("No valid Google Play Services APK found."); - } - SharedConfig.pushStringStatus = "__NO_GOOGLE_PLAY_SERVICES__"; - GcmPushListenerService.sendRegistrationToServer(null); - } - }, 1000); - } - - private boolean checkPlayServices() { - try { - int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); - return resultCode == ConnectionResult.SUCCESS; - } catch (Exception e) { - FileLog.e(e); - } - return true; - } private static void ensureCurrentNetworkGet(boolean force) { if (force || currentNetworkInfo == null) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java b/TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java deleted file mode 100755 index 2ecee3704..000000000 --- a/TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java +++ /dev/null @@ -1,993 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 5.x.x. - * It is licensed under GNU GPL v. 2 or later. - * You should have received a copy of the license in this archive (see LICENSE). - * - * Copyright Nikolai Kudashov, 2013-2018. - */ - -package org.telegram.messenger; - -import android.os.SystemClock; -import android.text.TextUtils; -import android.util.Base64; -import android.util.SparseArray; - -import com.google.firebase.messaging.FirebaseMessagingService; -import com.google.firebase.messaging.RemoteMessage; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.telegram.tgnet.ConnectionsManager; -import org.telegram.tgnet.NativeByteBuffer; -import org.telegram.tgnet.TLRPC; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.CountDownLatch; - -public class GcmPushListenerService extends FirebaseMessagingService { - - public static final int NOTIFICATION_ID = 1; - private CountDownLatch countDownLatch = new CountDownLatch(1); - - @Override - public void onMessageReceived(RemoteMessage message) { - String from = message.getFrom(); - final Map data = message.getData(); - final long time = message.getSentTime(); - final long receiveTime = SystemClock.elapsedRealtime(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM received data: " + data + " from: " + from); - } - AndroidUtilities.runOnUIThread(() -> { - ApplicationLoader.postInitApplication(); - Utilities.stageQueue.postRunnable(() -> { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM START PROCESSING"); - } - int currentAccount = -1; - String loc_key = null; - String jsonString = null; - try { - Object value = data.get("p"); - if (!(value instanceof String)) { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM DECRYPT ERROR 1"); - } - onDecryptError(); - return; - } - byte[] bytes = Base64.decode((String) value, Base64.URL_SAFE); - NativeByteBuffer buffer = new NativeByteBuffer(bytes.length); - buffer.writeBytes(bytes); - buffer.position(0); - - if (SharedConfig.pushAuthKeyId == null) { - SharedConfig.pushAuthKeyId = new byte[8]; - byte[] authKeyHash = Utilities.computeSHA1(SharedConfig.pushAuthKey); - System.arraycopy(authKeyHash, authKeyHash.length - 8, SharedConfig.pushAuthKeyId, 0, 8); - } - byte[] inAuthKeyId = new byte[8]; - buffer.readBytes(inAuthKeyId, true); - if (!Arrays.equals(SharedConfig.pushAuthKeyId, inAuthKeyId)) { - onDecryptError(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d(String.format(Locale.US, "GCM DECRYPT ERROR 2 k1=%s k2=%s, key=%s", Utilities.bytesToHex(SharedConfig.pushAuthKeyId), Utilities.bytesToHex(inAuthKeyId), Utilities.bytesToHex(SharedConfig.pushAuthKey))); - } - return; - } - - byte[] messageKey = new byte[16]; - buffer.readBytes(messageKey, true); - - MessageKeyData messageKeyData = MessageKeyData.generateMessageKeyData(SharedConfig.pushAuthKey, messageKey, true, 2); - Utilities.aesIgeEncryption(buffer.buffer, messageKeyData.aesKey, messageKeyData.aesIv, false, false, 24, bytes.length - 24); - - byte[] messageKeyFull = Utilities.computeSHA256(SharedConfig.pushAuthKey, 88 + 8, 32, buffer.buffer, 24, buffer.buffer.limit()); - if (!Utilities.arraysEquals(messageKey, 0, messageKeyFull, 8)) { - onDecryptError(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d(String.format("GCM DECRYPT ERROR 3, key = %s", Utilities.bytesToHex(SharedConfig.pushAuthKey))); - } - return; - } - - int len = buffer.readInt32(true); - byte[] strBytes = new byte[len]; - buffer.readBytes(strBytes, true); - jsonString = new String(strBytes); - JSONObject json = new JSONObject(jsonString); - - if (json.has("loc_key")) { - loc_key = json.getString("loc_key"); - } else { - loc_key = ""; - } - - JSONObject custom; - Object object = json.get("custom"); - if (object instanceof JSONObject) { - custom = json.getJSONObject("custom"); - } else { - custom = new JSONObject(); - } - - Object userIdObject; - if (json.has("user_id")) { - userIdObject = json.get("user_id"); - } else { - userIdObject = null; - } - int accountUserId; - if (userIdObject == null) { - accountUserId = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId(); - } else { - if (userIdObject instanceof Integer) { - accountUserId = (Integer) userIdObject; - } else if (userIdObject instanceof String) { - accountUserId = Utilities.parseInt((String) userIdObject); - } else { - accountUserId = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId(); - } - } - int account = UserConfig.selectedAccount; - for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { - if (UserConfig.getInstance(a).getClientUserId() == accountUserId) { - account = a; - break; - } - } - final int accountFinal = currentAccount = account; - if (!UserConfig.getInstance(currentAccount).isClientActivated()) { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM ACCOUNT NOT ACTIVATED"); - } - countDownLatch.countDown(); - return; - } - Object obj = data.get("google.sent_time"); - switch (loc_key) { - case "DC_UPDATE": { - int dc = custom.getInt("dc"); - String addr = custom.getString("addr"); - String[] parts = addr.split(":"); - if (parts.length != 2) { - countDownLatch.countDown(); - return; - } - String ip = parts[0]; - int port = Integer.parseInt(parts[1]); - ConnectionsManager.getInstance(currentAccount).applyDatacenterAddress(dc, ip, port); - ConnectionsManager.getInstance(currentAccount).resumeNetworkMaybe(); - countDownLatch.countDown(); - return; - } - case "MESSAGE_ANNOUNCEMENT": { - TLRPC.TL_updateServiceNotification update = new TLRPC.TL_updateServiceNotification(); - update.popup = false; - update.flags = 2; - update.inbox_date = (int) (time / 1000); - update.message = json.getString("message"); - update.type = "announcement"; - update.media = new TLRPC.TL_messageMediaEmpty(); - final TLRPC.TL_updates updates = new TLRPC.TL_updates(); - updates.updates.add(update); - Utilities.stageQueue.postRunnable(() -> MessagesController.getInstance(accountFinal).processUpdates(updates, false)); - ConnectionsManager.getInstance(currentAccount).resumeNetworkMaybe(); - countDownLatch.countDown(); - return; - } - case "SESSION_REVOKE": { - AndroidUtilities.runOnUIThread(() -> { - if (UserConfig.getInstance(accountFinal).getClientUserId() != 0) { - UserConfig.getInstance(accountFinal).clearConfig(); - MessagesController.getInstance(accountFinal).performLogout(0); - } - }); - countDownLatch.countDown(); - return; - } - case "GEO_LIVE_PENDING": { - Utilities.stageQueue.postRunnable(() -> LocationController.getInstance(accountFinal).setNewLocationEndWatchTime()); - countDownLatch.countDown(); - return; - } - } - - int channel_id; - int chat_id; - int user_id; - long dialog_id = 0; - boolean scheduled; - if (custom.has("channel_id")) { - channel_id = custom.getInt("channel_id"); - dialog_id = -channel_id; - } else { - channel_id = 0; - } - if (custom.has("from_id")) { - user_id = custom.getInt("from_id"); - dialog_id = user_id; - } else { - user_id = 0; - } - if (custom.has("chat_id")) { - chat_id = custom.getInt("chat_id"); - dialog_id = -chat_id; - } else { - chat_id = 0; - } - if (custom.has("encryption_id")) { - dialog_id = ((long) custom.getInt("encryption_id")) << 32; - } - if (custom.has("schedule")) { - scheduled = custom.getInt("schedule") == 1; - } else { - scheduled = false; - } - if (dialog_id == 0 && "ENCRYPTED_MESSAGE".equals(loc_key)) { - dialog_id = -(1L << 32); - } - boolean canRelease = true; - if (dialog_id != 0) { - if ("READ_HISTORY".equals(loc_key)) { - int max_id = custom.getInt("max_id"); - final ArrayList updates = new ArrayList<>(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM received read notification max_id = " + max_id + " for dialogId = " + dialog_id); - } - if (channel_id != 0) { - TLRPC.TL_updateReadChannelInbox update = new TLRPC.TL_updateReadChannelInbox(); - update.channel_id = channel_id; - update.max_id = max_id; - updates.add(update); - } else { - TLRPC.TL_updateReadHistoryInbox update = new TLRPC.TL_updateReadHistoryInbox(); - if (user_id != 0) { - update.peer = new TLRPC.TL_peerUser(); - update.peer.user_id = user_id; - } else { - update.peer = new TLRPC.TL_peerChat(); - update.peer.chat_id = chat_id; - } - update.max_id = max_id; - updates.add(update); - } - MessagesController.getInstance(accountFinal).processUpdateArray(updates, null, null, false, 0); - } else if ("MESSAGE_DELETED".equals(loc_key)) { - String messages = custom.getString("messages"); - String[] messagesArgs = messages.split(","); - SparseArray> deletedMessages = new SparseArray<>(); - ArrayList ids = new ArrayList<>(); - for (int a = 0; a < messagesArgs.length; a++) { - ids.add(Utilities.parseInt(messagesArgs[a])); - } - deletedMessages.put(channel_id, ids); - NotificationsController.getInstance(currentAccount).removeDeletedMessagesFromNotifications(deletedMessages); - - MessagesController.getInstance(currentAccount).deleteMessagesByPush(dialog_id, ids, channel_id); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM received " + loc_key + " for dialogId = " + dialog_id + " mids = " + TextUtils.join(",", ids)); - } - } else if (!TextUtils.isEmpty(loc_key)) { - int msg_id; - if (custom.has("msg_id")) { - msg_id = custom.getInt("msg_id"); - } else { - msg_id = 0; - } - - long random_id; - if (custom.has("random_id")) { - random_id = Utilities.parseLong(custom.getString("random_id")); - } else { - random_id = 0; - } - - boolean processNotification = false; - if (msg_id != 0) { - Integer currentReadValue = MessagesController.getInstance(currentAccount).dialogs_read_inbox_max.get(dialog_id); - if (currentReadValue == null) { - currentReadValue = MessagesStorage.getInstance(currentAccount).getDialogReadMax(false, dialog_id); - MessagesController.getInstance(accountFinal).dialogs_read_inbox_max.put(dialog_id, currentReadValue); - } - if (msg_id > currentReadValue) { - processNotification = true; - } - } else if (random_id != 0) { - if (!MessagesStorage.getInstance(account).checkMessageByRandomId(random_id)) { - processNotification = true; - } - } - if (processNotification) { - int chat_from_id; - - if (custom.has("chat_from_id")) { - chat_from_id = custom.getInt("chat_from_id"); - } else { - chat_from_id = 0; - } - boolean mention = custom.has("mention") && custom.getInt("mention") != 0; - boolean silent = custom.has("silent") && custom.getInt("silent") != 0; - - String[] args; - if (json.has("loc_args")) { - JSONArray loc_args = json.getJSONArray("loc_args"); - args = new String[loc_args.length()]; - for (int a = 0; a < args.length; a++) { - args[a] = loc_args.getString(a); - } - } else { - args = null; - } - String messageText = null; - String message1 = null; - String name = args[0]; - String userName = null; - boolean localMessage = false; - boolean supergroup = false; - boolean pinned = false; - boolean channel = false; - boolean edited = custom.has("edit_date"); - if (loc_key.startsWith("CHAT_")) { - supergroup = channel_id != 0; - userName = name; - name = args[1]; - } else if (loc_key.startsWith("PINNED_")) { - supergroup = chat_from_id != 0; - pinned = true; - } else if (loc_key.startsWith("CHANNEL_")) { - channel = true; - } - - if (BuildVars.LOGS_ENABLED) { - FileLog.d("GCM received message notification " + loc_key + " for dialogId = " + dialog_id + " mid = " + msg_id); - } - switch (loc_key) { - case "MESSAGE_TEXT": - case "CHANNEL_MESSAGE_TEXT": { - messageText = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, args[0], args[1]); - message1 = args[1]; - break; - } - case "MESSAGE_NOTEXT": { - messageText = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, args[0]); - message1 = LocaleController.getString("Message", R.string.Message); - break; - } - case "MESSAGE_PHOTO": { - messageText = LocaleController.formatString("NotificationMessagePhoto", R.string.NotificationMessagePhoto, args[0]); - message1 = LocaleController.getString("AttachPhoto", R.string.AttachPhoto); - break; - } - case "MESSAGE_PHOTO_SECRET": { - messageText = LocaleController.formatString("NotificationMessageSDPhoto", R.string.NotificationMessageSDPhoto, args[0]); - message1 = LocaleController.getString("AttachDestructingPhoto", R.string.AttachDestructingPhoto); - break; - } - case "MESSAGE_VIDEO": { - messageText = LocaleController.formatString("NotificationMessageVideo", R.string.NotificationMessageVideo, args[0]); - message1 = LocaleController.getString("AttachVideo", R.string.AttachVideo); - break; - } - case "MESSAGE_VIDEO_SECRET": { - messageText = LocaleController.formatString("NotificationMessageSDVideo", R.string.NotificationMessageSDVideo, args[0]); - message1 = LocaleController.getString("AttachDestructingVideo", R.string.AttachDestructingVideo); - break; - } - case "MESSAGE_SCREENSHOT": { - messageText = LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot).replace("un1", args[0]); - break; - } - case "MESSAGE_ROUND": { - messageText = LocaleController.formatString("NotificationMessageRound", R.string.NotificationMessageRound, args[0]); - message1 = LocaleController.getString("AttachRound", R.string.AttachRound); - break; - } - case "MESSAGE_DOC": { - messageText = LocaleController.formatString("NotificationMessageDocument", R.string.NotificationMessageDocument, args[0]); - message1 = LocaleController.getString("AttachDocument", R.string.AttachDocument); - break; - } - case "MESSAGE_STICKER": { - if (args.length > 1 && !TextUtils.isEmpty(args[1])) { - messageText = LocaleController.formatString("NotificationMessageStickerEmoji", R.string.NotificationMessageStickerEmoji, args[0], args[1]); - message1 = args[1] + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker); - } else { - messageText = LocaleController.formatString("NotificationMessageSticker", R.string.NotificationMessageSticker, args[0]); - message1 = LocaleController.getString("AttachSticker", R.string.AttachSticker); - } - break; - } - case "MESSAGE_AUDIO": { - messageText = LocaleController.formatString("NotificationMessageAudio", R.string.NotificationMessageAudio, args[0]); - message1 = LocaleController.getString("AttachAudio", R.string.AttachAudio); - break; - } - case "MESSAGE_CONTACT": { - messageText = LocaleController.formatString("NotificationMessageContact2", R.string.NotificationMessageContact2, args[0], args[1]); - message1 = LocaleController.getString("AttachContact", R.string.AttachContact); - break; - } - case "MESSAGE_QUIZ": { - messageText = LocaleController.formatString("NotificationMessageQuiz2", R.string.NotificationMessageQuiz2, args[0], args[1]); - message1 = LocaleController.getString("QuizPoll", R.string.QuizPoll); - break; - } - case "MESSAGE_POLL": { - messageText = LocaleController.formatString("NotificationMessagePoll2", R.string.NotificationMessagePoll2, args[0], args[1]); - message1 = LocaleController.getString("Poll", R.string.Poll); - break; - } - case "MESSAGE_GEO": { - messageText = LocaleController.formatString("NotificationMessageMap", R.string.NotificationMessageMap, args[0]); - message1 = LocaleController.getString("AttachLocation", R.string.AttachLocation); - break; - } - case "MESSAGE_GEOLIVE": { - messageText = LocaleController.formatString("NotificationMessageLiveLocation", R.string.NotificationMessageLiveLocation, args[0]); - message1 = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation); - break; - } - case "MESSAGE_GIF": { - messageText = LocaleController.formatString("NotificationMessageGif", R.string.NotificationMessageGif, args[0]); - message1 = LocaleController.getString("AttachGif", R.string.AttachGif); - break; - } - case "MESSAGE_GAME": { - messageText = LocaleController.formatString("NotificationMessageGame", R.string.NotificationMessageGame, args[0], args[1]); - message1 = LocaleController.getString("AttachGame", R.string.AttachGame); - break; - } - case "MESSAGE_GAME_SCORE": - case "CHANNEL_MESSAGE_GAME_SCORE":{ - messageText = LocaleController.formatString("NotificationMessageGameScored", R.string.NotificationMessageGameScored, args[0], args[1], args[2]); - break; - } - case "MESSAGE_INVOICE": { - messageText = LocaleController.formatString("NotificationMessageInvoice", R.string.NotificationMessageInvoice, args[0], args[1]); - message1 = LocaleController.getString("PaymentInvoice", R.string.PaymentInvoice); - break; - } - case "MESSAGE_FWDS": { - messageText = LocaleController.formatString("NotificationMessageForwardFew", R.string.NotificationMessageForwardFew, args[0], LocaleController.formatPluralString("messages", Utilities.parseInt(args[1]))); - localMessage = true; - break; - } - case "MESSAGE_PHOTOS": { - messageText = LocaleController.formatString("NotificationMessageFew", R.string.NotificationMessageFew, args[0], LocaleController.formatPluralString("Photos", Utilities.parseInt(args[1]))); - localMessage = true; - break; - } - case "MESSAGE_VIDEOS": { - messageText = LocaleController.formatString("NotificationMessageFew", R.string.NotificationMessageFew, args[0], LocaleController.formatPluralString("Videos", Utilities.parseInt(args[1]))); - localMessage = true; - break; - } - case "MESSAGES": { - messageText = LocaleController.formatString("NotificationMessageAlbum", R.string.NotificationMessageAlbum, args[0]); - localMessage = true; - break; - } - case "CHANNEL_MESSAGE_NOTEXT": { - messageText = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, args[0]); - message1 = LocaleController.getString("Message", R.string.Message); - break; - } - case "CHANNEL_MESSAGE_PHOTO": { - messageText = LocaleController.formatString("ChannelMessagePhoto", R.string.ChannelMessagePhoto, args[0]); - message1 = LocaleController.getString("AttachPhoto", R.string.AttachPhoto); - break; - } - case "CHANNEL_MESSAGE_VIDEO": { - messageText = LocaleController.formatString("ChannelMessageVideo", R.string.ChannelMessageVideo, args[0]); - message1 = LocaleController.getString("AttachVideo", R.string.AttachVideo); - break; - } - case "CHANNEL_MESSAGE_ROUND": { - messageText = LocaleController.formatString("ChannelMessageRound", R.string.ChannelMessageRound, args[0]); - message1 = LocaleController.getString("AttachRound", R.string.AttachRound); - break; - } - case "CHANNEL_MESSAGE_DOC": { - messageText = LocaleController.formatString("ChannelMessageDocument", R.string.ChannelMessageDocument, args[0]); - message1 = LocaleController.getString("AttachDocument", R.string.AttachDocument); - break; - } - case "CHANNEL_MESSAGE_STICKER": { - if (args.length > 1 && !TextUtils.isEmpty(args[1])) { - messageText = LocaleController.formatString("ChannelMessageStickerEmoji", R.string.ChannelMessageStickerEmoji, args[0], args[1]); - message1 = args[1] + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker); - } else { - messageText = LocaleController.formatString("ChannelMessageSticker", R.string.ChannelMessageSticker, args[0]); - message1 = LocaleController.getString("AttachSticker", R.string.AttachSticker); - } - break; - } - case "CHANNEL_MESSAGE_AUDIO": { - messageText = LocaleController.formatString("ChannelMessageAudio", R.string.ChannelMessageAudio, args[0]); - message1 = LocaleController.getString("AttachAudio", R.string.AttachAudio); - break; - } - case "CHANNEL_MESSAGE_CONTACT": { - messageText = LocaleController.formatString("ChannelMessageContact2", R.string.ChannelMessageContact2, args[0], args[1]); - message1 = LocaleController.getString("AttachContact", R.string.AttachContact); - break; - } - case "CHANNEL_MESSAGE_QUIZ": { - messageText = LocaleController.formatString("ChannelMessageQuiz2", R.string.ChannelMessageQuiz2, args[0], args[1]); - message1 = LocaleController.getString("QuizPoll", R.string.QuizPoll); - break; - } - case "CHANNEL_MESSAGE_POLL": { - messageText = LocaleController.formatString("ChannelMessagePoll2", R.string.ChannelMessagePoll2, args[0], args[1]); - message1 = LocaleController.getString("Poll", R.string.Poll); - break; - } - case "CHANNEL_MESSAGE_GEO": { - messageText = LocaleController.formatString("ChannelMessageMap", R.string.ChannelMessageMap, args[0]); - message1 = LocaleController.getString("AttachLocation", R.string.AttachLocation); - break; - } - case "CHANNEL_MESSAGE_GEOLIVE": { - messageText = LocaleController.formatString("ChannelMessageLiveLocation", R.string.ChannelMessageLiveLocation, args[0]); - message1 = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation); - break; - } - case "CHANNEL_MESSAGE_GIF": { - messageText = LocaleController.formatString("ChannelMessageGIF", R.string.ChannelMessageGIF, args[0]); - message1 = LocaleController.getString("AttachGif", R.string.AttachGif); - break; - } - case "CHANNEL_MESSAGE_GAME": { - messageText = LocaleController.formatString("NotificationMessageGame", R.string.NotificationMessageGame, args[0]); - message1 = LocaleController.getString("AttachGame", R.string.AttachGame); - break; - } - case "CHANNEL_MESSAGE_FWDS": { - messageText = LocaleController.formatString("ChannelMessageFew", R.string.ChannelMessageFew, args[0], LocaleController.formatPluralString("ForwardedMessageCount", Utilities.parseInt(args[1])).toLowerCase()); - localMessage = true; - break; - } - case "CHANNEL_MESSAGE_PHOTOS": { - messageText = LocaleController.formatString("ChannelMessageFew", R.string.ChannelMessageFew, args[0], LocaleController.formatPluralString("Photos", Utilities.parseInt(args[1]))); - localMessage = true; - break; - } - case "CHANNEL_MESSAGE_VIDEOS": { - messageText = LocaleController.formatString("ChannelMessageFew", R.string.ChannelMessageFew, args[0], LocaleController.formatPluralString("Videos", Utilities.parseInt(args[1]))); - localMessage = true; - break; - } - case "CHANNEL_MESSAGES": { - messageText = LocaleController.formatString("ChannelMessageAlbum", R.string.ChannelMessageAlbum, args[0]); - localMessage = true; - break; - } - case "CHAT_MESSAGE_TEXT": { - messageText = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, args[0], args[1], args[2]); - message1 = args[2]; - break; - } - case "CHAT_MESSAGE_NOTEXT": { - messageText = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, args[0], args[1]); - message1 = LocaleController.getString("Message", R.string.Message); - break; - } - case "CHAT_MESSAGE_PHOTO": { - messageText = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, args[0], args[1]); - message1 = LocaleController.getString("AttachPhoto", R.string.AttachPhoto); - break; - } - case "CHAT_MESSAGE_VIDEO": { - messageText = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, args[0], args[1]); - message1 = LocaleController.getString("AttachVideo", R.string.AttachVideo); - break; - } - case "CHAT_MESSAGE_ROUND": { - messageText = LocaleController.formatString("NotificationMessageGroupRound", R.string.NotificationMessageGroupRound, args[0], args[1]); - message1 = LocaleController.getString("AttachRound", R.string.AttachRound); - break; - } - case "CHAT_MESSAGE_DOC": { - messageText = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, args[0], args[1]); - message1 = LocaleController.getString("AttachDocument", R.string.AttachDocument); - break; - } - case "CHAT_MESSAGE_STICKER": { - if (args.length > 2 && !TextUtils.isEmpty(args[2])) { - messageText = LocaleController.formatString("NotificationMessageGroupStickerEmoji", R.string.NotificationMessageGroupStickerEmoji, args[0], args[1], args[2]); - message1 = args[2] + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker); - } else { - messageText = LocaleController.formatString("NotificationMessageGroupSticker", R.string.NotificationMessageGroupSticker, args[0], args[1]); - message1 = args[1] + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker); - } - break; - } - case "CHAT_MESSAGE_AUDIO": { - messageText = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, args[0], args[1]); - message1 = LocaleController.getString("AttachAudio", R.string.AttachAudio); - break; - } - case "CHAT_MESSAGE_CONTACT": { - messageText = LocaleController.formatString("NotificationMessageGroupContact2", R.string.NotificationMessageGroupContact2, args[0], args[1], args[2]); - message1 = LocaleController.getString("AttachContact", R.string.AttachContact); - break; - } - case "CHAT_MESSAGE_QUIZ": { - messageText = LocaleController.formatString("NotificationMessageGroupQuiz2", R.string.NotificationMessageGroupQuiz2, args[0], args[1], args[2]); - message1 = LocaleController.getString("PollQuiz", R.string.PollQuiz); - break; - } - case "CHAT_MESSAGE_POLL": { - messageText = LocaleController.formatString("NotificationMessageGroupPoll2", R.string.NotificationMessageGroupPoll2, args[0], args[1], args[2]); - message1 = LocaleController.getString("Poll", R.string.Poll); - break; - } - case "CHAT_MESSAGE_GEO": { - messageText = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, args[0], args[1]); - message1 = LocaleController.getString("AttachLocation", R.string.AttachLocation); - break; - } - case "CHAT_MESSAGE_GEOLIVE": { - messageText = LocaleController.formatString("NotificationMessageGroupLiveLocation", R.string.NotificationMessageGroupLiveLocation, args[0], args[1]); - message1 = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation); - break; - } - case "CHAT_MESSAGE_GIF": { - messageText = LocaleController.formatString("NotificationMessageGroupGif", R.string.NotificationMessageGroupGif, args[0], args[1]); - message1 = LocaleController.getString("AttachGif", R.string.AttachGif); - break; - } - case "CHAT_MESSAGE_GAME": { - messageText = LocaleController.formatString("NotificationMessageGroupGame", R.string.NotificationMessageGroupGame, args[0], args[1], args[2]); - message1 = LocaleController.getString("AttachGame", R.string.AttachGame); - break; - } - case "CHAT_MESSAGE_GAME_SCORE": { - messageText = LocaleController.formatString("NotificationMessageGroupGameScored", R.string.NotificationMessageGroupGameScored, args[0], args[1], args[2], args[3]); - break; - } - case "CHAT_MESSAGE_INVOICE": { - messageText = LocaleController.formatString("NotificationMessageGroupInvoice", R.string.NotificationMessageGroupInvoice, args[0], args[1], args[2]); - message1 = LocaleController.getString("PaymentInvoice", R.string.PaymentInvoice); - break; - } - case "CHAT_CREATED": - case "CHAT_ADD_YOU": { - messageText = LocaleController.formatString("NotificationInvitedToGroup", R.string.NotificationInvitedToGroup, args[0], args[1]); - break; - } - case "CHAT_TITLE_EDITED": { - messageText = LocaleController.formatString("NotificationEditedGroupName", R.string.NotificationEditedGroupName, args[0], args[1]); - break; - } - case "CHAT_PHOTO_EDITED": { - messageText = LocaleController.formatString("NotificationEditedGroupPhoto", R.string.NotificationEditedGroupPhoto, args[0], args[1]); - break; - } - case "CHAT_ADD_MEMBER": { - messageText = LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, args[0], args[1], args[2]); - break; - } - case "CHAT_DELETE_MEMBER": { - messageText = LocaleController.formatString("NotificationGroupKickMember", R.string.NotificationGroupKickMember, args[0], args[1]); - break; - } - case "CHAT_DELETE_YOU": { - messageText = LocaleController.formatString("NotificationGroupKickYou", R.string.NotificationGroupKickYou, args[0], args[1]); - break; - } - case "CHAT_LEFT": { - messageText = LocaleController.formatString("NotificationGroupLeftMember", R.string.NotificationGroupLeftMember, args[0], args[1]); - break; - } - case "CHAT_RETURNED": { - messageText = LocaleController.formatString("NotificationGroupAddSelf", R.string.NotificationGroupAddSelf, args[0], args[1]); - break; - } - case "CHAT_JOINED": { - messageText = LocaleController.formatString("NotificationGroupAddSelfMega", R.string.NotificationGroupAddSelfMega, args[0], args[1]); - break; - } - case "CHAT_MESSAGE_FWDS": { - messageText = LocaleController.formatString("NotificationGroupForwardedFew", R.string.NotificationGroupForwardedFew, args[0], args[1], LocaleController.formatPluralString("messages", Utilities.parseInt(args[2]))); - localMessage = true; - break; - } - case "CHAT_MESSAGE_PHOTOS": { - messageText = LocaleController.formatString("NotificationGroupFew", R.string.NotificationGroupFew, args[0], args[1], LocaleController.formatPluralString("Photos", Utilities.parseInt(args[2]))); - localMessage = true; - break; - } - case "CHAT_MESSAGE_VIDEOS": { - messageText = LocaleController.formatString("NotificationGroupFew", R.string.NotificationGroupFew, args[0], args[1], LocaleController.formatPluralString("Videos", Utilities.parseInt(args[2]))); - localMessage = true; - break; - } - case "CHAT_MESSAGES": { - messageText = LocaleController.formatString("NotificationGroupAlbum", R.string.NotificationGroupAlbum, args[0], args[1]); - localMessage = true; - break; - } - case "PINNED_TEXT": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, args[0], args[1], args[2]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, args[0], args[1]); - } - break; - } - case "PINNED_NOTEXT": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedNoText", R.string.NotificationActionPinnedNoText, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedNoTextChannel", R.string.NotificationActionPinnedNoTextChannel, args[0]); - } - break; - } - case "PINNED_PHOTO": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedPhoto", R.string.NotificationActionPinnedPhoto, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedPhotoChannel", R.string.NotificationActionPinnedPhotoChannel, args[0]); - } - break; - } - case "PINNED_VIDEO": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedVideo", R.string.NotificationActionPinnedVideo, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedVideoChannel", R.string.NotificationActionPinnedVideoChannel, args[0]); - } - break; - } - case "PINNED_ROUND": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedRound", R.string.NotificationActionPinnedRound, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedRoundChannel", R.string.NotificationActionPinnedRoundChannel, args[0]); - } - break; - } - case "PINNED_DOC": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedFile", R.string.NotificationActionPinnedFile, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedFileChannel", R.string.NotificationActionPinnedFileChannel, args[0]); - } - break; - } - case "PINNED_STICKER": { - if (chat_from_id != 0) { - if (args.length > 2 && !TextUtils.isEmpty(args[2])) { - messageText = LocaleController.formatString("NotificationActionPinnedStickerEmoji", R.string.NotificationActionPinnedStickerEmoji, args[0], args[2], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedSticker", R.string.NotificationActionPinnedSticker, args[0], args[1]); - } - } else { - if (args.length > 1 && !TextUtils.isEmpty(args[1])) { - messageText = LocaleController.formatString("NotificationActionPinnedStickerEmojiChannel", R.string.NotificationActionPinnedStickerEmojiChannel, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedStickerChannel", R.string.NotificationActionPinnedStickerChannel, args[0]); - } - } - break; - } - case "PINNED_AUDIO": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedVoice", R.string.NotificationActionPinnedVoice, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedVoiceChannel", R.string.NotificationActionPinnedVoiceChannel, args[0]); - } - break; - } - case "PINNED_CONTACT": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedContact2", R.string.NotificationActionPinnedContact2, args[0], args[2], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedContactChannel2", R.string.NotificationActionPinnedContactChannel2, args[0], args[1]); - } - break; - } - case "PINNED_QUIZ": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedQuiz2", R.string.NotificationActionPinnedQuiz2, args[0], args[2], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedQuizChannel2", R.string.NotificationActionPinnedQuizChannel2, args[0], args[1]); - } - break; - } - case "PINNED_POLL": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedPoll2", R.string.NotificationActionPinnedPoll2, args[0], args[2], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedPollChannel2", R.string.NotificationActionPinnedPollChannel2, args[0], args[1]); - } - break; - } - case "PINNED_GEO": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedGeo", R.string.NotificationActionPinnedGeo, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedGeoChannel", R.string.NotificationActionPinnedGeoChannel, args[0]); - } - break; - } - case "PINNED_GEOLIVE": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedGeoLive", R.string.NotificationActionPinnedGeoLive, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedGeoLiveChannel", R.string.NotificationActionPinnedGeoLiveChannel, args[0]); - } - break; - } - case "PINNED_GAME": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedGame", R.string.NotificationActionPinnedGame, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedGameChannel", R.string.NotificationActionPinnedGameChannel, args[0]); - } - break; - } - case "PINNED_GAME_SCORE": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedGameScore", R.string.NotificationActionPinnedGameScore, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedGameScoreChannel", R.string.NotificationActionPinnedGameScoreChannel, args[0]); - } - break; - } - case "PINNED_INVOICE": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedInvoice", R.string.NotificationActionPinnedInvoice, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedInvoiceChannel", R.string.NotificationActionPinnedInvoiceChannel, args[0]); - } - break; - } - case "PINNED_GIF": { - if (chat_from_id != 0) { - messageText = LocaleController.formatString("NotificationActionPinnedGif", R.string.NotificationActionPinnedGif, args[0], args[1]); - } else { - messageText = LocaleController.formatString("NotificationActionPinnedGifChannel", R.string.NotificationActionPinnedGifChannel, args[0]); - } - break; - } - case "ENCRYPTED_MESSAGE": { - messageText = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage); - name = LocaleController.getString("SecretChatName", R.string.SecretChatName); - localMessage = true; - break; - } - case "CONTACT_JOINED": - case "AUTH_UNKNOWN": - case "AUTH_REGION": - case "LOCKED_MESSAGE": - case "ENCRYPTION_REQUEST": - case "ENCRYPTION_ACCEPT": - case "PHONE_CALL_REQUEST": - case "MESSAGE_MUTED": - case "PHONE_CALL_MISSED": { - //ignored - break; - } - default: { - if (BuildVars.LOGS_ENABLED) { - FileLog.w("unhandled loc_key = " + loc_key); - } - break; - } - } - if (messageText != null) { - TLRPC.TL_message messageOwner = new TLRPC.TL_message(); - messageOwner.id = msg_id; - messageOwner.random_id = random_id; - messageOwner.message = message1 != null ? message1 : messageText; - messageOwner.date = (int) (time / 1000); - if (pinned) { - messageOwner.action = new TLRPC.TL_messageActionPinMessage(); - } - if (supergroup) { - messageOwner.flags |= TLRPC.MESSAGE_FLAG_MEGAGROUP; - } - messageOwner.dialog_id = dialog_id; - if (channel_id != 0) { - messageOwner.to_id = new TLRPC.TL_peerChannel(); - messageOwner.to_id.channel_id = channel_id; - } else if (chat_id != 0) { - messageOwner.to_id = new TLRPC.TL_peerChat(); - messageOwner.to_id.chat_id = chat_id; - } else { - messageOwner.to_id = new TLRPC.TL_peerUser(); - messageOwner.to_id.user_id = user_id; - } - messageOwner.flags |= 256; - messageOwner.from_id = chat_from_id; - messageOwner.mentioned = mention || pinned; - messageOwner.silent = silent; - messageOwner.from_scheduled = scheduled; - - MessageObject messageObject = new MessageObject(currentAccount, messageOwner, messageText, name, userName, localMessage, channel, edited); - ArrayList arrayList = new ArrayList<>(); - arrayList.add(messageObject); - canRelease = false; - NotificationsController.getInstance(currentAccount).processNewMessages(arrayList, true, true, countDownLatch); - } - } - } - } - if (canRelease) { - countDownLatch.countDown(); - } - - ConnectionsManager.onInternalPushReceived(currentAccount); - ConnectionsManager.getInstance(currentAccount).resumeNetworkMaybe(); - } catch (Throwable e) { - if (currentAccount != -1) { - ConnectionsManager.onInternalPushReceived(currentAccount); - ConnectionsManager.getInstance(currentAccount).resumeNetworkMaybe(); - countDownLatch.countDown(); - } else { - onDecryptError(); - } - if (BuildVars.LOGS_ENABLED) { - FileLog.e("error in loc_key = " + loc_key + " json " + jsonString); - } - FileLog.e(e); - } - }); - }); - try { - countDownLatch.await(); - } catch (Throwable ignore) { - - } - if (BuildVars.DEBUG_VERSION) { - FileLog.d("finished GCM service, time = " + (SystemClock.elapsedRealtime() - receiveTime)); - } - } - - private void onDecryptError() { - for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { - if (UserConfig.getInstance(a).isClientActivated()) { - ConnectionsManager.onInternalPushReceived(a); - ConnectionsManager.getInstance(a).resumeNetworkMaybe(); - } - } - countDownLatch.countDown(); - } - - @Override - public void onNewToken(String token) { - AndroidUtilities.runOnUIThread(() -> { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("Refreshed token: " + token); - } - ApplicationLoader.postInitApplication(); - sendRegistrationToServer(token); - }); - } - - public static void sendRegistrationToServer(final String token) { - Utilities.stageQueue.postRunnable(() -> { - ConnectionsManager.setRegId(token, SharedConfig.pushStringStatus); - if (token == null) { - return; - } - SharedConfig.pushString = token; - for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { - UserConfig userConfig = UserConfig.getInstance(a); - userConfig.registeredForPush = false; - userConfig.saveConfig(false); - if (userConfig.getClientUserId() != 0) { - final int currentAccount = a; - AndroidUtilities.runOnUIThread(() -> MessagesController.getInstance(currentAccount).registerForPush(token)); - } - } - }); - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 632854482..17377f056 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -4485,9 +4485,6 @@ public class MessagesController extends BaseController implements NotificationCe AndroidUtilities.runOnUIThread(passwordCheckRunnable); lastPasswordCheckTime = currentTime; } - if (lastPushRegisterSendTime != 0 && Math.abs(SystemClock.elapsedRealtime() - lastPushRegisterSendTime) >= 3 * 60 * 60 * 1000) { - GcmPushListenerService.sendRegistrationToServer(SharedConfig.pushString); - } getLocationController().update(); checkPromoInfoInternal(false); checkTosUpdate(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java index acd17f21b..2f211fdd0 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java @@ -2191,15 +2191,6 @@ public class NotificationsController extends BaseController { } wearNotificationsIds.clear(); AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.pushMessagesUpdated)); - if (WearDataLayerListenerService.isWatchConnected()) { - try { - JSONObject o = new JSONObject(); - o.put("id", getUserConfig().getClientUserId()); - o.put("cancel_all", true); - WearDataLayerListenerService.sendMessageToWatch("/notify", o.toString().getBytes(), "remote_notifications"); - } catch (JSONException ignore) { - } - } } catch (Exception e) { FileLog.e(e); } @@ -3076,9 +3067,6 @@ public class NotificationsController extends BaseController { ArrayList holders = new ArrayList<>(); JSONArray serializedNotifications = null; - if (WearDataLayerListenerService.isWatchConnected()) { - serializedNotifications = new JSONArray(); - } boolean useSummaryNotification = Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1 || Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1 && sortedDialogs.size() > 1; if (useSummaryNotification && Build.VERSION.SDK_INT >= 26) { @@ -3653,7 +3641,6 @@ public class NotificationsController extends BaseController { JSONObject s = new JSONObject(); s.put("id", selfUserId); s.put("n", serializedNotifications); - WearDataLayerListenerService.sendMessageToWatch("/notify", s.toString().getBytes(), "remote_notifications"); } catch (Exception ignore) { } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/WearDataLayerListenerService.java b/TMessagesProj/src/main/java/org/telegram/messenger/WearDataLayerListenerService.java deleted file mode 100644 index 03fe66641..000000000 --- a/TMessagesProj/src/main/java/org/telegram/messenger/WearDataLayerListenerService.java +++ /dev/null @@ -1,313 +0,0 @@ -package org.telegram.messenger; - -import android.text.TextUtils; - -import com.google.android.gms.common.api.GoogleApiClient; -import com.google.android.gms.wearable.CapabilityClient; -import com.google.android.gms.wearable.CapabilityInfo; -import com.google.android.gms.wearable.Channel; -import com.google.android.gms.wearable.MessageClient; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.Wearable; -import com.google.android.gms.wearable.WearableListenerService; - -import org.json.JSONObject; -import org.telegram.tgnet.ConnectionsManager; -import org.telegram.tgnet.TLRPC; - -import java.io.BufferedOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.Set; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class WearDataLayerListenerService extends WearableListenerService { - - private int currentAccount = UserConfig.selectedAccount; - private static boolean watchConnected; - - @Override - public void onCreate() { - super.onCreate(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("WearableDataLayer service created"); - } - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("WearableDataLayer service destroyed"); - } - } - - @Override - public void onChannelOpened(final Channel ch) { - //new Thread(new Runnable(){ - // @Override - // public void run(){ - GoogleApiClient apiClient = new GoogleApiClient.Builder(WearDataLayerListenerService.this).addApi(Wearable.API).build(); - if (!apiClient.blockingConnect().isSuccess()) { - if (BuildVars.LOGS_ENABLED) { - FileLog.e("failed to connect google api client"); - } - return; - } - String path = ch.getPath(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("wear channel path: " + path); - } - try { - if ("/getCurrentUser".equals(path)) { - DataOutputStream out = new DataOutputStream(new BufferedOutputStream(ch.getOutputStream(apiClient).await().getOutputStream())); - if (UserConfig.getInstance(currentAccount).isClientActivated()) { - final TLRPC.User user = UserConfig.getInstance(currentAccount).getCurrentUser(); - out.writeInt(user.id); - out.writeUTF(user.first_name); - out.writeUTF(user.last_name); - out.writeUTF(user.phone); - if (user.photo != null) { - final File photo = FileLoader.getPathToAttach(user.photo.photo_small, true); - final CyclicBarrier barrier = new CyclicBarrier(2); - if (!photo.exists()) { - final NotificationCenter.NotificationCenterDelegate listener = (id, account, args) -> { - if (id == NotificationCenter.fileDidLoad) { - if (BuildVars.LOGS_ENABLED) { - FileLog.d("file loaded: " + args[0] + " " + args[0].getClass().getName()); - } - if (args[0].equals(photo.getName())) { - if (BuildVars.LOGS_ENABLED) { - FileLog.e("LOADED USER PHOTO"); - } - try { - barrier.await(10, TimeUnit.MILLISECONDS); - } catch (Exception ignore) { - } - } - } - }; - AndroidUtilities.runOnUIThread(() -> { - NotificationCenter.getInstance(currentAccount).addObserver(listener, NotificationCenter.fileDidLoad); - FileLoader.getInstance(currentAccount).loadFile(ImageLocation.getForUser(user, false), user, null, 1, 1); - }); - try { - barrier.await(10, TimeUnit.SECONDS); - } catch (Exception ignore) { - } - AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(currentAccount).removeObserver(listener, NotificationCenter.fileDidLoad)); - } - if (photo.exists() && photo.length() <= 50 * 1024 * 1024) { - byte[] photoData = new byte[(int) photo.length()]; - FileInputStream photoIn = new FileInputStream(photo); - new DataInputStream(photoIn).readFully(photoData); - photoIn.close(); - out.writeInt(photoData.length); - out.write(photoData); - } else { - out.writeInt(0); - } - } else { - out.writeInt(0); - } - } else { - out.writeInt(0); - } - out.flush(); - out.close(); - } else if ("/waitForAuthCode".equals(path)) { - ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false); - final String[] code = {null}; - final CyclicBarrier barrier = new CyclicBarrier(2); - final NotificationCenter.NotificationCenterDelegate listener = (id, account, args) -> { - if (id == NotificationCenter.didReceiveNewMessages) { - long did = (Long) args[0]; - if (did == 777000) { - ArrayList arr = (ArrayList) args[1]; - if (arr.size() > 0) { - MessageObject msg = arr.get(0); - if (!TextUtils.isEmpty(msg.messageText)) { - Matcher matcher = Pattern.compile("[0-9]+").matcher(msg.messageText); - if (matcher.find()) { - code[0] = matcher.group(); - try { - barrier.await(10, TimeUnit.MILLISECONDS); - } catch (Exception ignore) { - } - } - } - } - } - } - }; - AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(currentAccount).addObserver(listener, NotificationCenter.didReceiveNewMessages)); - try { - barrier.await(30, TimeUnit.SECONDS); - } catch (Exception ignore) { - } - AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(currentAccount).removeObserver(listener, NotificationCenter.didReceiveNewMessages)); - DataOutputStream out = new DataOutputStream(ch.getOutputStream(apiClient).await().getOutputStream()); - if (code[0] != null) { - out.writeUTF(code[0]); - } else { - out.writeUTF(""); - } - out.flush(); - out.close(); - ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false); - } else if ("/getChatPhoto".equals(path)) { - try (DataInputStream in = new DataInputStream(ch.getInputStream(apiClient).await().getInputStream()); DataOutputStream out = new DataOutputStream(ch.getOutputStream(apiClient).await().getOutputStream())) { - String _req = in.readUTF(); - JSONObject req = new JSONObject(_req); - int chatID = req.getInt("chat_id"); - int accountID = req.getInt("account_id"); - int currentAccount = -1; - for (int i = 0; i < UserConfig.getActivatedAccountsCount(); i++) { - if (UserConfig.getInstance(i).getClientUserId() == accountID) { - currentAccount = i; - break; - } - } - if (currentAccount != -1) { - TLRPC.FileLocation location = null; - if (chatID > 0) { - TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(chatID); - if (user != null && user.photo != null) - location = user.photo.photo_small; - } else { - TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-chatID); - if (chat != null && chat.photo != null) - location = chat.photo.photo_small; - } - if (location != null) { - File file = FileLoader.getPathToAttach(location, true); - if (file.exists() && file.length() < 102400) { - out.writeInt((int) file.length()); - FileInputStream fin = new FileInputStream(file); - byte[] buf = new byte[10240]; - int read; - while ((read = fin.read(buf)) > 0) { - out.write(buf, 0, read); - } - fin.close(); - } else { - out.writeInt(0); - } - } else { - out.writeInt(0); - } - } else { - out.writeInt(0); - } - out.flush(); - } catch (Exception ignore) { - } - } - } catch (Exception x) { - if (BuildVars.LOGS_ENABLED) { - FileLog.e("error processing wear request", x); - } - } - ch.close(apiClient).await(); - apiClient.disconnect(); - if (BuildVars.LOGS_ENABLED) { - FileLog.d("WearableDataLayer channel thread exiting"); - } - // } - //}).start(); - } - - @Override - public void onMessageReceived(final MessageEvent messageEvent) { - if ("/reply".equals(messageEvent.getPath())) { - AndroidUtilities.runOnUIThread(() -> { - try { - ApplicationLoader.postInitApplication(); - String data = new String(messageEvent.getData(), "UTF-8"); - JSONObject r = new JSONObject(data); - CharSequence text = r.getString("text"); - if (text == null || text.length() == 0) { - return; - } - long dialog_id = r.getLong("chat_id"); - int max_id = r.getInt("max_id"); - int currentAccount = -1; - int accountID = r.getInt("account_id"); - for (int i = 0; i < UserConfig.getActivatedAccountsCount(); i++) { - if (UserConfig.getInstance(i).getClientUserId() == accountID) { - currentAccount = i; - break; - } - } - if (dialog_id == 0 || max_id == 0 || currentAccount == -1) { - return; - } - SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null, true, 0); - MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true, 0); - } catch (Exception x) { - if (BuildVars.LOGS_ENABLED) - FileLog.e(x); - } - }); - } - } - - public static void sendMessageToWatch(final String path, final byte[] data, String capability) { - Wearable.getCapabilityClient(ApplicationLoader.applicationContext) - .getCapability(capability, CapabilityClient.FILTER_REACHABLE) - .addOnCompleteListener(task -> { - CapabilityInfo info = task.getResult(); - if (info != null) { - MessageClient mc = Wearable.getMessageClient(ApplicationLoader.applicationContext); - Set nodes = info.getNodes(); - for (Node node : nodes) { - mc.sendMessage(node.getId(), path, data); - } - } - }); - } - - @Override - public void onCapabilityChanged(CapabilityInfo capabilityInfo) { - if ("remote_notifications".equals(capabilityInfo.getName())) { - watchConnected = false; - for (Node node : capabilityInfo.getNodes()) { - if (node.isNearby()) - watchConnected = true; - } - } - } - - public static void updateWatchConnectionState() { - try { - Wearable.getCapabilityClient(ApplicationLoader.applicationContext) - .getCapability("remote_notifications", CapabilityClient.FILTER_REACHABLE) - .addOnCompleteListener(task -> { - watchConnected = false; - try { - CapabilityInfo capabilityInfo = task.getResult(); - if (capabilityInfo == null) - return; - for (Node node : capabilityInfo.getNodes()) { - if (node.isNearby()) - watchConnected = true; - } - } catch (Exception ignore) { - } - }); - } catch (Throwable ignore) { - - } - } - - public static boolean isWatchConnected() { - return watchConnected; - } -}