Analysis of Android Mobile Guardian Equipment Management Authority Lock Screen

  • 2021-07-03 00:54:40
  • OfStack

Recommended reading:

Analysis of Android Mobile Phone Guardian sim Card Binding

In-depth analysis of md5 encryption when Android mobile phone guard saves password

Explanation of Android Mobile Guardian Setup Wizard Page

Analysis of Android Mobile Phone Guardian Turning off Automatic Update

Analysis on the Attributes of Android Mobile Guardian Custom Control

Analysis on Android Mobile Phone Guardian Reading Contacts

Analysis on Android mobile phone guards receiving short message instructions and executing corresponding operations

Analysis on the principle of mobile phone positioning of Android mobile phone guard

Analysis of Android Mobile Guardian's Mobile Phone Realizing SMS Command to Obtain Location

Equipment Manager Device Admin

Gets the DevicePolicyManager object, via getSystemService (DEVICE_POLICY_MANAGER), device policy manager

Call the lockNow () method of the DevicePolicyManager object, lock it, and report a security exception at this time

Create a new DeviceAdminReceiver class that inherits the system MyAdmin. This is the broadcast receiver

Manifest file for registration

Add < receiver > Node, setting name

Set permissions android: permission= "android.permission.BIND_DEVICE_ADMIN"

Add < meta-data > Metadata node, setting name android: name= "android. app.device_admin"

Set resource android: resource= "@ xml/device_admin_sample"

Create a new xml folder under the res directory, and create a new device_admin_sample. xml file

Add < intent-filter > Node, Add Action, android. app. action. DEVICE_ADMIN_ENABLED

At this time, an error will be reported

Open System Settings, find Device Manager, check Device Administrator privileges, and activate the device

Turn on administrator privileges

Get the Intent object, new Intent (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)

Call the Intent object putExtra (), pass the data, the component to activate,

Parameters: DevicePolicyManager.EXTRA_DEVICE_ADMIN, ComponentName Component Name Object

Get ComponentName object, new out, parameter: context, Myadmin. class

Call Intent object putExtra (), pass the explanation data, persuade the user to open, parameter:

DevicePolicyManager.EXTRA_ADD_EXPLANATION, text

Call startActivity ()

Call the isAdminActive () method of the DevicePolicyManager object to judge whether there is administrator authority. Parameter: ComponentName object

Call the resetPassword () method of the DevicePolicyManager object to reset the password with parameters: password, 0, and set password to "" to cancel the password

Clear the data by calling the wipeData () method of the DevicePolicyManager object. Parameter: Clear the sd card DevicePlocyManager.WIPE_EXTERANL_STORGE

If it is 0, the factory settings will be restored

Uninstall software

This can't be unloaded when it is installed

Calling removeActiveAdmin () method of DevicePolicyManager object, clearing administrator authority, parameter: ComponentName component name object, obtaining ComponentName object, new out, parameter: context, Myadmin. class

Get an Intent object

Invoke the setAction () method of the Intent object and set the action with the parameters: android. intent. action. VIEW

Call the addCategory () of the Intent object to add the type, parameter: android. intent. category. DEFAULT

Call setData () of the Intent object, set the data,

Parameter: Uri object, get Uri object Uri. parse ("package:" + getPackageName ())

Call startActivity ()

device_admin_sample.xml


<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>

package com.tsh.mylockscreen;


import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
private DevicePolicyManager dpm;
ComponentName who;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
who=new ComponentName(this, MyAdmin.class);
}
// 1 Key lock screen 
public void lockScreen(View v) {
if (dpm.isAdminActive(who)) {
dpm.lockNow();
dpm.resetPassword("123", 0);
} else {
Intent intent =new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, who);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION," Open it quickly ");
startActivity(intent);
Toast.makeText(this, " No device management rights ", 1).show();
}
}
//1 Key unload 
public void uninstall(View v) {
dpm.removeActiveAdmin(who);
Intent intent=new Intent();
intent.setAction(Intent.ACTION_DELETE);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:"+getPackageName()));
startActivity(intent);
}
}

The above is the site to introduce the Android mobile phone guard device management authority lock screen knowledge, I hope to help you!


Related articles: