Skip to content

Commit

Permalink
Merge branch 'release/5.209.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax the Deployer committed Jul 22, 2024
2 parents 7bb62c4 + 0c3b5c3 commit 2ddac13
Show file tree
Hide file tree
Showing 208 changed files with 7,889 additions and 722 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class ManageRecentAppsProtectionActivity :
}

override fun onBackPressed() {
super.onBackPressed()
onSupportNavigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class TrackingProtectionExclusionListActivity :
}

override fun onBackPressed() {
super.onBackPressed()
onSupportNavigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ReportBreakageAppListActivity : DuckDuckGoActivity(), ReportBreakageAppLis
}

override fun onBackPressed() {
super.onBackPressed()
onSupportNavigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DeviceInfoCollector @Inject constructor(
put("buildFlavor", appBuildConfig.flavor.toString())
put("os", appBuildConfig.sdkInt)
put("batteryOptimizations", (!isIgnoringBatteryOptimizations.get()).toString())
put("man", appBuildConfig.manufacturer)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,8 @@ enum class DeviceShieldPixelNames(override val pixelName: String, val enqueue: B
VPN_START_ATTEMPT("m_vpn_ev_start_attempt_c", enqueue = true),
VPN_START_ATTEMPT_SUCCESS("m_vpn_ev_start_attempt_success_c", enqueue = true),
VPN_START_ATTEMPT_FAILURE("m_vpn_ev_start_attempt_failure_c", enqueue = true),

NEW_TAB_SECTION_TOGGLED_OFF("m_new_tab_page_customize_section_off_appTP"),
NEW_TAB_SECTION_TOGGLED_ON("m_new_tab_page_customize_section_on_appTP"),
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ interface DeviceShieldPixels {
fun reportVpnStartAttempt()

fun reportVpnStartAttemptSuccess()

// New Tab Engagement pixels https://app.asana.com/0/72649045549333/1207667088727866/f
fun reportNewTabSectionToggled(enabled: Boolean)
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -827,6 +830,14 @@ class RealDeviceShieldPixels @Inject constructor(
tryToFireDailyPixel(String.format(Locale.US, DeviceShieldPixelNames.REPORT_TLS_PARSING_ERROR_CODE_DAILY.pixelName, errorCode))
}

override fun reportNewTabSectionToggled(enabled: Boolean) {
if (enabled) {
firePixel(DeviceShieldPixelNames.NEW_TAB_SECTION_TOGGLED_ON)
} else {
firePixel(DeviceShieldPixelNames.NEW_TAB_SECTION_TOGGLED_OFF)
}
}

private fun firePixel(
p: DeviceShieldPixelNames,
payload: Map<String, String> = emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.mobile.android.vpn.ui.newtab

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.anvil.annotations.PriorityKey
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.common.utils.ViewViewModelFactory
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.di.scopes.ViewScope
import com.duckduckgo.feature.toggles.api.Toggle
import com.duckduckgo.mobile.android.vpn.databinding.ViewApptpSettingsItemBinding
import com.duckduckgo.mobile.android.vpn.feature.removal.VpnFeatureRemover
import com.duckduckgo.mobile.android.vpn.ui.newtab.AppTrackingProtectionNewTabSettingsViewModel.ViewState
import com.duckduckgo.mobile.android.vpn.ui.onboarding.VpnStore
import com.duckduckgo.newtabpage.api.NewTabPageSection
import com.duckduckgo.newtabpage.api.NewTabPageSectionSettingsPlugin
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@InjectWith(ViewScope::class)
class AppTrackingProtectionNewTabSettingView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
) : LinearLayout(context, attrs, defStyle) {

@Inject
lateinit var viewModelFactory: ViewViewModelFactory

private val binding: ViewApptpSettingsItemBinding by viewBinding()

private var coroutineScope: CoroutineScope? = null

private val viewModel: AppTrackingProtectionNewTabSettingsViewModel by lazy {
ViewModelProvider(findViewTreeViewModelStoreOwner()!!, viewModelFactory)[AppTrackingProtectionNewTabSettingsViewModel::class.java]
}

override fun onAttachedToWindow() {
AndroidSupportInjection.inject(this)
super.onAttachedToWindow()
findViewTreeLifecycleOwner()?.lifecycle?.addObserver(viewModel)

@SuppressLint("NoHardcodedCoroutineDispatcher")
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

viewModel.viewState
.onEach { render(it) }
.launchIn(coroutineScope!!)
}

private fun render(viewState: ViewState) {
binding.root.quietlySetIsChecked(viewState.enabled) { _, enabled ->
viewModel.onSettingEnabled(enabled)
}
}
}

@ContributesMultibinding(scope = ActivityScope::class)
@PriorityKey(NewTabPageSectionSettingsPlugin.APP_TRACKING_PROTECTION)
class AppTrackingProtectionNewTabSettingViewPlugin @Inject constructor(
private val vpnStore: VpnStore,
private val vpnFeatureRemover: VpnFeatureRemover,
) : NewTabPageSectionSettingsPlugin {
override val name = NewTabPageSection.APP_TRACKING_PROTECTION.name

override fun getView(context: Context): View {
return AppTrackingProtectionNewTabSettingView(context)
}

override suspend fun isActive(): Boolean {
if (vpnFeatureRemover.isFeatureRemoved()) {
return false
}
return vpnStore.didShowOnboarding()
}
}

/**
* Local feature/settings - they will never be in remote config
*/
@ContributesRemoteFeature(
scope = AppScope::class,
featureName = "newTabAppTPSectionSetting",
)
interface NewTabAppTrackingProtectionSectionSetting {
@Toggle.DefaultValue(true)
fun self(): Toggle
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.mobile.android.vpn.ui.newtab

import android.annotation.SuppressLint
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.duckduckgo.anvil.annotations.ContributesViewModel
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.ViewScope
import com.duckduckgo.feature.toggles.api.Toggle.State
import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@SuppressLint("NoLifecycleObserver") // we don't observe app lifecycle
@ContributesViewModel(ViewScope::class)
class AppTrackingProtectionNewTabSettingsViewModel @Inject constructor(
private val dispatchers: DispatcherProvider,
private val setting: NewTabAppTrackingProtectionSectionSetting,
private val pixel: DeviceShieldPixels,
) : ViewModel(), DefaultLifecycleObserver {

private val _viewState = MutableStateFlow(ViewState(true))
val viewState = _viewState.asStateFlow()

data class ViewState(val enabled: Boolean)

override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)

viewModelScope.launch(dispatchers.io()) {
val isEnabled = setting.self().isEnabled()
withContext(dispatchers.main()) {
_viewState.update { ViewState(isEnabled) }
}
}
}

fun onSettingEnabled(enabled: Boolean) {
setting.self().setEnabled(State(enabled))
pixel.reportNewTabSectionToggled(enabled)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 DuckDuckGo
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.duckduckgo.mobile.android.vpn.ui.report
package com.duckduckgo.mobile.android.vpn.ui.newtab

import android.annotation.SuppressLint
import android.content.Context
Expand All @@ -33,9 +33,13 @@ import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.di.scopes.ViewScope
import com.duckduckgo.mobile.android.vpn.R
import com.duckduckgo.mobile.android.vpn.databinding.FragmentDeviceShieldCtaBinding
import com.duckduckgo.mobile.android.vpn.feature.removal.VpnFeatureRemover
import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnRunningState.ENABLED
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnStopReason.REVOKED
import com.duckduckgo.mobile.android.vpn.ui.onboarding.VpnStore
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel.PrivacyReportView.TrackersBlocked
import com.duckduckgo.mobile.android.vpn.ui.report.PrivacyReportViewModel.PrivacyReportView.ViewState
import com.duckduckgo.mobile.android.vpn.ui.tracker_activity.DeviceShieldTrackerActivity
import com.duckduckgo.newtabpage.api.NewTabPageSection
Expand Down Expand Up @@ -128,7 +132,7 @@ class AppTrackingProtectionStateView @JvmOverloads constructor(
binding.deviceShieldCtaImage.setImageResource(R.drawable.ic_apptp_warning)
}

private fun renderTrackersBlockedWhenEnabled(trackerBlocked: PrivacyReportViewModel.PrivacyReportView.TrackersBlocked) {
private fun renderTrackersBlockedWhenEnabled(trackerBlocked: TrackersBlocked) {
val trackersBlocked = trackerBlocked.trackers
val lastTrackingApp = trackerBlocked.latestApp
val otherApps = trackerBlocked.otherAppsSize
Expand Down Expand Up @@ -185,11 +189,28 @@ class AppTrackingProtectionStateView @JvmOverloads constructor(
@ContributesActivePlugin(
AppScope::class,
boundType = NewTabPageSectionPlugin::class,
priority = 2,
)
class AppTrackingProtectionNewTabPageSectionPlugin @Inject constructor() : NewTabPageSectionPlugin {
class AppTrackingProtectionNewTabPageSectionPlugin @Inject constructor(
private val vpnStore: VpnStore,
private val vpnFeatureRemover: VpnFeatureRemover,
private val setting: NewTabAppTrackingProtectionSectionSetting,
) : NewTabPageSectionPlugin {
override val name = NewTabPageSection.APP_TRACKING_PROTECTION.name

override fun getView(context: Context): View {
return AppTrackingProtectionStateView(context)
}

override suspend fun isUserEnabled(): Boolean {
if (vpnFeatureRemover.isFeatureRemoved()) {
return false
}

return if (vpnStore.didShowOnboarding()) {
setting.self().isEnabled()
} else {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class VpnOnboardingActivity : DuckDuckGoActivity() {
}

override fun onBackPressed() {
super.onBackPressed()
// go back to previous screen or get out if first page
onSupportNavigateUp()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DeviceShieldAppTrackersInfo : DuckDuckGoActivity() {
}

override fun onBackPressed() {
super.onBackPressed()
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class AppTPCompanyTrackersActivity : DuckDuckGoActivity() {
}

override fun onBackPressed() {
super.onBackPressed()
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DeviceShieldMostRecentActivity : DuckDuckGoActivity() {
}

override fun onBackPressed() {
super.onBackPressed()
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class DeviceShieldTrackerActivity :
}

override fun onBackPressed() {
super.onBackPressed()
onSupportNavigateUp()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
~ Copyright (c) 2024 DuckDuckGo
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16,3.5C16.552,3.5 17,3.948 17,4.5V5.5V18.5V19.5C17,20.052 16.552,20.5 16,20.5C15.448,20.5 15,20.052 15,19.5V19.212L12.744,18.431L12.656,18.694C12.092,20.387 10.319,21.361 8.587,20.928C7.067,20.548 6,19.181 6,17.614V16.097L3.926,15.379C3.777,15.743 3.418,16 3,16C2.448,16 2,15.552 2,15V14V10V9C2,8.448 2.448,8 3,8C3.418,8 3.777,8.257 3.926,8.621L15,4.788V4.5C15,3.948 15.448,3.5 16,3.5ZM4,10.712V13.288L15,17.096V6.904L4,10.712ZM10.854,17.777L8,16.789V17.614C8,18.264 8.442,18.83 9.072,18.987C9.79,19.167 10.525,18.763 10.759,18.062L10.854,17.777ZM21.894,6.553C22.141,7.047 21.941,7.647 21.447,7.894L19.447,8.894C18.953,9.141 18.353,8.941 18.106,8.447C17.859,7.953 18.059,7.353 18.553,7.106L20.553,6.106C21.047,5.859 21.647,6.059 21.894,6.553ZM18,12C18,11.448 18.448,11 19,11H21C21.552,11 22,11.448 22,12C22,12.552 21.552,13 21,13H19C18.448,13 18,12.552 18,12ZM18.106,15.553C18.353,15.059 18.953,14.859 19.447,15.106L21.447,16.105C21.941,16.353 22.141,16.953 21.894,17.447C21.647,17.941 21.047,18.141 20.553,17.894L18.553,16.894C18.059,16.647 17.859,16.047 18.106,15.553Z"
android:fillColor="?attr/daxColorPrimaryIcon"
android:fillAlpha="0.84"
android:fillType="evenOdd"/>
</vector>
Loading

0 comments on commit 2ddac13

Please sign in to comment.