Don't display footer text when calling app is DPC.
If the calling app has admin rights (DA/DO/PO), don't display footer text that the calling app is 'recommending' that a password is set. Fixes: 131888973 Test: atest com.android.settings.password.SetNewPasswordActivityTest --verbose Test: atest com.android.settings.password.ChooseLockGenericTest --verbose Test: manual Change-Id: I32785d33e6425416fc1dbba24540ece8917b58f3
This commit is contained in:
@@ -25,6 +25,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
|||||||
|
|
||||||
import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
|
import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
||||||
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
@@ -169,6 +170,12 @@ public class ChooseLockGeneric extends SettingsActivity {
|
|||||||
/** From intent extra {@link ChooseLockSettingsHelper#EXTRA_KEY_CALLER_APP_NAME}. */
|
/** From intent extra {@link ChooseLockSettingsHelper#EXTRA_KEY_CALLER_APP_NAME}. */
|
||||||
private String mCallerAppName = null;
|
private String mCallerAppName = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value from the intent extra {@link
|
||||||
|
* ChooseLockSettingsHelper#EXTRA_KEY_IS_CALLING_APP_ADMIN}.
|
||||||
|
*/
|
||||||
|
private boolean mIsCallingAppAdmin;
|
||||||
|
|
||||||
protected boolean mForFingerprint = false;
|
protected boolean mForFingerprint = false;
|
||||||
protected boolean mForFace = false;
|
protected boolean mForFace = false;
|
||||||
|
|
||||||
@@ -217,6 +224,8 @@ public class ChooseLockGeneric extends SettingsActivity {
|
|||||||
.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE);
|
.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE);
|
||||||
mCallerAppName =
|
mCallerAppName =
|
||||||
getActivity().getIntent().getStringExtra(EXTRA_KEY_CALLER_APP_NAME);
|
getActivity().getIntent().getStringExtra(EXTRA_KEY_CALLER_APP_NAME);
|
||||||
|
mIsCallingAppAdmin = getActivity().getIntent()
|
||||||
|
.getBooleanExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, /* defValue= */ false);
|
||||||
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
|
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
|
||||||
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
|
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
|
||||||
mUserManager = UserManager.get(getActivity());
|
mUserManager = UserManager.get(getActivity());
|
||||||
@@ -490,7 +499,7 @@ public class ChooseLockGeneric extends SettingsActivity {
|
|||||||
protected void addPreferences() {
|
protected void addPreferences() {
|
||||||
addPreferencesFromResource(R.xml.security_settings_picker);
|
addPreferencesFromResource(R.xml.security_settings_picker);
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(mCallerAppName)) {
|
if (!TextUtils.isEmpty(mCallerAppName) && !mIsCallingAppAdmin) {
|
||||||
FooterPreferenceMixinCompat footerMixin =
|
FooterPreferenceMixinCompat footerMixin =
|
||||||
new FooterPreferenceMixinCompat(this, getSettingsLifecycle());
|
new FooterPreferenceMixinCompat(this, getSettingsLifecycle());
|
||||||
FooterPreference footer = footerMixin.createFooterPreference();
|
FooterPreference footer = footerMixin.createFooterPreference();
|
||||||
|
@@ -60,6 +60,12 @@ public final class ChooseLockSettingsHelper {
|
|||||||
*/
|
*/
|
||||||
public static final String EXTRA_KEY_CALLER_APP_NAME = "caller_app_name";
|
public static final String EXTRA_KEY_CALLER_APP_NAME = "caller_app_name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intent extra indicating that the calling app is an admin, such as a Device Adimn, Device
|
||||||
|
* Owner, or Profile Owner.
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_KEY_IS_CALLING_APP_ADMIN = "is_calling_app_admin";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When invoked via {@link ConfirmLockPassword.InternalActivity}, this flag
|
* When invoked via {@link ConfirmLockPassword.InternalActivity}, this flag
|
||||||
* controls if we relax the enforcement of
|
* controls if we relax the enforcement of
|
||||||
|
@@ -23,6 +23,7 @@ import static android.app.admin.DevicePolicyManager.EXTRA_PASSWORD_COMPLEXITY;
|
|||||||
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
||||||
|
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
||||||
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -30,6 +31,8 @@ import android.app.admin.DevicePolicyManager;
|
|||||||
import android.app.admin.DevicePolicyManager.PasswordComplexity;
|
import android.app.admin.DevicePolicyManager.PasswordComplexity;
|
||||||
import android.app.admin.PasswordMetrics;
|
import android.app.admin.PasswordMetrics;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -39,6 +42,8 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and
|
* Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and
|
||||||
* {@link DevicePolicyManager#ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} intent to the appropriate UI
|
* {@link DevicePolicyManager#ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} intent to the appropriate UI
|
||||||
@@ -116,10 +121,28 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo
|
|||||||
if (mRequestedMinComplexity != PASSWORD_COMPLEXITY_NONE) {
|
if (mRequestedMinComplexity != PASSWORD_COMPLEXITY_NONE) {
|
||||||
intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, mRequestedMinComplexity);
|
intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, mRequestedMinComplexity);
|
||||||
}
|
}
|
||||||
|
if (isCallingAppAdmin()) {
|
||||||
|
intent.putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true);
|
||||||
|
}
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isCallingAppAdmin() {
|
||||||
|
DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class);
|
||||||
|
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(getActivityToken());
|
||||||
|
List<ComponentName> admins = devicePolicyManager.getActiveAdmins();
|
||||||
|
if (admins == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (ComponentName componentName : admins) {
|
||||||
|
if (componentName.getPackageName().equals(callingAppPackageName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void logSetNewPasswordIntent() {
|
private void logSetNewPasswordIntent() {
|
||||||
final String callingAppPackageName =
|
final String callingAppPackageName =
|
||||||
PasswordUtils.getCallingAppPackageName(getActivityToken());
|
PasswordUtils.getCallingAppPackageName(getActivityToken());
|
||||||
|
@@ -23,6 +23,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
|
|||||||
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
||||||
|
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
||||||
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
@@ -182,12 +183,22 @@ public class ChooseLockGenericTest {
|
|||||||
CharSequence expectedTitle =
|
CharSequence expectedTitle =
|
||||||
mActivity.getString(R.string.unlock_footer_none_complexity_requested, "app name");
|
mActivity.getString(R.string.unlock_footer_none_complexity_requested, "app name");
|
||||||
|
|
||||||
mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
|
mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
|
||||||
FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
|
FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
|
||||||
|
|
||||||
assertThat(footer.getTitle()).isEqualTo(expectedTitle);
|
assertThat(footer.getTitle()).isEqualTo(expectedTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePreferencesOrFinish_callingAppIsAdmin_noFooter() {
|
||||||
|
initActivity(new Intent().putExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, true));
|
||||||
|
|
||||||
|
mFragment.updatePreferencesOrFinish(/* isRecreatingActivity= */ false);
|
||||||
|
|
||||||
|
FooterPreference footer = mFragment.findPreference(FooterPreference.KEY_FOOTER);
|
||||||
|
assertThat(footer).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityResult_requestcode0_shouldNotFinish() {
|
public void onActivityResult_requestcode0_shouldNotFinish() {
|
||||||
initActivity(null);
|
initActivity(null);
|
||||||
|
@@ -24,6 +24,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH;
|
|||||||
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
|
||||||
|
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
|
||||||
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
|
||||||
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
@@ -32,8 +33,10 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -54,6 +57,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.Shadows;
|
import org.robolectric.Shadows;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowActivity;
|
import org.robolectric.shadows.ShadowActivity;
|
||||||
|
import org.robolectric.shadows.ShadowDevicePolicyManager;
|
||||||
|
import org.robolectric.shadows.ShadowLog;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class SetNewPasswordActivityTest {
|
public class SetNewPasswordActivityTest {
|
||||||
@@ -91,7 +96,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
||||||
activity.launchChooseLock(new Bundle());
|
activity.launchChooseLock(new Bundle());
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent intent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent intent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
|
|
||||||
assertThat(intent.getComponent())
|
assertThat(intent.getComponent())
|
||||||
.isEqualTo(new ComponentName(activity, ChooseLockGeneric.class));
|
.isEqualTo(new ComponentName(activity, ChooseLockGeneric.class));
|
||||||
@@ -105,7 +110,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
||||||
activity.launchChooseLock(new Bundle());
|
activity.launchChooseLock(new Bundle());
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent intent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent intent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
|
|
||||||
assertThat(intent.getComponent())
|
assertThat(intent.getComponent())
|
||||||
.isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class));
|
.isEqualTo(new ComponentName(activity, SetupChooseLockGeneric.class));
|
||||||
@@ -149,7 +154,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isTrue();
|
||||||
assertThat(actualIntent.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE))
|
assertThat(actualIntent.getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE))
|
||||||
@@ -179,7 +184,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
||||||
@@ -207,7 +212,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
||||||
@@ -234,7 +239,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
||||||
@@ -262,7 +267,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
||||||
@@ -289,7 +294,7 @@ public class SetNewPasswordActivityTest {
|
|||||||
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
Robolectric.buildActivity(SetNewPasswordActivity.class, intent).create().get();
|
||||||
|
|
||||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||||
Intent actualIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
Intent actualIntent = getLaunchChooseLockIntent(shadowActivity);
|
||||||
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
|
assertThat(actualIntent.getAction()).isEqualTo(ACTION_SET_NEW_PARENT_PROFILE_PASSWORD);
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
|
||||||
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
assertThat(actualIntent.hasExtra(EXTRA_KEY_CALLER_APP_NAME)).isTrue();
|
||||||
@@ -301,4 +306,45 @@ public class SetNewPasswordActivityTest {
|
|||||||
PKG_NAME,
|
PKG_NAME,
|
||||||
Integer.MIN_VALUE);
|
Integer.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = {ShadowPasswordUtils.class})
|
||||||
|
public void launchChooseLock_callingAppIsAdmin_setsAdminExtra() {
|
||||||
|
SetNewPasswordActivity activity =
|
||||||
|
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
||||||
|
DevicePolicyManager devicePolicyManager =
|
||||||
|
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
Shadows.shadowOf(devicePolicyManager).setActiveAdmin(buildTestComponentName(PKG_NAME));
|
||||||
|
ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
|
||||||
|
|
||||||
|
activity.launchChooseLock(new Bundle());
|
||||||
|
|
||||||
|
Intent intent = getLaunchChooseLockIntent(Shadows.shadowOf(activity));
|
||||||
|
assertThat(intent.hasExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = {ShadowPasswordUtils.class})
|
||||||
|
public void launchChooseLock_callingAppIsNotAdmin_doesNotSetAdminExtra() {
|
||||||
|
SetNewPasswordActivity activity =
|
||||||
|
Robolectric.buildActivity(SetNewPasswordActivity.class).get();
|
||||||
|
DevicePolicyManager devicePolicyManager =
|
||||||
|
(DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
Shadows.shadowOf(devicePolicyManager)
|
||||||
|
.setActiveAdmin(buildTestComponentName("other_pkg_name"));
|
||||||
|
ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME);
|
||||||
|
|
||||||
|
activity.launchChooseLock(new Bundle());
|
||||||
|
|
||||||
|
Intent intent = getLaunchChooseLockIntent(Shadows.shadowOf(activity));
|
||||||
|
assertThat(intent.hasExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComponentName buildTestComponentName(String packageName) {
|
||||||
|
return new ComponentName(packageName, "clazz");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent getLaunchChooseLockIntent(ShadowActivity shadowActivity) {
|
||||||
|
return shadowActivity.getNextStartedActivityForResult().intent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user