am 4cb85319: [Rlog15] ResearchLogger option to include account name in feedback

* commit '4cb853191ca4e515c2291779aa6b21975d5711d6':
  [Rlog15] ResearchLogger option to include account name in feedback
This commit is contained in:
Kurt Partridge 2013-01-21 12:23:22 -08:00 committed by Android Git Automerger
commit 86139412df
5 changed files with 66 additions and 7 deletions

View file

@ -70,6 +70,14 @@
android:text="@string/research_feedback_include_history_label"
/>
<CheckBox
android:id="@+id/research_feedback_include_account_name"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginBottom="8dip"
android:checked="false"
android:text="@string/research_feedback_include_account_name_label"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -21,4 +21,6 @@
<!-- Contents of note explaining what data is collected and how. -->
<!-- TODO: remove translatable=false attribute once text is stable -->
<string name="research_splash_content" translatable="false"></string>
<string name="research_account_type" translatable="false"></string>
<string name="research_allowed_account_domain" translatable="false"></string>
</resources>

View file

@ -270,6 +270,9 @@
<!-- Text for checkbox option to include user data in feedback for research purposes [CHAR LIMIT=50] -->
<!-- TODO: remove translatable=false attribute once text is stable -->
<string name="research_feedback_include_history_label" translatable="false">Include session history</string>
<!-- Text for checkbox option to include user account name in feedback for research purposes [CHAR LIMIT=50] -->
<!-- TODO: remove translatable=false attribute once text is stable -->
<string name="research_feedback_include_account_name_label" translatable="false">Include account name</string>
<!-- Hint to user about the text entry field where they should enter research feedback [CHAR LIMIT=40] -->
<!-- TODO: remove translatable=false attribute once text is stable -->
<string name="research_feedback_hint" translatable="false">Enter your feedback here.</string>

View file

@ -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();

View file

@ -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() {