Skip to content

Commit

Permalink
Android informer for deleted sync account
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Jul 15, 2022
1 parent 6ae60de commit 989ea5c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 3 deletions.
1 change: 1 addition & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/homepage/settings/BraveHomepageSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/infobar/BraveInfoBarIdentifier.java",
"../../brave/android/java/org/chromium/chrome/browser/informers/BraveAndroidSyncDisabledInformer.java",
"../../brave/android/java/org/chromium/chrome/browser/informers/BraveSyncAccountDeletedInformer.java",
"../../brave/android/java/org/chromium/chrome/browser/language/settings/BraveLanguageSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/BraveStatsTable.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/DatabaseHelper.java",
Expand Down
10 changes: 10 additions & 0 deletions android/java/org/chromium/chrome/browser/BraveSyncWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ public void permanentlyDeleteAccount(Callback<String> callback) {
BraveSyncWorkerJni.get().permanentlyDeleteAccount(mNativeBraveSyncWorker, callback);
}

public void clearAccountDeletedNoticePending() {
BraveSyncWorkerJni.get().clearAccountDeletedNoticePending(mNativeBraveSyncWorker);
}

public boolean isAccountDeletedNoticePending() {
return BraveSyncWorkerJni.get().isAccountDeletedNoticePending(mNativeBraveSyncWorker);
}

@NativeMethods
interface Natives {
void init(BraveSyncWorker caller);
Expand Down Expand Up @@ -242,5 +250,7 @@ interface Natives {
boolean getSyncV2MigrateNoticeDismissed(long nativeBraveSyncWorker);
void setSyncV2MigrateNoticeDismissed(long nativeBraveSyncWorker, boolean isDismissed);
void permanentlyDeleteAccount(long nativeBraveSyncWorker, Callback<String> callback);
void clearAccountDeletedNoticePending(long nativeBraveSyncWorker);
boolean isAccountDeletedNoticePending(long nativeBraveSyncWorker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.fullscreen.BrowserControlsManager;
import org.chromium.chrome.browser.informers.BraveAndroidSyncDisabledInformer;
import org.chromium.chrome.browser.informers.BraveSyncAccountDeletedInformer;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil;
import org.chromium.chrome.browser.ntp_background_images.util.NewTabPageListener;
import org.chromium.chrome.browser.onboarding.BraveTalkOptInPopupListener;
Expand Down Expand Up @@ -810,6 +811,7 @@ public void finishNativeInitialization() {
}
BraveSyncInformers.show();
BraveAndroidSyncDisabledInformer.showInformers();
BraveSyncAccountDeletedInformer.show();

if (!OnboardingPrefManager.getInstance().isOneTimeNotificationStarted()
&& PackageUtils.isFirstInstall(this)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Copyright (c) 2022 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 android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;

import org.chromium.base.ContextUtils;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveSyncWorker;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.infobar.BraveInfoBarIdentifier;
import org.chromium.chrome.browser.settings.BraveSyncScreensPreference;
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;
import org.chromium.components.browser_ui.settings.SettingsLauncher;

public class BraveSyncAccountDeletedInformer {
@CalledByNative
public static void show() {
BraveActivity activity = BraveActivity.getBraveActivity();
if (activity == null) return;

Tab tab = activity.getActivityTabProvider().get();
if (tab == null) return;

if (!BraveSyncWorker.get().isAccountDeletedNoticePending()) {
return;
}

BraveSimpleConfirmInfoBarBuilder.createInfobarWithDrawable(tab.getWebContents(),
new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {
// Pressing cross
// In any way don't show the informer again
disableInformer();
}

@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
assert isPrimary : "We don't have secondary button";
// Pressing `Begin Setup`
// Don't show the informer again
disableInformer();
SettingsLauncher settingsLauncher = new SettingsLauncherImpl();
settingsLauncher.launchSettingsActivity(
ContextUtils.getApplicationContext(),
BraveSyncScreensPreference.class);
return false;
}

@Override
public boolean onInfoBarLinkClicked() {
assert false : "We don't have link here";
return false;
}
},
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR, activity,
R.drawable.ic_warning_circle,
activity.getString(R.string.brave_sync_account_deleted_infobar_message),
activity.getString(R.string.brave_sync_account_deleted_infobar_command), "", "",
false);
}

private static void disableInformer() {
BraveSyncWorker.get().clearAccountDeletedNoticePending();
}
}
14 changes: 14 additions & 0 deletions browser/android/brave_sync_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ void BraveSyncWorker::PermanentlyDeleteAccount(
&NativePermanentlyDeleteAccountCallback, env, java_callback));
}

void BraveSyncWorker::ClearAccountDeletedNoticePending(JNIEnv* env) {
Profile* profile =
ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
brave_sync::Prefs brave_sync_prefs(profile->GetPrefs());
brave_sync_prefs.SetSyncAccountDeletedNoticePending(false);
}

bool BraveSyncWorker::IsAccountDeletedNoticePending(JNIEnv* env) {
Profile* profile =
ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
brave_sync::Prefs brave_sync_prefs(profile->GetPrefs());
return brave_sync_prefs.IsSyncAccountDeletedNoticePending();
}

static void JNI_BraveSyncWorker_Init(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
Expand Down
3 changes: 3 additions & 0 deletions browser/android/brave_sync_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BraveSyncWorker : public syncer::SyncServiceObserver {
JNIEnv* env,
const base::android::JavaParamRef<jobject>& callback);

void ClearAccountDeletedNoticePending(JNIEnv* env);
bool IsAccountDeletedNoticePending(JNIEnv* env);

private:
syncer::BraveSyncServiceImpl* GetSyncService() const;
void MarkFirstSetupComplete();
Expand Down
3 changes: 2 additions & 1 deletion browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#if !BUILDFLAG(IS_ANDROID)
BookmarkPrefsServiceFactory::GetInstance();
SearchEngineProviderServiceFactory::GetInstance();
BraveSyncAlertsServiceFactory::GetInstance();
#else
ntp_background_images::NTPBackgroundImagesBridgeFactory::GetInstance();
#endif
Expand Down Expand Up @@ -117,6 +116,8 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#if BUILDFLAG(ENABLE_PLAYLIST)
playlist::PlaylistServiceFactory::GetInstance();
#endif

BraveSyncAlertsServiceFactory::GetInstance();
}

} // namespace brave
8 changes: 6 additions & 2 deletions browser/sync/brave_sync_alerts_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include "chrome/browser/ui/browser_finder.h"
#include "components/infobars/content/content_infobar_manager.h"

#if !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_android.h"
#include "brave/build/android/jni_headers/BraveSyncAccountDeletedInformer_jni.h"
#else
#include "chrome/browser/ui/browser.h"
#endif

Expand Down Expand Up @@ -57,7 +60,8 @@ void BraveSyncAlertsService::OnSyncShutdown(syncer::SyncService* sync_service) {
#if BUILDFLAG(IS_ANDROID)

void BraveSyncAlertsService::ShowAndroidInfobar() {
DCHECK(false);
JNIEnv* env = base::android::AttachCurrentThread();
Java_BraveSyncAccountDeletedInformer_show(env);
}

#else
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ until they verify, or until 90 days have passed.
<message name="IDS_BRAVE_ANDROID_SYNC_DISABLED_DONT_SHOW" desc="The text on button on informer which is fired when Android system sync settings switch is toggled off, to disable informer">
Don't show again
</message>
<message name="IDS_BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR_MESSAGE" desc="Message text shown to users who's Sync account was deleted">
This Brave Sync account was deleted. You can setup a new chain instead
</message>
<message name="IDS_BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR_COMMAND" desc="Command text shown to users who's Sync account was disabled if they want to setup a new chain.">
Begin Setup
</message>
<message name="IDS_SYNC_FINAL_WARNING_TITLE" desc="Sync final warning alert dialog title">
Warning
</message>
Expand Down
1 change: 1 addition & 0 deletions build/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ generate_jni("jni_headers") {
"//brave/android/java/org/chromium/chrome/browser/crypto_wallet/TxServiceFactory.java",
"//brave/android/java/org/chromium/chrome/browser/crypto_wallet/permission/BraveEthereumPermissionPromptDialog.java",
"//brave/android/java/org/chromium/chrome/browser/crypto_wallet/util/WalletNativeUtils.java",
"//brave/android/java/org/chromium/chrome/browser/informers/BraveSyncAccountDeletedInformer.java",
"//brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java",
"//brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationSettingsBridge.java",
"//brave/android/java/org/chromium/chrome/browser/ntp_background_images/NTPBackgroundImagesBridge.java",
Expand Down

0 comments on commit 989ea5c

Please sign in to comment.