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:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.byod_nfc_test_activity); mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName()); mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mUserMangaer = (UserManager) getSystemService(Context.USER_SERVICE); mDisallowByPolicy = getIntent().getBooleanExtra(EXTRA_DISALLOW_BY_POLICY, false); if (mDisallowByPolicy) { mDevicePolicyManager.addUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM); }/*from ww w. ja v a 2s. c o m*/ final Uri uri = createUriForImage(SAMPLE_IMAGE_FILENAME, SAMPLE_IMAGE_CONTENT); Uri[] uris = new Uri[] { uri }; mNfcAdapter = NfcAdapter.getDefaultAdapter(this); mNfcAdapter.setBeamPushUris(uris, this); findViewById(R.id.manual_beam_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mNfcAdapter.invokeBeam(NfcTestActivity.this); } }); findViewById(R.id.intent_share_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpg"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Specify the package name of NfcBeamActivity so that the tester don't need to // select the activity manually. shareIntent.setClassName(NFC_BEAM_PACKAGE, NFC_BEAM_ACTIVITY); try { startActivity(shareIntent); } catch (ActivityNotFoundException e) { Toast.makeText(NfcTestActivity.this, R.string.provisioning_byod_cannot_resolve_beam_activity, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Nfc beam activity not found", e); } } }); }
From source file:com.afwsamples.testdpc.common.ProvisioningStateUtil.java
/** * @param action Action to be checked/*from w w w . j ava 2 s . c o m*/ * @param context Calling activity's context * @return true, if provisioning is allowed for corresponding action */ @TargetApi(Build.VERSION_CODES.N) public static boolean isProvisioningAllowed(Context context, String action) { if (BuildCompat.isAtLeastN()) { DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); return dpm.isProvisioningAllowed(action); } else { if (ACTION_PROVISION_MANAGED_DEVICE.equals(action)) { return (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) ? isDeviceUnprovisionedAndNoDeviceOwner(context) : false; } if (ACTION_PROVISION_MANAGED_PROFILE.equals(action)) { return true; } return false; } }
From source file:org.wso2.emm.agent.RegistrationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); demoDeviceAdmin = new ComponentName(this, WSO2DeviceAdminReceiver.class); context = this; Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(getResources().getString(R.string.intent_extra_username))) { username = extras.getString(getResources().getString(R.string.intent_extra_username)); }//from w ww.j a v a 2 s .co m } SharedPreferences mainPref = this .getSharedPreferences(getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE); regId = mainPref.getString(getResources().getString(R.string.shared_pref_regId), ""); //Enroll automatically final Context context = RegistrationActivity.this; registerDevice(); btnEnroll = (Button) findViewById(R.id.btnEnroll); btnLayout = (RelativeLayout) findViewById(R.id.enrollPanel); //ImageView optionBtn = (ImageView) findViewById(R.id.option_button); btnEnroll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //registrateDevice(); } }); }
From source file:org.wso2.cdm.agent.services.PolicyTester.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public PolicyTester(Context context, JSONArray recJArray, int type, String msgID) { this.context = context; devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); appList = new ApplicationManager(context); deviceInfo = new DeviceInfo(context); deviceState = new PhoneState(context); if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_RETURN) { IS_ENFORCE = false;//from w w w.ja v a2 s .co m } else if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) { IS_ENFORCE = false; } else if (type == POLICY_MONITOR_TYPE_ENFORCE_RETURN) { IS_ENFORCE = true; } else { IS_ENFORCE = false; type = POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN; } SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); policy = mainPref.getString("policy", ""); try { JSONArray jArray = null; if (recJArray != null) { jArray = recJArray; } else { jArray = new JSONArray(policy); } Log.e("POLICY ARAY : ", jArray.toString()); for (int i = 0; i < jArray.length(); i++) { JSONObject policyObj = (JSONObject) jArray.getJSONObject(i); if (policyObj.getString("data") != null && policyObj.getString("data") != "") { testPolicy(policyObj.getString("code"), policyObj.getString("data")); } } JSONObject rootObj = new JSONObject(); try { if (deviceInfo.isRooted()) { rootObj.put("status", false); } else { rootObj.put("status", true); } rootObj.put("code", "notrooted"); finalArray.put(rootObj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Log.e("MONITOR POLICY : ", policy); Log.e("MONITOR USER MESSAGE : ", usermessage); //Display an alert to the user about policy violation if (policy != null && policy != "") { if (usermessage != null && usermessage != "" && type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) { Intent intent = new Intent(context, AlertActivity.class); intent.putExtra("message", usermessage); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } returnJSON.put("code", CommonUtilities.OPERATION_POLICY_MONITOR); returnJSON.put("data", finalArray); Map<String, String> params = new HashMap<String, String>(); params.put("code", CommonUtilities.OPERATION_POLICY_MONITOR); params.put("msgID", msgID); params.put("status", "200"); params.put("data", finalArray.toString()); //ServerUtilities.pushData(params, context); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.wso2.mobile.mdm.services.PolicyTester.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public PolicyTester(Context context, JSONArray recJArray, int type, String msgID) { this.context = context; devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); appList = new ApplicationManager(context); deviceInfo = new DeviceInfo(context); deviceState = new PhoneState(context); if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_RETURN) { IS_ENFORCE = false;//from w ww .j a v a 2s .com } else if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) { IS_ENFORCE = false; } else if (type == POLICY_MONITOR_TYPE_ENFORCE_RETURN) { IS_ENFORCE = true; } else { IS_ENFORCE = false; type = POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN; } SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE); policy = mainPref.getString("policy", ""); try { JSONArray jArray = null; if (recJArray != null) { jArray = recJArray; } else { jArray = new JSONArray(policy); } Log.e("POLICY ARAY : ", jArray.toString()); for (int i = 0; i < jArray.length(); i++) { JSONObject policyObj = (JSONObject) jArray.getJSONObject(i); if (policyObj.getString("data") != null && policyObj.getString("data") != "") { testPolicy(policyObj.getString("code"), policyObj.getString("data")); } } JSONObject rootObj = new JSONObject(); try { if (deviceInfo.isRooted()) { rootObj.put("status", false); } else { rootObj.put("status", true); } rootObj.put("code", "notrooted"); finalArray.put(rootObj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Log.e("MONITOR POLICY : ", policy); Log.e("MONITOR USER MESSAGE : ", usermessage); //Display an alert to the user about policy violation if (policy != null && policy != "") { if (usermessage != null && usermessage != "" && type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) { Intent intent = new Intent(context, AlertActivity.class); intent.putExtra("message", usermessage); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } returnJSON.put("code", CommonUtilities.OPERATION_POLICY_MONITOR); returnJSON.put("data", finalArray); Map<String, String> params = new HashMap<String, String>(); params.put("code", CommonUtilities.OPERATION_POLICY_MONITOR); params.put("msgID", msgID); params.put("status", "200"); params.put("data", finalArray.toString()); ServerUtilities.pushData(params, context); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.teclib.flyvemdm.TabSecurityPolicies.java
@TargetApi(11) private int getDeviceEncryptionStatus() { int status = DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; if (Build.VERSION.SDK_INT >= 11) { final DevicePolicyManager dpm = (DevicePolicyManager) mContext .getSystemService(Context.DEVICE_POLICY_SERVICE); if (dpm != null) { status = dpm.getStorageEncryptionStatus(); }/*from w ww . j a v a 2s .c om*/ } return status; }
From source file:org.nick.ghettounlock.GhettoTrustAgent.java
@Override public void onCreate() { super.onCreate(); localBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_GRANT_TRUST); filter.addAction(ACTION_REVOKE_TRUST); localBroadcastManager.registerReceiver(receiver, filter); setManagingTrust(getIsManagingTrust(this)); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); nfcAdapter = NfcAdapter.getDefaultAdapter(this); installUnlockHandler();/*from ww w .j av a2s .co m*/ dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); long maxTimeToLock = dpm.getMaximumTimeToLock(null); Log.d(TAG, "max time to lock: " + maxTimeToLock); }
From source file:org.wso2.mdm.agent.AlreadyRegisteredActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_already_registered); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar); getSupportActionBar().setTitle(R.string.empty_app_title); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); ComponentName cdmDeviceAdmin = new ComponentName(this, AgentDeviceAdminReceiver.class); context = this; resources = context.getResources();//from w w w .j ava2s . c om Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(getResources().getString(R.string.intent_extra_fresh_reg_flag))) { freshRegFlag = extras.getBoolean(getResources().getString(R.string.intent_extra_fresh_reg_flag)); } } String registrationId = Preference.getString(context, resources.getString(R.string.shared_pref_regId)); if (registrationId != null && !registrationId.isEmpty()) { regId = registrationId; } if (freshRegFlag) { Preference.putString(context, resources.getString(R.string.shared_pref_registered), resources.getString(R.string.shared_pref_reg_success)); if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) { startDeviceAdminPrompt(cdmDeviceAdmin); } freshRegFlag = false; } txtRegText = (TextView) findViewById(R.id.txtRegText); btnUnregister = (Button) findViewById(R.id.btnUnreg); btnUnregister.setTag(TAG_BTN_UNREGISTER); btnUnregister.setOnClickListener(onClickListenerButtonClicked); LocalNotification.startPolling(context); }
From source file:com.google.codelabs.cosu.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Setup button which calls intent to camera app to take a picture takePicButton = (Button) findViewById(R.id.pic_button); takePicButton.setOnClickListener(new View.OnClickListener() { @Override/*from ww w.j a va 2 s . co m*/ public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File photoFile = null; try { photoFile = createImageFile(); } catch (IOException e) { Log.e(FILE_TAG, e.getMessage()); } if (photoFile != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } else { Toast.makeText(getApplicationContext(), R.string.no_camera_apps, Toast.LENGTH_SHORT).show(); } } }); // Retrieve Device Policy Manager so that we can check whether we can // lock to screen later mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); lockTaskButton = (Button) findViewById(R.id.start_lock_button); lockTaskButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mDevicePolicyManager.isLockTaskPermitted(getApplicationContext().getPackageName())) { Intent lockIntent = new Intent(getApplicationContext(), LockedActivity.class); lockIntent.putExtra(EXTRA_FILEPATH, mCurrentPhotoPath); startActivity(lockIntent); finish(); } else { Toast.makeText(getApplicationContext(), R.string.not_lock_whitelisted, Toast.LENGTH_SHORT) .show(); } } }); imageView = (ImageView) findViewById(R.id.main_imageView); // Check to see if permission to access external storage is granted, // and request if not permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }
From source file:org.digitalcampus.oppia.application.AdminGCMListener.java
@Override public void onMessageReceived(String from, Bundle messageData) { Log.d(TAG, "Push message received from: " + from); if (from.startsWith("/topics/")) { // message received from some topic. } else {// w w w .ja v a 2 s.c om String type = messageData.getString(MESSAGE_TYPE); if ((type != null) && (type.equals(TYPE_ADMIN))) { if (!BuildConfig.FLAVOR.equals("admin")) { //Is not the admin-flavor app (we don't have the permission, would produce crash) Log.d(TAG, "Device Administration is disabled :("); return; } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean adminEnabled = prefs.getBoolean(PrefsActivity.PREF_REMOTE_ADMIN, false); //First, we need to check if admin option is enabled if (!adminEnabled) { Log.d(TAG, "Device Administration is disabled :("); return; } String action = messageData.getString(MESSAGE_ACTION); Log.d(TAG, "Remote admin action: " + action); if (ACTION_DISABLE_CAMERA.equals(action)) { ComponentName adminReceiver = new ComponentName(this, AdminReceiver.class); DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.setCameraDisabled(adminReceiver, true); sendNotification(getString(R.string.notification_remote_admin_camera_disabled)); } else if (ACTION_ENABLE_CAMERA.equals(action)) { ComponentName adminReceiver = new ComponentName(this, AdminReceiver.class); DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.setCameraDisabled(adminReceiver, false); sendNotification(getString(R.string.notification_remote_admin_camera_enabled)); } else if (ACTION_PASSWORD_LOCK.equals(action)) { String password = messageData.getString(MESSAGE_PASSWORD); if ((password != null) && !password.equals("")) { DevicePolicyManager policyManager = (DevicePolicyManager) getSystemService( Context.DEVICE_POLICY_SERVICE); policyManager.resetPassword(password, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); policyManager.lockNow(); } } } } }