About Android Device Manager-devicepolicymanager (ii)

Source: Internet
Author: User

The last time I analyzed the/data/system/device_policies.xml, this file changed when the package change event happened, so take a look at its contents. According to previous experience, several files (Packages.xml packages.list) under/data/system are generated from the manifest files of each package in Packagemanager sweep, which is estimated to be similar.

<?xml version= ' 1.0 ' encoding= ' utf-8 ' standalone= ' yes '? ><policies><admin name= " Com.bgsoft.securitycamera/com.bgsoft.securitycamera.adminreceiver "><policies flags=" 2 "/></admin> <active-password quality= "65536" length= "5" uppercase= "0" lowercase= "0" letters= "0" numeric= "0" symbols= "0" Nonletter= "0"/></policies>

After I installed Securitycamera this apk, this file became so, more than a section of admin, the description of things seems really securitycamera related things, then take a look at its manifest file it.

        <receiver android:label= "@string/labelvalue" Android:name= ". Adminreceiver "android:permission=" Android.permission.BIND_DEVICE_ADMIN "android:description=" @string/ Description "> <meta-data android:name=" android.app.device_admin "android:resource=" @xml/lockourscreen "/>            <intent-filter>                <action android:name= "Android.app.action.DEVICE_ADMIN_ENABLED"/>            </ Intent-filter>        </receiver>
Can be found that there is a receiver of the paragraph and the above mentioned east is related, adminreceiver this thing seems to be the specific implementation of the part, need specific research.

View Code find it is a subclass of Deviceadminreceiver, is a broadcast receiver, but very strange, as a broadcast receiver, not registered in the manifest, there is no dynamic registration in the code, it is how it receives the action event it wants, very strange. Only in the code to find who used it.

   This.componentname = new ComponentName (this, adminreceiver.class);
......
private void Startdevicemanager () {Intent localintent = new Intent ("Android.app.action.ADD_DEVICE_ADMIN");    Localintent.putextra ("Android.app.extra.DEVICE_ADMIN", this.componentname);    Localintent.putextra ("Android.app.extra.ADD_EXPLANATION", "anti-theft photo assistant");  Startactivityforresult (localintent, 0); }
OK, here it is. But the problem comes, dig. No, no, what is this? Search through the source code of Android and discover that setting can handle this intent.

I/activitymanager (3138): START u0 {cmp=com.android.settings/. Deviceadminadd (have extras)} from PID 24508

Byw: This log read so much, only to understand that the original CMP is component.

No nonsense, see Deviceadminadd, code more, do not post the main analysis, is that the activity in the processing of this action is waiting to pop up a box, asked if you confirm the activation of this Device Manager.

If OK then will call Setactiveadmin, this is the previous article mentioned in the Setactiveadmin, set this to active. If it's activated, you'll get the broadcast. And what is the use of this manager is still not solved.

Still have to go on with the study. The clue can only be to analyze the list mentioned earlier, the previous article only looked if add, but did not pay attention to the list is what to do with, mistakes.

Find out a bunch of places to use, tune a typical look.

    void sendadmincommandlocked (String action, int reqpolicy, int userhandle) {        final devicepolicydata policy = Getuserda Ta (userhandle);        Final int count = Policy.mAdminList.size ();        if (Count > 0) {for            (int i = 0; i < count; i++) {                activeadmin admin = policy.mAdminList.get (i);                if (Admin.info.usesPolicy (Reqpolicy)) {                    sendadmincommandlocked (admin, Action);}}}}    
Traverse this list, you know this list is active admin, send them the message, yes, there is a door, this is the way it received the broadcast? See who called this method. Find a typical, found in the Keyguard on the wrong password when the call to. This device manager's role seems to be guessed.

From

Admin.info.usesPolicy (Reqpolicy)

You can see that there are a lot of policy that can be used

Uses_policy_limit_password

Uses_policy_watch_login

。。。。

Later also Google was originally with the application of some XML correspondence, is manifest inside the Meta-data

<meta-data android:name= "Android.app.device_admin" android:resource= "@xml/lockourscreen"/>
<?xml version= "1.0" encoding= "Utf-8"? ><device-admin  xmlns:android= "http://schemas.android.com/apk/ Res/android ">    <uses-policies>        <watch-login/>    </uses-policies></ Device-admin>
OK, whole.











About Android Device Manager-devicepolicymanager (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.