Added back PowerManager hacks + quick link to battery optimized apps list
This commit is contained in:
parent
324399b782
commit
7ba796c27a
5 changed files with 235 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.main.settings.fragments
|
package org.linphone.activities.main.settings.fragments
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -34,7 +35,10 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.settings.viewmodels.AdvancedSettingsViewModel
|
import org.linphone.activities.main.settings.viewmodels.AdvancedSettingsViewModel
|
||||||
|
import org.linphone.core.tools.Log
|
||||||
|
import org.linphone.core.tools.compatibility.DeviceUtils
|
||||||
import org.linphone.databinding.SettingsAdvancedFragmentBinding
|
import org.linphone.databinding.SettingsAdvancedFragmentBinding
|
||||||
|
import org.linphone.utils.PowerManagerUtils
|
||||||
|
|
||||||
class AdvancedSettingsFragment : Fragment() {
|
class AdvancedSettingsFragment : Fragment() {
|
||||||
private lateinit var binding: SettingsAdvancedFragmentBinding
|
private lateinit var binding: SettingsAdvancedFragmentBinding
|
||||||
|
@ -72,6 +76,29 @@ class AdvancedSettingsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.backgroundModeEnabled.value = !DeviceUtils.isAppUserRestricted(requireContext())
|
||||||
|
|
||||||
|
viewModel.goToBatterySettingsEvent.observe(viewLifecycleOwner, Observer { it.consume {
|
||||||
|
try {
|
||||||
|
val intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS")
|
||||||
|
startActivity(intent)
|
||||||
|
} catch (anfe: ActivityNotFoundException) {
|
||||||
|
Log.e("[Advanced Settings] ActivityNotFound exception: ", anfe)
|
||||||
|
}
|
||||||
|
} })
|
||||||
|
|
||||||
|
viewModel.powerManagerSettingsVisibility.value = PowerManagerUtils.getDevicePowerManagerIntent(requireContext()) != null
|
||||||
|
viewModel.goToPowerManagerSettingsEvent.observe(viewLifecycleOwner, Observer { it.consume {
|
||||||
|
val intent = PowerManagerUtils.getDevicePowerManagerIntent(requireActivity())
|
||||||
|
if (intent != null) {
|
||||||
|
try {
|
||||||
|
startActivity(intent)
|
||||||
|
} catch (se: SecurityException) {
|
||||||
|
Log.e("[Advanced Settings] Security exception: ", se)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} })
|
||||||
|
|
||||||
viewModel.goToAndroidSettingsEvent.observe(viewLifecycleOwner, Observer { it.consume {
|
viewModel.goToAndroidSettingsEvent.observe(viewLifecycleOwner, Observer { it.consume {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.lifecycle.MutableLiveData
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.settings.SettingListenerStub
|
import org.linphone.activities.main.settings.SettingListenerStub
|
||||||
|
import org.linphone.mediastream.Version
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
|
@ -45,6 +46,7 @@ class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val backgroundMode = MutableLiveData<Boolean>()
|
val backgroundMode = MutableLiveData<Boolean>()
|
||||||
|
val backgroundModeEnabled = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val autoStartListener = object : SettingListenerStub() {
|
val autoStartListener = object : SettingListenerStub() {
|
||||||
override fun onBoolValueChanged(newValue: Boolean) {
|
override fun onBoolValueChanged(newValue: Boolean) {
|
||||||
|
@ -91,6 +93,22 @@ class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
}
|
}
|
||||||
val logsServerUrl = MutableLiveData<String>()
|
val logsServerUrl = MutableLiveData<String>()
|
||||||
|
|
||||||
|
val goToBatterySettingsListener = object : SettingListenerStub() {
|
||||||
|
override fun onClicked() {
|
||||||
|
goToBatterySettingsEvent.value = Event(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val goToBatterySettingsEvent = MutableLiveData<Event<Boolean>>()
|
||||||
|
val batterySettingsVisibility = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
|
val goToPowerManagerSettingsListener = object : SettingListenerStub() {
|
||||||
|
override fun onClicked() {
|
||||||
|
goToPowerManagerSettingsEvent.value = Event(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val goToPowerManagerSettingsEvent = MutableLiveData<Event<Boolean>>()
|
||||||
|
val powerManagerSettingsVisibility = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val goToAndroidSettingsListener = object : SettingListenerStub() {
|
val goToAndroidSettingsListener = object : SettingListenerStub() {
|
||||||
override fun onClicked() {
|
override fun onClicked() {
|
||||||
goToAndroidSettingsEvent.value = Event(true)
|
goToAndroidSettingsEvent.value = Event(true)
|
||||||
|
@ -113,5 +131,7 @@ class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
deviceName.value = prefs.deviceName
|
deviceName.value = prefs.deviceName
|
||||||
remoteProvisioningUrl.value = core.provisioningUri
|
remoteProvisioningUrl.value = core.provisioningUri
|
||||||
logsServerUrl.value = core.logCollectionUploadServerUrl
|
logsServerUrl.value = core.logCollectionUploadServerUrl
|
||||||
|
|
||||||
|
batterySettingsVisibility.value = Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
162
app/src/main/java/org/linphone/utils/PowerManagerUtils.kt
Normal file
162
app/src/main/java/org/linphone/utils/PowerManagerUtils.kt
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2020 Belledonne Communications SARL.
|
||||||
|
*
|
||||||
|
* This file is part of linphone-android
|
||||||
|
* (see https://www.linphone.org).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.linphone.utils
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.pm.ResolveInfo
|
||||||
|
import android.net.Uri
|
||||||
|
|
||||||
|
class PowerManagerUtils {
|
||||||
|
companion object {
|
||||||
|
// https://stackoverflow.com/questions/31638986/protected-apps-setting-on-huawei-phones-and-how-to-handle-it
|
||||||
|
private val POWER_MANAGER_INTENTS = arrayOf(
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.miui.securitycenter",
|
||||||
|
"com.miui.permcenter.autostart.AutoStartManagementActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.letv.android.letvsafe",
|
||||||
|
"com.letv.android.letvsafe.AutobootManageActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.huawei.systemmanager",
|
||||||
|
"com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.huawei.systemmanager",
|
||||||
|
"com.huawei.systemmanager.optimize.process.ProtectActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.coloros.safecenter",
|
||||||
|
"com.coloros.safecenter.permission.startup.StartupAppListActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.coloros.safecenter",
|
||||||
|
"com.coloros.safecenter.startupapp.StartupAppListActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.oppo.safe",
|
||||||
|
"com.oppo.safe.permission.startup.StartupAppListActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.iqoo.secure",
|
||||||
|
"com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.iqoo.secure",
|
||||||
|
"com.iqoo.secure.ui.phoneoptimize.BgStartUpManager"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.vivo.permissionmanager",
|
||||||
|
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.samsung.android.lool",
|
||||||
|
"com.samsung.android.sm.ui.battery.BatteryActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.htc.pitroad",
|
||||||
|
"com.htc.pitroad.landingpage.activity.LandingPageActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.asus.mobilemanager", "com.asus.mobilemanager.MainActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.asus.mobilemanager",
|
||||||
|
"com.asus.mobilemanager.autostart.AutoStartActivity"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.asus.mobilemanager",
|
||||||
|
"com.asus.mobilemanager.entry.FunctionActivity"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setData(Uri.parse("mobilemanager://function/entry/AutoStart")),
|
||||||
|
Intent()
|
||||||
|
.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
"com.dewav.dwappmanager",
|
||||||
|
"com.dewav.dwappmanager.memory.SmartClearupWhiteList"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun getDevicePowerManagerIntent(context: Context): Intent? {
|
||||||
|
for (intent in POWER_MANAGER_INTENTS) {
|
||||||
|
if (isIntentCallable(context, intent)) {
|
||||||
|
return intent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isIntentCallable(context: Context, intent: Intent): Boolean {
|
||||||
|
val list: List<ResolveInfo> = context.packageManager
|
||||||
|
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||||
|
return list.isNotEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,6 +74,7 @@
|
||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/settings_widget_switch"
|
layout="@layout/settings_widget_switch"
|
||||||
|
linphone:enabled="@{viewModel.backgroundModeEnabled}"
|
||||||
linphone:title="@{@string/advanced_settings_background_mode_title}"
|
linphone:title="@{@string/advanced_settings_background_mode_title}"
|
||||||
linphone:subtitle="@{@string/advanced_settings_background_mode_summary}"
|
linphone:subtitle="@{@string/advanced_settings_background_mode_summary}"
|
||||||
linphone:listener="@{viewModel.backgroundModeListener}"
|
linphone:listener="@{viewModel.backgroundModeListener}"
|
||||||
|
@ -117,6 +118,28 @@
|
||||||
linphone:defaultValue="@{viewModel.logsServerUrl}"
|
linphone:defaultValue="@{viewModel.logsServerUrl}"
|
||||||
linphone:inputType="@{InputType.TYPE_TEXT_VARIATION_URI}"/>
|
linphone:inputType="@{InputType.TYPE_TEXT_VARIATION_URI}"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/settings_category_font"
|
||||||
|
android:id="@+id/pref_video_codecs_header"
|
||||||
|
android:text="@string/android_settings_codecs_title"
|
||||||
|
android:paddingTop="15dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_basic"
|
||||||
|
android:visibility="@{viewModel.batterySettingsVisibility ? View.VISIBLE : View.GONE}"
|
||||||
|
linphone:listener="@{viewModel.goToBatterySettingsListener}"
|
||||||
|
linphone:title="@{@string/advanced_settings_go_to_battery_optimization_settings}" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_basic"
|
||||||
|
android:visibility="@{viewModel.powerManagerSettingsVisibility ? View.VISIBLE : View.GONE}"
|
||||||
|
linphone:listener="@{viewModel.goToPowerManagerSettingsListener}"
|
||||||
|
linphone:title="@{@string/advanced_settings_go_to_power_manager_settings}" />
|
||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/settings_widget_basic"
|
layout="@layout/settings_widget_basic"
|
||||||
linphone:listener="@{viewModel.goToAndroidSettingsListener}"
|
linphone:listener="@{viewModel.goToAndroidSettingsListener}"
|
||||||
|
|
|
@ -391,6 +391,9 @@
|
||||||
<string name="advanced_settings_remote_provisioning_url_summary"></string>
|
<string name="advanced_settings_remote_provisioning_url_summary"></string>
|
||||||
<string name="advanced_settings_logs_server_url_title">Logs upload server URL</string>
|
<string name="advanced_settings_logs_server_url_title">Logs upload server URL</string>
|
||||||
<string name="advanced_settings_logs_server_url_summary">Do not edit unless you know what you are doing!</string>
|
<string name="advanced_settings_logs_server_url_summary">Do not edit unless you know what you are doing!</string>
|
||||||
|
<string name="android_settings_codecs_title">Android</string>
|
||||||
|
<string name="advanced_settings_go_to_battery_optimization_settings">Battery optimization settings</string>
|
||||||
|
<string name="advanced_settings_go_to_power_manager_settings">Power manager settings</string>
|
||||||
<string name="advanced_settings_go_to_android_app_settings">Android app settings</string>
|
<string name="advanced_settings_go_to_android_app_settings">Android app settings</string>
|
||||||
|
|
||||||
<!-- Tunnel settings -->
|
<!-- Tunnel settings -->
|
||||||
|
|
Loading…
Reference in a new issue