Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c80b5ed authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AR/FR: Updated resources to confirm via component."

parents 90d1392e 51146047
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -9231,11 +9231,15 @@
    <string name="keywords_directory_access">directory access</string>
    <!-- Account type associated with the backup account. Empty for AOSP. [DO NOT TRANSLATE] -->
    <string name="account_type"></string>
    <string name="account_type" translatable="false"></string>
    <!-- Package to target for Account credential confirmation. This will allow users to
         remind/rediscover their backup account password prior to a reset. Empty for AOSP.
         [DO NOT TRANSLATE] -->
    <string name="account_confirmation_package"></string>
    <string name="account_confirmation_package" translatable="false"></string>
    <!-- Class to target for Account credential confirmation. This will allow users to
         remind/rediscover their backup account password prior to a reset. Empty for AOSP.
         [DO NOT TRANSLATE] -->
    <string name="account_confirmation_class" translatable="false"></string>
    <!-- Title for the new About Phone screen [CHAR LIMIT=40] -->
    <string name="my_device_info_title" product="default">My Phone</string>
+12 −5
Original line number Diff line number Diff line
@@ -123,17 +123,21 @@ public class MasterClear extends InstrumentedPreferenceFragment {
        return !((requestCode != KEYGUARD_REQUEST) && (requestCode != CREDENTIAL_CONFIRM_REQUEST));
    }

    @VisibleForTesting
    boolean isShowFinalConfirmation(int requestCode, int resultCode) {
        return (resultCode == Activity.RESULT_OK) || (requestCode == CREDENTIAL_CONFIRM_REQUEST);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (!isValidRequestCode(requestCode)) {
            return;
        }

        // If the user entered a valid keyguard trace, present the final
        // confirmation prompt; otherwise, go back to the initial state.
        if (resultCode == Activity.RESULT_OK) {
        if (isShowFinalConfirmation(requestCode, resultCode)) {
            showFinalConfirmation();
        } else {
            establishInitialState();
@@ -155,7 +159,10 @@ public class MasterClear extends InstrumentedPreferenceFragment {
        final Context context = getActivity();
        final String accountType = context.getString(R.string.account_type);
        final String packageName = context.getString(R.string.account_confirmation_package);
        if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(packageName)) {
        final String className = context.getString(R.string.account_confirmation_class);
        if (TextUtils.isEmpty(accountType)
                || TextUtils.isEmpty(packageName)
                || TextUtils.isEmpty(className)) {
            return false;
        }
        final AccountManager am = AccountManager.get(context);
@@ -163,7 +170,7 @@ public class MasterClear extends InstrumentedPreferenceFragment {
        if (accounts != null && accounts.length > 0) {
            final Intent requestAccountConfirmation = new Intent()
                .setPackage(packageName)
                .setAction("android.accounts.action.PRE_FACTORY_RESET");
                .setComponent(new ComponentName(packageName, className));
            // Check to make sure that the intent is supported.
            final PackageManager pm = context.getPackageManager();
            final ResolveInfo resolution = pm.resolveActivity(requestAccountConfirmation, 0);
@@ -172,7 +179,7 @@ public class MasterClear extends InstrumentedPreferenceFragment {
                    && packageName.equals(resolution.activityInfo.packageName)) {
                // Note that we need to check the packagename to make sure that an Activity resolver
                // wasn't returned.
                getActivity().startActivityForResult(
                startActivityForResult(
                    requestAccountConfirmation, CREDENTIAL_CONFIRM_REQUEST);
                return true;
            }
+6 −2
Original line number Diff line number Diff line
@@ -66,7 +66,8 @@ import org.robolectric.shadows.ShadowActivity;
)
public class MasterClearTest {
    private static final String TEST_ACCOUNT_TYPE = "android.test.account.type";
    private static final String TEST_CONFIRMATION_PACKAGE = "android.test.confirmation.pkg";
    private static final String TEST_CONFIRMATION_PACKAGE = "android.test.conf.pkg";
    private static final String TEST_CONFIRMATION_CLASS = "android.test.conf.pkg.ConfActivity";
    private static final String TEST_ACCOUNT_NAME = "test@example.com";

    @Mock
@@ -223,6 +224,7 @@ public class MasterClearTest {
        when(mMasterClear.getActivity()).thenReturn(mMockActivity);
        when(mMockActivity.getString(R.string.account_type)).thenReturn(TEST_ACCOUNT_TYPE);
        when(mMockActivity.getString(R.string.account_confirmation_package)).thenReturn(TEST_CONFIRMATION_PACKAGE);
        when(mMockActivity.getString(R.string.account_confirmation_class)).thenReturn(TEST_CONFIRMATION_CLASS);

        Account[] accounts = new Account[0];
        when(mMockActivity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
@@ -235,6 +237,7 @@ public class MasterClearTest {
        when(mMasterClear.getActivity()).thenReturn(mMockActivity);
        when(mMockActivity.getString(R.string.account_type)).thenReturn(TEST_ACCOUNT_TYPE);
        when(mMockActivity.getString(R.string.account_confirmation_package)).thenReturn(TEST_CONFIRMATION_PACKAGE);
        when(mMockActivity.getString(R.string.account_confirmation_class)).thenReturn(TEST_CONFIRMATION_CLASS);
        Account[] accounts = new Account[] { new Account(TEST_ACCOUNT_NAME, TEST_ACCOUNT_TYPE) };
        when(mMockActivity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
        when(mAccountManager.getAccountsByType(TEST_ACCOUNT_TYPE)).thenReturn(accounts);
@@ -250,6 +253,7 @@ public class MasterClearTest {
        // Only try to show account confirmation if the appropriate resource overlays are available.
        when(mMockActivity.getString(R.string.account_type)).thenReturn(TEST_ACCOUNT_TYPE);
        when(mMockActivity.getString(R.string.account_confirmation_package)).thenReturn(TEST_CONFIRMATION_PACKAGE);
        when(mMockActivity.getString(R.string.account_confirmation_class)).thenReturn(TEST_CONFIRMATION_CLASS);
        // Add accounts to trigger the search for a resolving intent.
        Account[] accounts = new Account[] { new Account(TEST_ACCOUNT_NAME, TEST_ACCOUNT_TYPE) };
        when(mMockActivity.getSystemService(Context.ACCOUNT_SERVICE)).thenReturn(mAccountManager);
@@ -265,7 +269,7 @@ public class MasterClearTest {
        when(mPackageManager.resolveActivity(any(), eq(0))).thenReturn(resolveInfo);

        // Finally mock out the startActivityForResultCall
        doNothing().when(mMockActivity).startActivityForResult(any(), eq(MasterClear.CREDENTIAL_CONFIRM_REQUEST));
        doNothing().when(mMasterClear).startActivityForResult(any(), eq(MasterClear.CREDENTIAL_CONFIRM_REQUEST));

        assertThat(mMasterClear.tryShowAccountConfirmation()).isTrue();
    }