-
Notifications
You must be signed in to change notification settings - Fork 887
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 #8577 from brave/android_webrtc_policy_1.24.x
Android webrtc policy 1.24.x
- Loading branch information
Showing
12 changed files
with
309 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
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
89 changes: 89 additions & 0 deletions
89
android/java/org/chromium/chrome/browser/settings/BraveWebrtcPolicyPreference.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,89 @@ | ||
/* Copyright (c) 2021 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.settings; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.RadioGroup; | ||
|
||
import androidx.annotation.IntDef; | ||
import androidx.preference.Preference; | ||
import androidx.preference.PreferenceViewHolder; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.components.browser_ui.widget.RadioButtonWithDescription; | ||
import org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
public class BraveWebrtcPolicyPreference | ||
extends Preference implements RadioGroup.OnCheckedChangeListener { | ||
@IntDef({WebrtcPolicy.DEFAULT, WebrtcPolicy.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES, | ||
WebrtcPolicy.DEFAULT_PUBLIC_INTERFACE_ONLY, WebrtcPolicy.DISABLE_NON_PROXIED_UDP}) | ||
public @interface WebrtcPolicy { | ||
int DEFAULT = 0; | ||
int DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES = 1; | ||
int DEFAULT_PUBLIC_INTERFACE_ONLY = 2; | ||
int DISABLE_NON_PROXIED_UDP = 3; | ||
|
||
int NUM_ENTRIES = 4; | ||
} | ||
|
||
private @WebrtcPolicy int mSetting; | ||
private RadioButtonWithDescription mSettingRadioButton; | ||
private RadioButtonWithDescriptionLayout mGroup; | ||
private ArrayList<RadioButtonWithDescription> mButtons; | ||
|
||
public BraveWebrtcPolicyPreference(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
|
||
setLayoutResource(R.layout.brave_webrtc_policy_preference); | ||
|
||
mButtons = new ArrayList<>(Collections.nCopies(WebrtcPolicy.NUM_ENTRIES, null)); | ||
} | ||
|
||
public void initialize(@WebrtcPolicy int policy) { | ||
mSetting = policy; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(PreferenceViewHolder holder) { | ||
super.onBindViewHolder(holder); | ||
|
||
mGroup = (RadioButtonWithDescriptionLayout) holder.findViewById(R.id.radio_button_layout); | ||
mGroup.setOnCheckedChangeListener(this); | ||
|
||
mButtons.set(WebrtcPolicy.DEFAULT, | ||
(RadioButtonWithDescription) holder.findViewById(R.id.webrtc_policy_default)); | ||
mButtons.set(WebrtcPolicy.DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES, | ||
(RadioButtonWithDescription) holder.findViewById( | ||
R.id.webrtc_policy_default_public_and_private_interfaces)); | ||
mButtons.set(WebrtcPolicy.DEFAULT_PUBLIC_INTERFACE_ONLY, | ||
(RadioButtonWithDescription) holder.findViewById( | ||
R.id.webrtc_policy_default_public_interface_only)); | ||
mButtons.set(WebrtcPolicy.DISABLE_NON_PROXIED_UDP, | ||
(RadioButtonWithDescription) holder.findViewById( | ||
R.id.webrtc_policy_disable_non_proxied_udp)); | ||
|
||
mSettingRadioButton = mButtons.get(mSetting); | ||
mSettingRadioButton.setChecked(true); | ||
} | ||
|
||
@Override | ||
public void onCheckedChanged(RadioGroup group, int checkedId) { | ||
for (int i = 0; i < WebrtcPolicy.NUM_ENTRIES; i++) { | ||
if (mButtons.get(i).isChecked()) { | ||
mSetting = i; | ||
mSettingRadioButton = mButtons.get(i); | ||
break; | ||
} | ||
} | ||
assert mSetting >= 0 && mSetting < WebrtcPolicy.NUM_ENTRIES : "No matching setting found."; | ||
|
||
callChangeListener(mSetting); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
android/java/org/chromium/chrome/browser/settings/BraveWebrtcPolicyPreferencesFragment.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,50 @@ | ||
/* Copyright (c) 2021 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.settings; | ||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge; | ||
import org.chromium.components.browser_ui.settings.SettingsUtils; | ||
import org.chromium.ui.UiUtils; | ||
|
||
/** | ||
* Fragment to manage webrtc policy settings. | ||
*/ | ||
public class BraveWebrtcPolicyPreferencesFragment extends BravePreferenceFragment { | ||
static final String PREF_WEBRTC_POLICY = "webrtc_policy"; | ||
|
||
@Override | ||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) { | ||
SettingsUtils.addPreferencesFromResource(this, R.xml.brave_webrtc_policy_preferences); | ||
getActivity().setTitle(R.string.settings_webrtc_policy_label); | ||
|
||
BraveWebrtcPolicyPreference webrtcPolicyPreference = | ||
(BraveWebrtcPolicyPreference) findPreference(PREF_WEBRTC_POLICY); | ||
webrtcPolicyPreference.initialize(BravePrefServiceBridge.getInstance().getWebrtcPolicy()); | ||
|
||
webrtcPolicyPreference.setOnPreferenceChangeListener((preference, newValue) -> { | ||
BravePrefServiceBridge.getInstance().setWebrtcPolicy((int) newValue); | ||
return true; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
|
||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) { | ||
UiUtils.setNavigationBarIconColor(getActivity().getWindow().getDecorView(), | ||
getResources().getBoolean(R.bool.window_light_navigation_bar)); | ||
} | ||
|
||
setDivider(null); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
android/java/res/layout/brave_webrtc_policy_preference.xml
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,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2021 The Brave Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. --> | ||
|
||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:focusable="false"> | ||
|
||
<org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout | ||
android:id="@+id/radio_button_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription | ||
android:id="@+id/webrtc_policy_default" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:primaryText="@string/settings_webrtc_policy_default" /> | ||
|
||
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription | ||
android:id="@+id/webrtc_policy_default_public_and_private_interfaces" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="@dimen/min_touch_target_size" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="8dp" | ||
app:primaryText="@string/settings_webrtc_policy_default_public_and_private_interfaces" /> | ||
|
||
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription | ||
android:id="@+id/webrtc_policy_default_public_interface_only" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="@dimen/min_touch_target_size" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="8dp" | ||
app:primaryText="@string/settings_webrtc_policy_default_public_interface_only" /> | ||
|
||
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription | ||
android:id="@+id/webrtc_policy_disable_non_proxied_udp" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="@dimen/min_touch_target_size" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="8dp" | ||
app:primaryText="@string/settings_webrtc_policy_disable_non_proxied_udp" /> | ||
|
||
</org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout> | ||
|
||
</LinearLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2021 The Brave Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. --> | ||
|
||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<org.chromium.chrome.browser.settings.BraveWebrtcPolicyPreference | ||
android:key="webrtc_policy" /> | ||
</PreferenceScreen> |
Oops, something went wrong.