diff --git a/app/build.gradle b/app/build.gradle index e3e3b79..e57dd9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,13 +2,13 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 30 + compileSdkVersion 33 buildToolsVersion '30.0.3' defaultConfig { applicationId "me.hackerchick.raisetoanswer" minSdkVersion 26 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 32 versionName "3.6.5" @@ -36,11 +36,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.core:core-ktx:1.3.2' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ea73ca..18a366f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,8 @@ + + + android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" + android:exported="true"> @@ -25,7 +28,8 @@ - + diff --git a/app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt b/app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt index cdcdd99..68a2a02 100644 --- a/app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt +++ b/app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt @@ -1,12 +1,17 @@ package me.hackerchick.raisetoanswer import android.Manifest -import android.content.* +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent import android.content.pm.PackageManager import android.content.res.Configuration import android.net.Uri import android.os.Build import android.os.Bundle +import android.os.PowerManager +import android.provider.Settings import android.view.Menu import android.view.MenuInflater import android.view.MenuItem @@ -25,7 +30,7 @@ class MainActivity : AppCompatActivity() { private var PERMISSION_REQUEST_READ_PHONE_STATE = 1 - private var mMenu : Menu? = null + private var mMenu: Menu? = null private var mTestMode = false private var mTestRunning = false @@ -79,6 +84,20 @@ class MainActivity : AppCompatActivity() { startApp() } + + private fun checkPowerSettings() { + val intent = Intent() + val pm: PowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager + if (pm.isIgnoringBatteryOptimizations(applicationContext.packageName)) { + /** Already battery optimization is ignored for this app so nothing to do here, + * the foreground service can we invoked even if the app is in the background**/ + } else { + intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS + intent.data = Uri.parse("package:${applicationContext.packageName}") + this.startActivity(intent) + } + } + override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) @@ -90,6 +109,7 @@ class MainActivity : AppCompatActivity() { permissions: Array, grantResults: IntArray ) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { PERMISSION_REQUEST_READ_PHONE_STATE -> { if (!grantResults.all { it == PackageManager.PERMISSION_GRANTED }) { @@ -156,7 +176,11 @@ class MainActivity : AppCompatActivity() { val vibrateBehaviour: SwitchCompat = binding.behaviourVibrate setAnswerFeature(Util.answerFeatureEnabled(applicationContext), false) - setAnswerAllAnglesFeatureIfSupported(Util.answerAllAnglesFeatureEnabled(applicationContext)) + setAnswerAllAnglesFeatureIfSupported( + Util.answerAllAnglesFeatureEnabled( + applicationContext + ) + ) setDeclineFeatureIfSupported(Util.declineFeatureEnabled(applicationContext)) setBeepBehaviour(Util.beepBehaviourEnabled(applicationContext)) @@ -182,14 +206,12 @@ class MainActivity : AppCompatActivity() { setVibrateBehaviour(isChecked) } + checkPowerSettings() + // Debugging val debugLog: TextView = binding.debugLog debugLog.setOnClickListener { - val logData = Util.getLog().value - - if (logData == null) { - return@setOnClickListener - } + val logData = Util.getLog().value ?: return@setOnClickListener val clipboard: ClipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager @@ -294,13 +316,13 @@ class MainActivity : AppCompatActivity() { testButton.visibility = View.VISIBLE debugLog.visibility = View.VISIBLE - Util.getLog().observe(this, { + Util.getLog().observe(this) { try { debugLog.text = it.reversed().joinToString(separator = "\n") } catch (ConcurrentModificationException: Exception) { // We don't care, just skip this update then... } - }) + } testButton.text = getString(R.string.start_test) } else { diff --git a/app/src/main/java/me/hackerchick/raisetoanswer/RaiseToAnswerSensorEventListener.kt b/app/src/main/java/me/hackerchick/raisetoanswer/RaiseToAnswerSensorEventListener.kt index d1f7b51..db9e971 100644 --- a/app/src/main/java/me/hackerchick/raisetoanswer/RaiseToAnswerSensorEventListener.kt +++ b/app/src/main/java/me/hackerchick/raisetoanswer/RaiseToAnswerSensorEventListener.kt @@ -2,6 +2,7 @@ package me.hackerchick.raisetoanswer import android.annotation.SuppressLint import android.app.* +import android.app.PendingIntent.FLAG_IMMUTABLE import android.content.Context import android.content.Intent import android.hardware.Sensor @@ -83,7 +84,7 @@ class RaiseToAnswerSensorEventListener : Service(), SensorEventListener { val pendingIntent: PendingIntent = Intent(this, MainActivity::class.java).let { notificationIntent -> - PendingIntent.getActivity(this, 0, notificationIntent, 0) + PendingIntent.getActivity(this, 0, notificationIntent, FLAG_IMMUTABLE) } val channel = NotificationChannel("incoming_call", getString(R.string.incoming_call_service), NotificationManager.IMPORTANCE_LOW) diff --git a/build.gradle b/build.gradle index 1f100d5..a124182 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.32' + ext.kotlin_version = '1.7.20' repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' + classpath 'com.android.tools.build:gradle:7.0.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -18,7 +18,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } }