Skip to content

Commit

Permalink
Merge pull request #5096 from brave/disable_android_permissions
Browse files Browse the repository at this point in the history
removes unneeded permiossions on Android
  • Loading branch information
SergeyZhukovsky authored Mar 30, 2020
2 parents d30ee6d + 32468dd commit dae2071
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* 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.brave.bytecode;

import org.objectweb.asm.ClassVisitor;

public class BraveAndroidSyncSettingsClassAdapter extends BraveClassVisitor {
static String sAndroidSyncSettingsClassName =
"org/chromium/components/sync/AndroidSyncSettings";
static String sBraveAndroidSyncSettingsClassName =
"org/chromium/components/sync/BraveAndroidSyncSettings";

public BraveAndroidSyncSettingsClassAdapter(ClassVisitor visitor) {
super(visitor);
deleteMethod(sBraveAndroidSyncSettingsClassName,
"notifyObservers");
makePublicMethod(sAndroidSyncSettingsClassName,
"notifyObservers");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class BraveClassAdapter {
public static ClassVisitor createAdapter(ClassVisitor chain) {
chain = new BraveBookmarkModelClassAdapter(chain);
chain = new BraveMainPreferenceBaseClassAdapter(chain);
chain = new BraveAndroidSyncSettingsClassAdapter(chain);
return chain;
}
}
1 change: 1 addition & 0 deletions build/android/bytecode/java_sources.gni
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
brave_java_bytecode_files = [
"../../../brave/build/android/bytecode/java/org/brave/bytecode/BraveClassAdapter.java",
"../../../brave/build/android/bytecode/java/org/brave/bytecode/BraveClassVisitor.java",
"../../../brave/build/android/bytecode/java/org/brave/bytecode/BraveAndroidSyncSettingsClassAdapter.java",
"../../../brave/build/android/bytecode/java/org/brave/bytecode/BraveBookmarkModelClassAdapter.java",
"../../../brave/build/android/bytecode/java/org/brave/bytecode/BraveMainPreferenceBaseClassAdapter.java",
]
1 change: 1 addition & 0 deletions build/android/config.gni
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import("//brave/android/brave_java_sources.gni")
import("//brave/build/android/bytecode/java_sources.gni")
import("//brave/components/sync/android/java_sources.gni")

declare_args() {
brave_android_manifest_includes = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* 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.components.sync;


public class BraveAndroidSyncSettings extends AndroidSyncSettings {
public BraveAndroidSyncSettings(SyncContentResolverDelegate syncContentResolverDelegate) {
super(syncContentResolverDelegate, null);
}

@Override
protected void setChromeSyncEnabled(boolean value) {
mChromeSyncEnabled = false;
notifyObservers();
}

@Override
protected boolean updateCachedSettings() {
boolean oldChromeSyncEnabled = mChromeSyncEnabled;
boolean oldMasterSyncEnabled = mMasterSyncEnabled;

mIsSyncable = false;
mChromeSyncEnabled = false;
mMasterSyncEnabled = false;

return oldChromeSyncEnabled != mChromeSyncEnabled
|| oldMasterSyncEnabled != mMasterSyncEnabled;
}

public void notifyObservers() {
assert false;
}
}
1 change: 1 addition & 0 deletions components/sync/android/java_sources.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brave_sync_java_sources = [ "//brave/components/sync/android/java/src/org/chromium/components/sync/BraveAndroidSyncSettings.java" ]
59 changes: 56 additions & 3 deletions patches/chrome-android-java-AndroidManifest.xml.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/AndroidManifest.xml
index 8cd1fb84e55c6fb971db3441fa41bd7460ed738e..85ce9a713785ff7c9fa83100735d889b848a175f 100644
index 8cd1fb84e55c6fb971db3441fa41bd7460ed738e..369cd188698f05263ce2cbe20971049a5812afcc 100644
--- a/chrome/android/java/AndroidManifest.xml
+++ b/chrome/android/java/AndroidManifest.xml
@@ -125,6 +125,7 @@ by a child template that "extends" this file.
@@ -34,7 +34,9 @@ by a child template that "extends" this file.
{% endif %}
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH"/>
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH_ADMIN"/>
+<!--
<uses-permission-sdk-23 android:name="android.permission.READ_CONTACTS"/>
+-->
<uses-permission-sdk-23 android:name="android.permission.REORDER_TASKS"/>
<uses-permission-sdk-23 android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

@@ -43,22 +45,32 @@ by a child template that "extends" this file.
{% if target_sdk_version|int > 27 or target_sdk_version == "Q" %}
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
{% endif %}
+<!--
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
+-->
<uses-permission android:name="android.permission.INTERNET"/>
+<!--
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
+-->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+<!--
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.READ_SYNC_STATS"/>
+-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
+<!--
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
+-->
<uses-permission-sdk-23 android:name="android.permission.USE_FINGERPRINT"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+<!--
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
+-->
{% set enable_vr = enable_vr|default(0) %}
{% if enable_vr == "true" %}
<!-- Indicates use of Android's VR-mode, available only on Android N+. -->
@@ -99,7 +111,9 @@ by a child template that "extends" this file.
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

+<!--
<uses-permission android:name="com.google.android.apps.now.CURRENT_ACCOUNT_ACCESS" />
+-->

{% block extra_uses_permissions %}
{% endblock %}
@@ -125,6 +139,7 @@ by a child template that "extends" this file.
<!-- Set android:largeHeap to "true" to allow more than the default
Java heap limit (32Mb on Nexus S, 48Mb on Xoom). -->
<application android:name="{% block application_name %}org.chromium.chrome.browser.ChromeApplication{% endblock %}"
+ android:requestLegacyExternalStorage="true"
android:icon="@drawable/ic_launcher"
android:roundIcon="@drawable/ic_launcher_round"
android:label="{% block application_label %}@string/app_name{% endblock %}"
@@ -1294,6 +1295,7 @@ android:value="true" />
@@ -1294,6 +1309,7 @@ android:value="true" />
</activity>
{% endif %}

Expand Down
12 changes: 12 additions & 0 deletions patches/components-sync-android-BUILD.gn.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/components/sync/android/BUILD.gn b/components/sync/android/BUILD.gn
index fba93d0a3c69ddab8fa3d00b3edd804b535921a1..a382885bf8ee66eb947ba5810726751e2caa7c89 100644
--- a/components/sync/android/BUILD.gn
+++ b/components/sync/android/BUILD.gn
@@ -32,6 +32,7 @@ android_library("sync_java") {
"java/src/org/chromium/components/sync/notifier/InvalidationPreferences.java",
"java/src/org/chromium/components/sync/notifier/RandomizedInvalidationClientNameGenerator.java",
]
+ sources += brave_sync_java_sources
}

android_library("sync_javatests") {
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/components/sync/android/java/src/org/chromium/components/sync/AndroidSyncSettings.java b/components/sync/android/java/src/org/chromium/components/sync/AndroidSyncSettings.java
index 84a8b66912a2f6847771486e62556b772c192fd2..57e756941d38433c21fb7aaa4bcd472044894cb9 100644
--- a/components/sync/android/java/src/org/chromium/components/sync/AndroidSyncSettings.java
+++ b/components/sync/android/java/src/org/chromium/components/sync/AndroidSyncSettings.java
@@ -55,11 +55,11 @@ public class AndroidSyncSettings {

private Account mAccount;

- private boolean mIsSyncable;
+ protected boolean mIsSyncable;

- private boolean mChromeSyncEnabled;
+ protected boolean mChromeSyncEnabled;

- private boolean mMasterSyncEnabled;
+ protected boolean mMasterSyncEnabled;

private final ObserverList<AndroidSyncSettingsObserver> mObservers =
new ObserverList<AndroidSyncSettingsObserver>();
@@ -77,7 +77,7 @@ public class AndroidSyncSettings {
if (sInstance == null) {
SyncContentResolverDelegate contentResolver =
new SystemSyncContentResolverDelegate();
- sInstance = new AndroidSyncSettings(contentResolver);
+ sInstance = new BraveAndroidSyncSettings(contentResolver);
}
return sInstance;
}
@@ -103,7 +103,7 @@ public class AndroidSyncSettings {
* @param callback Callback that will be called after updating account is finished. Boolean
* passed to the callback indicates whether syncability was changed.
*/
- private AndroidSyncSettings(SyncContentResolverDelegate syncContentResolverDelegate,
+ public AndroidSyncSettings(SyncContentResolverDelegate syncContentResolverDelegate,
@Nullable Callback<Boolean> callback) {
mContractAuthority = ContextUtils.getApplicationContext().getPackageName();
mSyncContentResolverDelegate = syncContentResolverDelegate;
@@ -211,7 +211,7 @@ public class AndroidSyncSettings {
}
}

- private void setChromeSyncEnabled(boolean value) {
+ protected void setChromeSyncEnabled(boolean value) {
synchronized (mLock) {
updateSyncability(null);
if (value == mChromeSyncEnabled || mAccount == null) return;
@@ -295,7 +295,7 @@ public class AndroidSyncSettings {
*
* @return Whether either chromeSyncEnabled or masterSyncEnabled changed.
*/
- private boolean updateCachedSettings() {
+ protected boolean updateCachedSettings() {
synchronized (mLock) {
boolean oldChromeSyncEnabled = mChromeSyncEnabled;
boolean oldMasterSyncEnabled = mMasterSyncEnabled;

0 comments on commit dae2071

Please sign in to comment.