com.android.inputmethod.annotations.UsedForTesting Java Examples

The following examples show how to use com.android.inputmethod.annotations.UsedForTesting. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MatrixUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * A matrix operation to multiply m0 and m1.
 */
@UsedForTesting
public static void multiply(final float[][] m0, final float[][] m1,
        final float[][] retval) throws MatrixOperationFailedException {
    if (m0[0].length != m1.length) {
        throw new MatrixOperationFailedException(
                "--- invalid length for multiply " + m0[0].length + ", " + m1.length);
    }
    final int m0h = m0.length;
    final int m0w = m0[0].length;
    final int m1w = m1[0].length;
    if (retval.length != m0h || retval[0].length != m1w) {
        throw new MatrixOperationFailedException(
                "--- invalid length of retval " + retval.length + ", " + retval[0].length);
    }

    for (int i = 0; i < m0h; i++) {
        Arrays.fill(retval[i], 0);
        for (int j = 0; j < m1w; j++) {
            for (int k = 0; k < m0w; k++) {
                retval[i][j] += m0[i][k] * m1[k][j];
            }
        }
    }
}
 
Example #2
Source File: LatinIME.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@UsedForTesting
void loadSettings() {
    final Locale locale = mRichImm.getCurrentSubtypeLocale();
    final EditorInfo editorInfo = getCurrentInputEditorInfo();
    final InputAttributes inputAttributes = new InputAttributes(
            editorInfo, isFullscreenMode(), getPackageName());
    mSettings.loadSettings(this, locale, inputAttributes);
    final SettingsValues currentSettingsValues = mSettings.getCurrent();
    AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
    // This method is called on startup and language switch, before the new layout has
    // been displayed. Opening dictionaries never affects responsivity as dictionaries are
    // asynchronously loaded.
    if (!mHandler.hasPendingReopenDictionaries()) {
        resetDictionaryFacilitator(locale);
    }
    refreshPersonalizationDictionarySession(currentSettingsValues);
    resetDictionaryFacilitatorIfNecessary();
    mStatsUtilsManager.onLoadSettings(this /* context */, currentSettingsValues);
}
 
Example #3
Source File: WordProperty.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@UsedForTesting
public WordProperty(final String word, final ProbabilityInfo probabilityInfo,
        @Nullable final ArrayList<WeightedString> bigrams,
        final boolean isNotAWord, final boolean isPossiblyOffensive) {
    mWord = word;
    mProbabilityInfo = probabilityInfo;
    if (null == bigrams) {
        mNgrams = null;
    } else {
        mNgrams = new ArrayList<>();
        final NgramContext ngramContext = new NgramContext(new WordInfo(mWord));
        for (final WeightedString bigramTarget : bigrams) {
            mNgrams.add(new NgramProperty(bigramTarget, ngramContext));
        }
    }
    mIsBeginningOfSentence = false;
    mIsNotAWord = isNotAWord;
    mIsPossiblyOffensive = isPossiblyOffensive;
    mHasNgrams = bigrams != null && !bigrams.isEmpty();
}
 
Example #4
Source File: StringUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert hex string to byte array. The string length must be an even number.
 */
@UsedForTesting
public static byte[] hexStringToByteArray(final String hexString) {
    if (isEmpty(hexString)) {
        return null;
    }
    final int N = hexString.length();
    if (N % 2 != 0) {
        throw new NumberFormatException("Input hex string length must be an even number."
                + " Length = " + N);
    }
    final byte[] bytes = new byte[N / 2];
    for (int i = 0; i < N; i += 2) {
        bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
                + Character.digit(hexString.charAt(i + 1), 16));
    }
    return bytes;
}
 
Example #5
Source File: MatrixUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * A function to inverse matrix.
 * The inverse matrix of squareMatrix will be output to inverseMatrix. Please notice that
 * the value of squareMatrix is modified in this function and can't be resuable.
 */
@UsedForTesting
public static void inverse(final float[][] squareMatrix,
        final float[][] inverseMatrix) throws MatrixOperationFailedException {
    final int size = squareMatrix.length;
    if (squareMatrix[0].length != size || inverseMatrix.length != size
            || inverseMatrix[0].length != size) {
        throw new MatrixOperationFailedException(
                "--- invalid length. column should be 2 times larger than row.");
    }
    for (int i = 0; i < size; ++i) {
        Arrays.fill(inverseMatrix[i], 0.0f);
        inverseMatrix[i][i] = 1.0f;
    }
    for (int i = 0; i < size; ++i) {
        findPivotAndSwapRow(i, squareMatrix, inverseMatrix, size);
        sweep(i, squareMatrix, inverseMatrix, size);
    }
}
 
Example #6
Source File: MatrixUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function to dump the specified matrix in a readable way
 */
@UsedForTesting
public static void dump(final String title, final float[][] a) {
    final int column = a[0].length;
    final int row = a.length;
    Log.d(TAG, "Dump matrix: " + title);
    Log.d(TAG, "/*---------------------");
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < row; ++i) {
        sb.setLength(0);
        for (int j = 0; j < column; ++j) {
            sb.append(String.format("%4f", a[i][j])).append(' ');
        }
        Log.d(TAG, sb.toString());
    }
    Log.d(TAG, "---------------------*/");
}
 
Example #7
Source File: CodePointUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a random word.
 */
@UsedForTesting
@NonNull
public static String generateWord(@NonNull final Random random,
                                  @NonNull final int[] codePointSet) {
    final StringBuilder builder = new StringBuilder();
    // 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward
    // longer words. This should be closer to natural language, and more importantly, it will
    // exercise the algorithms in dicttool much more.
    final int count = 1 + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5)
            + (Math.abs(random.nextInt()) % 5);
    while (builder.length() < count) {
        builder.appendCodePoint(codePointSet[Math.abs(random.nextInt()) % codePointSet.length]);
    }
    return builder.toString();
}
 
Example #8
Source File: BinaryDictionary.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@UsedForTesting
public void updateEntriesForInputEvents(final WordInputEventForPersonalization[] inputEvents) {
    if (!isValidDictionary()) {
        return;
    }
    int processedEventCount = 0;
    while (processedEventCount < inputEvents.length) {
        if (needsToRunGC(true /* mindsBlockByGC */)) {
            flushWithGC();
        }
        processedEventCount = updateEntriesForInputEventsNative(mNativeDict, inputEvents,
                processedEventCount);
        mHasUpdated = true;
        if (processedEventCount <= 0) {
            return;
        }
    }
}
 
Example #9
Source File: InputPointers.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public void addPointer(final int x, final int y, final int pointerId, final int time) {
    mXCoordinates.add(x);
    mYCoordinates.add(y);
    mPointerIds.add(pointerId);
    mTimes.add(time);
}
 
Example #10
Source File: TextInfoCompatUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public static TextInfo newInstance(CharSequence charSequence, int start, int end, int cookie,
        int sequenceNumber) {
    if (TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE != null) {
        return (TextInfo) CompatUtils.newInstance(TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE,
                charSequence, start, end, cookie, sequenceNumber);
    }
    return new TextInfo(charSequence.subSequence(start, end).toString(), cookie,
            sequenceNumber);
}
 
Example #11
Source File: WordProperty.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public ArrayList<WeightedString> getBigrams() {
    if (null == mNgrams) {
        return null;
    }
    final ArrayList<WeightedString> bigrams = new ArrayList<>();
    for (final NgramProperty ngram : mNgrams) {
        if (ngram.mNgramContext.getPrevWordCount() == 1) {
            bigrams.add(ngram.mTargetWord);
        }
    }
    return bigrams;
}
 
Example #12
Source File: LatinIME.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public void recycle() {
    unregisterReceiver(mDictionaryPackInstallReceiver);
    unregisterReceiver(mDictionaryDumpBroadcastReceiver);
    unregisterReceiver(mRingerModeChangeReceiver);
    mInputLogic.recycle();
}
 
Example #13
Source File: HttpUrlConnectionBuilder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the connect timeout. Defaults to {@value #DEFAULT_TIMEOUT_MILLIS} milliseconds.
 *
 * TODO: Remove @UsedForTesting after this method is actually used.
 */
@UsedForTesting
public HttpUrlConnectionBuilder setConnectTimeout(int timeoutMillis) {
    if (timeoutMillis < 0) {
        throw new IllegalArgumentException("connect-timeout must be >= 0, but was "
                + timeoutMillis);
    }
    mConnectTimeoutMillis = timeoutMillis;
    return this;
}
 
Example #14
Source File: DictionaryInfoUtils.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public static boolean looksValidForDictionaryInsertion(final CharSequence text,
        final SpacingAndPunctuations spacingAndPunctuations) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }
    final int length = text.length();
    if (length > DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH) {
        return false;
    }
    int i = 0;
    int digitCount = 0;
    while (i < length) {
        final int codePoint = Character.codePointAt(text, i);
        final int charCount = Character.charCount(codePoint);
        i += charCount;
        if (Character.isDigit(codePoint)) {
            // Count digits: see below
            digitCount += charCount;
            continue;
        }
        if (!spacingAndPunctuations.isWordCodePoint(codePoint)) {
            return false;
        }
    }
    // We reject strings entirely comprised of digits to avoid using PIN codes or credit
    // card numbers. It would come in handy for word prediction though; a good example is
    // when writing one's address where the street number is usually quite discriminative,
    // as well as the postal code.
    return digitCount < length;
}
 
Example #15
Source File: ExpandableBinaryDictionary.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public void waitAllTasksForTests() {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    asyncExecuteTaskWithWriteLock(new Runnable() {
        @Override
        public void run() {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        Log.e(TAG, "Interrupted while waiting for finishing dictionary operations.", e);
    }
}
 
Example #16
Source File: HttpUrlConnectionBuilder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the read timeout. Defaults to {@value #DEFAULT_TIMEOUT_MILLIS} milliseconds.
 *
 * TODO: Remove @UsedForTesting after this method is actually used.
 */
@UsedForTesting
public HttpUrlConnectionBuilder setReadTimeout(int timeoutMillis) {
    if (timeoutMillis < 0) {
        throw new IllegalArgumentException("read-timeout must be >= 0, but was "
                + timeoutMillis);
    }
    mReadTimeoutMillis = timeoutMillis;
    return this;
}
 
Example #17
Source File: LatinIME.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public void loadKeyboard() {
    // Since we are switching languages, the most urgent thing is to let the keyboard graphics
    // update. LoadKeyboard does that, but we need to wait for buffer flip for it to be on
    // the screen. Anything we do right now will delay this, so wait until the next frame
    // before we do the rest, like reopening dictionaries and updating suggestions. So we
    // post a message.
    mHandler.postReopenDictionaries();
    loadSettings();
    if (KeyboardSwitcher.getInstance().getMainKeyboardView() != null) {
        // Reload keyboard because the current language has been changed.
        KeyboardSwitcher.getInstance().loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(),
                getCurrentAutoCapsState(), getCurrentRecapitalizeState());
    }
}
 
Example #18
Source File: HttpUrlConnectionBuilder.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the read timeout. Defaults to {@value #DEFAULT_TIMEOUT_MILLIS} milliseconds.
 *
 * TODO: Remove @UsedForTesting after this method is actually used.
 */
@UsedForTesting
public HttpUrlConnectionBuilder setReadTimeout(int timeoutMillis) {
    if (timeoutMillis < 0) {
        throw new IllegalArgumentException("read-timeout must be >= 0, but was "
                + timeoutMillis);
    }
    mReadTimeoutMillis = timeoutMillis;
    return this;
}
 
Example #19
Source File: UserHistoryDictionary.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * @returns the name of the {@link UserHistoryDictionary}.
 */
@UsedForTesting
static String getUserHistoryDictName(final String name, final Locale locale,
        @Nullable final File dictFile, @Nullable final String account) {
    if (!ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) {
        return getDictName(name, locale, dictFile);
    }
    return getUserHistoryDictNamePerAccount(name, locale, dictFile, account);
}
 
Example #20
Source File: HttpUrlConnectionBuilder.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the URL that'll be used for the request.
 * This *must* be set before calling {@link #build()}
 *
 * TODO: Remove @UsedForTesting after this method is actually used.
 */
@UsedForTesting
public HttpUrlConnectionBuilder setUrl(String url) throws MalformedURLException {
    if (TextUtils.isEmpty(url)) {
        throw new IllegalArgumentException("URL must not be empty");
    }
    mUrl = new URL(url);
    return this;
}
 
Example #21
Source File: HttpUrlConnectionBuilder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the {@link HttpURLConnection} instance that can be used to execute the request.
 *
 * TODO: Remove @UsedForTesting after this method is actually used.
 */
@UsedForTesting
public HttpURLConnection build() throws IOException {
    if (mUrl == null) {
        throw new IllegalArgumentException("A URL must be specified!");
    }
    final HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
    connection.setConnectTimeout(mConnectTimeoutMillis);
    connection.setReadTimeout(mReadTimeoutMillis);
    connection.setUseCaches(mUseCache);
    switch (mMode) {
        case MODE_UPLOAD_ONLY:
            connection.setDoInput(true);
            connection.setDoOutput(false);
            break;
        case MODE_DOWNLOAD_ONLY:
            connection.setDoInput(false);
            connection.setDoOutput(true);
            break;
        case MODE_BI_DIRECTIONAL:
            connection.setDoInput(true);
            connection.setDoOutput(true);
            break;
    }
    for (final Entry<String, String> entry : mHeaderMap.entrySet()) {
        connection.addRequestProperty(entry.getKey(), entry.getValue());
    }
    if (mContentLength >= 0) {
        connection.setFixedLengthStreamingMode(mContentLength);
    }
    return connection;
}
 
Example #22
Source File: ResourceUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Find the condition that fulfills specified key value pairs from an array of
 * "condition,constant", and return the corresponding string constant. A condition is
 * "pattern1[:pattern2...] (or an empty string for the default). A pattern is
 * "key=regexp_value" string. The condition matches only if all patterns of the condition
 * are true for the specified key value pairs.
 *
 * For example, "condition,constant" has the following format.
 *  - HARDWARE=mako,constantForNexus4
 *  - MODEL=Nexus 4:MANUFACTURER=LGE,constantForNexus4
 *  - ,defaultConstant
 *
 * @param keyValuePairs attributes to be used to look for a matched condition.
 * @param conditionConstantArray an array of "condition,constant" elements to be searched.
 * @return the constant part of the matched "condition,constant" element. Returns null if no
 * condition matches.
 * @see com.android.inputmethod.latin.utils.ResourceUtilsTests#testFindConstantForKeyValuePairsRegexp()
 */
@UsedForTesting
static String findConstantForKeyValuePairs(final HashMap<String, String> keyValuePairs,
        final String[] conditionConstantArray) {
    if (conditionConstantArray == null || keyValuePairs == null) {
        return null;
    }
    String foundValue = null;
    for (final String conditionConstant : conditionConstantArray) {
        final int posComma = conditionConstant.indexOf(',');
        if (posComma < 0) {
            Log.w(TAG, "Array element has no comma: " + conditionConstant);
            continue;
        }
        final String condition = conditionConstant.substring(0, posComma);
        if (condition.isEmpty()) {
            Log.w(TAG, "Array element has no condition: " + conditionConstant);
            continue;
        }
        try {
            if (fulfillsCondition(keyValuePairs, condition)) {
                // Take first match
                if (foundValue == null) {
                    foundValue = conditionConstant.substring(posComma + 1);
                }
                // And continue walking through all conditions.
            }
        } catch (final DeviceOverridePatternSyntaxError e) {
            Log.w(TAG, "Syntax error, ignored", e);
        }
    }
    return foundValue;
}
 
Example #23
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
static boolean shouldOmitTypedWord(final int inputStyle,
        final boolean gestureFloatingPreviewTextEnabled,
        final boolean shouldShowUiToAcceptTypedWord) {
    final boolean omitTypedWord = (inputStyle == SuggestedWords.INPUT_STYLE_TYPING)
            || (inputStyle == SuggestedWords.INPUT_STYLE_TAIL_BATCH)
            || (inputStyle == SuggestedWords.INPUT_STYLE_UPDATE_BATCH
                    && gestureFloatingPreviewTextEnabled);
    return shouldShowUiToAcceptTypedWord && omitTypedWord;
}
 
Example #24
Source File: WordInputEventForPersonalization.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public WordInputEventForPersonalization(final CharSequence targetWord,
        final NgramContext ngramContext, final int timestamp) {
    mTargetWord = StringUtils.toCodePointArray(targetWord);
    mPrevWordsCount = ngramContext.getPrevWordCount();
    ngramContext.outputToArray(mPrevWordArray, mIsPrevWordBeginningOfSentenceArray);
    mTimestamp = timestamp;
}
 
Example #25
Source File: DictionaryFacilitatorImpl.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public void resetDictionariesForTesting(final Context context, final Locale locale,
        final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles,
        final Map<String, Map<String, String>> additionalDictAttributes,
        @Nullable final String account) {
    Dictionary mainDictionary = null;
    final Map<String, ExpandableBinaryDictionary> subDicts = new HashMap<>();

    for (final String dictType : dictionaryTypes) {
        if (dictType.equals(Dictionary.TYPE_MAIN)) {
            mainDictionary = DictionaryFactory.createMainDictionaryFromManager(context,
                    locale);
        } else {
            final File dictFile = dictionaryFiles.get(dictType);
            final ExpandableBinaryDictionary dict = getSubDict(
                    dictType, context, locale, dictFile, "" /* dictNamePrefix */, account);
            if (additionalDictAttributes.containsKey(dictType)) {
                dict.clearAndFlushDictionaryWithAdditionalAttributes(
                        additionalDictAttributes.get(dictType));
            }
            if (dict == null) {
                throw new RuntimeException("Unknown dictionary type: " + dictType);
            }
            dict.reloadDictionaryIfRequired();
            dict.waitAllTasksForTests();
            subDicts.put(dictType, dict);
        }
    }
    mDictionaryGroup = new DictionaryGroup(locale, mainDictionary, account, subDicts);
}
 
Example #26
Source File: BinaryDictionaryUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public static boolean createEmptyDictFile(final String filePath, final long dictVersion,
        final Locale locale, final Map<String, String> attributeMap) {
    final String[] keyArray = new String[attributeMap.size()];
    final String[] valueArray = new String[attributeMap.size()];
    int index = 0;
    for (final String key : attributeMap.keySet()) {
        keyArray[index] = key;
        valueArray[index] = attributeMap.get(key);
        index++;
    }
    return createEmptyDictFileNative(filePath, dictVersion, locale.toString(), keyArray,
            valueArray);
}
 
Example #27
Source File: DictionaryFacilitator.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
void resetDictionariesForTesting(
        final Context context,
        final Locale locale,
        final ArrayList<String> dictionaryTypes,
        final HashMap<String, File> dictionaryFiles,
        final Map<String, Map<String, String>> additionalDictAttributes,
        @Nullable final String account);
 
Example #28
Source File: DictionaryInfoUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
public static boolean looksValidForDictionaryInsertion(final CharSequence text,
        final SpacingAndPunctuations spacingAndPunctuations) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }
    final int length = text.length();
    if (length > DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH) {
        return false;
    }
    int i = 0;
    int digitCount = 0;
    while (i < length) {
        final int codePoint = Character.codePointAt(text, i);
        final int charCount = Character.charCount(codePoint);
        i += charCount;
        if (Character.isDigit(codePoint)) {
            // Count digits: see below
            digitCount += charCount;
            continue;
        }
        if (!spacingAndPunctuations.isWordCodePoint(codePoint)) {
            return false;
        }
    }
    // We reject strings entirely comprised of digits to avoid using PIN codes or credit
    // card numbers. It would come in handy for word prediction though; a good example is
    // when writing one's address where the street number is usually quite discriminative,
    // as well as the postal code.
    return digitCount < length;
}
 
Example #29
Source File: ImportantNoticeUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
static boolean isInSystemSetupWizard(final Context context) {
    try {
        final int userSetupComplete = Settings.Secure.getInt(
                context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
        return userSetupComplete == USER_SETUP_IS_NOT_COMPLETE;
    } catch (final SettingNotFoundException e) {
        Log.w(TAG, "Can't find settings in Settings.Secure: key="
                + Settings_Secure_USER_SETUP_COMPLETE);
        return false;
    }
}
 
Example #30
Source File: ImportantNoticeUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@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();
    }
    final long firstDisplayTimeInMillis = prefs.getLong(
            KEY_TIMESTAMP_OF_CONTACTS_NOTICE, currentTimeInMillis);
    final long elapsedTime = currentTimeInMillis - firstDisplayTimeInMillis;
    return elapsedTime >= TIMEOUT_OF_IMPORTANT_NOTICE;
}