diff --git a/java/res/layout/research_feedback_fragment_layout.xml b/java/res/layout/research_feedback_fragment_layout.xml
index cc04cedf4..2a90ba2a0 100644
--- a/java/res/layout/research_feedback_fragment_layout.xml
+++ b/java/res/layout/research_feedback_fragment_layout.xml
@@ -70,6 +70,14 @@
android:text="@string/research_feedback_include_history_label"
/>
+
+
+
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 54ff23b1a..fdae3020a 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -270,6 +270,9 @@
Include session history
+
+
+ Include account name
Enter your feedback here.
diff --git a/java/src/com/android/inputmethod/research/FeedbackFragment.java b/java/src/com/android/inputmethod/research/FeedbackFragment.java
index a9adbb73d..fee61a923 100644
--- a/java/src/com/android/inputmethod/research/FeedbackFragment.java
+++ b/java/src/com/android/inputmethod/research/FeedbackFragment.java
@@ -32,7 +32,8 @@ import com.android.inputmethod.latin.R;
public class FeedbackFragment extends Fragment {
private EditText mEditText;
- private CheckBox mCheckBox;
+ private CheckBox mIncludingHistoryCheckBox;
+ private CheckBox mIncludingAccountNameCheckBox;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -40,7 +41,10 @@ public class FeedbackFragment extends Fragment {
final View view = inflater.inflate(R.layout.research_feedback_fragment_layout, container,
false);
mEditText = (EditText) view.findViewById(R.id.research_feedback_contents);
- mCheckBox = (CheckBox) view.findViewById(R.id.research_feedback_include_history);
+ mIncludingHistoryCheckBox = (CheckBox) view.findViewById(
+ R.id.research_feedback_include_history);
+ mIncludingAccountNameCheckBox = (CheckBox) view.findViewById(
+ R.id.research_feedback_include_account_name);
final Button sendButton = (Button) view.findViewById(
R.id.research_feedback_send_button);
@@ -49,8 +53,10 @@ public class FeedbackFragment extends Fragment {
public void onClick(View v) {
final Editable editable = mEditText.getText();
final String feedbackContents = editable.toString();
- final boolean includeHistory = mCheckBox.isChecked();
- ResearchLogger.getInstance().sendFeedback(feedbackContents, includeHistory);
+ final boolean isIncludingHistory = mIncludingHistoryCheckBox.isChecked();
+ final boolean isIncludingAccountName = mIncludingAccountNameCheckBox.isChecked();
+ ResearchLogger.getInstance().sendFeedback(feedbackContents, isIncludingHistory,
+ isIncludingAccountName);
final Activity activity = FeedbackFragment.this.getActivity();
activity.finish();
ResearchLogger.getInstance().onLeavingSendFeedbackDialog();
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index 0a24af6d5..2da571d5a 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -18,6 +18,8 @@ package com.android.inputmethod.research;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -30,6 +32,7 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -115,6 +118,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final String PREF_RESEARCH_LOGGER_UUID_STRING = "pref_research_logger_uuid";
private static final ResearchLogger sInstance = new ResearchLogger();
+ private static String sAccountType = null;
+ private static String sAllowedAccountDomain = null;
// to write to a different filename, e.g., for testing, set mFile before calling start()
/* package */ File mFilesDir;
/* package */ String mUUIDString;
@@ -199,6 +204,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
e.apply();
}
}
+ final Resources res = latinIME.getResources();
+ sAccountType = res.getString(R.string.research_account_type);
+ sAllowedAccountDomain = res.getString(R.string.research_allowed_account_domain);
mLatinIME = latinIME;
mPrefs = prefs;
mUploadIntent = new Intent(mLatinIME, UploaderService.class);
@@ -593,6 +601,36 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
*/
+ /**
+ * Get the name of the first allowed account on the device.
+ *
+ * Allowed accounts must be in the domain given by ALLOWED_ACCOUNT_DOMAIN.
+ *
+ * @return The user's account name.
+ */
+ public String getAccountName() {
+ if (sAccountType == null || sAccountType.isEmpty()) {
+ return null;
+ }
+ if (sAllowedAccountDomain == null || sAllowedAccountDomain.isEmpty()) {
+ return null;
+ }
+ final AccountManager manager = AccountManager.get(mLatinIME);
+ // Filter first by account type.
+ final Account[] accounts = manager.getAccountsByType(sAccountType);
+
+ for (final Account account : accounts) {
+ if (DEBUG) {
+ Log.d(TAG, account.name);
+ }
+ final String[] parts = account.name.split("@");
+ if (parts.length > 1 && parts[1].equals(sAllowedAccountDomain)) {
+ return parts[0];
+ }
+ }
+ return null;
+ }
+
static class LogStatement {
final String mName;
@@ -626,8 +664,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
private static final LogStatement LOGSTATEMENT_FEEDBACK =
- new LogStatement("UserFeedback", false, false, "contents");
- public void sendFeedback(final String feedbackContents, final boolean includeHistory) {
+ new LogStatement("UserFeedback", false, false, "contents", "accountName");
+ public void sendFeedback(final String feedbackContents, final boolean includeHistory,
+ final boolean isIncludingAccountName) {
if (mSavedFeedbackLogBuffer == null) {
return;
}
@@ -635,8 +674,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mSavedFeedbackLogBuffer.clear();
}
final LogUnit feedbackLogUnit = new LogUnit();
+ final String accountName = isIncludingAccountName ? getAccountName() : "";
feedbackLogUnit.addLogStatement(LOGSTATEMENT_FEEDBACK, SystemClock.uptimeMillis(),
- feedbackContents);
+ feedbackContents, accountName);
mFeedbackLogBuffer.shiftIn(feedbackLogUnit);
publishLogBuffer(mFeedbackLogBuffer, mSavedFeedbackLog, true /* isIncludingPrivateData */);
mSavedFeedbackLog.close(new Runnable() {