diff options
author | 2015-07-15 13:32:50 -0700 | |
---|---|---|
committer | 2015-07-15 22:51:53 +0000 | |
commit | 604158669b407a40cd0f23538fad4dce5d738f24 (patch) | |
tree | 85aab20d4da9aa12bdd409ce04541db25de1e2f4 /java/src/com/android/inputmethod/latin/utils | |
parent | 7d5fb3a9430550a3ccf1ed5afd70dbf8cc81574a (diff) | |
download | latinime-604158669b407a40cd0f23538fad4dce5d738f24.tar.gz latinime-604158669b407a40cd0f23538fad4dce5d738f24.tar.xz latinime-604158669b407a40cd0f23538fad4dce5d738f24.zip |
[LatinIME] Support MNC permissions.
This build has been compiled against API 23
This build is approved to go out with the M OTA, but may NOT be released
to the public until the Play Store has enabled API level 23 apps
Version: 4.1.2300x.build_id
1. Replaces the personalization is on information with the suggest
contacts.
2. Enables "Use Contacts" only if the app has permission to read
contacts.
3. Disables the contacts dictionary in the Facilitator.
4. Do not register/read the contacts in the contact observer.
Bug: 22236416
Change-Id: I9674e13d0d0f4a2014c5024fde0178de684c07e7
Diffstat (limited to 'java/src/com/android/inputmethod/latin/utils')
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java | 107 |
1 files changed, 44 insertions, 63 deletions
diff --git a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java index df0cd8437..cea263b3b 100644 --- a/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ImportantNoticeUtils.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin.utils; +import android.Manifest; import android.content.Context; import android.content.SharedPreferences; import android.provider.Settings; @@ -25,6 +26,7 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.permissions.PermissionsUtil; import com.android.inputmethod.latin.settings.SettingsValues; import java.util.concurrent.TimeUnit; @@ -35,14 +37,14 @@ public final class ImportantNoticeUtils { // {@link SharedPreferences} name to save the last important notice version that has been // displayed to users. private static final String PREFERENCE_NAME = "important_notice_pref"; + + private static final String KEY_SUGGEST_CONTACTS_NOTICE = "important_notice_suggest_contacts"; + @UsedForTesting - static final String KEY_IMPORTANT_NOTICE_VERSION = "important_notice_version"; - @UsedForTesting - static final String KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE = - "timestamp_of_first_important_notice"; + static final String KEY_TIMESTAMP_OF_CONTACTS_NOTICE = "timestamp_of_suggest_contacts_notice"; + @UsedForTesting static final long TIMEOUT_OF_IMPORTANT_NOTICE = TimeUnit.HOURS.toMillis(23); - public static final int VERSION_TO_ENABLE_PERSONALIZED_SUGGESTIONS = 1; // Copy of the hidden {@link Settings.Secure#USER_SETUP_COMPLETE} settings key. // The value is zero until each multiuser completes system setup wizard. @@ -73,87 +75,66 @@ public final class ImportantNoticeUtils { } @UsedForTesting - static int getCurrentImportantNoticeVersion(final Context context) { - return context.getResources().getInteger(R.integer.config_important_notice_version); - } - - @UsedForTesting - static int getLastImportantNoticeVersion(final Context context) { - return getImportantNoticePreferences(context).getInt(KEY_IMPORTANT_NOTICE_VERSION, 0); - } - - public static int getNextImportantNoticeVersion(final Context context) { - return getLastImportantNoticeVersion(context) + 1; - } - - @UsedForTesting - static boolean hasNewImportantNotice(final Context context) { - final int lastVersion = getLastImportantNoticeVersion(context); - return getCurrentImportantNoticeVersion(context) > lastVersion; - } - - @UsedForTesting - static boolean hasTimeoutPassed(final Context context, final long currentTimeInMillis) { - final SharedPreferences prefs = getImportantNoticePreferences(context); - if (!prefs.contains(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE)) { - prefs.edit() - .putLong(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE, currentTimeInMillis) - .apply(); - } - final long firstDisplayTimeInMillis = prefs.getLong( - KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE, currentTimeInMillis); - final long elapsedTime = currentTimeInMillis - firstDisplayTimeInMillis; - return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE; + static boolean hasContactsNoticeShown(final Context context) { + return getImportantNoticePreferences(context).getBoolean( + KEY_SUGGEST_CONTACTS_NOTICE, false); } public static boolean shouldShowImportantNotice(final Context context, final SettingsValues settingsValues) { - // Check to see whether personalization is enabled by the user. - if (!settingsValues.isPersonalizationEnabled()) { + // Check to see whether "Use Contacts" is enabled by the user. + if (!settingsValues.mUseContactsDict) { return false; } - if (!hasNewImportantNotice(context)) { + + if (hasContactsNoticeShown(context)) { + return false; + } + + // Don't show the dialog if we have all the permissions. + if (PermissionsUtil.checkAllPermissionsGranted( + context, Manifest.permission.READ_CONTACTS)) { return false; } - final String importantNoticeTitle = getNextImportantNoticeTitle(context); + + final String importantNoticeTitle = getSuggestContactsNoticeTitle(context); if (TextUtils.isEmpty(importantNoticeTitle)) { return false; } if (isInSystemSetupWizard(context)) { return false; } - if (hasTimeoutPassed(context, System.currentTimeMillis())) { - updateLastImportantNoticeVersion(context); + if (hasContactsNoticeTimeoutPassed(context, System.currentTimeMillis())) { + updateContactsNoticeShown(context); return false; } return true; } - public static void updateLastImportantNoticeVersion(final Context context) { - getImportantNoticePreferences(context) - .edit() - .putInt(KEY_IMPORTANT_NOTICE_VERSION, getNextImportantNoticeVersion(context)) - .remove(KEY_TIMESTAMP_OF_FIRST_IMPORTANT_NOTICE) - .apply(); + public static String getSuggestContactsNoticeTitle(final Context context) { + return context.getResources().getString(R.string.important_notice_suggest_contact_names); } - public static String getNextImportantNoticeTitle(final Context context) { - final int nextVersion = getNextImportantNoticeVersion(context); - final String[] importantNoticeTitleArray = context.getResources().getStringArray( - R.array.important_notice_title_array); - if (nextVersion > 0 && nextVersion < importantNoticeTitleArray.length) { - return importantNoticeTitleArray[nextVersion]; + @UsedForTesting + static boolean hasContactsNoticeTimeoutPassed( + final Context context, final long currentTimeInMillis) { + final SharedPreferences prefs = getImportantNoticePreferences(context); + if (!prefs.contains(KEY_TIMESTAMP_OF_CONTACTS_NOTICE)) { + prefs.edit() + .putLong(KEY_TIMESTAMP_OF_CONTACTS_NOTICE, currentTimeInMillis) + .apply(); } - return null; + final long firstDisplayTimeInMillis = prefs.getLong( + KEY_TIMESTAMP_OF_CONTACTS_NOTICE, currentTimeInMillis); + final long elapsedTime = currentTimeInMillis - firstDisplayTimeInMillis; + return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE; } - public static String getNextImportantNoticeContents(final Context context) { - final int nextVersion = getNextImportantNoticeVersion(context); - final String[] importantNoticeContentsArray = context.getResources().getStringArray( - R.array.important_notice_contents_array); - if (nextVersion > 0 && nextVersion < importantNoticeContentsArray.length) { - return importantNoticeContentsArray[nextVersion]; - } - return null; + public static void updateContactsNoticeShown(final Context context) { + getImportantNoticePreferences(context) + .edit() + .putBoolean(KEY_SUGGEST_CONTACTS_NOTICE, true) + .remove(KEY_TIMESTAMP_OF_CONTACTS_NOTICE) + .apply(); } } |