Logging SetNewPasswordActivity events

Every launch of the activity with either ACTION_SET_NEW_PASSWORD
or ACTION_SET_NEW_PARENT_PROFILE_PASSWORD is logged, regardless
of whether extra EXTRA_PASSWORD_COMPLEXITY is used or whether
the caller has the required permisssion or not
- action: ACTION_SET_NEW_PASSWORD or
ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
- pageId: SET_NEW_PASSWORD_ACTIVITY
- key: calling app package name
- value: raw value of intent extra EXTRA_PASSWORD_COMPLEXITY, or
Integer.MIN_VALUE if it does not exist

Bug: 120840632
Test: atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/PasswordUtilsTest.java
      atest packages/apps/Settings/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java
Change-Id: I57dc55110f7f284ddad7d3fc971d1f2298b46cbd
This commit is contained in:
Bernard Chau
2019-01-29 18:28:13 +00:00
parent 09c932b2b9
commit 00870bff0d
5 changed files with 176 additions and 9 deletions

View File

@@ -29,12 +29,15 @@ import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager.PasswordComplexity;
import android.app.admin.PasswordMetrics;
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import com.android.settings.Utils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/**
* Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and
@@ -73,19 +76,23 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo
return;
}
IBinder activityToken = getActivityToken();
logSetNewPasswordIntent();
final IBinder activityToken = getActivityToken();
mCallerAppName = (String) PasswordUtils.getCallingAppLabel(this, activityToken);
if (ACTION_SET_NEW_PASSWORD.equals(mNewPasswordAction)
&& getIntent().hasExtra(EXTRA_PASSWORD_COMPLEXITY)) {
boolean hasPermission = PasswordUtils.isCallingAppPermitted(
final boolean hasPermission = PasswordUtils.isCallingAppPermitted(
this, activityToken, GET_AND_REQUEST_SCREEN_LOCK_COMPLEXITY);
if (hasPermission) {
mRequestedMinComplexity = PasswordMetrics.sanitizeComplexityLevel(getIntent()
.getIntExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_NONE));
mRequestedMinComplexity =
PasswordMetrics.sanitizeComplexityLevel(getIntent()
.getIntExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_NONE));
} else {
PasswordUtils.crashCallingApplication(activityToken,
"Must have permission " + GET_AND_REQUEST_SCREEN_LOCK_COMPLEXITY
+ " to use extra " + EXTRA_PASSWORD_COMPLEXITY);
"Must have permission "
+ GET_AND_REQUEST_SCREEN_LOCK_COMPLEXITY + " to use extra "
+ EXTRA_PASSWORD_COMPLEXITY);
finish();
return;
}
@@ -112,4 +119,29 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo
startActivity(intent);
finish();
}
private void logSetNewPasswordIntent() {
final String callingAppPackageName =
PasswordUtils.getCallingAppPackageName(getActivityToken());
// use int min value to denote absence of EXTRA_PASSWORD_COMPLEXITY
final int extraPasswordComplexity = getIntent().hasExtra(EXTRA_PASSWORD_COMPLEXITY)
? getIntent().getIntExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_NONE)
: Integer.MIN_VALUE;
// this activity is launched by either ACTION_SET_NEW_PASSWORD or
// ACTION_SET_NEW_PARENT_PROFILE_PASSWORD
final int action = ACTION_SET_NEW_PASSWORD.equals(mNewPasswordAction)
? SettingsEnums.ACTION_SET_NEW_PASSWORD
: SettingsEnums.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD;
final MetricsFeatureProvider metricsProvider =
FeatureFactory.getFactory(this).getMetricsFeatureProvider();
metricsProvider.action(
metricsProvider.getAttribution(this),
action,
SettingsEnums.SET_NEW_PASSWORD_ACTIVITY,
callingAppPackageName,
extraPasswordComplexity);
}
}