Skip to content

Commit

Permalink
Update permission management
Browse files Browse the repository at this point in the history
  • Loading branch information
Domi04151309 committed Aug 4, 2022
1 parent 6902f55 commit f2b9a13
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import io.github.domi04151309.alwayson.R
import io.github.domi04151309.alwayson.services.AlwaysOnTileService
import io.github.domi04151309.alwayson.helpers.Global
Expand Down Expand Up @@ -146,6 +147,24 @@ class MainActivity : AppCompatActivity() {
class GeneralPreferenceFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_main)

if (!Permissions.isDeviceAdminOrRoot(requireContext())) {
var currentPref: Preference?
var currentPrefAsSwitch: SwitchPreference?
Permissions.DEVICE_ADMIN_OR_ROOT_PERMISSION_PREFS.forEach {
currentPref = findPreference(it)
if (currentPref != null) {
currentPref?.isEnabled = false
currentPref?.setSummary(R.string.permissions_device_admin_or_root)
currentPrefAsSwitch = currentPref as? SwitchPreference
if (currentPrefAsSwitch != null) {
currentPrefAsSwitch?.setSummaryOff(R.string.permissions_device_admin_or_root)
currentPrefAsSwitch?.setSummaryOn(R.string.permissions_device_admin_or_root)
}
}
}
}

findPreference<Preference>("always_on")?.setOnPreferenceClickListener {
TileService.requestListeningState(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ object Permissions {
)

val DEVICE_ADMIN_OR_ROOT_PERMISSION_PREFS: Array<String> = arrayOf(
P.RULES_CHARGING_STATE, P.RULES_BATTERY, "rules_time", P.RULES_TIMEOUT
"charging_animation", P.RULES_CHARGING_STATE, P.RULES_BATTERY, "rules_time",
P.RULES_TIMEOUT, P.CHARGING_STYLE
)

private val CALENDAR_PERMISSION_PREFS: Array<String> = arrayOf(
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
android:padding="?dialogPreferredPadding"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:text="@string/missing_permissions"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?dialogPreferredPadding"
android:text="@string/help_center_missing_permissions_text"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@

<string name="help_center">Hilfe Center</string>
<string name="help_center_summary">Deinstallation, Verzögerungen, Batterieverbrauch</string>
<string name="help_center_missing_permissions_text">Wenn eine Einstellung ausgegraut ist und Sie auffordert, zuerst etwas zu aktivieren, haben Sie die erforderlichen Berechtigungen noch nicht aktiviert. Um fehlende Berechtigungen zu erteilen, öffnen Sie die Seite „Berechtigungen“ auf der Hauptseite und stimmen Sie der Verwendung der erforderlichen Berechtigungen zu. Sie können jetzt die Einstellungen aktivieren, die diese Berechtigungen benötigen.</string>
<string name="help_center_uninstall">Deinstallieren</string>
<string name="help_center_uninstall_text">Der Deinstallationsprozess kann aufgrund eines Designfehlers im Android-Betriebssystem fehlschlagen. Wenn die Administratorberechtigung des Geräts vor der Deinstallation nicht deaktiviert wurde, schlägt der Prozess fehl. Sie müssen die Administratorrechte des Geräts deaktivieren, bevor Sie die App deinstallieren können.</string>
<string name="help_center_uninstall_button">Jetzt deinstallieren</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@

<string name="help_center">Help center</string>
<string name="help_center_summary">Uninstalling, unresponsiveness, battery drain</string>
<string name="help_center_missing_permissions_text">When a setting is grayed out and tells you to enable something first, you have not enabled the needed permissions yet. To grant missing permissions open the “Permissions” page on the main page and consent to using the required permissions. You can now enable the settings that need those permissions.</string>
<string name="help_center_uninstall">How to uninstall</string>
<string name="help_center_uninstall_text">The uninstall process can fail due to a design flaw in the Android operating system. If the device admin permission was not disabled before uninstalling the process will fail. You have to disable the device admin permission before uninstalling.</string>
<string name="help_center_uninstall_button">Uninstall now</string>
Expand Down

0 comments on commit f2b9a13

Please sign in to comment.