List of usage examples for android.content Context DEVICE_POLICY_SERVICE
String DEVICE_POLICY_SERVICE
To view the source code for android.content Context DEVICE_POLICY_SERVICE.
Click Source Link
From source file:Main.java
/** * @return true if the device or profile is already owned by TestDPC *//*from w w w .j av a 2 s. c om*/ public static boolean isManagedByTestDPC(Context context) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); String packageName = context.getPackageName(); return devicePolicyManager.isProfileOwnerApp(packageName) || devicePolicyManager.isDeviceOwnerApp(packageName); }
From source file:Main.java
/** * @return true if the device or profile is already owned *///from ww w. j av a 2 s. c o m public static boolean isManaged(Context context) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); List<ComponentName> admins = devicePolicyManager.getActiveAdmins(); if (admins == null) return false; for (ComponentName admin : admins) { String adminPackageName = admin.getPackageName(); if (devicePolicyManager.isDeviceOwnerApp(adminPackageName) || devicePolicyManager.isProfileOwnerApp(adminPackageName)) { return true; } } return false; }
From source file:com.example.android.apprestrictionenforcer.EnableProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (null == savedInstanceState) { // Enable the newly created profile DevicePolicyManager manager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName componentName = EnforcerDeviceAdminReceiver.getComponentName(this); manager.setProfileName(componentName, getString(R.string.profile_name)); manager.setProfileEnabled(componentName); }/*from ww w.j a v a 2 s . com*/ // Open the main screen startActivity(new Intent(this, MainActivity.class)); finish(); }
From source file:com.example.android.apprestrictionenforcer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_real); if (null == savedInstanceState) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); PackageManager packageManager = getPackageManager(); if (!devicePolicyManager.isProfileOwnerApp(getApplicationContext().getPackageName())) { // If the managed profile is not yet set up, we show the setup screen. showSetupProfile();/*from w w w . j av a2 s . c o m*/ } else { try { ApplicationInfo info = packageManager.getApplicationInfo( Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, PackageManager.GET_UNINSTALLED_PACKAGES); if (0 == (info.flags & ApplicationInfo.FLAG_INSTALLED)) { // Need to reinstall the sample app showStatusProfile(); } else if (devicePolicyManager.isApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(this), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA)) { // The app is installed but hidden in this profile showStatusProfile(); } else { // Everything is clear; show the main screen showMainFragment(); } } catch (PackageManager.NameNotFoundException e) { showStatusProfile(); } } } }
From source file:at.wada811.utils.CameraUtils.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean isCameraDisabled(Context context) { if (AndroidUtils.isMoreThanBuildVersion(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); return devicePolicyManager.getCameraDisabled(null); } else {/*from w w w .j a va2 s . c o m*/ return false; } }
From source file:org.wso2.iot.agent.events.listeners.KioskAppInstallationListener.java
@RequiresApi(api = Build.VERSION_CODES.M) @Override/*w ww . j a v a 2 s .c o m*/ public void onReceive(Context context, Intent intent) { devicePolicyManager = (DevicePolicyManager) context.getApplicationContext() .getSystemService(Context.DEVICE_POLICY_SERVICE); cdmfDeviceAdmin = AgentDeviceAdminReceiver.getComponentName(context.getApplicationContext()); String lockTaskPackages; String packageName = intent.getData().getEncodedSchemeSpecificPart(); if (!Constants.ALLOW_MULTIPLE_APPS_IN_COSU_MODE) { Preference.putString(context.getApplicationContext(), Constants.KIOSK_APP_PACKAGE_NAME, packageName); lockTaskPackages = context.getApplicationContext().getPackageName() + context.getString(R.string.kiosk_application_package_split_regex) + packageName; } else { String currentList = Preference.getString(context, Constants.KIOSK_APP_PACKAGE_NAME); if (currentList == null) { Preference.putString(context.getApplicationContext(), Constants.KIOSK_APP_PACKAGE_NAME, packageName); lockTaskPackages = context.getApplicationContext().getPackageName() + context.getString(R.string.kiosk_application_package_split_regex) + packageName; } else { if (!currentList.contains(packageName)) { Preference.putString(context.getApplicationContext(), Constants.KIOSK_APP_PACKAGE_NAME, currentList + context.getString(R.string.kiosk_application_package_split_regex) + packageName); lockTaskPackages = context.getApplicationContext().getPackageName() + context.getString(R.string.kiosk_application_package_split_regex) + currentList + context.getString(R.string.kiosk_application_package_split_regex) + packageName; } else { String newPackageList = ""; String[] currentListArr = currentList .split(context.getString(R.string.kiosk_application_package_split_regex)); for (String appPN : currentListArr) { if (!appPN.equals(packageName)) { newPackageList += appPN + context.getString(R.string.kiosk_application_package_split_regex); } } newPackageList += packageName; Preference.putString(context.getApplicationContext(), Constants.KIOSK_APP_PACKAGE_NAME, newPackageList); lockTaskPackages = context.getApplicationContext().getPackageName() + context.getString(R.string.kiosk_application_package_split_regex) + newPackageList; } } } devicePolicyManager.setLockTaskPackages(cdmfDeviceAdmin, lockTaskPackages.split(context.getString(R.string.kiosk_application_package_split_regex))); addIfPermissionEnforcementExist(packageName, context); launchKioskApp(context, packageName); }
From source file:org.wso2.emm.agent.services.PolicyRevokeHandler.java
public PolicyRevokeHandler(Context context) { this.context = context; this.resources = context.getResources(); this.devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); this.deviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); this.applicationManager = new ApplicationManager(context.getApplicationContext()); }
From source file:org.wso2.mdm.agent.utils.CommonUtils.java
/** * Clear application data./*from www . j a va 2s . c om*/ * @param context - Application context. */ public static void clearAppData(Context context) { DevicePolicyManager devicePolicyManager; ComponentName demoDeviceAdmin; Resources resources = context.getResources(); devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); SharedPreferences mainPref = context.getSharedPreferences( context.getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString(context.getResources().getString(R.string.shared_pref_policy), resources.getString(R.string.shared_pref_default_string)); editor.putString(context.getResources().getString(R.string.shared_pref_isagreed), resources.getString(R.string.shared_pref_device_active)); editor.putString(context.getResources().getString(R.string.shared_pref_regId), resources.getString(R.string.shared_pref_default_string)); editor.putString(context.getResources().getString(R.string.shared_pref_registered), resources.getString(R.string.shared_pref_device_active)); editor.putString(context.getResources().getString(R.string.shared_pref_ip), resources.getString(R.string.shared_pref_default_string)); editor.putString(context.getResources().getString(R.string.shared_pref_sender_id), resources.getString(R.string.shared_pref_default_string)); editor.putString(context.getResources().getString(R.string.shared_pref_eula), resources.getString(R.string.shared_pref_default_string)); editor.putString(resources.getString(R.string.shared_pref_device_active), resources.getString(R.string.shared_pref_reg_fail)); editor.commit(); devicePolicyManager.removeActiveAdmin(demoDeviceAdmin); }
From source file:org.wso2.emm.agent.services.PolicyComplianceChecker.java
public PolicyComplianceChecker(Context context) { this.context = context; this.resources = context.getResources(); this.devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); this.deviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); this.applicationManager = new ApplicationManager(context.getApplicationContext()); }
From source file:com.afwsamples.testdpc.AddAccountActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mAdminComponentName = DeviceAdminReceiver.getComponentName(this); setContentView(R.layout.activity_add_account); SetupWizardLayout layout = (SetupWizardLayout) findViewById(R.id.setup_wizard_layout); layout.getNavigationBar().setNavigationBarListener(this); NavigationBar navigationBar = layout.getNavigationBar(); navigationBar.getBackButton().setEnabled(false); Bundle extras = getIntent().getExtras(); if (extras != null) { mNextActivityIntent = (Intent) extras.get(EXTRA_NEXT_ACTIVITY_INTENT); }//from w ww . j a va 2s . c om }