Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

java - Having trouble receiving ACTION_PASSWORD_SUCCEEDED and ACTION_PASSWORD_FAILED intents

I am using Android's Administration API and have a DeviceAdminReceiver, and override the following functions:

@Override
public void onEnabled(Context context, Intent intent)
{
    System.out.println("Admin On======================");       
}

@Override
public void onDisabled(Context context, Intent intent)
{
    System.out.println("Admin Off======================");
}

@Override
public void onPasswordFailed(Context context, Intent intent)
{
    System.out.println("PW Bad============================");
}

@Override
public void onPasswordSucceeded(Context context, Intent intent)
{
    System.out.println("PW Good===========================");       
}

@Override
public void onPasswordChanged(Context context, Intent intent)
{
    System.out.println("Changed PW=======================");        
}

On enabled, Disabled, and PW changed work, however password failed and succeeded do not. Strangely, they randomly work once in a while and then stop working. Is there anything wrong with my code, or could this be an API problem?

The receiver in AndroidMaifest

<receiver android:name="AdminReciever"
            android:label="Administration"
            android:permission="android.permission.BIND_DEVICE_ADMIN" android:enabled="true">
            <meta-data android:name="android.app.device_admin"
                android:resource="@xml/adminpolicies" />
            <intent-filter>
                <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
                <action android:name="android.app.action.ACTION_PASSWORD_FAILED"></action>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"></action>
                <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"></action>

            </intent-filter>
</receiver>

FIXED

Found out the problem, it seems this wasn't documented. I had set a minimum password length with dpm.setPasswordMinimumLength(). The password entry activity does not fire a PASSWORD_FAILED intent if the password entered is less then the minimum length. Also PASSWORD_SUCCEEDED only fires if a bad password (PASSWORD_FAILED fired) was entered before the successful one. So two successful passwords in a row will not fire the second intent.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Very late answer here but I was having the same issue and your 'Fixed' edit helped me work out why.

As you say, this isn't very well documented at all so can be quite misleading. The documentation suggests that any password failure will result in onPasswordFailed being called.

ACTION_PASSWORD_FAILED

Action sent to a device administrator when the user has entered an incorrect device or profile challenge password. You can at this point check the number of failed password attempts there have been with DevicePolicyManager.getCurrentFailedPasswordAttempts(). You will generally handle this in onPasswordFailed(Context, Intent, UserHandle).

However, that's not true. onPasswordFailed only appears to be called when the password/PIN/Pattern satisfies the Default Policy. This is different from your minimum password length.

Although I can't find any documentation stating the default policies, it appears to be 4 numbers (PIN), 4 characters (Password) or 4 points (Pattern). Anything less than these will not trigger the call.

For an example, set minimum length to 6 and set your password to 123ABC. Now try to login using the following :-

  • 123 - onPasswordFailed is not called
  • 123A - onPasswordFailed is called

Nice little tester project here you can try this with.

Even though you've probably well and truly moved on from this issue, someone else may gain some clarity.

Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...