-
Notifications
You must be signed in to change notification settings - Fork 879
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 #3537 from brave/exclude_unused_settings_from_main…
…_settings Remove unused settings from main settings screen
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
android/java/org/chromium/chrome/browser/preferences/BraveMainPreferencesBase.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,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); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
android/java/org/chromium/chrome/browser/signin/BraveSigninManager.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,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); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
chromium_src/chrome/browser/android/signin/signin_manager_android.cc
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,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 | ||
|
13 changes: 13 additions & 0 deletions
13
...hrome-android-java-src-org-chromium-chrome-browser-preferences-MainPreferences.java.patch
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,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"; |