Fields Summary |
---|
private static final boolean | ALLOW_EXTERNAL_BROADCASTSIf true, allows anyone to control this trust agent, e.g. using adb:
$ adb shell am broadcast -a action.sample_trust_agent.grant_trust\
-e extra.message SampleTrust\
--el extra.duration 1000 --ez extra.init_by_user false
|
android.support.v4.content.LocalBroadcastManager | mLocalBroadcastManager |
private static final String | ACTION_GRANT_TRUST |
private static final String | ACTION_REVOKE_TRUST |
private static final String | EXTRA_MESSAGE |
private static final String | EXTRA_DURATION |
private static final String | EXTRA_INITIATED_BY_USER |
private static final String | PREFERENCE_REPORT_UNLOCK_ATTEMPTS |
private static final String | PREFERENCE_MANAGING_TRUST |
private static final String | PREFERENCE_REPORT_DEVICE_LOCKED |
private static final String | TAG |
private android.content.BroadcastReceiver | mReceiver |
Methods Summary |
---|
public static boolean | getIsManagingTrust(android.content.Context context)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREFERENCE_MANAGING_TRUST, false);
|
public static boolean | getReportDeviceLocked(android.content.Context context)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREFERENCE_REPORT_DEVICE_LOCKED, false);
|
public static boolean | getReportUnlockAttempts(android.content.Context context)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREFERENCE_REPORT_UNLOCK_ATTEMPTS, false);
|
private void | logAndShowToast(java.lang.String text)
Log.i(TAG, text);
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
public boolean | onConfigure(java.util.List options)
if (options != null) {
for (int i = 0; i < options.size(); i++) {
Log.v(TAG, "Policy options received: " + options.get(i));
}
} else {
Log.w(TAG, "onConfigure() called with no options");
}
// TODO: Handle options
return true; // inform DPM that we support it
|
public void | onCreate()
super.onCreate();
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_GRANT_TRUST);
filter.addAction(ACTION_REVOKE_TRUST);
mLocalBroadcastManager.registerReceiver(mReceiver, filter);
if (ALLOW_EXTERNAL_BROADCASTS) {
registerReceiver(mReceiver, filter);
}
setManagingTrust(getIsManagingTrust(this));
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
|
public void | onDestroy()
super.onDestroy();
mLocalBroadcastManager.unregisterReceiver(mReceiver);
if (ALLOW_EXTERNAL_BROADCASTS) {
unregisterReceiver(mReceiver);
}
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
|
public void | onDeviceLocked()
super.onDeviceLocked();
if (getReportDeviceLocked(this)) {
logAndShowToast("onDeviceLocked(): device is now locked");
}
|
public void | onDeviceUnlocked()
super.onDeviceUnlocked();
if (getReportDeviceLocked(this)) {
logAndShowToast("onDeviceUnlocked(): device is now unlocked");
}
|
public void | onSharedPreferenceChanged(android.content.SharedPreferences sharedPreferences, java.lang.String key)
if (PREFERENCE_MANAGING_TRUST.equals(key)) {
setManagingTrust(getIsManagingTrust(this));
}
|
public void | onTrustTimeout()
super.onTrustTimeout();
logAndShowToast("onTrustTimeout(): timeout expired");
|
public void | onUnlockAttempt(boolean successful)
if (getReportUnlockAttempts(this)) {
logAndShowToast("onUnlockAttempt(successful=" + successful + ")");
}
|
public static void | sendGrantTrust(android.content.Context context, java.lang.String message, long durationMs, boolean initiatedByUser)
Intent intent = new Intent(ACTION_GRANT_TRUST);
intent.putExtra(EXTRA_MESSAGE, message);
intent.putExtra(EXTRA_DURATION, durationMs);
intent.putExtra(EXTRA_INITIATED_BY_USER, initiatedByUser);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
public static void | sendRevokeTrust(android.content.Context context)
Intent intent = new Intent(ACTION_REVOKE_TRUST);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
public static void | setIsManagingTrust(android.content.Context context, boolean enabled)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
sharedPreferences.edit().putBoolean(PREFERENCE_MANAGING_TRUST, enabled).apply();
|
public static void | setReportDeviceLocked(android.content.Context context, boolean enabled)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
sharedPreferences.edit().putBoolean(PREFERENCE_REPORT_DEVICE_LOCKED, enabled).apply();
|
public static void | setReportUnlockAttempts(android.content.Context context, boolean enabled)
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
sharedPreferences.edit().putBoolean(PREFERENCE_REPORT_UNLOCK_ATTEMPTS, enabled).apply();
|