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.afwsamples.testdpc.common.ProfileOrParentFragment.java
@Override public void onCreate(Bundle savedInstanceState) { // Check arguments- see whether we're supposed to run on behalf of the parent profile. final Bundle arguments = getArguments(); if (arguments != null) { mParentInstance = arguments.getBoolean(EXTRA_PARENT_PROFILE, false); }//from ww w. j a v a 2 s. co m mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity()); // Get a device policy manager for the current user. mDevicePolicyManager = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE); // Store whether we are the profile owner for faster lookup. mProfileOwner = mDevicePolicyManager.isProfileOwnerApp(getActivity().getPackageName()); mDeviceOwner = mDevicePolicyManager.isDeviceOwnerApp(getActivity().getPackageName()); if (mParentInstance) { mDevicePolicyManager = mDevicePolicyManager.getParentProfileInstance(mAdminComponent); } // Put at last to make sure all initializations above are done before subclass's // onCreatePreferences is called. super.onCreate(savedInstanceState); // Switch to parent profile if we are running on their behalf. // This needs to be called after super.onCreate because preference manager is set up // inside super.onCreate. if (mParentInstance) { final PreferenceManager pm = getPreferenceManager(); pm.setSharedPreferencesName(pm.getSharedPreferencesName() + TAG_PARENT); } }
From source file:org.wso2.emm.agent.services.operation.OperationManager.java
public OperationManager(Context context) { this.context = context; this.resources = context.getResources(); this.devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); this.cdmDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class); this.appList = new ApplicationManager(context.getApplicationContext()); this.resultBuilder = new ResultPayload(); AGENT_PACKAGE_NAME = context.getPackageName(); AUTHORIZED_PINNING_APPS = new String[] { AGENT_PACKAGE_NAME }; applicationManager = new ApplicationManager(context); notificationService = NotificationService.getInstance(context.getApplicationContext()); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "New OperationManager created."); }//from w w w.java 2s. c o m }
From source file:com.javadog.bluetoothproximitylock.BluetoothFragment.java
/** * Initializes object references and performs some other set-up tasks. *//*w w w . j av a 2 s. co m*/ private void initialize() { //Get a reference to the user preferences editor userPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); //Get fresh references to our views serviceToggle = new BetterCompoundButton<>(getActivity(), (Switch) getView().findViewById(R.id.button_bt_service_start_stop)); signalStrengthView = (TextView) getView().findViewById(R.id.bt_signal_strength); deviceChooser = (Spinner) getView().findViewById(R.id.bt_device_chooser); lockDistance = (Spinner) getView().findViewById(R.id.bt_lock_distances); //TODO: This doesn't do anything yet. lockInstantly = new BetterCompoundButton<>(getActivity(), (CheckBox) getView().findViewById(R.id.bt_lock_instantly)); refreshIntervalSpinner = (Spinner) getView().findViewById(R.id.bt_refresh_interval); //Get a reference to the local broadcast manager, and specify which intent actions we want to listen for LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity().getApplicationContext()); IntentFilter filter = new IntentFilter(); filter.addAction(SignalReaderService.ACTION_SIGNAL_STRENGTH_UPDATE); filter.addAction(SignalReaderService.ACTION_UNBIND_SERVICE); //Instantiate the ssReceiver if it's not already, then register it with the broadcast manager if (ssReceiver == null) { ssReceiver = new LocalBroadcastReceiver(); } manager.registerReceiver(ssReceiver, filter); //Check whether device admin privileges are active, and show a dialog if not DevicePolicyManager dpm = (DevicePolicyManager) getActivity() .getSystemService(Context.DEVICE_POLICY_SERVICE); if (!dpm.isAdminActive(new ComponentName(getActivity().getApplicationContext(), DeviceLockManager.class))) { AdminDialogFragment adminDialogFragment = new AdminDialogFragment(); adminDialogFragment.setCancelable(false); adminDialogFragment.show(getFragmentManager(), "needsAdmin"); } populateBtDevices(); //Start the device chooser in a disabled state if Bluetooth is disabled if (BluetoothAdapter.getDefaultAdapter().isEnabled()) { deviceChooser.setEnabled(true); } else { deviceChooser.setEnabled(false); } //Register a listener with the system to get updates about changes to Bluetooth state if (btStateReceiver == null) { btStateReceiver = new BluetoothStateReceiver(); } IntentFilter btFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); getActivity().registerReceiver(btStateReceiver, btFilter); /** * Will attach the Activity to the Service as soon as the service is started. */ serviceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { serviceBound = true; updateBtServiceUI(); } @Override public void onServiceDisconnected(ComponentName componentName) { //This should never be called because our service resides in the same process. } }; }
From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); this.devicePolicyManager = (DevicePolicyManager) application .getSystemService(Context.DEVICE_POLICY_SERVICE); }
From source file:org.wso2.iot.system.service.SystemService.java
@Override protected void onHandleIntent(Intent intent) { context = this.getApplicationContext(); cdmDeviceAdmin = new ComponentName(this, ServiceDeviceAdminReceiver.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); String AGENT_PACKAGE_NAME = context.getPackageName(); AUTHORIZED_PINNING_APPS = new String[] { AGENT_PACKAGE_NAME, Constants.AGENT_APP_PACKAGE_NAME }; if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) { startAdmin();// www . j a v a 2s. c o m } else { /*This function handles the "Execute Command on Device" Operation. All requests are handled on a single worker thread. They may take as long as necessary (and will not block the application's main thread), but only one request will be processed at a time.*/ Log.d(TAG, "Entered onHandleIntent of the Command Runner Service."); Bundle extras = intent.getExtras(); if (extras != null) { operationCode = extras.getString("operation"); if (extras.containsKey("command")) { command = extras.getString("command"); if (command != null) { restrictionCode = command.equals("true"); } } if (extras.containsKey("appUri")) { appUri = extras.getString("appUri"); } if (extras.containsKey("operationId")) { operationId = extras.getInt("operationId"); } } if ((operationCode != null)) { if (Constants.AGENT_APP_PACKAGE_NAME.equals(intent.getPackage())) { Log.d(TAG, "IoT agent has sent a command with operation code: " + operationCode + " command: " + command); doTask(operationCode); } else { Log.d(TAG, "Received command from external application. operation code: " + operationCode + " command: " + command); boolean isAutomaticRetry; switch (operationCode) { case Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY: if ("false".equals(command) || "true".equals(command)) { isAutomaticRetry = "true".equals(command); Preference.putBoolean(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry), isAutomaticRetry); if (isAutomaticRetry) { String status = Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)); if (Constants.Status.WIFI_OFF.equals(status) && !checkNetworkOnline()) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED); } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD.equals(status)) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED); } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL .equals(Preference.getString(context, context.getResources() .getString(R.string.upgrade_install_status)))) { Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status), Constants.Status.FAILED); } } CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, command); //Sending command as the message CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, Constants.Code.SUCCESS, Constants.Status.SUCCESSFUL, "Updated"); } else { CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, "Invalid command argument."); } break; case Constants.Operation.UPGRADE_FIRMWARE: try { JSONObject upgradeData = new JSONObject(command); isAutomaticRetry = !Preference.hasPreferenceKey(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry)) || Preference.getBoolean(context, context.getResources() .getString(R.string.firmware_upgrade_automatic_retry)); if (!upgradeData.isNull( context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { isAutomaticRetry = upgradeData.getBoolean(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry)); } CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, (isAutomaticRetry ? "true" : "false")); } catch (JSONException e) { String error = "Failed to build JSON object form the request: " + command; Log.e(TAG, error); Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.MALFORMED_REQUEST); CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, error); break; } case Constants.Operation.GET_FIRMWARE_UPGRADE_PACKAGE_STATUS: case Constants.Operation.GET_FIRMWARE_BUILD_DATE: case Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS: doTask(operationCode); break; default: Log.e(TAG, "Invalid operation code: " + operationCode); break; } } } } context.registerReceiver(new BatteryChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); //Checking is there any interrupted firmware download is there String status = Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)); if (Constants.Status.OTA_UPGRADE_ONGOING.equals(status)) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.REQUEST_PLACED); Timer timeoutTimer = new Timer(); timeoutTimer.schedule(new TimerTask() { @Override public void run() { if (Constants.Status.REQUEST_PLACED.equals(Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)))) { if (Preference.getBoolean(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { Log.i(TAG, "Found incomplete firmware download. Proceeding with last download request from the agent."); OTADownload otaDownload = new OTADownload(context); otaDownload.startOTA(); } } } }, Constants.FIRMWARE_UPGRADE_READ_TIMEOUT); } }
From source file:org.wso2.emm.system.service.EMMSystemService.java
@Override protected void onHandleIntent(Intent intent) { context = this.getApplicationContext(); cdmDeviceAdmin = new ComponentName(this, ServiceDeviceAdminReceiver.class); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); AGENT_PACKAGE_NAME = context.getPackageName(); AUTHORIZED_PINNING_APPS = new String[] { AGENT_PACKAGE_NAME, Constants.AGENT_APP_PACKAGE_NAME }; if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) { startAdmin();//from w w w. j a va 2s . c om } else { /*This function handles the "Execute Command on Device" Operation. All requests are handled on a single worker thread. They may take as long as necessary (and will not block the application's main thread), but only one request will be processed at a time.*/ Log.d(TAG, "Entered onHandleIntent of the Command Runner Service."); Bundle extras = intent.getExtras(); if (extras != null) { operationCode = extras.getString("operation"); if (extras.containsKey("command")) { command = extras.getString("command"); if (command != null) { restrictionCode = command.equals("true"); } } if (extras.containsKey("appUri")) { appUri = extras.getString("appUri"); } if (extras.containsKey("operationId")) { operationId = extras.getInt("operationId"); } } if ((operationCode != null)) { if (Constants.AGENT_APP_PACKAGE_NAME.equals(intent.getPackage())) { Log.d(TAG, "EMM agent has sent a command with operation code: " + operationCode + " command: " + command); doTask(operationCode); } else { Log.d(TAG, "Received command from external application. operation code: " + operationCode + " command: " + command); boolean isAutomaticRetry; switch (operationCode) { case Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY: if ("false".equals(command) || "true".equals(command)) { isAutomaticRetry = "true".equals(command); Preference.putBoolean(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry), isAutomaticRetry); if (isAutomaticRetry) { String status = Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)); if (Constants.Status.WIFI_OFF.equals(status) && !checkNetworkOnline()) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED); } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_DOWNLOAD.equals(status)) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.FAILED); } else if (Constants.Status.BATTERY_LEVEL_INSUFFICIENT_TO_INSTALL .equals(Preference.getString(context, context.getResources() .getString(R.string.upgrade_install_status)))) { Preference.putString(context, context.getResources().getString(R.string.upgrade_install_status), Constants.Status.FAILED); } } CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, command); //Sending command as the message CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, Constants.Code.SUCCESS, Constants.Status.SUCCESSFUL, "Updated"); } else { CommonUtils.sendBroadcast(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, "Invalid command argument."); } break; case Constants.Operation.UPGRADE_FIRMWARE: try { JSONObject upgradeData = new JSONObject(command); isAutomaticRetry = (Preference.hasPreferenceKey(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry)) && Preference.getBoolean(context, context.getResources() .getString(R.string.firmware_upgrade_automatic_retry))) || !Preference.hasPreferenceKey(context, context.getResources() .getString(R.string.firmware_upgrade_automatic_retry)); if (!upgradeData.isNull( context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { isAutomaticRetry = upgradeData.getBoolean(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry)); } CommonUtils.callAgentApp(context, Constants.Operation.FIRMWARE_UPGRADE_AUTOMATIC_RETRY, 0, (isAutomaticRetry ? "true" : "false")); } catch (JSONException e) { String error = "Failed to build JSON object form the request: " + command; Log.e(TAG, error); Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.MALFORMED_REQUEST); CommonUtils.sendBroadcast(context, Constants.Operation.UPGRADE_FIRMWARE, Constants.Code.FAILURE, Constants.Status.MALFORMED_REQUEST, error); break; } case Constants.Operation.GET_FIRMWARE_UPGRADE_PACKAGE_STATUS: case Constants.Operation.GET_FIRMWARE_BUILD_DATE: case Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS: doTask(operationCode); break; default: Log.e(TAG, "Invalid operation code: " + operationCode); break; } } } } context.registerReceiver(new BatteryChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); //Checking is there any interrupted firmware download is there String status = Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)); if (Constants.Status.OTA_UPGRADE_ONGOING.equals(status)) { Preference.putString(context, context.getResources().getString(R.string.upgrade_download_status), Constants.Status.REQUEST_PLACED); Timer timeoutTimer = new Timer(); timeoutTimer.schedule(new TimerTask() { @Override public void run() { if (Constants.Status.REQUEST_PLACED.equals(Preference.getString(context, context.getResources().getString(R.string.upgrade_download_status)))) { if (Preference.getBoolean(context, context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { Log.i(TAG, "Found incomplete firmware download. Proceeding with last download request from the agent."); OTADownload otaDownload = new OTADownload(context); otaDownload.startOTA(); } } } }, Constants.FIRMWARE_UPGRADE_READ_TIMEOUT); } }
From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else {/*from www. j a v a 2 s . c o m*/ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } setContentView(R.layout.activity_authentication); RelativeLayout relativeLayout = (RelativeLayout) this.findViewById(R.id.relavtiveLayoutAuthentication); if (Constants.DEFAULT_OWNERSHIP.equals(Constants.OWNERSHIP_COSU)) { relativeLayout.setVisibility(RelativeLayout.GONE); } deviceInfo = new DeviceInfo(context); etDomain = (EditText) findViewById(R.id.etDomain); etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); etDomain.setFocusable(true); etDomain.requestFocus(); btnSignIn = (Button) findViewById(R.id.btnSignIn); btnSignIn.setOnClickListener(onClickAuthenticate); btnSignIn.setEnabled(false); // change button color background till user enters a valid input btnSignIn.setBackgroundResource(R.drawable.btn_grey); btnSignIn.setTextColor(ContextCompat.getColor(this, R.color.black)); TextView textViewSignIn = (TextView) findViewById(R.id.textViewSignIn); LinearLayout loginLayout = (LinearLayout) findViewById(R.id.loginLayout); if (Preference.hasPreferenceKey(context, Constants.TOKEN_EXPIRED)) { etDomain.setEnabled(false); etDomain.setTextColor(ContextCompat.getColor(this, R.color.black)); etUsername.setEnabled(false); etUsername.setTextColor(ContextCompat.getColor(this, R.color.black)); btnSignIn.setText(R.string.btn_sign_in); etPassword.setFocusable(true); etPassword.requestFocus(); String tenantedUserName = Preference.getString(context, Constants.USERNAME); int tenantSeparator = tenantedUserName.lastIndexOf('@'); etUsername.setText(tenantedUserName.substring(0, tenantSeparator)); etDomain.setText(tenantedUserName.substring(tenantSeparator + 1, tenantedUserName.length())); isReLogin = true; textViewSignIn.setText(R.string.msg_need_to_sign_in); } else if (Constants.CLOUD_MANAGER != null) { isCloudLogin = true; etDomain.setVisibility(View.GONE); textViewSignIn.setText(R.string.txt_sign_in_cloud); } if (Preference.getBoolean(context, Constants.PreferenceFlag.DEVICE_ACTIVE) && !isReLogin) { Intent intent = new Intent(AuthenticationActivity.this, AlreadyRegisteredActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); return; } TextView textViewSignUp = (TextView) findViewById(R.id.textViewSignUp); if (!isReLogin && Constants.SIGN_UP_URL != null) { Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() { @Override public String transformUrl(Matcher match, String url) { return Constants.SIGN_UP_URL; } }; Pattern pattern = Pattern.compile(getResources().getString(R.string.txt_sign_up_linkify)); Linkify.addLinks(textViewSignUp, pattern, null, null, transformFilter); } else { textViewSignUp.setVisibility(View.GONE); } if (Constants.HIDE_LOGIN_UI) { loginLayout.setVisibility(View.GONE); } if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { startLockTask(); } } TextView textViewWipeData = (TextView) this.findViewById(R.id.textViewWipeData); if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP) && Constants.DISPLAY_WIPE_DEVICE_BUTTON) { textViewWipeData.setVisibility(View.VISIBLE); textViewWipeData.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { new AlertDialog.Builder(AuthenticationActivity.this).setTitle(getString(R.string.app_name)) .setMessage(R.string.wipe_confirmation) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getApplicationContext() .getSystemService(Context.DEVICE_POLICY_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE | DevicePolicyManager.WIPE_RESET_PROTECTION_DATA); } else { devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE); } } }).setNegativeButton(android.R.string.no, null).show(); } }); } ImageView logo = (ImageView) findViewById(R.id.imageViewLogo); if (Constants.COSU_SECRET_EXIT) { logo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { kioskExit++; if (kioskExit == 6) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { stopLockTask(); } finish(); } } }); } etUsername.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { enableSubmitIfReady(); } @Override public void afterTextChanged(Editable s) { enableSubmitIfReady(); } }); etPassword.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { enableSubmitIfReady(); } @Override public void afterTextChanged(Editable s) { enableSubmitIfReady(); } }); if (org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE .equals(org.wso2.iot.agent.proxy.utils.Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR)) { AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory(); ClientAuthenticator authenticator = authenticatorFactory.getClient( org.wso2.iot.agent.proxy.utils.Constants.Authenticator.AUTHENTICATOR_IN_USE, AuthenticationActivity.this, Constants.AUTHENTICATION_REQUEST_CODE); authenticator.doAuthenticate(); } //This is an override to ownership type. if (Constants.DEFAULT_OWNERSHIP != null) { deviceType = Constants.DEFAULT_OWNERSHIP; Preference.putString(context, Constants.DEVICE_TYPE, deviceType); } else { deviceType = Constants.OWNERSHIP_BYOD; } if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) { Intent intent = getIntent(); if (intent.hasExtra("android.app.extra.token")) { adminAccessToken = intent.getStringExtra("android.app.extra.token"); proceedToAuthentication(); } } // This is added so that in case due to an agent customisation, if the authentication // activity is called the AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED is set, the activity // must be finished. if (Constants.AUTO_ENROLLMENT_BACKGROUND_SERVICE_ENABLED) { finish(); } }
From source file:de.jerleo.samsung.knox.firewall.MainActivity.java
private boolean hasActiveAdministrator() { admin = new ComponentName(MainActivity.this, AdminReceiver.class); DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); return dpm.isAdminActive(admin); }
From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final LayoutInflater inflater = getLayoutInflater(); View contentView = inflater.inflate(R.layout.user_consent, null); setContentView(contentView);/*from ww w . j a va2 s. co m*/ // Check whether system has the required managed profile feature. if (!systemHasManagedProfileFeature()) { showErrorAndClose(R.string.managed_provisioning_not_supported, "Exiting managed profile provisioning, " + "managed profiles feature is not available"); return; } if (Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) { showErrorAndClose(R.string.user_is_not_owner, "Exiting managed profile provisioning, calling user is not owner."); return; } // Initialize member variables from the intent, stop if the intent wasn't valid. try { initialize(getIntent()); } catch (ProvisioningFailedException e) { showErrorAndClose(R.string.managed_provisioning_error_text, e.getMessage()); return; } setMdmIcon(mMdmPackageName); // If the caller started us via ALIAS_NO_CHECK_CALLER then they must have permission to // MANAGE_USERS since it is a restricted intent. Otherwise, check the calling package. boolean hasManageUsersPermission = (getComponentName().equals(ALIAS_NO_CHECK_CALLER)); if (!hasManageUsersPermission) { // Calling package has to equal the requested device admin package or has to be system. String callingPackage = getCallingPackage(); if (callingPackage == null) { showErrorAndClose(R.string.managed_provisioning_error_text, "Calling package is null. " + "Was startActivityForResult used to start this activity?"); return; } if (!callingPackage.equals(mMdmPackageName) && !packageHasManageUsersPermission(callingPackage)) { showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, " + "calling package tried to set a different package as profile owner. " + "The system MANAGE_USERS permission is required."); return; } } DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); String deviceOwner = dpm.getDeviceOwner(); if (deviceOwner != null && !deviceOwner.equals(mMdmPackageName)) { showErrorAndClose(R.string.managed_provisioning_error_text, "Permission denied, " + "profile owner must be in the same package as device owner."); return; } // If there is already a managed profile, allow the user to cancel or delete it. int existingManagedProfileUserId = alreadyHasManagedProfile(); if (existingManagedProfileUserId != -1) { showManagedProfileExistsDialog(existingManagedProfileUserId); } else { showStartProvisioningScreen(); } }
From source file:com.configurer.easyscreenlock.MainActivity.java
/** * Initialise below components ://from ww w. ja v a2 s . c o m * <li><b>Device Policy Manager </b> - Public interface for managing policies enforced on a device. </li> * <li><b>Activity Manager </b> - Interact with the overall activities running in the system. </li> * <li><b>Component Name </b> - Identifier for a specific application component.</li> */ private void initializeComponents() { try { deviceManger = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); compName = new ComponentName(this, DeviceAdministratorReceiver.class); } catch (Exception e) { deviceManger = null; activityManager = null; compName = null; Log.e(TAG, e.getMessage()); } }