From 3fffd410328f3816d0056b9e4269228c70538825 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 10 Nov 2015 15:32:59 +0100 Subject: [PATCH] Request device admin on credentials enabled Refs #92 --- .../eu/faircode/netguard/ActivitySettings.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 20c55b2a..c13101d5 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -19,6 +19,8 @@ package eu.faircode.netguard; Copyright 2015 by Marcel Bokhorst (M66B) */ +import android.app.admin.DevicePolicyManager; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -127,7 +129,17 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else if ("manage_system".equals(name)) SinkholeService.reload(null, this); - else if ("dark_theme".equals(name)) + else if ("credentials".equals(name)) { + ComponentName component = new ComponentName(this, DeviceAdministratorReceiver.class); + DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); + if (prefs.getBoolean(name, false) && !dpm.isAdminActive(component)) { + Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); + intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component); + if (intent.resolveActivity(getPackageManager()) != null) + startActivity(intent); + } + + } else if ("dark_theme".equals(name)) recreate(); }