Merge "Allow punctuation through privacy filter"
This commit is contained in:
commit
e6a39d5677
1 changed files with 46 additions and 31 deletions
|
@ -379,29 +379,43 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
mCurrentLogUnit.addLogAtom(keys, values, false);
|
mCurrentLogUnit.addLogAtom(keys, values, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInDictionary(CharSequence word) {
|
/* package for test */ boolean isPrivacyThreat(String word) {
|
||||||
return (mDictionary != null) && (mDictionary.isValidWord(word));
|
// currently: word not in dictionary or contains numbers.
|
||||||
|
if (TextUtils.isEmpty(word)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
final int length = word.length();
|
||||||
/**
|
boolean hasLetter = false;
|
||||||
* Write out enqueued LogEvents to the log, filtered for privacy.
|
for (int i = 0; i < length; i = word.offsetByCodePoints(i, 1)) {
|
||||||
*
|
final int codePoint = Character.codePointAt(word, i);
|
||||||
* If word is in the dictionary, then it is not privacy-sensitive and all LogEvents related to
|
if (Character.isDigit(codePoint)) {
|
||||||
* it can be written to the log. If the word is not in the dictionary, then it may correspond
|
return true;
|
||||||
* to a proper name, which might reveal private information, so neither the word nor any
|
}
|
||||||
* information related to the word (e.g. the down/motion/up coordinates) should be revealed.
|
if (Character.isLetter(codePoint)) {
|
||||||
* These LogEvents have been marked as privacy-sensitive; non privacy-sensitive events are still
|
hasLetter = true;
|
||||||
* written out.
|
break; // Word may contain digits, but will only be allowed if in the dictionary.
|
||||||
*
|
}
|
||||||
* @param word the word to be checked for inclusion in the dictionary
|
}
|
||||||
*/
|
if (hasLetter) {
|
||||||
/* package for test */ synchronized void flushQueue(CharSequence word) {
|
|
||||||
if (isAllowedToLog()) {
|
|
||||||
// check for dictionary
|
|
||||||
if (mDictionary == null && mSuggest != null && mSuggest.hasMainDictionary()) {
|
if (mDictionary == null && mSuggest != null && mSuggest.hasMainDictionary()) {
|
||||||
mDictionary = mSuggest.getMainDictionary();
|
mDictionary = mSuggest.getMainDictionary();
|
||||||
}
|
}
|
||||||
mCurrentLogUnit.setIsPrivacySafe(word != null && isInDictionary(word));
|
if (mDictionary == null) {
|
||||||
|
// Can't access dictionary. Assume privacy threat.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !(mDictionary.isValidWord(word));
|
||||||
|
}
|
||||||
|
// No letters, no numbers. Punctuation, space, or something else.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write out enqueued LogEvents to the log, possibly dropping privacy sensitive events.
|
||||||
|
*/
|
||||||
|
/* package for test */ synchronized void flushQueue(boolean removePotentiallyPrivateEvents) {
|
||||||
|
if (isAllowedToLog()) {
|
||||||
|
mCurrentLogUnit.setRemovePotentiallyPrivateEvents(removePotentiallyPrivateEvents);
|
||||||
mLoggingHandler.post(mCurrentLogUnit);
|
mLoggingHandler.post(mCurrentLogUnit);
|
||||||
mCurrentLogUnit = new LogUnit();
|
mCurrentLogUnit = new LogUnit();
|
||||||
}
|
}
|
||||||
|
@ -513,7 +527,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
private final List<String[]> mKeysList = new ArrayList<String[]>();
|
private final List<String[]> mKeysList = new ArrayList<String[]>();
|
||||||
private final List<Object[]> mValuesList = new ArrayList<Object[]>();
|
private final List<Object[]> mValuesList = new ArrayList<Object[]>();
|
||||||
private final List<Boolean> mIsPotentiallyPrivate = new ArrayList<Boolean>();
|
private final List<Boolean> mIsPotentiallyPrivate = new ArrayList<Boolean>();
|
||||||
private boolean mIsPrivacySafe = false;
|
private boolean mRemovePotentiallyPrivateEvents = true;
|
||||||
|
|
||||||
private void addLogAtom(final String[] keys, final Object[] values,
|
private void addLogAtom(final String[] keys, final Object[] values,
|
||||||
final Boolean isPotentiallyPrivate) {
|
final Boolean isPotentiallyPrivate) {
|
||||||
|
@ -522,15 +536,15 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
mIsPotentiallyPrivate.add(isPotentiallyPrivate);
|
mIsPotentiallyPrivate.add(isPotentiallyPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsPrivacySafe(boolean isPrivacySafe) {
|
void setRemovePotentiallyPrivateEvents(boolean removePotentiallyPrivateEvents) {
|
||||||
mIsPrivacySafe = isPrivacySafe;
|
mRemovePotentiallyPrivateEvents = removePotentiallyPrivateEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final int numAtoms = mKeysList.size();
|
final int numAtoms = mKeysList.size();
|
||||||
for (int atomIndex = 0; atomIndex < numAtoms; atomIndex++) {
|
for (int atomIndex = 0; atomIndex < numAtoms; atomIndex++) {
|
||||||
if (!mIsPrivacySafe && mIsPotentiallyPrivate.get(atomIndex)) {
|
if (mRemovePotentiallyPrivateEvents && mIsPotentiallyPrivate.get(atomIndex)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String[] keys = mKeysList.get(atomIndex);
|
final String[] keys = mKeysList.get(atomIndex);
|
||||||
|
@ -548,7 +562,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
StringBuilder sb = null;
|
StringBuilder sb = null;
|
||||||
final int length = s.length();
|
final int length = s.length();
|
||||||
for (int i = 0; i < length; i = s.offsetByCodePoints(i, 1)) {
|
for (int i = 0; i < length; i = s.offsetByCodePoints(i, 1)) {
|
||||||
int codePoint = Character.codePointAt(s, i);
|
final int codePoint = Character.codePointAt(s, i);
|
||||||
if (Character.isDigit(codePoint)) {
|
if (Character.isDigit(codePoint)) {
|
||||||
if (sb == null) {
|
if (sb == null) {
|
||||||
sb = new StringBuilder(length);
|
sb = new StringBuilder(length);
|
||||||
|
@ -638,19 +652,20 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
researchLogger.enqueuePotentiallyPrivateEvent(
|
researchLogger.enqueuePotentiallyPrivateEvent(
|
||||||
EVENTKEYS_LATINIME_COMMITCURRENTAUTOCORRECTION, values);
|
EVENTKEYS_LATINIME_COMMITCURRENTAUTOCORRECTION, values);
|
||||||
researchLogger.flushQueue(autoCorrection);
|
researchLogger.flushQueue(researchLogger.isPrivacyThreat(autoCorrection));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] EVENTKEYS_LATINIME_COMMITTEXT = {
|
private static final String[] EVENTKEYS_LATINIME_COMMITTEXT = {
|
||||||
"LatinIMECommitText", "typedWord"
|
"LatinIMECommitText", "typedWord"
|
||||||
};
|
};
|
||||||
public static void latinIME_commitText(final CharSequence typedWord) {
|
public static void latinIME_commitText(final CharSequence typedWord) {
|
||||||
|
final String scrubbedWord = scrubDigitsFromString(typedWord.toString());
|
||||||
final Object[] values = {
|
final Object[] values = {
|
||||||
scrubDigitsFromString(typedWord.toString())
|
scrubbedWord
|
||||||
};
|
};
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_LATINIME_COMMITTEXT, values);
|
researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_LATINIME_COMMITTEXT, values);
|
||||||
researchLogger.flushQueue(typedWord);
|
researchLogger.flushQueue(researchLogger.isPrivacyThreat(scrubbedWord));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] EVENTKEYS_LATINIME_DELETESURROUNDINGTEXT = {
|
private static final String[] EVENTKEYS_LATINIME_DELETESURROUNDINGTEXT = {
|
||||||
|
@ -728,7 +743,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
}
|
}
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
researchLogger.enqueueEvent(EVENTKEYS_LATINIME_ONWINDOWHIDDEN, values);
|
researchLogger.enqueueEvent(EVENTKEYS_LATINIME_ONWINDOWHIDDEN, values);
|
||||||
researchLogger.flushQueue(null);
|
researchLogger.flushQueue(true); // Play it safe. Remove privacy-sensitive events.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,7 +824,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
researchLogger.enqueuePotentiallyPrivateEvent(
|
researchLogger.enqueuePotentiallyPrivateEvent(
|
||||||
EVENTKEYS_LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION, values);
|
EVENTKEYS_LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION, values);
|
||||||
researchLogger.flushQueue(cs.toString());
|
researchLogger.flushQueue(researchLogger.isPrivacyThreat(cs.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] EVENTKEYS_LATINIME_PICKSUGGESTIONMANUALLY = {
|
private static final String[] EVENTKEYS_LATINIME_PICKSUGGESTIONMANUALLY = {
|
||||||
|
@ -824,7 +839,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
|
||||||
final ResearchLogger researchLogger = getInstance();
|
final ResearchLogger researchLogger = getInstance();
|
||||||
researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_LATINIME_PICKSUGGESTIONMANUALLY,
|
researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_LATINIME_PICKSUGGESTIONMANUALLY,
|
||||||
values);
|
values);
|
||||||
researchLogger.flushQueue(suggestion.toString());
|
researchLogger.flushQueue(researchLogger.isPrivacyThreat(suggestion.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] EVENTKEYS_LATINIME_PUNCTUATIONSUGGESTION = {
|
private static final String[] EVENTKEYS_LATINIME_PUNCTUATIONSUGGESTION = {
|
||||||
|
|
Loading…
Reference in a new issue