From 1cfc5d426eb1d6b77a9f41ef5dfb500393371737 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 13 Feb 2024 11:04:38 +0100 Subject: [PATCH] access Android_id only on push --- .../services/XmppConnectionService.java | 44 +++++++++++++------ .../conversations/utils/PhoneHelper.java | 8 ++-- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 723dea69a..0a3e9059b 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -913,27 +913,45 @@ public class XmppConnectionService extends Service { manageAccountConnectionStates(ACTION_INTERNAL_PING, null); } - private synchronized void manageAccountConnectionStates(final String action, final Bundle extras) { + private synchronized void manageAccountConnectionStates( + final String action, final Bundle extras) { final String pushedAccountHash = extras == null ? null : extras.getString("account"); - final boolean interactive = Arrays.asList(ACTION_TRY_AGAIN).contains(action); + final boolean interactive = java.util.Objects.equals(ACTION_TRY_AGAIN, action); WakeLockHelper.acquire(wakeLock); - boolean pingNow = ConnectivityManager.CONNECTIVITY_ACTION.equals(action) || (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL > 0 && ACTION_POST_CONNECTIVITY_CHANGE.equals(action)); + boolean pingNow = + ConnectivityManager.CONNECTIVITY_ACTION.equals(action) + || (Config.POST_CONNECTIVITY_CHANGE_PING_INTERVAL > 0 + && ACTION_POST_CONNECTIVITY_CHANGE.equals(action)); final HashSet pingCandidates = new HashSet<>(); - final String androidId = PhoneHelper.getAndroidId(this); + final String androidId = pushedAccountHash == null ? null : PhoneHelper.getAndroidId(this); for (final Account account : accounts) { - final boolean pushWasMeantForThisAccount = CryptoHelper.getAccountFingerprint(account, androidId).equals(pushedAccountHash); - pingNow |= processAccountState(account, - interactive, - "ui".equals(action), - pushWasMeantForThisAccount, - pingCandidates); + final boolean pushWasMeantForThisAccount = + androidId != null + && CryptoHelper.getAccountFingerprint(account, androidId) + .equals(pushedAccountHash); + pingNow |= + processAccountState( + account, + interactive, + "ui".equals(action), + pushWasMeantForThisAccount, + pingCandidates); } if (pingNow) { - for (Account account : pingCandidates) { + for (final Account account : pingCandidates) { final boolean lowTimeout = isInLowPingTimeoutMode(account); account.getXmppConnection().sendPing(); - Log.d(Config.LOGTAG, account.getJid().asBareJid() + " send ping (action=" + action + ",lowTimeout=" + lowTimeout + ")"); - scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode()); + Log.d( + Config.LOGTAG, + account.getJid().asBareJid() + + " send ping (action=" + + action + + ",lowTimeout=" + + lowTimeout + + ")"); + scheduleWakeUpCall( + lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, + account.getUuid().hashCode()); } } WakeLockHelper.release(wakeLock); diff --git a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java index 9ff492578..edb181f4f 100644 --- a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java @@ -13,14 +13,12 @@ import android.provider.Settings; public class PhoneHelper { @SuppressLint("HardwareIds") - public static String getAndroidId(Context context) { + public static String getAndroidId(final Context context) { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } - public static Uri getProfilePictureUri(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) - != PackageManager.PERMISSION_GRANTED) { + public static Uri getProfilePictureUri(final Context context) { + if (context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { return null; } final String[] projection = new String[] {Profile._ID, Profile.PHOTO_URI};