Skip to content

Commit

Permalink
Increase minSdk to 26 (Android 8 / Oreo) (#4177)
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/1206486003155266/f

### Description
Increases the `minSdk` to API 26 (aka, Android 8.0 / Oreo). Other than
the `minSdk` change, there should be no actual behaviour changes.

This also includes the following changes:

- removes dead code that can no longer run due to OS-version guards
- removes redundant OS-version guards
- removes any now-redundant usages of `@Suppress("NewApi")` that I
spotted


### Steps to test this PR

- [ ] Ensure CI passes
- [ ] Smoke test app, as much as you can 🙏
  • Loading branch information
CDRussell authored Feb 15, 2024
1 parent 6a48a0c commit 570d943
Show file tree
Hide file tree
Showing 61 changed files with 227 additions and 860 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,11 @@ private fun parseAppCategory(category: Int): AppCategory {
}

fun ApplicationInfo.parseAppCategory(): AppCategory {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
parseAppCategory(category)
} else {
AppCategory.Undefined
}
}

fun ApplicationInfo.getAppCategoryCompat(): Int {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
category
} else {
-1 // inlined value of CATEGORY_UNDEFINED
}
return parseAppCategory(category)
}

fun ApplicationInfo.isGame(): Boolean {
val category = getAppCategoryCompat()
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
category == ApplicationInfo.CATEGORY_GAME
} else {
category == 0 // inlined value of CATEGORY_GAME
}
return category == ApplicationInfo.CATEGORY_GAME
}

fun ApplicationInfo.isSystemApp(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ManageRecentAppsProtectionActivity :
private fun bindViews() {
binding.manageRecentAppsSkeleton.startShimmer()
binding.alwaysOn.setOnClickListener {
this.launchAlwaysOnSystemSettings(appBuildConfig.sdkInt)
this.launchAlwaysOnSystemSettings()
}
binding.unrestrictedBatteryUsage.setOnClickListener {
this.launchIgnoreBatteryOptimizationSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import android.os.Bundle
import android.service.quicksettings.Tile.STATE_ACTIVE
import android.service.quicksettings.Tile.STATE_INACTIVE
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.duckduckgo.anvil.annotations.InjectWith
Expand All @@ -44,7 +43,6 @@ import kotlinx.coroutines.*
import logcat.logcat

@Suppress("NoHardcodedCoroutineDispatcher")
@RequiresApi(Build.VERSION_CODES.N)
// We don't use the DeviceShieldTileService::class as binding key because TileService (Android) class does not
// exist in all APIs, and so using it DeviceShieldTileService::class as key would compile but immediately crash
// at startup when Java class loader tries to resolve the TileService::class upon Dagger setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import android.net.LinkProperties
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.mobile.android.vpn.network.util.getActiveNetwork
import java.net.InetAddress
Expand All @@ -37,7 +35,6 @@ import logcat.asLog
import logcat.logcat

class DnsChangeCallback @Inject constructor(
private val appBuildConfig: AppBuildConfig,
private val context: Context,
@AppCoroutineScope private val coroutineScope: CoroutineScope,
private val dispatcherProvider: DispatcherProvider,
Expand All @@ -56,7 +53,7 @@ class DnsChangeCallback @Inject constructor(
// we only care about changes in the active network
if (activeNetwork != null && activeNetwork != network) return@launch

if (appBuildConfig.sdkInt >= Build.VERSION_CODES.O && !same(lastDns, dns)) {
if (!same(lastDns, dns)) {
logcat {
"""
onLinkPropertiesChanged: DNS changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,6 @@ class TrackerBlockingVpnService : VpnService(), CoroutineScope by MainScope(), V

for (service in manager.getRunningServices(Int.MAX_VALUE)) {
if (TrackerBlockingVpnService::class.java.name == service.service.className) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
return service.started
}
return true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.ResultReceiver
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.TaskStackBuilder
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.mobile.android.vpn.R
import com.duckduckgo.mobile.android.vpn.ui.notification.DeviceShieldNotificationFactory.DeviceShieldNotification
Expand All @@ -41,10 +39,8 @@ import dagger.Provides
object DeviceShieldAlertNotificationBuilderModule {

@Provides
fun providesDeviceShieldAlertNotificationBuilder(
appBuildConfig: AppBuildConfig,
): DeviceShieldAlertNotificationBuilder {
return AndroidDeviceShieldAlertNotificationBuilder(appBuildConfig)
fun providesDeviceShieldAlertNotificationBuilder(): DeviceShieldAlertNotificationBuilder {
return AndroidDeviceShieldAlertNotificationBuilder()
}
}

Expand All @@ -63,19 +59,14 @@ interface DeviceShieldAlertNotificationBuilder {
): Notification
}

class AndroidDeviceShieldAlertNotificationBuilder constructor(
private val appBuildConfig: AppBuildConfig,
) : DeviceShieldAlertNotificationBuilder {
class AndroidDeviceShieldAlertNotificationBuilder : DeviceShieldAlertNotificationBuilder {

@Suppress("NewApi") // we use appBuildConfig
private fun registerAlertChannel(context: Context) {
if (appBuildConfig.sdkInt >= Build.VERSION_CODES.O) {
val notificationManager = NotificationManagerCompat.from(context)
if (notificationManager.getNotificationChannel(VPN_ALERTS_CHANNEL_ID) == null) {
val channel = NotificationChannel(VPN_ALERTS_CHANNEL_ID, VPN_ALERTS_CHANNEL_NAME, IMPORTANCE_DEFAULT)
channel.description = VPN_ALERTS_CHANNEL_DESCRIPTION
notificationManager.createNotificationChannel(channel)
}
val notificationManager = NotificationManagerCompat.from(context)
if (notificationManager.getNotificationChannel(VPN_ALERTS_CHANNEL_ID) == null) {
val channel = NotificationChannel(VPN_ALERTS_CHANNEL_ID, VPN_ALERTS_CHANNEL_NAME, IMPORTANCE_DEFAULT)
channel.description = VPN_ALERTS_CHANNEL_DESCRIPTION
notificationManager.createNotificationChannel(channel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,20 @@ class VpnEnabledNotificationBuilder {
private const val VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_DESCRIPTION = "Ongoing state of App Tracking Protection"

private fun registerOngoingNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(
VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_ID,
VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_NAME,
IMPORTANCE_LOW,
)
channel.setShowBadge(false)
channel.description = VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_DESCRIPTION
val notificationManager = NotificationManagerCompat.from(context)
notificationManager.createNotificationChannel(channel)
/**
* We needed to create a new channel to fix: https://app.asana.com/0/488551667048375/1206484244032061/f
*/
notificationManager.deleteNotificationChannel("com.duckduckgo.mobile.android.vpn.notification.ongoing")
}
val channel =
NotificationChannel(
VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_ID,
VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_NAME,
IMPORTANCE_LOW,
)
channel.setShowBadge(false)
channel.description = VPN_FOREGROUND_SERVICE_NOTIFICATION_CHANNEL_DESCRIPTION
val notificationManager = NotificationManagerCompat.from(context)
notificationManager.createNotificationChannel(channel)
/**
* We needed to create a new channel to fix: https://app.asana.com/0/488551667048375/1206484244032061/f
*/
notificationManager.deleteNotificationChannel("com.duckduckgo.mobile.android.vpn.notification.ongoing")
}

fun buildVpnEnabledNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.duckduckgo.di.scopes.AppScope
Expand All @@ -41,17 +40,15 @@ class RealVpnReminderNotificationBuilder @Inject constructor(
) : VpnReminderNotificationBuilder {

private fun registerAlertChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = NotificationManagerCompat.from(context)
if (notificationManager.getNotificationChannel(AndroidDeviceShieldAlertNotificationBuilder.VPN_ALERTS_CHANNEL_ID) == null) {
val channel = NotificationChannel(
VPN_ALERTS_CHANNEL_ID,
VPN_ALERTS_CHANNEL_NAME,
IMPORTANCE_DEFAULT,
)
channel.description = VPN_ALERTS_CHANNEL_DESCRIPTION
notificationManager.createNotificationChannel(channel)
}
val notificationManager = NotificationManagerCompat.from(context)
if (notificationManager.getNotificationChannel(AndroidDeviceShieldAlertNotificationBuilder.VPN_ALERTS_CHANNEL_ID) == null) {
val channel = NotificationChannel(
VPN_ALERTS_CHANNEL_ID,
VPN_ALERTS_CHANNEL_NAME,
IMPORTANCE_DEFAULT,
)
channel.description = VPN_ALERTS_CHANNEL_DESCRIPTION
notificationManager.createNotificationChannel(channel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class VpnOnboardingActivity : DuckDuckGoActivity() {
fun onVpnConflictDialogGoToSettings() {
deviceShieldPixels.didChooseToOpenSettingsFromVpnConflictDialog()

this.launchAlwaysOnSystemSettings(appBuildConfig.sdkInt)
this.launchAlwaysOnSystemSettings()
}

fun onVpnConflictDialogContinue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class DeviceShieldTrackerActivity :

@SuppressLint("InlinedApi")
private fun openVPNSettings() {
this.launchAlwaysOnSystemSettings(appBuildConfig.sdkInt)
this.launchAlwaysOnSystemSettings()
}

fun onVpnConflictDialogContinue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.duckduckgo.vpn.internal.flipper

import android.content.Context
import android.content.SharedPreferences
import android.os.Build
import android.preference.PreferenceManager
import androidx.core.content.edit
import com.duckduckgo.di.scopes.AppScope
Expand Down Expand Up @@ -202,11 +201,7 @@ class PreferencesFlipperPlugin @Inject constructor(context: Context) : FlipperPl
}

private fun getDefaultSharedPreferencesName(context: Context): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PreferenceManager.getDefaultSharedPreferencesName(context)
} else {
context.packageName + "_preferences"
}
return PreferenceManager.getDefaultSharedPreferencesName(context)
}
}
}
Expand Down
Loading

0 comments on commit 570d943

Please sign in to comment.