Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'
}
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
<uses-feature android:name="android.hardware.sensor.accelerometer" />
<uses-feature android:name="android.hardware.sensor.proximity" />

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name=".RaiseToAnswerCallReceiver" >
<receiver android:name=".RaiseToAnswerCallReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
Expand Down
42 changes: 32 additions & 10 deletions app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -90,6 +109,7 @@ class MainActivity : AppCompatActivity() {
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
PERMISSION_REQUEST_READ_PHONE_STATE -> {
if (!grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down