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

Commit 866fd420 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Add dictionary dump buttons in debug settings."

parents f7d682cc 36c7a62d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -498,6 +498,14 @@ mobile devices. [CHAR LIMIT=25] -->
    <string name="read_external_dictionary_confirm_install_message">Really install this file for <xliff:g id="locale_name">%s</xliff:g>?</string>
    <!-- Title for an error dialog that contains the details of the error in the body [CHAR LIMIT=80] -->
    <string name="error">There was an error</string>
    <!-- Title of the settings for dumpping contacts dictionary file [CHAR LIMIT=35] -->
    <string name="prefs_dump_contacts_dict">Dump contacts dictionary</string>
    <!-- Title of the settings for dumpping personal dictionary file [CHAR LIMIT=35] -->
    <string name="prefs_dump_user_dict">Dump personal dictionary</string>
    <!-- Title of the settings for dumpping user history dictionary file [CHAR LIMIT=35] -->
    <string name="prefs_dump_user_history_dict">Dump user history dictionary</string>
    <!-- Title of the settings for dumpping personalization dictionary file [CHAR LIMIT=35] -->
    <string name="prefs_dump_personalization_dict">Dump personalization dictionary</string>

    <!-- Title of the button to revert to the default value of the device in the settings dialog [CHAR LIMIT=15] -->
    <string name="button_default">Default</string>
+17 −0
Original line number Diff line number Diff line
@@ -61,4 +61,21 @@
    <PreferenceScreen
        android:key="read_external_dictionary"
        android:title="@string/prefs_read_external_dictionary" />

    <PreferenceScreen
        android:key="dump_contacts_dict"
        android:title="@string/prefs_dump_contacts_dict" />

    <PreferenceScreen
        android:key="dump_user_dict"
        android:title="@string/prefs_dump_user_dict" />

    <PreferenceScreen
        android:key="dump_user_history_dict"
        android:title="@string/prefs_dump_user_history_dict" />

    <PreferenceScreen
        android:key="dump_personalization_dict"
        android:title="@string/prefs_dump_personalization_dict" />

</PreferenceScreen>
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.latin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class DictionaryDumpBroadcastReceiver extends BroadcastReceiver {
  private static final String TAG = DictionaryDumpBroadcastReceiver.class.getSimpleName();

    private static final String DOMAIN = "com.android.inputmethod.latin";
    public static final String DICTIONARY_DUMP_INTENT_ACTION = DOMAIN + ".DICT_DUMP";
    public static final String DICTIONARY_NAME_KEY = "dictName";

    final LatinIME mLatinIme;

    public DictionaryDumpBroadcastReceiver(final LatinIME latinIme) {
        mLatinIme = latinIme;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (action.equals(DICTIONARY_DUMP_INTENT_ACTION)) {
            final String dictName = intent.getStringExtra(DICTIONARY_NAME_KEY);
            if (dictName == null) {
                Log.e(TAG, "Received dictionary dump intent action " +
                      "but the dictionary name is not set.");
                return;
            }
            mLatinIme.dumpDictionaryForDebug(dictName);
        }
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -534,4 +534,25 @@ public class DictionaryFacilitatorForSuggest {
        mPersonalizationDictionary.addMultipleDictionaryEntriesToDictionary(languageModelParams,
                callback);
    }

    public void dumpDictionaryForDebug(final String dictName) {
        final ExpandableBinaryDictionary dictToDump;
        if (dictName.equals(Dictionary.TYPE_CONTACTS)) {
            dictToDump = mContactsDictionary;
        } else if (dictName.equals(Dictionary.TYPE_USER)) {
            dictToDump = mUserDictionary;
        } else if (dictName.equals(Dictionary.TYPE_USER_HISTORY)) {
            dictToDump = mUserHistoryDictionary;
        } else if (dictName.equals(Dictionary.TYPE_PERSONALIZATION)) {
            dictToDump = mPersonalizationDictionary;
        } else {
            dictToDump = null;
        }
        if (dictToDump == null) {
            Log.e(TAG, "Cannot dump " + dictName + ". "
                    + "The dictionary is not being used for suggestion or cannot be dumped.");
            return;
        }
        dictToDump.dumpAllWordsForDebug();
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -133,6 +133,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    private BroadcastReceiver mDictionaryPackInstallReceiver =
            new DictionaryPackInstallBroadcastReceiver(this);

    private BroadcastReceiver mDictionaryDumpBroadcastReceiver =
            new DictionaryDumpBroadcastReceiver(this);

    private AlertDialog mOptionsDialog;

    private final boolean mIsHardwareAcceleratedDrawingEnabled;
@@ -487,6 +490,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);
        registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);

        final IntentFilter dictDumpFilter = new IntentFilter();
        dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
        registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);

        DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this);
    }

@@ -1758,6 +1765,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        resetSuggest(new Suggest(locale, dictionaryFacilitator));
    }

    public void dumpDictionaryForDebug(final String dictName) {
        if (mInputLogic.mSuggest == null) {
            initSuggest();
        }
        mInputLogic.mSuggest.mDictionaryFacilitator.dumpDictionaryForDebug(dictName);
    }

    public void debugDumpStateAndCrashWithException(final String context) {
        final SettingsValues settingsValues = mSettings.getCurrent();
        final StringBuilder s = new StringBuilder(settingsValues.toString());
Loading