Show a toast when filtering obscured touch input

We can't verify user consent if the touch input is obscured, so the
best we can do is fail with an informative message.

BUG: 18082299
Change-Id: I99bea51171d998c0e0ba58dd7bbf1167d4af925d
This commit is contained in:
Alan Viverette
2014-12-16 16:51:19 -08:00
parent 7068d702bd
commit 3c682c32a4
2 changed files with 28 additions and 3 deletions

View File

@@ -3689,6 +3689,11 @@
<!-- Title for the list of capabilities of an accessibility service. --> <!-- Title for the list of capabilities of an accessibility service. -->
<string name="capabilities_list_title"><xliff:g id="service" example="TalkBack">%1$s</xliff:g> <string name="capabilities_list_title"><xliff:g id="service" example="TalkBack">%1$s</xliff:g>
needs to:</string> needs to:</string>
<!-- Warning shown when user input has been blocked due to another app overlaying screen
content. Since we don't know what the app is showing on top of the input target, we
can't verify user consent. [CHAR LIMIT=NONE] -->
<string name="touch_filtered_warning">Because an app is obscuring a permission request, Settings
cant verify your response.</string>
<!-- Warning that the device data will not be encrypted with password or PIN if <!-- Warning that the device data will not be encrypted with password or PIN if
enabling an accessibility service and there is a secure lock setup. [CHAR LIMIT=NONE] --> enabling an accessibility service and there is a secure lock setup. [CHAR LIMIT=NONE] -->
<string name="enable_service_encryption_warning">If you turn on <xliff:g id="service" <string name="enable_service_encryption_warning">If you turn on <xliff:g id="service"

View File

@@ -32,11 +32,13 @@ import android.os.Handler;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.ConfirmDeviceCredentialActivity; import com.android.settings.ConfirmDeviceCredentialActivity;
@@ -168,11 +170,13 @@ public class ToggleAccessibilityServicePreferenceFragment
switch (dialogId) { switch (dialogId) {
case DIALOG_ID_ENABLE_WARNING: { case DIALOG_ID_ENABLE_WARNING: {
mShownDialogId = DIALOG_ID_ENABLE_WARNING; mShownDialogId = DIALOG_ID_ENABLE_WARNING;
AccessibilityServiceInfo info = getAccessibilityServiceInfo();
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
if (info == null) { if (info == null) {
return null; return null;
} }
AlertDialog ad = new AlertDialog.Builder(getActivity())
final AlertDialog ad = new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.enable_service_title, .setTitle(getString(R.string.enable_service_title,
info.getResolveInfo().loadLabel(getPackageManager()))) info.getResolveInfo().loadLabel(getPackageManager())))
.setView(createEnableDialogContentView(info)) .setView(createEnableDialogContentView(info))
@@ -180,8 +184,24 @@ public class ToggleAccessibilityServicePreferenceFragment
.setPositiveButton(android.R.string.ok, this) .setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this) .setNegativeButton(android.R.string.cancel, this)
.create(); .create();
final View.OnTouchListener filterTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Filter obscured touches by consuming them.
if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Toast.makeText(v.getContext(), R.string.touch_filtered_warning,
Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
}
};
ad.create(); ad.create();
ad.getButton(AlertDialog.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true); ad.getButton(AlertDialog.BUTTON_POSITIVE).setOnTouchListener(filterTouchListener);
return ad; return ad;
} }
case DIALOG_ID_DISABLE_WARNING: { case DIALOG_ID_DISABLE_WARNING: {