Skip to content

Commit bb69dde

Browse files
authored
Fix/custom backend (#2113)
* Rename BackendSelector to BackendController * Update comment * Update changes for SE * WIP: backend urls * Bind BackendController as a global controller * Refactor browser controller * Reload blacklist when switching BE * Wrap host placeholders in delimiters * Escape delimiters in regex * Tidy up * Pin SE * Clean up string identifiers * Bump SE
1 parent ef20c89 commit bb69dde

33 files changed

+250
-188
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ext {
2222
playServicesVersion = '15.0.1'
2323
audioVersion = System.getenv("AUDIO_VERSION") ?: '1.209.0@aar'
2424
stethoVersion = '1.5.0'
25-
zMessagingVersion = "141.0.2266"
25+
zMessagingVersion = "141.0.2267"
2626
paging_version = "1.0.0"
2727

2828
avsVersion = '4.9.170@aar'

app/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@
518518
<string name="pref_about_tos_title">Terms of Use</string>
519519
<string name="pref_about_privacy_policy_title">Privacy Policy</string>
520520
<string name="pref_about_licenses_title">License information</string>
521-
<string name="pref_about_licenses_url">@string/url_third_party_licences</string>
522521
<string name="pref_about_version_title">Version %s</string>
523522
<string name="pref_about_copyright_title">\u00A9 Wire Swiss GmbH</string>
524523

app/src/main/res/values/strings_no_translate.xml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,36 +175,36 @@
175175
<string translatable="false" name="pref_dev_category_sign_in_account_title">Sign into account</string>
176176
<string translatable="false" name="pref_dev_category_sign_in_account_summary">Sign into another account and switch to that one</string>
177177

178-
<string translatable="false" name="pref_manage_team_url">https://teams.wire.com/login/?utm_source=client_settings&amp;utm_term=android</string>
179-
180-
<string translatable="false" name="pick_user_manage_team_url">https://teams.wire.com/login/?utm_source=client_landing&amp;utm_term=android</string>
181-
182-
<string translatable="false" name="invalid_email_help">https://support.wire.com/hc/en-us/articles/115004082129-My-email-address-is-already-in-use-and-I-cannot-create-an-account-What-can-I-do-</string>
183-
<string translatable="false" name="teams_set_email_about_url">https://support.wire.com/hc/en-us/articles/115004082129</string>
184-
185-
<string translatable="false" name="url_home">https://wire.com</string>
186-
<string translatable="false" name="url_terms_of_service_personal">https://wire.com/legal/terms/personal/</string>
187-
<string translatable="false" name="url_terms_of_service_teams">https://wire.com/legal/terms/teams/</string>
188-
<string translatable="false" name="url_privacy_policy">https://wire.com/legal/privacy/embed/</string>
189-
<string translatable="false" name="url__help">https://support.wire.com</string>
190-
191-
<string translatable="false" name="url_password_reset">https://account.wire.com/forgot/</string>
192-
<string translatable="false" name="url_password_reset_staging">https://wire-account-staging.zinfra.io/forgot/</string>
193-
194-
<string translatable="false" name="url_third_party_licences">https://wire.com/legal/#licenses</string>
195-
<string translatable="false" name="url_otr_learn_why">https://wire.com/privacy/why</string>
196-
<string translatable="false" name="url_otr_learn_how">https://wire.com/privacy/how</string>
197-
<string translatable="false" name="url_otr_decryption_error_1">https://wire.com/privacy/error-1</string>
198-
<string translatable="false" name="url_otr_decryption_error_2">https://wire.com/privacy/error-2</string>
199-
<string translatable="false" name="url_about_teams">https://wire.com/products/pro-secure-team-collaboration/</string>
200-
201-
<string translatable="false" name="url_manage_services">https://teams.wire.com/</string>
202-
<string translatable="false" name="url_manage_services_staging">https://wire-admin-dev.zinfra.io/services/</string>
203-
<string translatable="false" name="usernames__learn_more__link">https://wire.com/support/username/</string>
204-
<string translatable="false" name="pref_support_website_url">https://support.wire.com</string>
205-
<string translatable="false" name="pref_support_contact_url">https://support.wire.com/hc/requests/new</string>
206-
<string translatable="false" name="pref_about_website_url">https://wire.com</string>
207-
178+
<!--
179+
The prefixes |ACCOUNTS|, |TEAMS|, and |WEBSITE| are placeholders for hosts. These are
180+
replaced at runtime with corresponding endpoints defined in the BackendConfig.
181+
Custom whitelabel versions can overwrite these with urls (without prefixes of course).
182+
-->
183+
184+
<string translatable="false" name="url_password_forgot">|ACCOUNTS|/forgot/</string>
185+
186+
<string translatable="false" name="url_pref_manage_team">|TEAMS|/login/?utm_source=client_settings&amp;utm_term=android</string>
187+
<string translatable="false" name="url_start_ui_manage_team">|TEAMS|/login/?utm_source=client_landing&amp;utm_term=android</string>
188+
<string translatable="false" name="url_manage_services">|TEAMS|/services</string>
189+
190+
<string translatable="false" name="url_home">|WEBSITE|</string>
191+
<string translatable="false" name="url_about_website">|WEBSITE|</string>
192+
<string translatable="false" name="url_about_teams">|WEBSITE|/products/pro-secure-team-collaboration/</string>
193+
<string translatable="false" name="url_usernames_learn_more">|WEBSITE|/support/username/</string>
194+
<string translatable="false" name="url_terms_of_service_personal">|WEBSITE|/legal/terms/personal/</string>
195+
<string translatable="false" name="url_terms_of_service_teams">|WEBSITE|/legal/terms/teams/</string>
196+
<string translatable="false" name="url_privacy_policy">|WEBSITE|/legal/privacy/embed/</string>
197+
<string translatable="false" name="url_third_party_licences">|WEBSITE|/legal/#licenses</string>
198+
<string translatable="false" name="url_otr_learn_why">|WEBSITE|/privacy/why</string>
199+
<string translatable="false" name="url_otr_learn_how">|WEBSITE|/privacy/how</string>
200+
<string translatable="false" name="url_otr_decryption_error_1">|WEBSITE|/privacy/error-1</string>
201+
<string translatable="false" name="url_otr_decryption_error_2">|WEBSITE|/privacy/error-2</string>
202+
203+
<string translatable="false" name="url_help">https://support.wire.com</string>
204+
<string translatable="false" name="url_support_website">https://support.wire.com</string>
205+
<string translatable="false" name="url_contact_support">https://support.wire.com/hc/requests/new</string>
206+
<string translatable="false" name="url_invalid_email_help">https://support.wire.com/hc/en-us/articles/115004082129-My-email-address-is-already-in-use-and-I-cannot-create-an-account-What-can-I-do-</string>
207+
<string translatable="false" name="url_teams_set_email_about">https://support.wire.com/hc/en-us/articles/115004082129</string>
208208

209209
</resources>
210210

app/src/main/scala/com/waz/zclient/Backend.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ object Backend {
4545
baseUrl = "https://staging-nginz-https.zinfra.io",
4646
websocketUrl = "https://staging-nginz-ssl.zinfra.io/await",
4747
blacklistHost = s"https://clientblacklist.wire.com/staging/android",
48+
teamsUrl = "https://wire-teams-staging.zinfra.io",
49+
accountsUrl = "https://wire-account-staging.zinfra.io",
50+
websiteUrl = "https://wire.com",
4851
StagingFirebaseOptions,
4952
certPin)
5053

@@ -53,6 +56,9 @@ object Backend {
5356
BuildConfig.BACKEND_URL,
5457
BuildConfig.WEBSOCKET_URL,
5558
BuildConfig.BLACKLIST_HOST,
59+
teamsUrl = "https://teams.wire.com",
60+
accountsUrl = "https://account.wire.com",
61+
websiteUrl = "https://wire.com",
5662
ProdFirebaseOptions,
5763
certPin)
5864
}

app/src/main/scala/com/waz/zclient/CredentialsFragment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class SetOrRequestPasswordFragment extends CredentialsFragment {
374374
confirmationButton.foreach(_.setAccentColor(Color.WHITE))
375375

376376
Option(findById[View](R.id.ttv_signin_forgot_password)).foreach { forgotPw =>
377-
forgotPw.onClick(inject[BrowserController].openForgotPasswordPage())
377+
forgotPw.onClick(inject[BrowserController].openForgotPassword())
378378
forgotPw.setVisibility(if (hasPw) View.VISIBLE else View.INVISIBLE)
379379
}
380380

app/src/main/scala/com/waz/zclient/LaunchActivity.scala

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,59 @@
1818

1919
package com.waz.zclient
2020

21-
import android.content.Intent
21+
import android.app.AlertDialog
22+
import android.content.{DialogInterface, Intent}
2223
import android.support.v7.app.AppCompatActivity
2324
import com.waz.log.BasicLogging.LogTag
2425
import com.waz.log.BasicLogging.LogTag.DerivedLogTag
25-
import com.waz.service.AccountsService
26+
import com.waz.service.{AccountsService, BackendConfig}
2627
import com.waz.threading.Threading
2728
import com.waz.zclient.appentry.AppEntryActivity
2829
import com.waz.zclient.log.LogUI._
29-
import com.waz.zclient.utils.BackendSelector
30+
import com.waz.zclient.utils.BackendController
3031

3132
class LaunchActivity extends AppCompatActivity with ActivityHelper with DerivedLogTag {
3233

34+
private lazy val backendController = inject[BackendController]
35+
3336
override def onStart() = {
3437
super.onStart()
3538

36-
new BackendSelector()(this).selectBackend { be =>
39+
val callback: BackendConfig => Unit = { be =>
3740
getApplication.asInstanceOf[WireApplication].ensureInitialized(be)
3841
inject[AccountsService].activeAccountId.head(LogTag("BackendSelector")).map {
3942
case Some(_) => startMain()
4043
case _ => startSignUp()
4144
}(Threading.Ui)
4245
}
46+
47+
if (backendController.shouldShowBackendSelector) showDialog(callback)
48+
else callback(backendController.getStoredBackendConfig.getOrElse(Backend.ProdBackend))
49+
}
50+
51+
/// Presents a dialog to select backend.
52+
private def showDialog(callback: BackendConfig => Unit): Unit = {
53+
val environments = Backend.byName
54+
val items: Array[CharSequence] = environments.keys.toArray
55+
56+
val builder = new AlertDialog.Builder(this)
57+
builder.setTitle("Select Backend")
58+
59+
builder.setItems(items, new DialogInterface.OnClickListener {
60+
override def onClick(dialog: DialogInterface, which: Int): Unit = {
61+
val choice = items.apply(which).toString
62+
val config = environments.apply(choice)
63+
backendController.setStoredBackendConfig(config)
64+
callback(config)
65+
}
66+
})
67+
68+
builder.setCancelable(false)
69+
builder.create().show()
70+
71+
// QA needs to be able to switch backends via intents. Any changes to the backend
72+
// preference while the dialog is open will be treated as a user selection.
73+
backendController.onPreferenceSet(callback)
4374
}
4475

4576
override protected def onNewIntent(intent: Intent) = {

app/src/main/scala/com/waz/zclient/SetHandleFragment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SetHandleFragment extends BaseFragment[SetHandleFragment.Container] with F
111111

112112
summaryTextView.foreach { summaryTextView =>
113113
TextViewUtils.linkifyText(summaryTextView, Color.WHITE, R.string.wire__typeface__light, false, new Runnable() {
114-
def run(): Unit = browser.openUrl(getString(R.string.usernames__learn_more__link))
114+
def run(): Unit = browser.openUserNamesLearnMore()
115115
})
116116
}
117117

app/src/main/scala/com/waz/zclient/WireApplication.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import com.waz.zclient.pages.main.pickuser.controller.IPickUserController
8686
import com.waz.zclient.participants.ParticipantsController
8787
import com.waz.zclient.preferences.PreferencesController
8888
import com.waz.zclient.tracking.{CrashController, GlobalTrackingController, UiTrackingController}
89-
import com.waz.zclient.utils.{AndroidBase64Delegate, BackStackNavigator, BackendSelector, ExternalFileSharing, LocalThumbnailCache, UiStorage}
89+
import com.waz.zclient.utils.{AndroidBase64Delegate, BackStackNavigator, BackendController, ExternalFileSharing, LocalThumbnailCache, UiStorage}
9090
import com.waz.zclient.views.DraftMap
9191
import javax.net.ssl.SSLContext
9292
import org.threeten.bp.Clock
@@ -201,6 +201,7 @@ object WireApplication extends DerivedLogTag {
201201
bind [IConfirmationController] toProvider controllerFactory.getConfirmationController
202202

203203
// global controllers
204+
bind [BackendController] to new BackendController()
204205
bind [WebSocketController] to new WebSocketController
205206
bind [CrashController] to new CrashController
206207
bind [AccentColorController] to new AccentColorController()
@@ -366,7 +367,7 @@ class WireApplication extends MultiDexApplication with WireContext with Injectab
366367

367368
controllerFactory = new ControllerFactory(getApplicationContext)
368369

369-
new BackendSelector()(this).getStoredBackendConfig.foreach { be =>
370+
inject[BackendController].getStoredBackendConfig.foreach { be =>
370371
ensureInitialized(be)
371372
}
372373
}

app/src/main/scala/com/waz/zclient/appentry/AppEntryActivity.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import com.waz.zclient.newreg.fragments.country.CountryController
4646
import com.waz.zclient.ui.text.{GlyphTextView, TypefaceTextView}
4747
import com.waz.zclient.ui.utils.KeyboardUtils
4848
import com.waz.zclient.utils.ContextUtils.{showConfirmationDialog, showErrorDialog}
49-
import com.waz.zclient.utils.{BackendSelector, ContextUtils, RichView, ViewUtils}
49+
import com.waz.zclient.utils.{BackendController, ContextUtils, RichView, ViewUtils}
5050
import com.waz.zclient.views.LoadingIndicatorView
5151

5252
import scala.collection.JavaConverters._
@@ -189,7 +189,7 @@ class AppEntryActivity extends BaseActivity {
189189
verbose(l"got config response: $config")
190190
enableProgress(false)
191191

192-
new BackendSelector().switchBackend(inject[GlobalModule], config, configUrl)
192+
inject[BackendController].switchBackend(inject[GlobalModule], config, configUrl)
193193
verbose(l"switched backend")
194194

195195
// re-present fragment for updated ui.

app/src/main/scala/com/waz/zclient/appentry/AppEntryDialogs.scala

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@
1818
package com.waz.zclient.appentry
1919

2020
import android.content.DialogInterface.OnDismissListener
21-
import android.content.Intent.{ACTION_VIEW, FLAG_ACTIVITY_NEW_TASK}
22-
import android.content.{Context, DialogInterface, Intent}
23-
import android.net.Uri
21+
import android.content.{Context, DialogInterface}
2422
import android.support.v7.app.AlertDialog
2523
import com.waz.log.BasicLogging.LogTag.DerivedLogTag
26-
import com.waz.utils.returning
2724
import com.waz.zclient.R
28-
import com.waz.zclient.log.LogUI._
25+
import com.waz.zclient.common.controllers.BrowserController
2926

3027
import scala.concurrent.{Future, Promise}
3128

3229
object AppEntryDialogs extends DerivedLogTag {
33-
def showTermsAndConditions(context: Context): Future[Boolean] = {
30+
def showTermsAndConditions(context: Context, browser: BrowserController): Future[Boolean] = {
3431
val dialogResult = Promise[Boolean]()
3532
val dialog = new AlertDialog.Builder(context)
3633
.setPositiveButton(R.string.app_entry_dialog_accept, new DialogInterface.OnClickListener {
@@ -41,7 +38,7 @@ object AppEntryDialogs extends DerivedLogTag {
4138
})
4239
.setNeutralButton(R.string.app_entry_dialog_view, new DialogInterface.OnClickListener {
4340
override def onClick(dialog: DialogInterface, which: Int): Unit = {
44-
onOpenUrl(context, context.getString(R.string.url_terms_of_service_teams))
41+
browser.openTeamsTermsOfService()
4542
dialogResult.trySuccess(false)
4643
}
4744
})
@@ -54,7 +51,7 @@ object AppEntryDialogs extends DerivedLogTag {
5451
dialogResult.future
5552
}
5653

57-
def showNotificationsWarning(context: Context): Future[Boolean] = {
54+
def showNotificationsWarning(context: Context, browser: BrowserController): Future[Boolean] = {
5855
val dialogResult = Promise[Boolean]()
5956
val dialog = new AlertDialog.Builder(context)
6057
.setPositiveButton(R.string.app_entry_dialog_accept, new DialogInterface.OnClickListener {
@@ -65,7 +62,7 @@ object AppEntryDialogs extends DerivedLogTag {
6562
})
6663
.setNeutralButton(R.string.app_entry_dialog_view, new DialogInterface.OnClickListener {
6764
override def onClick(dialog: DialogInterface, which: Int): Unit = {
68-
onOpenUrl(context, context.getString(R.string.url_privacy_policy))
65+
browser.openPrivacyPolicy()
6966
dialogResult.trySuccess(false)
7067
}
7168
})
@@ -77,15 +74,4 @@ object AppEntryDialogs extends DerivedLogTag {
7774
dialog.show()
7875
dialogResult.future
7976
}
80-
81-
private def onOpenUrl(context: Context, url: String) = {
82-
try {
83-
val normUrl = Uri.parse(if (!url.startsWith("http://") && !url.startsWith("https://")) s"http://$url" else url)
84-
val browserIntent = returning(new Intent(ACTION_VIEW, normUrl))(_.addFlags(FLAG_ACTIVITY_NEW_TASK))
85-
context.startActivity(browserIntent)
86-
}
87-
catch {
88-
case _: Exception => error(l"Failed to open URL: ${redactedString(url)}")
89-
}
90-
}
9177
}

0 commit comments

Comments
 (0)