Skip to content

Commit

Permalink
Merge pull request #3537 from brave/exclude_unused_settings_from_main…
Browse files Browse the repository at this point in the history
…_settings

Remove unused settings from main settings screen
  • Loading branch information
simonhong authored Oct 1, 2019
2 parents 94003fb + 20b5205 commit 6a7619d
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/document/BraveLauncherActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java",
"../../brave/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/BraveMainPreferencesBase.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/BravePreferenceManager.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/BravePrefServiceBridge.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/privacy/BravePrivacyPreferences.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettingsObserver.java",
"../../brave/android/java/org/chromium/chrome/browser/signin/BraveSigninManager.java",
"../../brave/android/java/org/chromium/chrome/browser/toolbar/bottom/BookmarksButton.java",
"../../brave/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright (c) 2019 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.preferences;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;

import java.util.HashMap;

// This exculdes some settings in main settings screen.
public class BraveMainPreferencesBase extends PreferenceFragmentCompat {
// Below prefs are removed from main settings.
private static final String PREF_ACCOUNT_SECTION = "account_section";
private static final String PREF_SIGN_IN = "sign_in";
private static final String PREF_DATA_REDUCTION = "data_reduction";
private static final String PREF_AUTOFILL_ASSISTANT = "autofill_assistant";
private static final String PREF_SYNC_AND_SERVICES = "sync_and_services";
private static final String PREF_DEVELOPER = "developer";

private final HashMap<String, Preference> mRemovedPreferences = new HashMap<>();

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {}

@Override
public void onResume() {
super.onResume();
// Run updateBravePreferences() after fininshing MainPreferences::updatePreferences().
// Otherwise, some prefs could be added after finishing updateBravePreferences().
new Handler().post(() -> updateBravePreferences());
}

private void updateBravePreferences() {
removePreferenceIfPresent(PREF_SIGN_IN);
removePreferenceIfPresent(PREF_ACCOUNT_SECTION);
removePreferenceIfPresent(PREF_DATA_REDUCTION);
removePreferenceIfPresent(PREF_AUTOFILL_ASSISTANT);
removePreferenceIfPresent(PREF_SYNC_AND_SERVICES);
removePreferenceIfPresent(PREF_DEVELOPER);
}

/**
* We need to override it to avoid NullPointerException in Chromium's child classes
*/
@Override
public Preference findPreference(CharSequence key) {
Preference result = super.findPreference(key);
if (result == null) {
result = mRemovedPreferences.get(key);
}
return result;
}

private void removePreferenceIfPresent(String key) {
Preference preference = getPreferenceScreen().findPreference(key);
if (preference != null) {
getPreferenceScreen().removePreference(preference);
mRemovedPreferences.put(preference.getKey(), preference);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2019 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.signin;

import android.content.Context;

import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.signin.AccountTrackerService;

public class BraveSigninManager extends SigninManager {
BraveSigninManager(Context context, long nativeSigninManagerAndroid, SigninManagerDelegate delegate,
AccountTrackerService accountTrackerService) {
super(context, nativeSigninManagerAndroid, delegate, accountTrackerService);
}

@Override
public boolean isSignInAllowed() {
return false;
}

@Override
public boolean isSigninSupported() {
return false;
}

@CalledByNative
private static SigninManager create(long nativeSigninManagerAndroid,
SigninManagerDelegate delegate, AccountTrackerService accountTrackerService) {
assert nativeSigninManagerAndroid != 0;
assert delegate != null;
assert accountTrackerService != null;
return new BraveSigninManager(ContextUtils.getApplicationContext(), nativeSigninManagerAndroid,
delegate, accountTrackerService);
}
}
1 change: 1 addition & 0 deletions build/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ generate_jni("jni_headers") {
"//brave/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java",
"//brave/android/java/org/chromium/chrome/browser/preferences/BravePrefServiceBridge.java",
"//brave/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java",
"//brave/android/java/org/chromium/chrome/browser/signin/BraveSigninManager.java",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2019 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/. */

#include "brave/build/android/jni_headers/BraveSigninManager_jni.h"
#include "chrome/browser/android/signin/signin_manager_android.h"
#include "chrome/android/chrome_jni_headers/SigninManager_jni.h"

namespace {
// For preventing "unused Java_SigninManager_create method" compile error.
class UnusedClass {
private:
void test() {
Java_SigninManager_create(nullptr, 0ll, nullptr, nullptr);
}
};
} // namespace

#define Java_SigninManager_create Java_BraveSigninManager_create
#include "../../../../../../chrome/browser/android/signin/signin_manager_android.cc" // NOLINT
#undef Java_SigninManager_create

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
index 56f952c159ffb94c0b51a47d6949e8bc3f99871c..ea90e440c35ae95c6579d27d22feeefd421a376f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
@@ -41,7 +41,7 @@ import java.util.Map;
/**
* The main settings screen, shown when the user first opens Settings.
*/
-public class MainPreferences extends PreferenceFragmentCompat
+public class MainPreferences extends BraveMainPreferencesBase
implements TemplateUrlService.LoadListener, ProfileSyncService.SyncStateChangedListener,
SigninManager.SignInStateObserver {
public static final String PREF_ACCOUNT_SECTION = "account_section";

0 comments on commit 6a7619d

Please sign in to comment.