access Android_id only on push

This commit is contained in:
Daniel Gultsch 2024-02-13 11:04:38 +01:00
parent 5fa1caf7ee
commit 1cfc5d426e
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 34 additions and 18 deletions

View file

@ -913,27 +913,45 @@ public class XmppConnectionService extends Service {
manageAccountConnectionStates(ACTION_INTERNAL_PING, null); 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 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); 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<Account> pingCandidates = new HashSet<>(); final HashSet<Account> pingCandidates = new HashSet<>();
final String androidId = PhoneHelper.getAndroidId(this); final String androidId = pushedAccountHash == null ? null : PhoneHelper.getAndroidId(this);
for (final Account account : accounts) { for (final Account account : accounts) {
final boolean pushWasMeantForThisAccount = CryptoHelper.getAccountFingerprint(account, androidId).equals(pushedAccountHash); final boolean pushWasMeantForThisAccount =
pingNow |= processAccountState(account, androidId != null
&& CryptoHelper.getAccountFingerprint(account, androidId)
.equals(pushedAccountHash);
pingNow |=
processAccountState(
account,
interactive, interactive,
"ui".equals(action), "ui".equals(action),
pushWasMeantForThisAccount, pushWasMeantForThisAccount,
pingCandidates); pingCandidates);
} }
if (pingNow) { if (pingNow) {
for (Account account : pingCandidates) { for (final Account account : pingCandidates) {
final boolean lowTimeout = isInLowPingTimeoutMode(account); final boolean lowTimeout = isInLowPingTimeoutMode(account);
account.getXmppConnection().sendPing(); account.getXmppConnection().sendPing();
Log.d(Config.LOGTAG, account.getJid().asBareJid() + " send ping (action=" + action + ",lowTimeout=" + lowTimeout + ")"); Log.d(
scheduleWakeUpCall(lowTimeout ? Config.LOW_PING_TIMEOUT : Config.PING_TIMEOUT, account.getUuid().hashCode()); 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); WakeLockHelper.release(wakeLock);

View file

@ -13,14 +13,12 @@ import android.provider.Settings;
public class PhoneHelper { public class PhoneHelper {
@SuppressLint("HardwareIds") @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); return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
} }
public static Uri getProfilePictureUri(Context context) { public static Uri getProfilePictureUri(final Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M if (context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
&& context.checkSelfPermission(Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
return null; return null;
} }
final String[] projection = new String[] {Profile._ID, Profile.PHOTO_URI}; final String[] projection = new String[] {Profile._ID, Profile.PHOTO_URI};