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

Commit b56f7d8c authored by Chieu Nguyen's avatar Chieu Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Disable message if personalization is disabled."

parents 59d34087 8ec36026
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1450,7 +1450,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        }

        final boolean shouldShowImportantNotice =
                ImportantNoticeUtils.shouldShowImportantNotice(this);
                ImportantNoticeUtils.shouldShowImportantNotice(this, currentSettingsValues);
        final boolean shouldShowSuggestionCandidates =
                currentSettingsValues.mInputAttributes.mShouldShowSuggestions
                && currentSettingsValues.isSuggestionsEnabledPerUserSettings();
+4 −0
Original line number Diff line number Diff line
@@ -237,6 +237,10 @@ public class SettingsValues {
        return mSuggestionsEnabledPerUserSettings;
    }

    public boolean isPersonalizationEnabled() {
        return mUsePersonalizedDicts;
    }

    public boolean isWordSeparator(final int code) {
        return mSpacingAndPunctuations.isWordSeparator(code);
    }
+2 −1
Original line number Diff line number Diff line
@@ -213,7 +213,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
    // it has been shown once already or not, and if in the setup wizard). If applicable, it shows
    // the notice. In all cases, it returns true if it was shown, false otherwise.
    public boolean maybeShowImportantNoticeTitle() {
        if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext())) {
        final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
        if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), currentSettingsValues)) {
            return false;
        }
        if (getWidth() <= 0) {
+7 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.Log;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.settings.SettingsValues;

import java.util.concurrent.TimeUnit;

@@ -105,7 +106,12 @@ public final class ImportantNoticeUtils {
        return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE;
    }

    public static boolean shouldShowImportantNotice(final Context context) {
    public static boolean shouldShowImportantNotice(final Context context,
            final SettingsValues settingsValues) {
        // Check to see whether personalization is enabled by the user.
        if (!settingsValues.isPersonalizationEnabled()) {
            return false;
        }
        if (!hasNewImportantNotice(context)) {
            return false;
        }
+33 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils;

import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_IMPORTANT_NOTICE_VERSION;
import static com.android.inputmethod.latin.utils.ImportantNoticeUtils.KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.SharedPreferences;
@@ -25,6 +26,11 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.text.TextUtils;

import com.android.inputmethod.latin.settings.SettingsValues;

import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.concurrent.TimeUnit;

@MediumTest
@@ -34,6 +40,8 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {

    private ImportantNoticePreferences mImportantNoticePreferences;

    @Mock private SettingsValues mMockSettingsValues;

    private static class ImportantNoticePreferences {
        private final SharedPreferences mPref;

@@ -97,8 +105,10 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        MockitoAnnotations.initMocks(this);
        mImportantNoticePreferences = new ImportantNoticePreferences(getContext());
        mImportantNoticePreferences.save();
        when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
    }

    @Override
@@ -117,9 +127,9 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {

        // Check internal state of {@link ImportantNoticeUtils.shouldShowImportantNotice(Context)}
        // after fresh install.
        assertEquals("Has new imortant notice after fresh install", true,
        assertEquals("Has new important notice after fresh install", true,
                ImportantNoticeUtils.hasNewImportantNotice(getContext()));
        assertEquals("Next important norice title after fresh install", false, TextUtils.isEmpty(
        assertEquals("Next important notice title after fresh install", false, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeTitle(getContext())));
        assertEquals("Is in system setup wizard after fresh install", false,
                ImportantNoticeUtils.isInSystemSetupWizard(getContext()));
@@ -131,14 +141,14 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
                mImportantNoticePreferences.getLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE));

        assertEquals("Current boolean before update", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
    }

    public void testUpdateVersion() {
        mImportantNoticePreferences.clear();

        assertEquals("Current boolean before update", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version before update", 0,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version before update ", 1,
@@ -151,7 +161,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
        ImportantNoticeUtils.updateLastImportantNoticeVersion(getContext());

        assertEquals("Current boolean after update", false,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version after update", 1,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version after update", 2,
@@ -180,7 +190,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {

        // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout.
        assertEquals("Current boolean before timeout 1", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version before timeout 1", 0,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version before timeout 1", 1,
@@ -197,7 +207,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
        // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} before timeout
        // again.
        assertEquals("Current boolean before timeout 2", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version before timeout 2", 0,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version before timeout 2", 1,
@@ -213,7 +223,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {

        // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout.
        assertEquals("Current boolean after timeout 1", false,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version after timeout 1", 1,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version after timeout 1", 2,
@@ -229,7 +239,7 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {

        // Call {@link ImportantNoticeUtils#shouldShowImportantNotice(Context)} after timeout again.
        assertEquals("Current boolean after timeout 2", false,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext()));
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
        assertEquals("Last version after timeout 2", 1,
                ImportantNoticeUtils.getLastImportantNoticeVersion(getContext()));
        assertEquals("Next version after timeout 2", 2,
@@ -241,4 +251,18 @@ public class ImportantNoticeUtilsTests extends AndroidTestCase {
        assertEquals("Current contents after timeout 2", true, TextUtils.isEmpty(
                ImportantNoticeUtils.getNextImportantNoticeContents(getContext())));
    }

    public void testPersonalizationSetting() {
        mImportantNoticePreferences.clear();

        // Personalization enabled.
        when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(true);
        assertEquals("Current boolean with personalization enabled", true,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));

        // Personalization disabled.
        when(mMockSettingsValues.isPersonalizationEnabled()).thenReturn(false);
        assertEquals("Current boolean with personalization disabled", false,
                ImportantNoticeUtils.shouldShowImportantNotice(getContext(), mMockSettingsValues));
    }
}