Request device admin on credentials enabled

Refs #92
This commit is contained in:
M66B 2015-11-10 15:32:59 +01:00
parent 98b0ee7a3a
commit 3fffd41032
1 changed files with 13 additions and 1 deletions

View File

@ -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();
}