Remove unused code to increase code coverage.
This commit is contained in:
parent
6e4635b4cd
commit
304be71122
1 changed files with 0 additions and 79 deletions
|
|
@ -16,48 +16,22 @@
|
||||||
|
|
||||||
package io.element.android.libraries.androidutils.system
|
package io.element.android.libraries.androidutils.system
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.NotificationManager
|
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.annotation.ChecksSdkIntAtLeast
|
import androidx.annotation.ChecksSdkIntAtLeast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import io.element.android.libraries.androidutils.R
|
import io.element.android.libraries.androidutils.R
|
||||||
import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat
|
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<PowerManager>()?.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)
|
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
|
||||||
fun supportNotificationChannels() = Build.VERSION.SDK_INT >= 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<NotificationManager>()!!.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<Intent>) {
|
|
||||||
val intent = Intent()
|
|
||||||
intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
|
||||||
intent.data = Uri.parse("package:$packageName")
|
|
||||||
activityResultLauncher.launch(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==============================================================================================================
|
// ==============================================================================================================
|
||||||
// Clipboard helper
|
// Clipboard helper
|
||||||
// ==============================================================================================================
|
// ==============================================================================================================
|
||||||
|
|
@ -169,19 +117,6 @@ fun Activity.startNotificationChannelSettingsIntent(channelID: String) {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.startAddGoogleAccountIntent(
|
|
||||||
activityResultLauncher: ActivityResultLauncher<Intent>,
|
|
||||||
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)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
fun Context.startInstallFromSourceIntent(
|
fun Context.startInstallFromSourceIntent(
|
||||||
activityResultLauncher: ActivityResultLauncher<Intent>,
|
activityResultLauncher: ActivityResultLauncher<Intent>,
|
||||||
|
|
@ -227,20 +162,6 @@ fun Context.startSharePlainTextIntent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.startImportTextFromFileIntent(
|
|
||||||
activityResultLauncher: ActivityResultLauncher<Intent>,
|
|
||||||
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")
|
@Suppress("SwallowedException")
|
||||||
fun Context.openUrlInExternalApp(
|
fun Context.openUrlInExternalApp(
|
||||||
url: String,
|
url: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue