Skip to content

Commit

Permalink
Merge pull request #279 from ivpn/bugfix/notifications-on-android-13
Browse files Browse the repository at this point in the history
Notifications no longer show on Android 13
  • Loading branch information
jurajhilje authored Sep 16, 2023
2 parents 6e114d4 + 719296d commit aeecc45
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
}
}

compileSdkVersion 32
compileSdkVersion 33
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@

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

<!-- For Split Tunneling feature-->
<!-- For Split Tunneling feature-->
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- For Start on boot feature-->
<!-- For Start on boot feature-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- For Network Protection Feature-->
<!-- For Network Protection Feature-->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Used to scan Wi-Fi networks-->

<!-- Used to scan Wi-Fi networks-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<!-- To scan QR code-->
<!-- To scan QR code-->
<uses-permission android:name="android.permission.CAMERA" />

<!-- App notifications for API Level 33+ -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- To mock location-->
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fun setImageResource(imageView: ImageView, server: Server?) {
+ countryCode.lowercase() + ".png")
val drawable: Drawable
try {
drawable = Drawable.createFromStream(context.assets.open(path), null)
drawable = Drawable.createFromStream(context.assets.open(path), null)!!
imageView.setImageDrawable(drawable)
} catch (e: IOException) {
e.printStackTrace()
Expand All @@ -98,7 +98,7 @@ fun setImageResource(imageView: ImageView, countryCode: String?) {
+ countryCode.lowercase() + ".png")
val drawable: Drawable
try {
drawable = Drawable.createFromStream(context.assets.open(path), null)
drawable = Drawable.createFromStream(context.assets.open(path), null)!!
imageView.setImageDrawable(drawable)
} catch (e: IOException) {
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import android.view.View
import android.view.View.FOCUS_UP
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
Expand Down Expand Up @@ -119,6 +121,8 @@ class ConnectFragment : Fragment(), MultiHopViewModel.MultiHopNavigator,
var mapPopup: PopupWindow? = null

var notificationDialog: Dialog? = null

private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -135,6 +139,11 @@ class ConnectFragment : Fragment(), MultiHopViewModel.MultiHopNavigator,
LOGGER.info("On view created")
IVPNApplication.appComponent.provideActivityComponent().create().inject(this)
initViews()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}

override fun onViewStateRestored(savedInstanceState: Bundle?) {
Expand Down
36 changes: 20 additions & 16 deletions core/src/main/java/net/ivpn/core/v2/map/MapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package net.ivpn.core.v2.map
along with the IVPN Android app. If not, see <https://www.gnu.org/licenses/>.
*/

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
Expand Down Expand Up @@ -95,10 +96,10 @@ class MapView @JvmOverloads constructor(
}

override fun onScroll(
e1: MotionEvent?,
e2: MotionEvent?,
distanceX: Float,
distanceY: Float
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
math.appendX(distanceX)
math.appendY(distanceY)
Expand All @@ -120,30 +121,27 @@ class MapView @JvmOverloads constructor(
return super.onSingleTapUp(event)
}

override fun onDoubleTap(e: MotionEvent?): Boolean {
return super.onDoubleTap(e)
}
}
private val gestureDetector = GestureDetector(this.context, gestureListener)

private val scaleGestureListener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector?): Boolean {
override fun onScale(detector: ScaleGestureDetector): Boolean {

serverLocationsData.isReady = false
locationData.isReady = false
detector?.let {
detector.let {
math.applyScaleFactor(it.scaleFactor, it.focusX, it.focusY)
}

return true
}

override fun onScaleEnd(detector: ScaleGestureDetector?) {
override fun onScaleEnd(detector: ScaleGestureDetector) {
updateCoordinates()
super.onScaleEnd(detector)
}

override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean {
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
serverLocationsData.isReady = false
locationData.isReady = false
return super.onScaleBegin(detector)
Expand Down Expand Up @@ -172,9 +170,14 @@ class MapView @JvmOverloads constructor(
}
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent?): Boolean {
scaleGestureDetector.onTouchEvent(event)
gestureDetector.onTouchEvent(event)
if (event != null) {
scaleGestureDetector.onTouchEvent(event)
}
if (event != null) {
gestureDetector.onTouchEvent(event)
}
return true
}

Expand Down Expand Up @@ -478,7 +481,7 @@ class MapView @JvmOverloads constructor(
updateCoordinates(true)
}

var coordinateJob: Job? = null
private var coordinateJob: Job? = null
private fun updateCoordinates(isFirstInit: Boolean = false) {
coordinateJob?.cancel()

Expand Down Expand Up @@ -524,7 +527,7 @@ class MapView @JvmOverloads constructor(
}
}

var bitmapCache: LruCache<String, Bitmap?>? = null
private var bitmapCache: LruCache<String, Bitmap?>? = null
private var thumbnails: HashMap<String, Bitmap?>? = null
private fun initTiles() {
val path = resources.getString(R.string.path_to_tiles)
Expand Down Expand Up @@ -574,7 +577,7 @@ class MapView @JvmOverloads constructor(
return prepareBitmapJob
}

val defaultTransparentDrawable = ResourcesCompat.getDrawable(
private val defaultTransparentDrawable = ResourcesCompat.getDrawable(
context.resources,
R.drawable.fill_transparent,
null
Expand All @@ -601,6 +604,7 @@ class MapView @JvmOverloads constructor(
}
}

@SuppressLint("DiscouragedApi")
private fun getIdentifier(context: Context, name: String): Int {
return context.resources.getIdentifier(name, "drawable", IVPNApplication.application.packageName)
}
Expand Down
40 changes: 20 additions & 20 deletions core/src/main/java/net/ivpn/core/v2/map/animation/MapAnimator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ class MapAnimator(val listener: AnimatorListener) {
val movementAnimator = ValueAnimator.ofFloat(0f, 1f)
movementAnimator.duration = MapView.CENTER_ANIMATION_DURATION
movementAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationState = AnimationState.NONE
listener.onCenterAnimationFinish(locations, dialogState)
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
}

})
Expand All @@ -87,18 +87,18 @@ class MapAnimator(val listener: AnimatorListener) {
val movementAnimator = ValueAnimator.ofFloat(0f, 1f)
movementAnimator.duration = MapView.CENTER_ANIMATION_DURATION
movementAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationState = AnimationState.NONE
listener.onCenterAnimationFinish(null, dialogState)
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
}

})
Expand All @@ -115,18 +115,18 @@ class MapAnimator(val listener: AnimatorListener) {
val hideAnimator = ValueAnimator.ofFloat(0f, 1f)
hideAnimator.duration = MapView.HIDE_ANIMATION_DURATION
hideAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
startMovementAnimation(startX, startY)
// listener.onEndMovementAnimation()
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
stopWaveAnimation()
}

Expand All @@ -146,18 +146,18 @@ class MapAnimator(val listener: AnimatorListener) {
val movementAnimator = ValueAnimator.ofFloat(0f, 1f)
movementAnimator.duration = MapView.MOVEMENT_ANIMATION_DURATION
movementAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
startAppearAnimation()
listener.onEndMovementAnimation()
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
stopWaveAnimation()
listener.onStartMovementAnimation()
}
Expand All @@ -175,18 +175,18 @@ class MapAnimator(val listener: AnimatorListener) {
val appearAnimator = ValueAnimator.ofFloat(0f, 1f)
appearAnimator.duration = MapView.APPEAR_ANIMATION_DURATION
appearAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
override fun onAnimationRepeat(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationState = AnimationState.NONE
listener.onEndAppearAnimation()
}

override fun onAnimationCancel(animation: Animator?) {
override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationStart(animation: Animator?) {
override fun onAnimationStart(animation: Animator) {
}

})
Expand Down
2 changes: 1 addition & 1 deletion fdroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
}

compileSdkVersion 32
compileSdkVersion 33
buildToolsVersion "30.0.3"

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion liboqs-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

android {
compileSdkVersion 32
compileSdkVersion 33
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
Expand Down
2 changes: 1 addition & 1 deletion site/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
}

compileSdkVersion 32
compileSdkVersion 33

defaultConfig {
applicationId "net.ivpn.client"
Expand Down
2 changes: 1 addition & 1 deletion store/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
}
}

compileSdkVersion 32
compileSdkVersion 33

defaultConfig {
applicationId "net.ivpn.client"
Expand Down

0 comments on commit aeecc45

Please sign in to comment.