Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit 7f5adc1

Browse files
committed
add China sync service
1 parent 71b63e4 commit 7f5adc1

File tree

14 files changed

+134
-6
lines changed

14 files changed

+134
-6
lines changed

.idea/codeStyles/Project.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/mozilla/lockbox/action/SettingAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ open class SettingAction(
1818
data class UnlockWithFingerprint(val unlockWithFingerprint: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_fingerprint, unlockWithFingerprint.toString())
1919
data class UnlockWithFingerprintPendingAuth(val unlockWithFingerprintPendingAuth: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_fingerprint_pending_auth, unlockWithFingerprintPendingAuth.toString())
2020
data class SendUsageData(val sendUsageData: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_record_usage_data, null)
21+
data class UseLocalService(val useLocalService: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_use_local_service, null)
2122
data class ItemListSortOrder(val sortOrder: Setting.ItemListSort) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_item_list_order, null)
2223
data class AutoLockTime(val time: Setting.AutoLockTime) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_autolock_time, time.seconds.toString())
2324
data class Autofill(val enable: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_autofill, null)

app/src/main/java/mozilla/lockbox/action/TelemetryAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum class TelemetryEventObject {
7373
settings_autolock,
7474
settings_reset,
7575
settings_record_usage_data,
76+
settings_use_local_service,
7677
settings_account,
7778
settings_faq,
7879
settings_provide_feedback,

app/src/main/java/mozilla/lockbox/presenter/AppRoutePresenter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class AppRoutePresenter(
122122
R.id.fragment_welcome to R.id.fragment_fxa_login -> R.id.action_welcome_to_fxaLogin
123123
R.id.fragment_welcome to R.id.fragment_item_list -> R.id.action_welcome_to_autoLogin
124124
R.id.fragment_welcome to R.id.fragment_webview -> R.id.action_welcome_to_faq
125+
R.id.fragment_welcome to R.id.fragment_setting -> R.id.action_welcome_to_settings
125126

126127
R.id.fragment_fxa_login to R.id.fragment_item_list -> R.id.action_fxaLogin_to_itemList
127128
R.id.fragment_fxa_login to R.id.fragment_fingerprint_onboarding -> R.id.action_fxaLogin_to_fingerprint_onboarding

app/src/main/java/mozilla/lockbox/presenter/SettingPresenter.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.reactivex.Observable
1212
import io.reactivex.functions.Consumer
1313
import io.reactivex.rxkotlin.Observables
1414
import io.reactivex.rxkotlin.addTo
15+
import kotlinx.coroutines.ExperimentalCoroutinesApi
1516
import mozilla.lockbox.BuildConfig
1617
import mozilla.lockbox.R
1718
import mozilla.lockbox.action.AppWebPageAction
@@ -27,6 +28,7 @@ import mozilla.lockbox.adapter.TextSettingConfiguration
2728
import mozilla.lockbox.adapter.ToggleSettingConfiguration
2829
import mozilla.lockbox.flux.Dispatcher
2930
import mozilla.lockbox.flux.Presenter
31+
import mozilla.lockbox.store.AccountStore
3032
import mozilla.lockbox.store.FingerprintStore
3133
import mozilla.lockbox.store.SettingStore
3234

@@ -37,9 +39,12 @@ interface SettingView {
3739
)
3840
}
3941

42+
@ExperimentalCoroutinesApi
4043
class SettingPresenter(
4144
val view: SettingView,
45+
val chinaBuild: Boolean,
4246
private val dispatcher: Dispatcher = Dispatcher.shared,
47+
private val accountStore: AccountStore = AccountStore.shared,
4348
private val settingStore: SettingStore = SettingStore.shared,
4449
private val fingerprintStore: FingerprintStore = FingerprintStore.shared
4550
) : Presenter() {
@@ -83,6 +88,11 @@ class SettingPresenter(
8388
dispatcher.dispatch(SettingAction.SendUsageData(newValue))
8489
}
8590

91+
private val useLocalServiceObserver: Consumer<Boolean>
92+
get() = Consumer { newValue ->
93+
dispatcher.dispatch((SettingAction.UseLocalService(newValue)))
94+
}
95+
8696
private val learnMoreSendUsageDataObserver: Consumer<Unit>
8797
get() = Consumer {
8898
dispatcher.dispatch(AppWebPageAction.Privacy)
@@ -163,11 +173,31 @@ class SettingPresenter(
163173
)
164174
)
165175

176+
val serviceSettings = listOf(
177+
ToggleSettingConfiguration(
178+
title = R.string.use_local_service,
179+
contentDescription = R.string.use_local_service_description,
180+
toggleDriver = settingStore.useLocalService,
181+
toggleObserver = useLocalServiceObserver
182+
)
183+
)
166184
val sections = listOf(
167185
SectionedAdapter.Section(0, R.string.configuration_title),
168186
SectionedAdapter.Section(configurationSettings.size, R.string.support_title)
169187
)
188+
val sectionsSync = listOf(
189+
SectionedAdapter.Section(0, R.string.service_title),
190+
SectionedAdapter.Section(serviceSettings.size, R.string.support_title)
191+
)
170192

171-
view.updateSettingList(configurationSettings + supportSettings, sections)
193+
if (chinaBuild) {
194+
if (accountStore.checkAccountExisting()) {
195+
view.updateSettingList(configurationSettings + supportSettings, sections)
196+
} else {
197+
view.updateSettingList(serviceSettings + supportSettings, sectionsSync)
198+
}
199+
} else {
200+
view.updateSettingList(configurationSettings + supportSettings, sections)
201+
}
172202
}
173203
}

app/src/main/java/mozilla/lockbox/presenter/WelcomePresenter.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ interface WelcomeView {
2424
val getStartedAutomaticallyClicks: Observable<Unit>
2525
val getStartedManuallyClicks: Observable<Unit>
2626
val learnMoreClicks: Observable<Unit>
27+
val switchServiceClicks: Observable<Unit>
28+
fun hideSwitchService()
2729
fun showExistingAccount(email: String)
2830
fun hideExistingAccount()
2931
}
3032

3133
@ExperimentalCoroutinesApi
3234
class WelcomePresenter(
3335
private val view: WelcomeView,
36+
private val chinaBuild: Boolean,
3437
private val dispatcher: Dispatcher = Dispatcher.shared,
3538
private val accountStore: AccountStore = AccountStore.shared,
3639
private val fingerprintStore: FingerprintStore = FingerprintStore.shared
@@ -51,6 +54,10 @@ class WelcomePresenter(
5154
view.hideExistingAccount()
5255
}
5356

57+
if (!chinaBuild) {
58+
view.hideSwitchService()
59+
}
60+
5461
view.getStartedManuallyClicks
5562
.map {
5663
routeToLoginManually()
@@ -63,6 +70,13 @@ class WelcomePresenter(
6370
dispatcher.dispatch(AppWebPageAction.FaqWelcome)
6471
}
6572
.addTo(compositeDisposable)
73+
74+
view.switchServiceClicks
75+
.map {
76+
RouteAction.SettingList
77+
}
78+
.subscribe(dispatcher::dispatch)
79+
.addTo(compositeDisposable)
6680
}
6781

6882
private fun routeToExistingAccount(account: ShareableAccount) =

app/src/main/java/mozilla/lockbox/store/AccountStore.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import kotlin.coroutines.CoroutineContext
5959
@ExperimentalCoroutinesApi
6060
open class AccountStore(
6161
private val lifecycleStore: LifecycleStore = LifecycleStore.shared,
62+
private val settingStore: SettingStore = SettingStore.shared,
6263
private val dispatcher: Dispatcher = Dispatcher.shared,
6364
private val securePreferences: SecurePreferences = SecurePreferences.shared,
6465
private val timingSupport: SystemTimingSupport = DeviceSystemTimingSupport.shared
@@ -142,6 +143,9 @@ open class AccountStore(
142143
this.context = context
143144
}
144145

146+
fun checkAccountExisting(): Boolean {
147+
return (storedAccountJSON != null)
148+
}
145149
fun shareableAccount(): ShareableAccount? {
146150
return AccountSharing.queryShareableAccounts(context).firstOrNull()
147151
}
@@ -266,9 +270,16 @@ open class AccountStore(
266270

267271
private fun generateNewFirefoxAccount() {
268272
try {
269-
val config = ServerConfig.release(Constant.FxA.clientID, Constant.FxA.redirectUri)
270-
fxa = FirefoxAccount(config)
271-
generateLoginURL()
273+
settingStore.useLocalService.subscribe {
274+
val config: ServerConfig
275+
if (it)
276+
config = ServerConfig("https://accounts.firefox.com.cn", Constant.FxA.clientID, Constant.FxA.redirectUri)
277+
else
278+
config = ServerConfig.release(Constant.FxA.clientID, Constant.FxA.redirectUri)
279+
280+
fxa = FirefoxAccount(config)
281+
generateLoginURL()
282+
}
272283
} catch (e: FxaException) {
273284
this.pushError(e)
274285
}

app/src/main/java/mozilla/lockbox/store/SettingStore.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ open class SettingStore(
4242
const val AUTO_LOCK_TIME = "auto_lock_time"
4343
const val DEVICE_SECURITY_PRESENT = "device_security_present"
4444
const val UNLOCK_WITH_FINGERPRINT_PENDING_AUTH = "unlock_with_fingerprint_pending_auth"
45+
const val USE_LOCAL_SERVICE = "use_local_service"
4546
}
4647

4748
private lateinit var preferences: SharedPreferences
@@ -53,6 +54,7 @@ open class SettingStore(
5354
private val _autoLockTime = ReplaySubject.createWithSize<Setting.AutoLockTime>(1)
5455

5556
open val sendUsageData: Observable<Boolean> = ReplaySubject.createWithSize(1)
57+
open val useLocalService: Observable<Boolean> = ReplaySubject.createWithSize(1)
5658
open val itemListSortOrder: Observable<Setting.ItemListSort> = ReplaySubject.createWithSize(1)
5759
open val unlockWithFingerprint: Observable<Boolean> = ReplaySubject.createWithSize(1)
5860
open val autoLockTime: Observable<Setting.AutoLockTime>
@@ -86,6 +88,8 @@ open class SettingStore(
8688
when (it) {
8789
is SettingAction.SendUsageData ->
8890
edit.putBoolean(Keys.SEND_USAGE_DATA, it.sendUsageData)
91+
is SettingAction.UseLocalService ->
92+
edit.putBoolean(Keys.USE_LOCAL_SERVICE, it.useLocalService)
8993
is SettingAction.ItemListSortOrder ->
9094
edit.putString(Keys.ITEM_LIST_SORT_ORDER, it.sortOrder.name)
9195
is SettingAction.UnlockWithFingerprint ->
@@ -98,6 +102,7 @@ open class SettingStore(
98102
handleAutofill(it.enable)
99103
is SettingAction.Reset -> {
100104
edit.putBoolean(Keys.SEND_USAGE_DATA, Constant.SettingDefault.sendUsageData)
105+
edit.putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse)
101106
edit.putString(Keys.ITEM_LIST_SORT_ORDER, Constant.SettingDefault.itemListSort.name)
102107
edit.putBoolean(Keys.UNLOCK_WITH_FINGERPRINT, Constant.SettingDefault.unlockWithFingerprint)
103108
edit.putString(Keys.AUTO_LOCK_TIME, Constant.SettingDefault.autoLockTime.name)
@@ -110,7 +115,15 @@ open class SettingStore(
110115
}
111116

112117
override fun injectContext(context: Context) {
118+
val chinaBuild = context.resources.configuration.locales.get(0).toString().equals("zh_CN_#Hans") &&
119+
context.resources.configuration.locales.get(0).displayLanguage.equals("中文") &&
120+
(!"com.android.vending".equals(context.packageManager.getInstallerPackageName(context.packageName)))
113121
preferences = PreferenceManager.getDefaultSharedPreferences(context)
122+
if (chinaBuild) {
123+
preferences.edit().putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceTrue)
124+
} else {
125+
preferences.edit().putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse)
126+
}
114127

115128
val rxPrefs = RxSharedPreferences.create(preferences)
116129

@@ -119,6 +132,18 @@ open class SettingStore(
119132
.asObservable()
120133
.subscribe(sendUsageData as Subject)
121134

135+
if (chinaBuild) {
136+
rxPrefs
137+
.getBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceTrue)
138+
.asObservable()
139+
.subscribe(useLocalService as Subject)
140+
} else {
141+
rxPrefs
142+
.getBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse)
143+
.asObservable()
144+
.subscribe(useLocalService as Subject)
145+
}
146+
122147
rxPrefs
123148
.getString(Keys.ITEM_LIST_SORT_ORDER, Constant.SettingDefault.itemListSort.name)
124149
.asObservable()

app/src/main/java/mozilla/lockbox/support/Constant.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ object Constant {
5454
val autoLockTime = Setting.AutoLockTime.FiveMinutes
5555
val noSecurityAutoLockTime = Setting.AutoLockTime.Never
5656
const val sendUsageData = true
57+
const val useLocalServiceFalse = false
58+
const val useLocalServiceTrue = true
5759
const val unlockWithFingerprint = false
5860
}
5961

app/src/main/java/mozilla/lockbox/view/SettingFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.view.ViewGroup
1515
import com.github.magiepooh.recycleritemdecoration.ItemDecorations
1616
import kotlinx.android.synthetic.main.fragment_setting.view.*
1717
import kotlinx.android.synthetic.main.list_cell_setting_toggle.view.*
18+
import kotlinx.coroutines.ExperimentalCoroutinesApi
1819
import mozilla.lockbox.R
1920
import mozilla.lockbox.adapter.SectionedAdapter
2021
import mozilla.lockbox.adapter.SettingCellConfiguration
@@ -24,6 +25,7 @@ import mozilla.lockbox.adapter.SettingListAdapter.Companion.SETTING_TOGGLE_TYPE
2425
import mozilla.lockbox.presenter.SettingPresenter
2526
import mozilla.lockbox.presenter.SettingView
2627

28+
@ExperimentalCoroutinesApi
2729
class SettingFragment : BackableFragment(), SettingView {
2830

2931
private val adapter = SettingListAdapter()
@@ -39,7 +41,10 @@ class SettingFragment : BackableFragment(), SettingView {
3941
container: ViewGroup?,
4042
savedInstanceState: Bundle?
4143
): View? {
42-
presenter = SettingPresenter(this)
44+
val chinaBuild = resources.configuration.locales.get(0).toString().equals("zh_CN_#Hans") &&
45+
resources.configuration.locales.get(0).displayLanguage.equals("中文") &&
46+
(!"com.android.vending".equals(context!!.packageManager.getInstallerPackageName(context!!.packageName)))
47+
presenter = SettingPresenter(this, chinaBuild)
4348

4449
// Inflate the layout for this fragment
4550
val view = inflater.inflate(R.layout.fragment_setting, container, false)

0 commit comments

Comments
 (0)