diff --git a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt index 1aee986d32..08155b2a34 100644 --- a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt @@ -16,48 +16,22 @@ package io.element.android.libraries.androidutils.system -import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.Activity -import android.app.NotificationManager import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Build -import android.os.PowerManager import android.provider.Settings import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.annotation.ChecksSdkIntAtLeast import androidx.annotation.RequiresApi -import androidx.core.content.getSystemService import io.element.android.libraries.androidutils.R import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat -/** - * Tells if the application ignores battery optimizations. - * - * Ignoring them allows the app to run in background to make background sync with the homeserver. - * This user option appears on Android M but Android O enforces its usage and kills apps not - * authorised by the user to run in background. - * - * @return true if battery optimisations are ignored - */ -fun Context.isIgnoringBatteryOptimizations(): Boolean { - // no issue before Android M, battery optimisations did not exist - return getSystemService()?.isIgnoringBatteryOptimizations(packageName) == true -} - -fun Context.isAirplaneModeOn(): Boolean { - return Settings.Global.getInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0) != 0 -} - -fun Context.isAnimationEnabled(): Boolean { - return Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) != 0f -} - @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O) fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O @@ -73,32 +47,6 @@ fun Context.getApplicationLabel(packageName: String): String { } } -/** - * Return true it the user has enabled the do not disturb mode. - */ -fun Context.isDoNotDisturbModeOn(): Boolean { - // We cannot use NotificationManagerCompat here. - val setting = getSystemService()!!.currentInterruptionFilter - - return setting == NotificationManager.INTERRUPTION_FILTER_NONE || - setting == NotificationManager.INTERRUPTION_FILTER_ALARMS -} - -/** - * display the system dialog for granting this permission. If previously granted, the - * system will not show it (so you should call this method). - * - * Note: If the user finally does not grant the permission, PushManager.isBackgroundSyncAllowed() - * will return false and the notification privacy will fallback to "LOW_DETAIL". - */ -@SuppressLint("BatteryLife") -fun Context.requestDisablingBatteryOptimization(activityResultLauncher: ActivityResultLauncher) { - val intent = Intent() - intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - intent.data = Uri.parse("package:$packageName") - activityResultLauncher.launch(intent) -} - // ============================================================================================================== // Clipboard helper // ============================================================================================================== @@ -169,19 +117,6 @@ fun Activity.startNotificationChannelSettingsIntent(channelID: String) { startActivity(intent) } -fun Context.startAddGoogleAccountIntent( - activityResultLauncher: ActivityResultLauncher, - noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found), -) { - val intent = Intent(Settings.ACTION_ADD_ACCOUNT) - intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, arrayOf("com.google")) - try { - activityResultLauncher.launch(intent) - } catch (activityNotFoundException: ActivityNotFoundException) { - toast(noActivityFoundMessage) - } -} - @RequiresApi(Build.VERSION_CODES.O) fun Context.startInstallFromSourceIntent( activityResultLauncher: ActivityResultLauncher, @@ -227,20 +162,6 @@ fun Context.startSharePlainTextIntent( } } -fun Context.startImportTextFromFileIntent( - activityResultLauncher: ActivityResultLauncher, - noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found), -) { - val intent = Intent(Intent.ACTION_GET_CONTENT).apply { - type = "text/plain" - } - try { - activityResultLauncher.launch(intent) - } catch (activityNotFoundException: ActivityNotFoundException) { - toast(noActivityFoundMessage) - } -} - @Suppress("SwallowedException") fun Context.openUrlInExternalApp( url: String,