aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-11-07 19:51:06 -0500
committerMatthew Wong <wongma@protonmail.ch>2015-11-07 19:51:06 -0500
commitb78465b744c418a562e920e763abd62cb2b5cb2e (patch)
treec12e4a27b602bb84622c4310928ecea052b0ae62 /app/src/main/java/com
parent54a05daa82c603d54f7b27dc0b5ac3a708412187 (diff)
Request system_alert_window permission in android m, fix #138,
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
index 42fed298..2b32a809 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -1,6 +1,5 @@
package com.zeapo.pwdstore.autofill;
-import android.Manifest;
import android.accessibilityservice.AccessibilityService;
import android.app.PendingIntent;
import android.content.ClipData;
@@ -11,10 +10,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.support.v4.content.ContextCompat;
+import android.provider.Settings;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.WindowManager;
@@ -69,12 +69,6 @@ public class AutofillService extends AccessibilityService {
// TODO change search/search results (just use first result)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW)
- == PackageManager.PERMISSION_DENIED) {
- // may need a way to request the permission but only activities can, so by notification?
- return;
- }
-
// if returning to the source app from a successful AutofillActivity
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
&& event.getPackageName().equals(packageName) && resultData != null) {
@@ -105,6 +99,16 @@ public class AutofillService extends AccessibilityService {
return;
}
+ // need to request permission before attempting to draw dialog
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
+ && !Settings.canDrawOverlays(this)) {
+ Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
+ Uri.parse("package:" + getApplicationContext().getPackageName()));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ return;
+ }
+
info = event.getSource();
// save the dialog's corresponding window so we can use getWindows() in dismissDialog