Skip to content

Commit 2b46548

Browse files
authored
Merge pull request #3972 from owncloud/technical/target_sdk_33
[TECHNICAL] Bump target sdk to 33
2 parents ab4b829 + 4e43e95 commit 2b46548

File tree

9 files changed

+84
-2
lines changed

9 files changed

+84
-2
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
// SDK
44
sdkCompileVersion = 33
55
sdkMinVersion = 21
6-
sdkTargetVersion = 31
6+
sdkTargetVersion = 33
77

88
// Android jetpack
99
androidxArchCore = "2.2.0"

changelog/unreleased/3973

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Change: Bump target SDK to 33
2+
3+
Target SDK was upgraded to 33 to keep the app updated with the latest android changes.
4+
A new setting was introduced to manage notifications in an easier way.
5+
6+
https://github.com/owncloud/android/issues/3617
7+
https://github.com/owncloud/android/pull/3972
8+
https://developer.android.com/about/versions/13/behavior-changes-13

owncloudApp/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
API >= 23; the app needs to handle this
4040
-->
4141
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
42+
<!--
43+
Notifications are off by default since API 33;
44+
See note in https://developer.android.com/develop/ui/views/notifications/notification-permission
45+
-->
46+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
4247
<!--
4348
Next permissions are always approved in installation time,
4449
the apps needs to do nothing special in runtime

owncloudApp/src/main/java/com/owncloud/android/presentation/settings/SettingsFragment.kt

+17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import android.content.ClipData
2424
import android.content.ClipboardManager
2525
import android.content.Context
2626
import android.content.Intent
27+
import android.os.Build
2728
import android.os.Bundle
29+
import android.provider.Settings
2830
import androidx.preference.Preference
2931
import androidx.preference.PreferenceFragmentCompat
3032
import androidx.preference.PreferenceScreen
@@ -50,6 +52,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
5052
private var subsectionMore: Preference? = null
5153
private var prefPrivacyPolicy: Preference? = null
5254
private var subsectionWhatsNew: Preference? = null
55+
private var subsectionNotifications: Preference? = null
5356
private var prefAboutApp: Preference? = null
5457

5558
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@@ -61,6 +64,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
6164
subsectionMore = findPreference(SUBSECTION_MORE)
6265
prefPrivacyPolicy = findPreference(PREFERENCE_PRIVACY_POLICY)
6366
subsectionWhatsNew = findPreference(SUBSECTION_WHATSNEW)
67+
subsectionNotifications = findPreference(SUBSECTION_NOTIFICATIONS)
6468
prefAboutApp = findPreference(PREFERENCE_ABOUT_APP)
6569

6670
subsectionPictureUploads?.isVisible = settingsViewModel.isThereAttachedAccount()
@@ -89,6 +93,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
8993
true
9094
}
9195

96+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
97+
subsectionNotifications?.setOnPreferenceClickListener {
98+
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
99+
putExtra(Settings.EXTRA_APP_PACKAGE, requireContext().packageName)
100+
}
101+
startActivity(intent)
102+
true
103+
}
104+
} else {
105+
settingsScreen.removePreferenceFromScreen(subsectionNotifications)
106+
}
107+
92108
prefAboutApp?.apply {
93109
summary = String.format(
94110
getString(R.string.prefs_app_version_summary),
@@ -114,6 +130,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
114130
private const val SUBSECTION_PICTURE_UPLOADS = "picture_uploads_subsection"
115131
private const val SUBSECTION_VIDEO_UPLOADS = "video_uploads_subsection"
116132
private const val SUBSECTION_MORE = "more_subsection"
133+
private const val SUBSECTION_NOTIFICATIONS = "notifications_subsection"
117134

118135
// Remove preference with nullability check
119136
fun PreferenceScreen?.removePreferenceFromScreen(preference: Preference?) {

owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

+34
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@
2727

2828
package com.owncloud.android.ui.activity
2929

30+
import android.Manifest.permission.POST_NOTIFICATIONS
3031
import android.accounts.Account
3132
import android.content.BroadcastReceiver
3233
import android.content.Context
3334
import android.content.Intent
3435
import android.content.IntentFilter
36+
import android.content.pm.PackageManager
3537
import android.net.Uri
38+
import android.os.Build
3639
import android.os.Bundle
3740
import android.os.RemoteException
3841
import android.view.Menu
3942
import android.view.MenuItem
4043
import android.view.View
4144
import android.widget.FrameLayout
45+
import androidx.activity.result.contract.ActivityResultContracts
46+
import androidx.core.content.ContextCompat
4247
import androidx.core.view.isVisible
4348
import androidx.fragment.app.Fragment
4449
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@@ -47,6 +52,7 @@ import com.owncloud.android.AppRater
4752
import com.owncloud.android.BuildConfig
4853
import com.owncloud.android.MainApp
4954
import com.owncloud.android.R
55+
import com.owncloud.android.data.preferences.datasources.SharedPreferencesProvider
5056
import com.owncloud.android.databinding.ActivityMainBinding
5157
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
5258
import com.owncloud.android.domain.capabilities.model.OCCapability
@@ -164,6 +170,8 @@ class FileDisplayActivity : FileActivity(),
164170
private val fileOperationsViewModel: FileOperationsViewModel by viewModel()
165171
private val transfersViewModel: TransfersViewModel by viewModel()
166172

173+
private val sharedPreferences: SharedPreferencesProvider by inject()
174+
167175
var filesUploadHelper: FilesUploadHelper? = null
168176
internal set
169177

@@ -246,9 +254,34 @@ class FileDisplayActivity : FileActivity(),
246254
AppRater.appLaunched(this, packageName)
247255
}
248256

257+
checkNotificationPermission()
249258
Timber.v("onCreate() end")
250259
}
251260

261+
private fun checkNotificationPermission() {
262+
// Ask for permission only in case it's api >= 33 and notifications are not granted.
263+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
264+
ContextCompat.checkSelfPermission(this, POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
265+
) return
266+
267+
// Permission denied. Can be because notifications are off by default or because they were denied by the user.
268+
val alreadyRequested = sharedPreferences.getBoolean(PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED, false)
269+
val shouldShowPermissionRequest = shouldShowRequestPermissionRationale(POST_NOTIFICATIONS)
270+
Timber.d("Already requested notification permission $alreadyRequested and should ask again $shouldShowPermissionRequest")
271+
if (!alreadyRequested || shouldShowPermissionRequest) {
272+
// Not requested yet or system considers we can request the permission again.
273+
val requestPermissionLauncher =
274+
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
275+
Timber.d("Permission to send notifications granted: $isGranted")
276+
if (!isGranted) {
277+
showSnackMessage(getString(R.string.notifications_permission_denied))
278+
}
279+
sharedPreferences.putBoolean(PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED, true)
280+
}
281+
requestPermissionLauncher.launch(POST_NOTIFICATIONS)
282+
}
283+
}
284+
252285
override fun onPostCreate(savedInstanceState: Bundle?) {
253286
super.onPostCreate(savedInstanceState)
254287

@@ -1535,6 +1568,7 @@ class FileDisplayActivity : FileActivity(),
15351568
private const val KEY_UPLOAD_HELPER = "FILE_UPLOAD_HELPER"
15361569
private const val KEY_FILE_LIST_OPTION = "FILE_LIST_OPTION"
15371570

1571+
private const val PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED = "PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED"
15381572
const val ALL_FILES_SAF_REGEX = "*/*"
15391573

15401574
const val ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
10+
</vector>

owncloudApp/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<string name="prefs_camera_video_upload_on_wifi">Upload videos via wifi only</string>
7474
<string name="prefs_camera_video_upload_on_charging">Upload videos only when charging</string>
7575
<string name="prefs_subsection_advanced">Advanced</string>
76+
<string name="prefs_subsection_notifications">Manage notifications</string>
7677
<string name="prefs_show_hidden_files">Show hidden files</string>
7778
<string name="prefs_log_open_logs_list_view">Log files</string>
7879
<string name="prefs_log_no_logs_list_view">Empty log folder!</string>
@@ -548,6 +549,7 @@
548549
<string name="prefs_camera_upload_behaviour_dialog_title">Original file will be</string>
549550
<string name="prefs_camera_upload_behaviour_title">Original file will be</string>
550551
<string name="prefs_camera_upload_last_sync_title">Last synchronization</string>
552+
<string name="notifications_permission_denied">You can update your preferences in Settings</string>
551553
<string name="upload_copy_files">Copy file</string>
552554
<string name="upload_move_files">Move file</string>
553555

owncloudApp/src/main/res/xml/settings.xml

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
app:summary="@string/prefs_subsection_security_summary"
2626
app:title="@string/prefs_subsection_security" />
2727

28+
<Preference
29+
app:allowDividerAbove="true"
30+
app:icon="@drawable/ic_notifications"
31+
app:key="notifications_subsection"
32+
app:title="@string/prefs_subsection_notifications" />
33+
2834
<Preference
2935
app:allowDividerAbove="true"
3036
app:fragment="com.owncloud.android.presentation.settings.logging.SettingsLogsFragment"

0 commit comments

Comments
 (0)