Skip to content

Commit

Permalink
Hide sync entries in system accounts (#1214)
Browse files Browse the repository at this point in the history
Hide sync entries in system settings; don't allow to manage accounts over system accounts anymore
  • Loading branch information
rfc2822 authored Jan 1, 2025
1 parent 365f879 commit 4cbe03b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.os.bundleOf
import at.bitfire.davdroid.ui.setup.LoginActivity
import at.bitfire.davdroid.R


/**
Expand All @@ -27,20 +27,21 @@ class AccountAuthenticatorService: Service() {
}

override fun onBind(intent: Intent?) =
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }


private class AccountAuthenticator(
val context: Context
val context: Context
): AbstractAccountAuthenticator(context) {

override fun addAccount(response: AccountAuthenticatorResponse?, accountType: String?, authTokenType: String?, requiredFeatures: Array<String>?, options: Bundle?): Bundle {
val intent = Intent(context, LoginActivity::class.java)
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response)
return bundleOf(AccountManager.KEY_INTENT to intent)
}
override fun addAccount(response: AccountAuthenticatorResponse?, accountType: String?, authTokenType: String?, requiredFeatures: Array<String>?, options: Bundle?) =
bundleOf(
AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE to response,
AccountManager.KEY_ERROR_CODE to AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
AccountManager.KEY_ERROR_MESSAGE to context.getString(R.string.account_prefs_use_app)
)

override fun editProperties(response: AccountAuthenticatorResponse?, accountType: String?) = null
override fun editProperties(response: AccountAuthenticatorResponse?, accountType: String?) = null
override fun getAuthTokenLabel(p0: String?) = null
override fun confirmCredentials(p0: AccountAuthenticatorResponse?, p1: Account?, p2: Bundle?) = null
override fun updateCredentials(p0: AccountAuthenticatorResponse?, p1: Account?, p2: String?, p3: Bundle?) = null
Expand All @@ -49,4 +50,4 @@ class AccountAuthenticatorService: Service() {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.os.bundleOf
import at.bitfire.davdroid.ui.AccountsActivity
import at.bitfire.davdroid.R

class AddressBookAuthenticatorService: Service() {

Expand All @@ -23,18 +23,18 @@ class AddressBookAuthenticatorService: Service() {
}

override fun onBind(intent: Intent?) =
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }
accountAuthenticator.iBinder.takeIf { intent?.action == AccountManager.ACTION_AUTHENTICATOR_INTENT }


private class AccountAuthenticator(
val context: Context
val context: Context
): AbstractAccountAuthenticator(context) {

override fun addAccount(response: AccountAuthenticatorResponse?, accountType: String?, authTokenType: String?, requiredFeatures: Array<String>?, options: Bundle?): Bundle {
val intent = Intent(context, AccountsActivity::class.java)
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response)
return bundleOf(AccountManager.KEY_INTENT to intent)
}
override fun addAccount(response: AccountAuthenticatorResponse?, accountType: String?, authTokenType: String?, requiredFeatures: Array<String>?, options: Bundle?) = bundleOf(
AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE to response,
AccountManager.KEY_ERROR_CODE to AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
AccountManager.KEY_ERROR_MESSAGE to context.getString(R.string.account_prefs_use_app)
)

override fun editProperties(response: AccountAuthenticatorResponse?, accountType: String?) = null
override fun getAuthTokenLabel(p0: String?) = null
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<string name="account_type" translatable="false">bitfire.at.davdroid</string>
<string name="account_type_address_book" translatable="false">at.bitfire.davdroid.address_book</string>
<string name="account_title_address_book">DAVx⁵ Address book</string>
<string name="account_prefs_use_app">Don\'t change the account here! Directly use the app to manage accounts instead.</string>
<string name="address_books_authority" translatable="false">at.bitfire.davdroid.addressbooks</string>
<string name="address_books_authority_title">Address books</string>
<string name="dialog_delete">Delete</string>
<string name="dialog_remove">Remove</string>
<string name="dialog_deny">Cancel</string>
<string name="field_required">This field is required</string>
<string name="help">Help</string>
<string name="manage_accounts">Manage accounts</string>
<string name="navigate_up">Navigate up</string>
<string name="optional_label">* optional</string>
<string name="options_menu">Options menu</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/xml/sync_calendars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:contentAuthority="com.android.calendar"
android:userVisible="false"
android:allowParallelSyncs="true"
android:supportsUploading="true" />
android:supportsUploading="true" />
3 changes: 2 additions & 1 deletion app/src/main/res/xml/sync_contacts.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type_address_book"
android:contentAuthority="com.android.contacts"
android:userVisible="false"
android:allowParallelSyncs="true"
android:supportsUploading="true" />
android:supportsUploading="true" />
1 change: 1 addition & 0 deletions app/src/main/res/xml/sync_notes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:contentAuthority="at.techbee.jtx.provider"
android:userVisible="false"
android:allowParallelSyncs="true"
android:supportsUploading="true" />
3 changes: 2 additions & 1 deletion app/src/main/res/xml/sync_opentasks.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:contentAuthority="org.dmfs.tasks"
android:userVisible="false"
android:allowParallelSyncs="true"
android:supportsUploading="true" />
android:supportsUploading="true" />
11 changes: 3 additions & 8 deletions app/src/main/res/xml/sync_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<PreferenceScreen android:title="@string/manage_accounts">
<intent
android:targetPackage="at.bitfire.davdroid"
android:targetClass="at.bitfire.davdroid.ui.AccountsActivity"
android:action="ACTION_VIEW" />
</PreferenceScreen>

</PreferenceScreen>
<PreferenceCategory android:title="@string/account_prefs_use_app"/>

</PreferenceScreen>
3 changes: 2 additions & 1 deletion app/src/main/res/xml/sync_tasks_org.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:contentAuthority="org.tasks.opentasks"
android:userVisible="false"
android:allowParallelSyncs="true"
android:supportsUploading="true" />
android:supportsUploading="true" />

0 comments on commit 4cbe03b

Please sign in to comment.