Introducing a new way to review your PRs.

Read the announcement

ayugram / ayugram4a

Just an exteraGram based client with ToS breaking features in mind.

View on GitHub

13 documents · Updated Nov 19, 2026

docs / auth-accounts-settings

Auth, Accounts, Settings, Privacy, Data, and Proxy

Overview

Owned coverage is the Android account/authentication and user-settings surface rooted in TMessagesProj/…/LoginActivity.java, PasscodeActivity.java, TwoStepVerification*.java, SessionsActivity.java, SessionBottomSheet.java, LogoutActivity.java, Privacy*.java, Data*.java, Proxy*.java, Change*.java, and QuickRepliesSettingsActivity.java; the platform integration helpers TMessagesProj/…/AuthenticatorService.java, AuthTokensHelper.java, ContactsSyncAdapterService.java, LocaleController.java, ProxyRotationController.java, SharedPrefsHelper.java, and SmsReceiver.java; and the Android XML/localization resources TMessagesProj/…/auth*.xml, contacts.xml, and values*/strings.xml.

TMessagesProj/…/LoginActivity.java is the login/change-phone/change-login-email flow. It models its screen stack with numeric view constants for phone input, app/SMS/call/missed-call/fragment-SMS/email code entry, registration, two-step password, recovery, password reset wait, new password setup, and email setup. Network state is driven through ConnectionsManager.sendRequest with TLRPC.TL_auth_* requests, then routed by fillNextCodeParams(...) into the proper code-entry view. Success is centralized in onAuthSuccess(...): it stores future auth tokens with AuthTokensHelper, loads controller state through MessagesController, MessagesStorage, ContactsController, and MediaDataController, and finishes by entering the main UI or forcing password setup when the server requests it. Automatic SMS code capture is outside the activity: TMessagesProj/…/SmsReceiver.java listens for Google SMS Retriever broadcasts, parses the first numeric code, records the sms_hash|code pair in mainconfig when a hash is present, and posts NotificationCenter.didReceiveSmsCode for the login code views.

TMessagesProj/…/PasscodeActivity.java is local app-lock management, not Telegram account password. It edits global SharedConfig passcode state (passcodeHash, salt, passcode type, bad-try throttling, fingerprint/biometric toggle, auto-lock duration, and screenshot allowance), persists it with SharedConfig.saveConfig() / UserConfig.saveConfig(false), and announces changes through global NotificationCenter.didSetPasscode. It has three entry modes: manage settings, create a passcode, or enter the existing passcode before settings. LogoutActivity.java routes to this screen when logout alternatives offer passcode setup.

Two-step verification is split between TMessagesProj/…/TwoStepVerificationActivity.java and TwoStepVerificationSetupActivity.java. The activity loads TL_account_getPassword, handles password entry and reset/recovery requests, and exposes the enabled/disabled settings rows. Setup performs the multi-step create/change/remove/recovery-email flow, computes SRP proofs and new password material with SRPHelper/Utilities, sends TL_account_updatePasswordSettings, TL_auth_recoverPassword, TL_account_confirmPasswordEmail, and related requests, and notifies the rest of the account settings UI with NotificationCenter.twoStepPasswordChanged, didSetOrRemoveTwoStepPassword, and didRemoveTwoStepPassword.

Session management lives in TMessagesProj/…/SessionsActivity.java and SessionBottomSheet.java. SessionsActivity loads either device authorizations (TL_account_getAuthorizations) or web authorizations (TL_account_getWebAuthorizations), separates current, password-pending, and other sessions, supports session TTL via TL_account_setAuthorizationTTL, and revokes individual/all sessions with TL_account_resetAuthorization, TL_auth_resetAuthorizations, TL_account_resetWebAuthorization, or TL_account_resetWebAuthorizations. It also hosts QR login for another client. SessionBottomSheet displays device metadata and sends TL_account_changeAuthorizationSettings when toggling whether a remote authorization can accept secret chats or calls.

TMessagesProj/…/LogoutActivity.java is a settings detour before actual logout. It offers adding an account (LoginActivity for a free account slot), passcode setup, cache control, phone-number change intro, support, and finally calls MessagesController.performLogout(1) after confirmation. Logout/login future-token persistence is handled by TMessagesProj/…/AuthTokensHelper.java, which serializes up to 20 TL_auth_loggedOut tokens into saved_tokens and up to 20 TL_auth_authorization future-login tokens into saved_tokens_login, using SerializedData hex strings and requesting backup after writes.

Privacy and security settings are anchored at TMessagesProj/…/PrivacySettingsActivity.java. On create it asks ContactsController to load privacy settings, asks MessagesController to load blocked peers, preloads SessionsActivity, fetches two-step password status, and subscribes to privacy/session/password/autodelete notifications. Rows route to blocked users (PrivacyUsersActivity), active sessions (SessionsActivity), web sessions, account self-delete TTL (TL_account_setAccountTTL), last seen/phone/group/call/photo/forward/voice-message controls (PrivacyControlActivity with ContactsController.PRIVACY_RULES_TYPE_*), login email change (LoginActivity.changeEmail(...)), two-step setup, local passcode, secret map/webpage-preview flags, contact sync/suggestions, contact deletion, passport, and payment clearing. PrivacyControlActivity edits the rule set for one privacy type, including plus/minus exception lists through PrivacyUsersActivity; it also handles fallback profile-photo upload with TL_photos_uploadProfilePhoto. PrivacyUsersActivity is reused for blocked peers and privacy exception lists, using MessagesController.blockPeer/unblockPeer for the blocked-users mode and a delegate callback for exception-list edits.

Profile/account edit screens are thin wrappers over account API calls and local caches. TMessagesProj/…/ChangeNameActivity.java sends TL_account_updateProfile for first/last name, updates UserConfig and MessagesController, and posts user-info/update-interface notifications. ChangeBioActivity.java enforces MessagesController.getAboutLimit(), sends TL_account_updateProfile with about, and refreshes UserFull. ChangeUsernameActivity.java supports primary username checking/updating (TL_account_checkUsername, TL_account_updateUsername), active/inactive username toggling, and username reordering for the current user or a bot, updating MessagesController/MessagesStorage and posting interface updates.

Data/storage settings are centered in TMessagesProj/…/DataSettingsActivity.java. It loads auto-download config through DownloadController, shows storage usage via CacheControlActivity.calculateTotalSize, routes to storage usage/cache control, network usage (DataUsageActivity or DataUsage2Activity), per-network auto-download editors (DataAutoDownloadActivity for mobile/Wi-Fi/roaming), save-to-gallery settings, streaming toggles, VoIP data-saving preferences, proxy settings, and draft clearing. DataAutoDownloadActivity.java edits DownloadController.Preset objects and writes current preset keys (mobilePreset, wifiPreset, roamingPreset and their current preset numbers). DataUsageActivity.java and DataUsage2Activity.java read and reset traffic counters from StatsController by network type and media type.

Proxy configuration has a list/details split. TMessagesProj/…/ProxyListActivity.java loads SharedConfig.proxyList, mirrors proxy_enabled and proxy_enabled_calls from MessagesController.getGlobalMainSettings(), checks proxy pings with ConnectionsManager.checkProxy, applies the selected proxy through ConnectionsManager.setProxySettings(...), and broadcasts NotificationCenter.proxySettingsChanged. It also controls proxy rotation (SharedConfig.proxyRotationEnabled and SharedConfig.proxyRotationTimeout) and deletes/shares selected proxies. ProxySettingsActivity.java edits one SOCKS5 or MTProto proxy, parses/pastes/share-links, persists proxy fields (proxy_ip, proxy_port, proxy_user, proxy_pass, proxy_secret) in global main settings when the proxy is current/new, and calls SharedConfig.addProxy/saveProxyList(). TMessagesProj/…/ProxyRotationController.java observes connection-state and proxy notifications across accounts, waits for the configured timeout while connecting to proxy, checks all proxies, and switches to the lowest-ping available proxy by writing the same global settings keys and calling ConnectionsManager.setProxySettings(...).

Android account and contacts integration is intentionally minimal. TMessagesProj/…/auth.xml declares the authenticator account type org.telegram.messenger, app icon/label, and @xml/auth_menu; auth_menu.xml exposes an Android account settings entry whose intent opens org.telegram.ui.LaunchActivity with org.telegram.messenger.OPEN_ACCOUNT. TMessagesProj/…/AuthenticatorService.java returns an AbstractAccountAuthenticator binder only for AccountManager.ACTION_AUTHENTICATOR_INTENT, but all authenticator methods return null except default removal handling. TMessagesProj/…/contacts.xml declares Telegram profile/audio-call/video-call contact MIME rows; ContactsSyncAdapterService.java supplies an AbstractThreadedSyncAdapter binder and currently only logs performSync, while actual contact import/sync toggles are controlled by PrivacySettingsActivity via UserConfig.syncContacts, ContactsController.forceImportContacts(), and ContactsController.deleteAllContacts(...).

Localization/config is owned by TMessagesProj/…/LocaleController.java plus TMessagesProj/…/strings.xml. Built-in strings are resolved through generated R.string resources; remote, local, and unofficial language packs are represented by LocaleInfo, saved in langconfig, and applied by applyLanguage(...), which updates ConnectionsManager language code, writes the selected language key to global main settings, reloads local XML overrides when needed, changes Android Resources configuration, recreates formatters, and posts NotificationCenter.reloadInterface. Remote language lists and packs use TL_langpack_getLanguages, TL_langpack_getDifference, and TL_langpack_getLangPack with RequestFlagWithoutLogin, then saveRemoteLocaleStrings(...) writes remote_*.xml / base files and posts reload/suggested-langpack notifications.

TMessagesProj/…/SharedPrefsHelper.java is a small account-scoped preference helper for WebView bot confirmation state in the webview_bots preferences file. It matters to account cleanup: cleanupAccount(account) removes keys prefixed with confirm_shown_<account>_ so per-account webview consent does not leak after account removal.

Path-routing notes: these are fragment screens, not standalone Android activities. Navigation is mostly by presentFragment(...) from settings rows (PrivacySettingsActivity, DataSettingsActivity, LogoutActivity, and profile screens). Direct OS entry into this area comes through auth_menu.xml targeting LaunchActivity, which must then route account-settings intents into the fragment stack. Login sub-flows are internal SlideViews inside LoginActivity; passcode and two-step flows use separate fragment classes for durable settings routes.

Coupling

  • If any login authorization result handling changes in TMessagesProj/…/LoginActivity.java, also verify TMessagesProj/…/AuthTokensHelper.java: LoginActivity.onAuthSuccess(...) saves future_auth_token data in the helper's serialized saved_tokens_login format, and bad serialization/deserialization prevents future-token reuse across installs/backups.
  • If SMS auto-fill behavior changes in LoginActivity.java, also check TMessagesProj/…/SmsReceiver.java and the mainconfig keys sms_hash / sms_hash_code; the receiver posts only NotificationCenter.didReceiveSmsCode, so code-entry views must remain subscribed through NotificationCenter rather than expecting a direct callback.
  • If two-step password fields or algorithms change in TwoStepVerificationActivity.java or TwoStepVerificationSetupActivity.java, verify SRPHelper, TLRPC.account_Password fields, and all password notifications consumed by PrivacySettingsActivity.java; the privacy settings row state depends on didSetOrRemoveTwoStepPassword and twoStepPasswordChanged, not on reloading the full settings screen.
  • If proxy preference keys or SharedConfig.ProxyInfo fields change, update ProxyListActivity.java, ProxySettingsActivity.java, and ProxyRotationController.java together. All three write/read proxy_ip, proxy_port, proxy_user, proxy_pass, proxy_secret, and proxy_enabled, and rotation silently bypasses the UI before calling ConnectionsManager.setProxySettings(...).
  • If contact sync toggles change in PrivacySettingsActivity.java, verify Android account XML (res/…/auth.xml, res/…/contacts.xml) and ContactsSyncAdapterService.java; Android exposes Telegram contact MIME rows and a sync adapter even though the service body only logs, while actual import/delete behavior is driven by ContactsController from the privacy screen.
  • If a new settings row opens a covered fragment, wire it through an existing fragment route rather than an Android manifest activity: auth_menu.xml only targets LaunchActivity, and covered screens expect BaseFragment.currentAccount, controller singletons, and NotificationCenter lifecycle from the Telegram fragment stack.
  • If localization keys are added or renamed in these screens, update the base TMessagesProj/…/strings.xml and any maintained values-* files, then check LocaleController.getString(...) fallback behavior; remote language packs can override keys at runtime and trigger NotificationCenter.reloadInterface without recreating the process.

Risks

  • TMessagesProj/…/ProxyRotationController.java linearly sorts proxies by ping and switches on global SharedConfig.currentProxy; if unavailable proxies keep stale ping/available state, rotation can select an old proxy and apply it globally with ConnectionsManager.setProxySettings(...), affecting every account using the shared proxy setting.
  • TMessagesProj/…/PasscodeActivity.java stores the app passcode in global SharedConfig, while UserConfig.saveConfig(false) is called for some toggle paths; if new passcode settings are made account-scoped without auditing these writes, one account can unexpectedly change app-lock behavior for all accounts.
  • TMessagesProj/…/LocaleController.java rewrites Android Resources configuration and posts global reloadInterface after remote XML parsing; malformed or partially downloaded language files cause fallback/reload paths, so changes to XML parsing or LocaleInfo persistence can leave the UI with missing strings until the next successful remote pack reload.