Commit 0ba820cc authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Update enabled state and settings for Unity, toolbar button

 * Updates EnabledStateMonitor to use a new unified consent helper method
   that determines whether URL-keyed anonymized data collection is enabled
 * Updates the EoC settings screen to open the new sync and
   personalization screen when unified consent is enabled.
 * Updates EoC settings screen text when toolbar button is enabled.

BUG=829457,859564

Change-Id: I727043abeaed33d68b179e9bef8d40b1f074a0a5
Reviewed-on: https://chromium-review.googlesource.com/1124970
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573430}
parent f69edefd
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
app:drawDivider="true" /> app:drawDivider="true" />
<org.chromium.chrome.browser.preferences.TextMessagePreference <org.chromium.chrome.browser.preferences.TextMessagePreference
android:title="@string/contextual_suggestions_description" /> android:key="contextual_suggestions_description" />
<org.chromium.chrome.browser.preferences.TextMessagePreference <org.chromium.chrome.browser.preferences.TextMessagePreference
android:key="contextual_suggestions_message" /> android:key="contextual_suggestions_message" />
......
...@@ -18,8 +18,6 @@ import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; ...@@ -18,8 +18,6 @@ import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener; import org.chromium.chrome.browser.sync.ProfileSyncService.SyncStateChangedListener;
import org.chromium.chrome.browser.util.AccessibilityUtil; import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.UploadState;
/** /**
* A monitor that is responsible for detecting changes to conditions required for contextual * A monitor that is responsible for detecting changes to conditions required for contextual
...@@ -94,13 +92,11 @@ public class EnabledStateMonitor implements SyncStateChangedListener, SignInStat ...@@ -94,13 +92,11 @@ public class EnabledStateMonitor implements SyncStateChangedListener, SignInStat
public static boolean getSettingsEnabled() { public static boolean getSettingsEnabled() {
if (sSettingsEnabledForTesting) return true; if (sSettingsEnabledForTesting) return true;
ProfileSyncService service = ProfileSyncService.get();
boolean isUploadToGoogleActive =
service.getUploadToGoogleState(ModelType.HISTORY_DELETE_DIRECTIVES)
== UploadState.ACTIVE;
boolean isAccessibilityEnabled = AccessibilityUtil.isAccessibilityEnabled(); boolean isAccessibilityEnabled = AccessibilityUtil.isAccessibilityEnabled();
return isUploadToGoogleActive && isDSEConditionMet() && !isAccessibilityEnabled // TODO(twellington): Update to also accept personalized activity collection
// ("Activity and interactions").
return ProfileSyncService.get().isUrlKeyedAnonymizedDataCollectionEnabled()
&& isDSEConditionMet() && !isAccessibilityEnabled
&& !ContextualSuggestionsBridge.isDisabledByEnterprisePolicy(); && !ContextualSuggestionsBridge.isDisabledByEnterprisePolicy();
} }
......
...@@ -10,16 +10,21 @@ import android.os.Bundle; ...@@ -10,16 +10,21 @@ import android.os.Bundle;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ImageSpan;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsBridge; import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsBridge;
import org.chromium.chrome.browser.contextual_suggestions.EnabledStateMonitor; import org.chromium.chrome.browser.contextual_suggestions.EnabledStateMonitor;
import org.chromium.chrome.browser.signin.AccountSigninActivity; import org.chromium.chrome.browser.signin.AccountSigninActivity;
import org.chromium.chrome.browser.signin.SigninAccessPoint; import org.chromium.chrome.browser.signin.SigninAccessPoint;
import org.chromium.chrome.browser.signin.SigninActivity;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.chrome.browser.util.IntentUtils; import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.widget.TintedDrawable;
import org.chromium.components.signin.ChromeSigninController; import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.text.NoUnderlineClickableSpan; import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.text.SpanApplier; import org.chromium.ui.text.SpanApplier;
...@@ -30,6 +35,8 @@ import org.chromium.ui.text.SpanApplier; ...@@ -30,6 +35,8 @@ import org.chromium.ui.text.SpanApplier;
public class ContextualSuggestionsPreference public class ContextualSuggestionsPreference
extends PreferenceFragment implements EnabledStateMonitor.Observer { extends PreferenceFragment implements EnabledStateMonitor.Observer {
static final String PREF_CONTEXTUAL_SUGGESTIONS_SWITCH = "contextual_suggestions_switch"; static final String PREF_CONTEXTUAL_SUGGESTIONS_SWITCH = "contextual_suggestions_switch";
private static final String PREF_CONTEXTUAL_SUGGESTIONS_DESCRIPTION =
"contextual_suggestions_description";
private static final String PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE = private static final String PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE =
"contextual_suggestions_message"; "contextual_suggestions_message";
...@@ -73,23 +80,61 @@ public class ContextualSuggestionsPreference ...@@ -73,23 +80,61 @@ public class ContextualSuggestionsPreference
/** Helper method to initialize the switch preference and the message preference. */ /** Helper method to initialize the switch preference and the message preference. */
private void initialize() { private void initialize() {
Context context = getActivity();
final TextMessagePreference message = final TextMessagePreference message =
(TextMessagePreference) findPreference(PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE); (TextMessagePreference) findPreference(PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE);
final NoUnderlineClickableSpan span = new NoUnderlineClickableSpan((widget) -> {
Context context = getActivity(); // Show a message prompting the user to turn on required settings. If unified consent is
if (ChromeSigninController.get().isSignedIn()) { // enabled, and the proper settings are already enabled, show nothing.
Intent intent = PreferencesLauncher.createIntentForSettingsPage( boolean isUnifiedConsentEnabled =
context, SyncCustomizationFragment.class.getName()); ChromeFeatureList.isEnabled(ChromeFeatureList.UNIFIED_CONSENT);
IntentUtils.safeStartActivity(context, intent); if (!isUnifiedConsentEnabled
} else { || !ProfileSyncService.get().isUrlKeyedAnonymizedDataCollectionEnabled()) {
startActivity(AccountSigninActivity.createIntentForDefaultSigninFlow( final NoUnderlineClickableSpan span = new NoUnderlineClickableSpan((widget) -> {
context, SigninAccessPoint.SETTINGS, false)); if (isUnifiedConsentEnabled) {
} if (ChromeSigninController.get().isSignedIn()) {
}); Intent intent = PreferencesLauncher.createIntentForSettingsPage(
final SpannableString spannable = SpanApplier.applySpans( context, SyncAndServicesPreferences.class.getName());
getResources().getString(R.string.contextual_suggestions_message), IntentUtils.safeStartActivity(context, intent);
new SpanApplier.SpanInfo("<link>", "</link>", span)); } else {
message.setTitle(spannable); startActivity(SigninActivity.createIntentForPromoChooseAccountFlow(
context, SigninAccessPoint.SETTINGS, null));
}
} else {
if (ChromeSigninController.get().isSignedIn()) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
context, SyncCustomizationFragment.class.getName());
IntentUtils.safeStartActivity(context, intent);
} else {
startActivity(AccountSigninActivity.createIntentForDefaultSigninFlow(
context, SigninAccessPoint.SETTINGS, false));
}
}
});
final SpannableString spannable = SpanApplier.applySpans(
getResources().getString(isUnifiedConsentEnabled
? R.string.contextual_suggestions_message_unified_consent
: R.string.contextual_suggestions_message),
new SpanApplier.SpanInfo("<link>", "</link>", span));
message.setTitle(spannable);
}
final TextMessagePreference description =
(TextMessagePreference) findPreference(PREF_CONTEXTUAL_SUGGESTIONS_DESCRIPTION);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_BUTTON)) {
TintedDrawable drawable = TintedDrawable.constructTintedDrawable(
context, R.drawable.btn_star_filled, R.color.default_icon_color);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
final ImageSpan imageSpan = new ImageSpan(drawable);
final SpannableString imageSpannable = SpanApplier.applySpans(
getResources().getString(
R.string.contextual_suggestions_description_toolbar_button),
new SpanApplier.SpanInfo("<icon>", "</icon>", imageSpan));
description.setTitle(imageSpannable);
} else {
description.setTitle(
getResources().getString(R.string.contextual_suggestions_description));
}
updateSwitch(); updateSwitch();
mSwitch.setOnPreferenceChangeListener((preference, newValue) -> { mSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
......
...@@ -12,7 +12,6 @@ import org.chromium.base.VisibleForTesting; ...@@ -12,7 +12,6 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.sync.ModelType; import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.PassphraseType; import org.chromium.components.sync.PassphraseType;
import org.chromium.components.sync.UploadState;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -404,12 +403,10 @@ public class ProfileSyncService { ...@@ -404,12 +403,10 @@ public class ProfileSyncService {
} }
/** /**
* @return Whether {@code modelType} is being uploaded to Google. This is useful for features * @return Whether URL-keyed anonymized data collection is enabled for the current profile.
* that depend on user consent for uploading data (e.g. history) to Google.
*/ */
@UploadState public boolean isUrlKeyedAnonymizedDataCollectionEnabled() {
public int getUploadToGoogleState(@ModelType int modelType) { return nativeIsUrlKeyedAnonymizedDataCollectionEnabled(mNativeProfileSyncServiceAndroid);
return nativeGetUploadToGoogleState(mNativeProfileSyncServiceAndroid, modelType);
} }
/** /**
...@@ -578,8 +575,8 @@ public class ProfileSyncService { ...@@ -578,8 +575,8 @@ public class ProfileSyncService {
private native boolean nativeIsSyncActive(long nativeProfileSyncServiceAndroid); private native boolean nativeIsSyncActive(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncServiceAndroid); private native boolean nativeHasKeepEverythingSynced(long nativeProfileSyncServiceAndroid);
private native boolean nativeHasUnrecoverableError(long nativeProfileSyncServiceAndroid); private native boolean nativeHasUnrecoverableError(long nativeProfileSyncServiceAndroid);
private native int nativeGetUploadToGoogleState( private native boolean nativeIsUrlKeyedAnonymizedDataCollectionEnabled(
long nativeProfileSyncServiceAndroid, int modelType); long nativeProfileSyncServiceAndroid);
private native boolean nativeIsPassphrasePrompted(long nativeProfileSyncServiceAndroid); private native boolean nativeIsPassphrasePrompted(long nativeProfileSyncServiceAndroid);
private native void nativeSetPassphrasePrompted(long nativeProfileSyncServiceAndroid, private native void nativeSetPassphrasePrompted(long nativeProfileSyncServiceAndroid,
boolean prompted); boolean prompted);
......
...@@ -585,10 +585,16 @@ CHAR-LIMIT guidelines: ...@@ -585,10 +585,16 @@ CHAR-LIMIT guidelines:
Suggest related pages Suggest related pages
</message> </message>
<message name="IDS_CONTEXTUAL_SUGGESTIONS_DESCRIPTION" desc="Description of contextual suggestions, which tells the user what contextual suggestions does."> <message name="IDS_CONTEXTUAL_SUGGESTIONS_DESCRIPTION" desc="Description of contextual suggestions, which tells the user what contextual suggestions does.">
When you scroll up, show quick links to related pages. When you scroll up, show quick links to related pages. The URLs of pages you visit are sent to Google.
</message>
<message name="IDS_CONTEXTUAL_SUGGESTIONS_DESCRIPTION_TOOLBAR_BUTTON" desc="Description of contextual suggestions, which tells the user that when they tap the ‘More like this’ button they will be shown links to pages related to their current page. An icon will be inserted into the string after ‘More like this’. Please ensure ‘More like this’ in this message matches the ‘More like this’ toolbar button.">
When you tap More like this <ph name="ICON">&lt;icon&gt; &lt;/icon&gt;</ph> in the address bar, show quick links to related pages. The URLs of pages you visit are sent to Google.
</message> </message>
<message name="IDS_CONTEXTUAL_SUGGESTIONS_MESSAGE" desc="Message of contextual suggestions settings, which tells the user how to opt in contextual suggestions."> <message name="IDS_CONTEXTUAL_SUGGESTIONS_MESSAGE" desc="Message of contextual suggestions settings, which tells the user how to opt in contextual suggestions.">
This feature uses <ph name="BEGIN_LINK">&lt;link&gt;</ph>sync<ph name="END_LINK">&lt;/link&gt;</ph>. The URLs of pages you visit are sent to Google. This feature uses <ph name="BEGIN_LINK">&lt;link&gt;</ph>sync<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
<message name="IDS_CONTEXTUAL_SUGGESTIONS_MESSAGE_UNIFIED_CONSENT" desc="Message of contextual suggestions settings, which tells the user how to opt in contextual suggestions. Please ensure ‘Activity and interactions’ in this message matches the ‘Activity and interactions’ in sync settings.">
To use this feature, turn on <ph name="BEGIN_LINK">&lt;link&gt;</ph>Activity and interactions<ph name="END_LINK">&lt;/link&gt;</ph>.
</message> </message>
<!-- Homepage preferences --> <!-- Homepage preferences -->
......
...@@ -25,8 +25,6 @@ import org.chromium.chrome.test.ChromeActivityTestRule; ...@@ -25,8 +25,6 @@ import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.ChromeModernDesign; import org.chromium.chrome.test.util.browser.ChromeModernDesign;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures; import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.sync.ModelType;
import org.chromium.components.sync.UploadState;
import org.chromium.policy.test.annotations.Policies; import org.chromium.policy.test.annotations.Policies;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
...@@ -52,9 +50,8 @@ public class EnabledStateMonitorTest implements EnabledStateMonitor.Observer { ...@@ -52,9 +50,8 @@ public class EnabledStateMonitorTest implements EnabledStateMonitor.Observer {
} }
@Override @Override
@UploadState public boolean isUrlKeyedAnonymizedDataCollectionEnabled() {
public int getUploadToGoogleState(@ModelType int modelType) { return true;
return UploadState.ACTIVE;
} }
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/unified_consent_helper.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include "components/sync/driver/sync_service_utils.h" #include "components/sync/driver/sync_service_utils.h"
#include "components/sync/engine/net/network_resources.h" #include "components/sync/engine/net/network_resources.h"
#include "components/sync/syncable/read_transaction.h" #include "components/sync/syncable/read_transaction.h"
#include "components/unified_consent/url_keyed_data_collection_consent_helper.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "google/cacheinvalidation/types.pb.h" #include "google/cacheinvalidation/types.pb.h"
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
...@@ -48,6 +50,7 @@ using base::android::JavaParamRef; ...@@ -48,6 +50,7 @@ using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef; using base::android::ScopedJavaLocalRef;
using browser_sync::ProfileSyncService; using browser_sync::ProfileSyncService;
using content::BrowserThread; using content::BrowserThread;
using unified_consent::UrlKeyedDataCollectionConsentHelper;
namespace { namespace {
...@@ -358,13 +361,17 @@ jboolean ProfileSyncServiceAndroid::HasUnrecoverableError( ...@@ -358,13 +361,17 @@ jboolean ProfileSyncServiceAndroid::HasUnrecoverableError(
return sync_service_->HasUnrecoverableError(); return sync_service_->HasUnrecoverableError();
} }
jint ProfileSyncServiceAndroid::GetUploadToGoogleState( jboolean ProfileSyncServiceAndroid::IsUrlKeyedAnonymizedDataCollectionEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>&, const base::android::JavaParamRef<jobject>& obj) {
jint model_type) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
return static_cast<int>(syncer::GetUploadToGoogleState( bool is_unified_consent_enabled = IsUnifiedConsentEnabled(profile_);
sync_service_, static_cast<syncer::ModelType>(model_type))); PrefService* pref_service = profile_->GetPrefs();
std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
unified_consent_url_helper = UrlKeyedDataCollectionConsentHelper::
NewAnonymizedDataCollectionConsentHelper(is_unified_consent_enabled,
pref_service, sync_service_);
return unified_consent_url_helper->IsEnabled();
} }
jint ProfileSyncServiceAndroid::GetProtocolErrorClientAction( jint ProfileSyncServiceAndroid::GetProtocolErrorClientAction(
......
...@@ -122,9 +122,9 @@ class ProfileSyncServiceAndroid : public syncer::SyncServiceObserver { ...@@ -122,9 +122,9 @@ class ProfileSyncServiceAndroid : public syncer::SyncServiceObserver {
jboolean HasUnrecoverableError( jboolean HasUnrecoverableError(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
jint GetUploadToGoogleState(JNIEnv* env, jboolean IsUrlKeyedAnonymizedDataCollectionEnabled(
const base::android::JavaParamRef<jobject>& obj, JNIEnv* env,
jint model_type); const base::android::JavaParamRef<jobject>& obj);
// Gets SyncProtocolError.ClientAction. // Gets SyncProtocolError.ClientAction.
jint GetProtocolErrorClientAction( jint GetProtocolErrorClientAction(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment