Skip to content

Commit

Permalink
Update Target SDK to 35
Browse files Browse the repository at this point in the history
Fix cold boot problem for Android 15
  • Loading branch information
lz233 committed Nov 18, 2024
1 parent 7d5d23c commit 14df8eb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ plugins {

android {
namespace 'cn.ac.lz233.tarnhelm'
compileSdk 34
compileSdk 35

defaultConfig {
Date date = new Date()
applicationId "cn.ac.lz233.tarnhelm"
minSdk 27
targetSdk 34
targetSdk 35
versionCode = date.format("yyyyMMdd").toInteger()
versionName "1.6.5"
versionName "1.6.6"

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
Expand Down Expand Up @@ -55,6 +55,7 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
aidl true
}
packagingOptions {
Expand All @@ -76,12 +77,12 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.room:room-runtime:2.6.1'
implementation 'androidx.viewpager2:viewpager2:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
implementation 'androidx.window:window:1.3.0'
ksp 'androidx.room:room-compiler:2.6.1'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/cn/ac/lz233/tarnhelm/App.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.ac.lz233.tarnhelm

import android.app.ActivityManager
import android.app.Application
import android.app.NotificationManager
import android.content.ClipboardManager
Expand Down Expand Up @@ -52,6 +53,7 @@ class App : Application() {
lateinit var redirectRuleDao: RedirectRuleDao
lateinit var extensionDao: ExtensionDao

lateinit var activityManager: ActivityManager
lateinit var clipboardManager: ClipboardManager
lateinit var notificationManager: NotificationManager

Expand All @@ -73,7 +75,7 @@ class App : Application() {
fun isXposedActive(): Boolean = false

fun checkClipboardPermission() =
(Build.VERSION.SDK_INT < 29) or (Settings.canDrawOverlays(context) && context.checkSelfPermission("android.permission.READ_LOGS") == PackageManager.PERMISSION_GRANTED)
(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) or (Settings.canDrawOverlays(context) && context.checkSelfPermission("android.permission.READ_LOGS") == PackageManager.PERMISSION_GRANTED)
}

override fun onCreate() {
Expand All @@ -95,6 +97,7 @@ class App : Application() {
redirectRuleDao = db.redirectRuleDao()
extensionDao = db.extensionDao()

activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/cn/ac/lz233/tarnhelm/receiver/BootBroadcast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cn.ac.lz233.tarnhelm.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import cn.ac.lz233.tarnhelm.App
import cn.ac.lz233.tarnhelm.logic.dao.SettingsDao
import cn.ac.lz233.tarnhelm.service.ClipboardService
Expand All @@ -25,6 +26,14 @@ class BootBroadcast : BroadcastReceiver() {
shouldExit = false
}
}
if (shouldExit) exitProcess(0)

if (shouldExit) {
// On Android 15, if a app is started since force stop, the ACTION_BOOT_COMPLETED broadcast will be delivered to the app again.
// https://developer.android.com/about/versions/15/behavior-changes-all#enhanced-stop-states
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
App.activityManager.killBackgroundProcesses(context.packageName)
else
exitProcess(0)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/cn/ac/lz233/tarnhelm/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import cn.ac.lz233.tarnhelm.util.LogUtil
import com.google.android.material.appbar.MaterialToolbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
Expand All @@ -17,6 +21,12 @@ abstract class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope()
super.onCreate(savedInstanceState)
rootView = findViewById(android.R.id.content)
WindowCompat.setDecorFitsSystemWindows(window, false)
ViewCompat.setOnApplyWindowInsetsListener(rootView) { _, insets ->
val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
LogUtil.d("systemBarInsets: $systemBarInsets")
rootView.updatePadding(systemBarInsets.left, systemBarInsets.top, systemBarInsets.right, systemBarInsets.bottom)
WindowInsetsCompat.CONSUMED
}
}

override fun onStart() {
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.7.1' apply false
id 'com.android.library' version '8.7.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
id 'com.android.application' version '8.7.2' apply false
id 'com.android.library' version '8.7.2' apply false
id 'org.jetbrains.kotlin.android' version '2.0.21' apply false
id 'dev.rikka.tools.materialthemebuilder' version '1.3.1'
id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false
id 'com.google.devtools.ksp' version '2.0.21-1.0.27' apply false
}

tasks.register('clean', Delete) {
delete rootProject.buildDir
delete rootProject.layout.buildDirectory
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

0 comments on commit 14df8eb

Please sign in to comment.