-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Fix synchronized contacts not appearing in some contact apps
Certain contact apps require the account to be syncable. In order to do this, we implement a stubbed sync service and adapter which does nothing and ask Android not to call it. Preexisting installations of the app will need to turn contact synchronization off and on again to receive this fix. Closes #6568. Co-authored-by: paw <[email protected]>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app-android/app/src/main/java/de/tutao/tutanota/StubSyncService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.tutao.tutanota | ||
|
||
import android.accounts.Account | ||
import android.app.Service | ||
import android.content.AbstractThreadedSyncAdapter | ||
import android.content.ContentProviderClient | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.SyncResult | ||
import android.os.Bundle | ||
import android.os.IBinder | ||
import android.util.Log | ||
|
||
private const val TAG = "Sync" | ||
|
||
/** A stubbed sync service that returns a stubbed sync adapter on `onBind()`. | ||
* It is used to mark Tuta accounts as syncable as a fix for #6568 */ | ||
class StubSyncService : Service() { | ||
override fun onCreate() { | ||
synchronized(syncAdapterLock) { | ||
syncAdapter = syncAdapter ?: StubSyncAdapter(applicationContext, true) | ||
} | ||
} | ||
|
||
override fun onBind(intent: Intent): IBinder { | ||
return syncAdapter?.syncAdapterBinder ?: throw IllegalStateException() | ||
} | ||
|
||
companion object { | ||
private var syncAdapter: StubSyncAdapter? = null | ||
private val syncAdapterLock = Any() | ||
} | ||
} | ||
|
||
/** A stubbed sync adapter that does nothing when called. */ | ||
private class StubSyncAdapter @JvmOverloads constructor( | ||
context: Context, | ||
autoInitialize: Boolean, | ||
allowParallelSyncs: Boolean = false, | ||
) : AbstractThreadedSyncAdapter(context, autoInitialize, allowParallelSyncs) { | ||
|
||
override fun onPerformSync( | ||
account: Account, | ||
extras: Bundle, | ||
authority: String, | ||
provider: ContentProviderClient, | ||
syncResult: SyncResult | ||
) { | ||
Log.w(TAG, "Sync requested to stub Sync Adapter!") | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!--Declare the stubbed sync adapter to fix #6568--> | ||
<sync-adapter | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:contentAuthority="com.android.contacts" | ||
android:accountType="@string/package_name" | ||
android:userVisible="false" | ||
android:supportsUploading="false" | ||
android:allowParallelSyncs="false" | ||
android:isAlwaysSyncable="true" | ||
/> |