Commit on finishInput

Change-Id: I26254cfdaecd0d85571be3f930476040de935d6c
main
satok 2010-05-19 14:03:00 +09:00
parent bfd3b8bf86
commit 01303e39f5
4 changed files with 60 additions and 23 deletions

View File

@ -354,4 +354,7 @@
<item>4</item> <item>4</item>
<item>5</item> <item>5</item>
</string-array> </string-array>
<string name="prefs_debug_mode">Debug (Temporary)</string>
</resources> </resources>

View File

@ -38,10 +38,11 @@
/> />
<CheckBoxPreference <CheckBoxPreference
android:key="enable_log" android:key="enable_logging"
android:title="@string/prefs_enable_log" android:title="@string/prefs_enable_log"
android:summary="@string/prefs_description_log" android:summary="@string/prefs_description_log"
android:persistent="true" android:persistent="true"
android:defaultValue="true"
/> />
<ListPreference <ListPreference
@ -99,4 +100,12 @@
/> />
</PreferenceCategory> </PreferenceCategory>
<CheckBoxPreference
android:key="debug_mode"
android:title="@string/prefs_debug_mode"
android:persistent="true"
android:defaultValue="false"
/>
</PreferenceScreen> </PreferenceScreen>

View File

@ -554,6 +554,8 @@ public class LatinIME extends InputMethodService
public void onFinishInput() { public void onFinishInput() {
super.onFinishInput(); super.onFinishInput();
LatinImeLogger.commit();
if (VOICE_INSTALLED && !mConfigurationChanging) { if (VOICE_INSTALLED && !mConfigurationChanging) {
if (mAfterVoiceInput) { if (mAfterVoiceInput) {
mVoiceInput.flushAllTextModificationCounters(); mVoiceInput.flushAllTextModificationCounters();
@ -655,6 +657,8 @@ public class LatinIME extends InputMethodService
@Override @Override
public void hideWindow() { public void hideWindow() {
LatinImeLogger.commit();
if (TRACE) Debug.stopMethodTracing(); if (TRACE) Debug.stopMethodTracing();
if (mOptionsDialog != null && mOptionsDialog.isShowing()) { if (mOptionsDialog != null && mOptionsDialog.isShowing()) {
mOptionsDialog.dismiss(); mOptionsDialog.dismiss();

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.DropBoxManager; import android.os.DropBoxManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.util.Log; import android.util.Log;
@ -28,7 +29,7 @@ import java.util.Collections;
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener { public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "LatinIMELogs"; private static final String TAG = "LatinIMELogs";
private static final boolean DBG = false; private static boolean sDBG = false;
// DEFAULT_LOG_ENABLED should be false when released to public. // DEFAULT_LOG_ENABLED should be false when released to public.
private static final boolean DEFAULT_LOG_ENABLED = true; private static final boolean DEFAULT_LOG_ENABLED = true;
@ -44,7 +45,8 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
private static final int ID_ACTUAL_CHAR_COUNT = 6; private static final int ID_ACTUAL_CHAR_COUNT = 6;
private static final int ID_THEME_ID = 7; private static final int ID_THEME_ID = 7;
private static final String PREF_ENABLE_LOG = "enable_log"; private static final String PREF_ENABLE_LOG = "enable_logging";
private static final String PREF_DEBUG_MODE = "debug_mode";
public static boolean sLogEnabled = true; public static boolean sLogEnabled = true;
private static LatinImeLogger sLatinImeLogger = new LatinImeLogger(); private static LatinImeLogger sLatinImeLogger = new LatinImeLogger();
@ -107,6 +109,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
sLogEnabled = prefs.getBoolean(PREF_ENABLE_LOG, DEFAULT_LOG_ENABLED); sLogEnabled = prefs.getBoolean(PREF_ENABLE_LOG, DEFAULT_LOG_ENABLED);
mThemeId = prefs.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT, mThemeId = prefs.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT,
KeyboardSwitcher.DEFAULT_LAYOUT_ID); KeyboardSwitcher.DEFAULT_LAYOUT_ID);
sDBG = prefs.getBoolean(PREF_DEBUG_MODE, sDBG);
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
} }
@ -126,6 +129,9 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
* Check if the input string is safe as an entry or not. * Check if the input string is safe as an entry or not.
*/ */
private static boolean checkStringDataSafe(String s) { private static boolean checkStringDataSafe(String s) {
if (sDBG) {
Log.d(TAG, "Check String safety: " + s);
}
for (int i = 0; i < s.length(); ++i) { for (int i = 0; i < s.length(); ++i) {
if (!Character.isDigit(s.charAt(i))) { if (!Character.isDigit(s.charAt(i))) {
return true; return true;
@ -134,15 +140,6 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
return false; return false;
} }
private static boolean checkStringsDataSafe(String[] strings) {
for(String s: strings) {
if (!checkStringDataSafe(s)) {
return false;
}
}
return true;
}
private void addCountEntry(long time) { private void addCountEntry(long time) {
mLogBuffer.add(new LogEntry (time, ID_DELETE_COUNT, mLogBuffer.add(new LogEntry (time, ID_DELETE_COUNT,
new String[] {String.valueOf(mDeleteCount)})); new String[] {String.valueOf(mDeleteCount)}));
@ -200,12 +197,18 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
case ID_AUTOSUGGESTION: case ID_AUTOSUGGESTION:
++mWordCount; ++mWordCount;
String[] dataStrings = (String[]) data; String[] dataStrings = (String[]) data;
if (dataStrings.length != 3) {
if (sDBG) {
Log.e(TAG, "The length of string array is invalid.");
}
break;
}
mActualCharCount += dataStrings[1].length(); mActualCharCount += dataStrings[1].length();
if (checkStringsDataSafe(dataStrings)) { if (checkStringDataSafe(dataStrings[0]) && checkStringDataSafe(dataStrings[1])) {
mPrivacyLogBuffer.add( mPrivacyLogBuffer.add(
new LogEntry (System.currentTimeMillis(), tag, dataStrings)); new LogEntry (System.currentTimeMillis(), tag, dataStrings));
} else { } else {
if (DBG) { if (sDBG) {
Log.d(TAG, "Skipped to add an entry because data is unsafe."); Log.d(TAG, "Skipped to add an entry because data is unsafe.");
} }
} }
@ -213,18 +216,24 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
case ID_AUTOSUGGESTIONCANCELED: case ID_AUTOSUGGESTIONCANCELED:
--mWordCount; --mWordCount;
dataStrings = (String[]) data; dataStrings = (String[]) data;
if (dataStrings.length != 3) {
if (sDBG) {
Log.e(TAG, "The length of string array is invalid.");
}
break;
}
mActualCharCount -= dataStrings[1].length(); mActualCharCount -= dataStrings[1].length();
if (checkStringsDataSafe(dataStrings)) { if (checkStringDataSafe(dataStrings[0]) && checkStringDataSafe(dataStrings[1])) {
mPrivacyLogBuffer.add( mPrivacyLogBuffer.add(
new LogEntry (System.currentTimeMillis(), tag, dataStrings)); new LogEntry (System.currentTimeMillis(), tag, dataStrings));
} else { } else {
if (DBG) { if (sDBG) {
Log.d(TAG, "Skipped to add an entry because data is unsafe."); Log.d(TAG, "Skipped to add an entry because data is unsafe.");
} }
} }
break; break;
default: default:
if (DBG) { if (sDBG) {
Log.e(TAG, "Log Tag is not entried."); Log.e(TAG, "Log Tag is not entried.");
} }
break; break;
@ -237,19 +246,29 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
addCountEntry(now); addCountEntry(now);
addThemeIdEntry(now); addThemeIdEntry(now);
String s = LogSerializer.createStringFromEntries(mLogBuffer); String s = LogSerializer.createStringFromEntries(mLogBuffer);
if (DBG) { if (!TextUtils.isEmpty(s)) {
Log.d(TAG, "Commit log: " + s); if (sDBG) {
Log.d(TAG, "Commit log: " + s);
}
mDropBox.addText(TAG, s);
} }
mDropBox.addText(TAG, s);
reset(); reset();
mLastTimeSend = now; mLastTimeSend = now;
} }
private synchronized void sendLogToDropBox(int tag, Object s) { private synchronized void sendLogToDropBox(int tag, Object s) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (DBG) { if (sDBG) {
Log.d(TAG, "SendLog: " + tag + ";" + s + "," String out = "";
+ (now - mLastTimeSend - MINIMUMSENDINTERVAL) ); if (s instanceof String[]) {
for (String str: ((String[]) s)) {
out += str + ",";
}
} else if (s instanceof Integer) {
out += (Integer) s;
}
Log.d(TAG, "SendLog: " + tag + ";" + out + ", will be sent after "
+ (- (now - mLastTimeSend - MINIMUMSENDINTERVAL) / 1000) + " sec.");
} }
if (now - mLastTimeActive > MINIMUMSENDINTERVAL) { if (now - mLastTimeActive > MINIMUMSENDINTERVAL) {
// Send a log before adding an log entry if the last data is too old. // Send a log before adding an log entry if the last data is too old.
@ -275,6 +294,8 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
} else if (KeyboardSwitcher.PREF_KEYBOARD_LAYOUT.equals(key)) { } else if (KeyboardSwitcher.PREF_KEYBOARD_LAYOUT.equals(key)) {
mThemeId = sharedPreferences.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT, mThemeId = sharedPreferences.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT,
KeyboardSwitcher.DEFAULT_LAYOUT_ID); KeyboardSwitcher.DEFAULT_LAYOUT_ID);
} else if (PREF_DEBUG_MODE.equals(key)) {
sDBG = sharedPreferences.getBoolean(PREF_DEBUG_MODE, sDBG);
} }
} }