mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
add consent dialog for accessibility service
This commit is contained in:
parent
46aaa91fe9
commit
97d10d09b5
6 changed files with 98 additions and 8 deletions
|
@ -1,12 +1,14 @@
|
|||
package de.jrpie.android.launcher.actions.lock
|
||||
|
||||
import android.accessibilityservice.AccessibilityService
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.widget.CheckBox
|
||||
import android.widget.Toast
|
||||
import de.jrpie.android.launcher.R
|
||||
|
||||
|
@ -50,6 +52,32 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
.contains("${context.packageName}/${LauncherAccessibilityService::class.java.name}")
|
||||
.also { Log.d(TAG, "Accessibility Service enabled: $it") }
|
||||
}
|
||||
|
||||
fun showEnableDialog(context: Context) {
|
||||
AlertDialog.Builder(context, R.style.AlertDialogDanger).apply {
|
||||
setView(R.layout.dialog_consent_accessibility)
|
||||
setTitle(R.string.dialog_consent_accessibility_title)
|
||||
setPositiveButton(R.string.dialog_consent_accessibility_ok) { _, _ ->
|
||||
lockScreen(context)
|
||||
}
|
||||
setNegativeButton(R.string.dialog_consent_accessibility_cancel) { _, _ -> }
|
||||
}.create().also { it.show() }.apply {
|
||||
val buttonOk = getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
val checkboxes = listOf(
|
||||
findViewById<CheckBox>(R.id.dialog_consent_accessibility_checkbox_1),
|
||||
findViewById(R.id.dialog_consent_accessibility_checkbox_2),
|
||||
findViewById(R.id.dialog_consent_accessibility_checkbox_3),
|
||||
findViewById(R.id.dialog_consent_accessibility_checkbox_4),
|
||||
)
|
||||
val update = {
|
||||
buttonOk.isEnabled = checkboxes.map { b -> b?.isChecked == true }.all { it }
|
||||
}
|
||||
update()
|
||||
checkboxes.forEach { c ->
|
||||
c?.setOnClickListener { _ -> update() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ enum class LockMethod(
|
|||
ACCESSIBILITY_SERVICE(
|
||||
LauncherAccessibilityService::lockScreen,
|
||||
LauncherAccessibilityService::isEnabled,
|
||||
LauncherAccessibilityService::lockScreen
|
||||
LauncherAccessibilityService::showEnableDialog
|
||||
),
|
||||
;
|
||||
|
||||
|
|
5
app/src/main/res/color/text_color_toggle.xml
Normal file
5
app/src/main/res/color/text_color_toggle.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="false" android:alpha="0.2" android:color="?android:color" />
|
||||
<item android:color="?android:color" />
|
||||
</selector>
|
50
app/src/main/res/layout/dialog_consent_accessibility.xml
Normal file
50
app/src/main/res/layout/dialog_consent_accessibility.xml
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/AlertDialogDanger"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<de.jrpie.android.launcher.ui.util.HtmlTextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_consent_accessibility_text" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dialog_consent_accessibility_checkbox_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="10dp"
|
||||
android:text="@string/dialog_consent_accessibility_privileges" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dialog_consent_accessibility_checkbox_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="10dp"
|
||||
android:text="@string/dialog_consent_accessibility_other_options" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dialog_consent_accessibility_checkbox_3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="10dp"
|
||||
android:text="@string/dialog_consent_accessibility_data_collection" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dialog_consent_accessibility_checkbox_4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="10dp"
|
||||
android:text="@string/dialog_consent_accessibility_consent" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -298,4 +298,12 @@
|
|||
<string name="dialog_select_color_cancel">Cancel</string>
|
||||
<string name="dialog_select_color_color_hex">Color</string>
|
||||
<string name="dialog_choose_color_title">Choose color</string>
|
||||
<string name="dialog_consent_accessibility_privileges">I am aware that this will grant far-reaching privileges to µLauncher.</string>
|
||||
<string name="dialog_consent_accessibility_other_options">I am aware that other options exist (using device administrator privileges or the power button).</string>
|
||||
<string name="dialog_consent_accessibility_consent">I consent to µLauncher using the accessibility service to provide functionality unrelated to accessibility.</string>
|
||||
<string name="dialog_consent_accessibility_data_collection">I consent to µLauncher not collecting any data.</string>
|
||||
<string name="dialog_consent_accessibility_text"><![CDATA[You are about to activate the accessibility service. This will grant <strong>far-reaching privileges</strong> to µLauncher.<br/>µLauncher will use these privileges <strong>only to lock the screen</strong>. µLauncher <strong>will never collect any data</strong>. In particular, µLauncher does not use the accessibility service to collect any data.]]></string>
|
||||
<string name="dialog_consent_accessibility_title">Activating the Accessibility Service</string>
|
||||
<string name="dialog_consent_accessibility_ok">Activate Accessibility Service</string>
|
||||
<string name="dialog_consent_accessibility_cancel">Cancel</string>
|
||||
</resources>
|
||||
|
|
|
@ -116,19 +116,18 @@
|
|||
<item name="android:textColor">#000</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<style name="PopupMenuCustom" parent="@android:style/Widget.PopupMenu" tools:keep="@style/PopupMenuCustom">
|
||||
<item name="android:popupBackground">#252827</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
|
||||
<item name="android:textColor">#000000</item>
|
||||
<item name="android:background">#ffffff</item>
|
||||
<item name="android:color">#000000</item>
|
||||
<item name="android:textColor">@color/text_color_toggle</item>
|
||||
<item name="android:background">#ffffff</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialogDanger" parent="AlertDialogCustom">
|
||||
<item name="buttonTint">#ff0000</item>
|
||||
</style>
|
||||
|
||||
<!-- Set the fade in animation on all activities by default -->
|
||||
|
|
Loading…
Add table
Reference in a new issue