-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7016 from brave/android_p3a
Android P3A
- Loading branch information
Showing
16 changed files
with
282 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
android/java/org/chromium/chrome/browser/informers/BraveP3AInformers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.informers; | ||
|
||
import org.chromium.base.ApplicationStatus; | ||
import org.chromium.base.ContextUtils; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.BraveConfig; | ||
import org.chromium.chrome.browser.app.BraveActivity; | ||
import org.chromium.chrome.browser.infobar.InfoBarIdentifier; | ||
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge; | ||
import org.chromium.chrome.browser.settings.BraveSyncScreensPreference; | ||
import org.chromium.chrome.browser.settings.SettingsLauncher; | ||
import org.chromium.chrome.browser.settings.SettingsLauncherImpl; | ||
import org.chromium.chrome.browser.tab.Tab; | ||
import org.chromium.chrome.browser.ui.messages.infobar.BraveSimpleConfirmInfoBarBuilder; | ||
import org.chromium.chrome.browser.ui.messages.infobar.SimpleConfirmInfoBarBuilder; | ||
import org.chromium.chrome.browser.util.TabUtils; | ||
|
||
public class BraveP3AInformers { | ||
public static final String P3A_LEARN_MORE_URL = "https://brave.com/P3A"; | ||
public static void show() { | ||
showIfRequired(); | ||
} | ||
|
||
private static void showIfRequired() { | ||
if (!BraveConfig.P3A_ENABLED) { | ||
return; | ||
} | ||
|
||
if (BravePrefServiceBridge.getInstance().getP3ANoticeAcknowledged()) { | ||
return; | ||
} | ||
|
||
showP3AInformer(); | ||
} | ||
|
||
private static void showP3AInformer() { | ||
BraveActivity activity = BraveActivity.getBraveActivity(); | ||
if (activity == null) return; | ||
|
||
Tab tab = activity.getActivityTabProvider().get(); | ||
if (tab == null) return; | ||
|
||
BraveSimpleConfirmInfoBarBuilder.createInfobarWithDrawable(tab.getWebContents(), | ||
new SimpleConfirmInfoBarBuilder.Listener() { | ||
@Override | ||
public void onInfoBarDismissed() { | ||
// Pressing cross | ||
BravePrefServiceBridge.getInstance().setP3AEnabled(true); | ||
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true); | ||
} | ||
|
||
@Override | ||
public boolean onInfoBarButtonClicked(boolean isPrimary) { | ||
if (isPrimary) { | ||
// Pressing `Got it` | ||
BravePrefServiceBridge.getInstance().setP3AEnabled(true); | ||
} else { | ||
// Pressing `Disable` | ||
BravePrefServiceBridge.getInstance().setP3AEnabled(false); | ||
} | ||
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true); | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onInfoBarLinkClicked() { | ||
// Pressing learn more | ||
TabUtils.openUrlInNewTab(false /* isIncognito */, P3A_LEARN_MORE_URL); | ||
return false; | ||
} | ||
}, | ||
// must be BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE, but now it is introduced through | ||
// src/brave/chromium_src/components/infobars/core/infobar_delegate.h and | ||
// java enums are generated by //components/infobars/core:infobar_generated_enums | ||
// who does not understand `brave/chromium_src` | ||
InfoBarIdentifier.INLINE_UPDATE_READY_INFOBAR_ANDROID, activity, | ||
R.drawable.btn_info /* drawableId */, | ||
activity.getString(R.string.brave_confirm_p3a_infobar) /* message */, | ||
activity.getString(R.string.brave_confirm_p3a_infobar_acknowledge) /* primaryText */, | ||
activity.getString(R.string.brave_confirm_p3a_infobar_disable) /* secondaryText */, | ||
activity.getString(R.string.brave_confirm_p3a_infobar_learn_more) /* linkText */, | ||
false /* autoExpire */); | ||
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.