access Android_id only on push
This commit is contained in:
parent
5fa1caf7ee
commit
1cfc5d426e
|
@ -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
|
||||||
interactive,
|
&& CryptoHelper.getAccountFingerprint(account, androidId)
|
||||||
"ui".equals(action),
|
.equals(pushedAccountHash);
|
||||||
pushWasMeantForThisAccount,
|
pingNow |=
|
||||||
pingCandidates);
|
processAccountState(
|
||||||
|
account,
|
||||||
|
interactive,
|
||||||
|
"ui".equals(action),
|
||||||
|
pushWasMeantForThisAccount,
|
||||||
|
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);
|
||||||
|
|
|
@ -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};
|
||||||
|
|
Loading…
Reference in a new issue