Skip to content

Commit

Permalink
Change targetsdk to 14 (#4063)
Browse files Browse the repository at this point in the history
<!--
Note: This checklist is a reminder of our shared engineering
expectations.
The items in Bold are required
If your PR involves UI changes:
1. Upload screenshots or screencasts that illustrate the changes before
/ after
2. Add them under the UI changes section (feel free to add more columns
if needed)
If your PR does not involve UI changes, you can remove the **UI
changes** section

At a minimum, make sure your changes are tested in API 23 and one of the
more recent API levels available.
-->

Task/Issue URL:
https://app.asana.com/0/488551667048375/1206318340789538/f

### Description
See attached task description

### Steps to test this PR
Smoke test app
  • Loading branch information
karlenDimla authored Jan 22, 2024
1 parent 4e6c4ab commit 622c65f
Show file tree
Hide file tree
Showing 32 changed files with 182 additions and 73 deletions.
4 changes: 4 additions & 0 deletions app-tracking-protection/vpn-impl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:largeHeap="true"
Expand Down Expand Up @@ -80,6 +83,7 @@
<service
android:name=".service.TrackerBlockingVpnService"
android:exported="false"
android:foregroundServiceType="systemExempted"
android:permission="android.permission.BIND_VPN_SERVICE"
android:process=":vpn">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.IntentFilter
import androidx.annotation.MainThread
import androidx.annotation.WorkerThread
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.registerExportedReceiver
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.vpn.AppTpVpnFeature
Expand Down Expand Up @@ -81,7 +82,7 @@ class NewAppBroadcastReceiver @Inject constructor(
addAction(Intent.ACTION_PACKAGE_ADDED)
addDataScheme("package")
}.run {
applicationContext.registerReceiver(this@NewAppBroadcastReceiver, this)
applicationContext.registerExportedReceiver(this@NewAppBroadcastReceiver, this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.common.utils.notification.checkPermissionAndNotify
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.mobile.android.vpn.ui.notification.*
import com.squareup.anvil.annotations.ContributesMultibinding
Expand All @@ -49,7 +51,7 @@ class DeviceShieldNotificationsDebugReceiver(
) : BroadcastReceiver() {

init {
context.registerReceiver(this, IntentFilter(intentAction))
context.registerNotExportedReceiver(this, IntentFilter(intentAction))
}

override fun onReceive(
Expand Down Expand Up @@ -116,7 +118,7 @@ class DeviceShieldNotificationsDebugReceiverRegister @Inject constructor(
}

notification?.let {
notificationManagerCompat.notify(DeviceShieldNotificationScheduler.VPN_WEEKLY_NOTIFICATION_ID, it)
notificationManagerCompat.checkPermissionAndNotify(context, DeviceShieldNotificationScheduler.VPN_WEEKLY_NOTIFICATION_ID, it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.content.Intent
import android.content.IntentFilter
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.common.utils.formatters.time.DatabaseDateFormatter
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.vpn.model.TrackingApp
Expand Down Expand Up @@ -66,7 +67,7 @@ class SendTrackerDebugReceiver @Inject constructor(
}

logcat { "Debug receiver SendTrackerDebugReceiver registered" }
context.registerReceiver(this, IntentFilter(INTENT_ACTION))
context.registerNotExportedReceiver(this, IntentFilter(INTENT_ACTION))
}

private fun unregister() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.appbuildconfig.api.isInternalBuild
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor
import com.squareup.anvil.annotations.ContributesMultibinding
Expand Down Expand Up @@ -56,7 +57,7 @@ class RestartReceiver @Inject constructor(
if (appBuildConfig.isInternalBuild()) {
logcat { "Starting vpn-service receiver" }
unregister()
context.registerReceiver(this, IntentFilter("vpn-service"))
context.registerNotExportedReceiver(this, IntentFilter("vpn-service"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package com.duckduckgo.mobile.android.vpn.service

import android.Manifest.permission
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.edit
import com.duckduckgo.common.utils.plugins.PluginPoint
Expand Down Expand Up @@ -50,18 +53,20 @@ class AndroidVpnReminderReceiverManager @Inject constructor(
logcat { "Vpn is already running, nothing to show" }
} else {
logcat { "Vpn is not running, showing reminder notification" }
val notification = vpnReminderNotificationContentPluginPoint.getHighestPriorityPluginForType(DISABLED)?.getContent()?.let { content ->
val actualContent = if (wasReminderNotificationShown()) {
content.copy(true)
} else {
notificationWasShown()
content.copy(false)
if (ActivityCompat.checkSelfPermission(context, permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
val notification = vpnReminderNotificationContentPluginPoint.getHighestPriorityPluginForType(DISABLED)?.getContent()?.let { content ->
val actualContent = if (wasReminderNotificationShown()) {
content.copy(true)
} else {
notificationWasShown()
content.copy(false)
}
vpnReminderNotificationBuilder.buildReminderNotification(actualContent)
}
if (notification != null) {
deviceShieldPixels.didShowReminderNotification()
notificationManager.notify(TrackerBlockingVpnService.VPN_REMINDER_NOTIFICATION_ID, notification)
}
vpnReminderNotificationBuilder.buildReminderNotification(actualContent)
}
if (notification != null) {
deviceShieldPixels.didShowReminderNotification()
notificationManager.notify(TrackerBlockingVpnService.VPN_REMINDER_NOTIFICATION_ID, notification)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import androidx.core.app.NotificationManagerCompat
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.notification.checkPermissionAndNotify
import com.duckduckgo.common.utils.plugins.PluginPoint
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnStopReason
Expand Down Expand Up @@ -71,6 +72,6 @@ class VpnTrackerNotificationUpdates @Inject constructor(
vpnNotification: VpnEnabledNotificationContentPlugin.VpnEnabledNotificationContent,
) {
val notification = VpnEnabledNotificationBuilder.buildVpnEnabledUpdateNotification(context, vpnNotification)
notificationManager.notify(TrackerBlockingVpnService.VPN_FOREGROUND_SERVICE_ID, notification)
notificationManager.checkPermissionAndNotify(context, TrackerBlockingVpnService.VPN_FOREGROUND_SERVICE_ID, notification)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.text.SpannableStringBuilder
import androidx.core.app.NotificationManagerCompat
import com.duckduckgo.common.utils.ConflatedJob
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.notification.checkPermissionAndNotify
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.app.tracking.AppTrackingProtection
import com.duckduckgo.mobile.android.app.tracking.ui.AppTrackingProtectionScreens.AppTrackerActivityWithEmptyParams
Expand Down Expand Up @@ -95,7 +96,7 @@ class AlwaysOnLockDownDetector @Inject constructor(
notification,
intent,
).also {
notificationManagerCompat.notify(notificationId, it)
notificationManagerCompat.checkPermissionAndNotify(context, notificationId, it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.notification.checkPermissionAndNotify
import com.duckduckgo.common.utils.plugins.PluginPoint
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.app.tracking.AppTrackingProtection
Expand Down Expand Up @@ -179,7 +180,8 @@ class AppTPReminderNotificationScheduler @Inject constructor(
vpnReminderNotificationContentPluginPoint.getHighestPriorityPluginForType(DISABLED)?.let {
it.getContent()?.let { content ->
logcat { "Showing disabled notification from $it" }
notificationManager.notify(
notificationManager.checkPermissionAndNotify(
context,
TrackerBlockingVpnService.VPN_REMINDER_NOTIFICATION_ID,
vpnReminderNotificationBuilder.buildReminderNotification(content),
)
Expand All @@ -191,7 +193,8 @@ class AppTPReminderNotificationScheduler @Inject constructor(
vpnReminderNotificationContentPluginPoint.getHighestPriorityPluginForType(REVOKED)?.let {
it.getContent()?.let { content ->
logcat { "Showing revoked notification from $it" }
notificationManager.notify(
notificationManager.checkPermissionAndNotify(
context,
TrackerBlockingVpnService.VPN_REMINDER_NOTIFICATION_ID,
vpnReminderNotificationBuilder.buildReminderNotification(content),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

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

import android.Manifest.permission
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.LifecycleOwner
import androidx.work.*
Expand Down Expand Up @@ -185,18 +188,20 @@ class DeviceShieldDailyNotificationWorker(
}

private suspend fun showNotification() {
val deviceShieldNotification = deviceShieldNotificationFactory.createDailyDeviceShieldNotification().also {
notificationPressedHandler.notificationVariant = it.notificationVariant
}
if (ActivityCompat.checkSelfPermission(context, permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
val deviceShieldNotification = deviceShieldNotificationFactory.createDailyDeviceShieldNotification().also {
notificationPressedHandler.notificationVariant = it.notificationVariant
}

if (!deviceShieldNotification.hidden) {
val notification =
deviceShieldAlertNotificationBuilder.buildStatusNotification(context, deviceShieldNotification, notificationPressedHandler)
deviceShieldPixels.didShowDailyNotification(deviceShieldNotification.notificationVariant)
notificationManager.notify(DeviceShieldNotificationScheduler.VPN_DAILY_NOTIFICATION_ID, notification)
logcat { "Vpn Daily notification is now shown" }
} else {
logcat { "Vpn Daily notification won't be shown because there is no data to show" }
if (!deviceShieldNotification.hidden) {
val notification =
deviceShieldAlertNotificationBuilder.buildStatusNotification(context, deviceShieldNotification, notificationPressedHandler)
deviceShieldPixels.didShowDailyNotification(deviceShieldNotification.notificationVariant)
notificationManager.notify(DeviceShieldNotificationScheduler.VPN_DAILY_NOTIFICATION_ID, notification)
logcat { "Vpn Daily notification is now shown" }
} else {
logcat { "Vpn Daily notification won't be shown because there is no data to show" }
}
}
}
}
Expand All @@ -223,20 +228,21 @@ class DeviceShieldWeeklyNotificationWorker(

override suspend fun doWork(): Result {
logcat { "Vpn Weekly notification worker is now awake" }
if (ActivityCompat.checkSelfPermission(context, permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
val deviceShieldNotification = deviceShieldNotificationFactory.createWeeklyDeviceShieldNotification().also {
notificationPressedHandler.notificationVariant = it.notificationVariant
}

val deviceShieldNotification = deviceShieldNotificationFactory.createWeeklyDeviceShieldNotification().also {
notificationPressedHandler.notificationVariant = it.notificationVariant
}

if (!deviceShieldNotification.hidden) {
logcat { "Vpn Daily notification won't be shown because there is no data to show" }
val notification = deviceShieldAlertNotificationBuilder.buildStatusNotification(
context,
deviceShieldNotification,
notificationPressedHandler,
)
deviceShieldPixels.didShowWeeklyNotification(deviceShieldNotification.notificationVariant)
notificationManager.notify(Companion.VPN_WEEKLY_NOTIFICATION_ID, notification)
if (!deviceShieldNotification.hidden) {
logcat { "Vpn Daily notification won't be shown because there is no data to show" }
val notification = deviceShieldAlertNotificationBuilder.buildStatusNotification(
context,
deviceShieldNotification,
notificationPressedHandler,
)
deviceShieldPixels.didShowWeeklyNotification(deviceShieldNotification.notificationVariant)
notificationManager.notify(Companion.VPN_WEEKLY_NOTIFICATION_ID, notification)
}
}

return Result.success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RestartReceiverTest {
receiver.onVpnStarted(coroutineRule.testScope)

verify(context).unregisterReceiver(any())
verify(context).registerReceiver(any(), any())
verify(context).registerReceiver(any(), any(), isNull(), isNull(), any())
}

@Test
Expand All @@ -66,7 +66,7 @@ class RestartReceiverTest {
receiver.onVpnStarted(coroutineRule.testScope)

verify(context, never()).unregisterReceiver(any())
verify(context, never()).registerReceiver(any(), any())
verify(context, never()).registerReceiver(any(), any(), isNull(), isNull(), any())
}

@Test
Expand All @@ -76,7 +76,7 @@ class RestartReceiverTest {
receiver.onVpnStopped(coroutineRule.testScope, VpnStateMonitor.VpnStopReason.SELF_STOP())

verify(context).unregisterReceiver(any())
verify(context, never()).registerReceiver(any(), any())
verify(context, never()).registerReceiver(any(), any(), isNull(), isNull(), any())
}

@Test
Expand All @@ -86,6 +86,6 @@ class RestartReceiverTest {
receiver.onVpnStopped(coroutineRule.testScope, VpnStateMonitor.VpnStopReason.SELF_STOP())

verify(context).unregisterReceiver(any())
verify(context, never()).registerReceiver(any(), any())
verify(context, never()).registerReceiver(any(), any(), isNull(), isNull(), any())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver

/**
* Abstract class to create generic receivers for internal features accessible through
Expand All @@ -44,7 +45,7 @@ abstract class InternalFeatureReceiver(

fun register() {
unregister()
context.registerReceiver(this, IntentFilter(intentAction()))
context.registerNotExportedReceiver(this, IntentFilter(intentAction()))
}

fun unregister() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.di.scopes.VpnScope
import com.duckduckgo.mobile.android.vpn.service.VpnServiceCallbacks
import com.duckduckgo.mobile.android.vpn.state.VpnStateMonitor.VpnStopReason
Expand Down Expand Up @@ -48,7 +49,7 @@ class ExceptionRulesDebugReceiver(

init {
kotlin.runCatching { context.unregisterReceiver(this) }
context.registerReceiver(this, IntentFilter(intentAction))
context.registerNotExportedReceiver(this, IntentFilter(intentAction))
}

override fun onReceive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.lifecycle.LifecycleOwner
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.app.trackerdetection.api.TrackerDataDownloader
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesMultibinding
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -39,7 +40,7 @@ class TrackerDataDevReceiver(
private val receiver: (Intent) -> Unit,
) : BroadcastReceiver() {
init {
context.registerReceiver(this, IntentFilter(intentAction))
context.registerNotExportedReceiver(this, IntentFilter(intentAction))
}

override fun onReceive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.duckduckgo.app.notification.db.NotificationDao
import com.duckduckgo.app.notification.model.Notification
import com.duckduckgo.app.notification.model.SchedulableNotification
import com.duckduckgo.app.notification.model.SchedulableNotificationPlugin
import com.duckduckgo.common.utils.notification.checkPermissionAndNotify
import com.duckduckgo.common.utils.plugins.PluginPoint
import timber.log.Timber

Expand Down Expand Up @@ -54,7 +55,7 @@ class AppNotificationSender(
val cancelIntent = NotificationHandlerService.pendingCancelNotificationHandlerIntent(context, notification.javaClass)
val systemNotification = factory.createNotification(specification, launchIntent, cancelIntent)
notificationDao.insert(Notification(notification.id))
manager.notify(specification.systemId, systemNotification)
manager.checkPermissionAndNotify(context, specification.systemId, systemNotification)

notificationPlugin.onNotificationShown()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.lifecycle.LifecycleOwner
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver
import com.duckduckgo.app.widget.AppWidgetManagerAddWidgetLauncher.Companion.ACTION_ADD_WIDGET
import com.duckduckgo.common.utils.extensions.registerNotExportedReceiver
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.SingleInstanceIn
Expand All @@ -46,7 +47,7 @@ class WidgetAddedReceiver @Inject constructor(

override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
context.registerReceiver(this, IntentFilter(ACTION_ADD_WIDGET))
context.registerNotExportedReceiver(this, IntentFilter(ACTION_ADD_WIDGET))
}

override fun onDestroy(owner: LifecycleOwner) {
Expand Down
Loading

0 comments on commit 622c65f

Please sign in to comment.