Commit 4c33b0fe authored by Joey Rizzoli's avatar Joey Rizzoli Committed by Nicholas Lim

Jelly: allow disabling clear text traffic at runtime

Change-Id: I6ea63aeb8f6264aec7fe5aea5fa90f167c886677
Signed-off-by: Joey Rizzoli's avatarJoey <joey@lineageos.org>
parent f3b8154b
......@@ -23,11 +23,13 @@
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application
android:name=".JellyApp"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:appCategory="productivity"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
......
/*
* Copyright (C) 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lineageos.jelly;
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.lineageos.jelly.utils.NetworkSecurityPolicyUtils;
public class JellyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
setClearTextTrafficConfig();
}
private void setClearTextTrafficConfig() {
if (!NetworkSecurityPolicyUtils.isSupported()) {
return;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean isPermitted = prefs.getBoolean("key_clear_text_traffic", true);
NetworkSecurityPolicyUtils.setCleartextTrafficPermitted(isPermitted);
}
}
......@@ -19,6 +19,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import android.support.v4.content.LocalBroadcastManager;
......@@ -33,6 +34,7 @@ import android.widget.LinearLayout;
import android.widget.Toast;
import org.lineageos.jelly.utils.IntentUtils;
import org.lineageos.jelly.utils.NetworkSecurityPolicyUtils;
import org.lineageos.jelly.utils.PrefsUtils;
import org.lineageos.jelly.utils.UiUtils;
......@@ -57,6 +59,9 @@ public class SettingsActivity extends AppCompatActivity {
super.onCreate(savedInstance);
addPreferencesFromResource(R.xml.settings);
PreferenceCategory securityCategory = (PreferenceCategory)
findPreference("category_security");
Preference homePage = findPreference("key_home_page");
homePage.setSummary(PrefsUtils.getHomePage(getContext()));
homePage.setOnPreferenceClickListener(preference -> {
......@@ -83,6 +88,17 @@ public class SettingsActivity extends AppCompatActivity {
return true;
});
}
SwitchPreference clearTextTraffic = (SwitchPreference)
findPreference("key_clear_text_traffic");
if (NetworkSecurityPolicyUtils.isSupported()) {
clearTextTraffic.setOnPreferenceChangeListener((preference, value) -> {
NetworkSecurityPolicyUtils.setCleartextTrafficPermitted((Boolean) value);
return true;
});
} else {
securityCategory.removePreference(clearTextTraffic);
}
}
private void editHomePage(Preference preference) {
......
/*
* Copyright (C) 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lineageos.jelly.utils;
import android.security.NetworkSecurityPolicy;
public final class NetworkSecurityPolicyUtils {
private NetworkSecurityPolicyUtils() {
}
public static boolean isSupported() {
return true;
}
public static void setCleartextTrafficPermitted(boolean permitted) {
NetworkSecurityPolicy policy = NetworkSecurityPolicy.getInstance();
policy.setCleartextTrafficPermitted(permitted);
}
}
/*
* Copyright (C) 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lineageos.jelly.utils;
public final class NetworkSecurityPolicyUtils {
private NetworkSecurityPolicyUtils() {
}
@SuppressWarnings("SameReturnValue")
public static boolean isSupported() {
return false;
}
@SuppressWarnings("UnusedParameters")
public static void setCleartextTrafficPermitted(boolean permitted) {
}
}
......@@ -115,6 +115,12 @@
<string name="pref_reach_mode_title">Reach mode</string>
<!-- Settings: reach mode summary -->
<string name="pref_reach_mode_summary">Relocate interface elements for easier one-hand usage</string>
<!-- Settings: clear traffic title -->
<string name="pref_clear_text_traffic_title">Allow unsecure websites</string>
<!-- Settings: clear traffic summary on -->
<string name="pref_clear_text_traffic_summary_on">Clear text traffic (such as http) is allowed</string>
<!-- Settings: clear traffic summary off -->
<string name="pref_clear_text_traffic_summary_off">Clear text traffic (such as http) is not allowed</string>
<!-- History: title -->
<string name="history_title">History</string>
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2018 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<network-security-config>
<!-- Allow http websites (matches 24 -> 27 targetSdk apps' behavior) -->
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
\ No newline at end of file
......@@ -47,7 +47,9 @@
android:summary="@string/pref_reach_mode_summary"
android:title="@string/pref_reach_mode_title" />
<PreferenceCategory android:title="@string/pref_privacy_security">
<PreferenceCategory
android:key="category_security"
android:title="@string/pref_privacy_security">
<SwitchPreference
android:defaultValue="0"
......@@ -73,6 +75,13 @@
android:summary="@string/pref_do_not_track_summary"
android:title="@string/pref_do_not_track_title" />
<SwitchPreference
android:defaultValue="1"
android:key="key_clear_text_traffic"
android:summaryOff="@string/pref_clear_text_traffic_summary_off"
android:summaryOn="@string/pref_clear_text_traffic_summary_on"
android:title="@string/pref_clear_text_traffic_title" />
<SwitchPreference
android:defaultValue="1"
android:key="key_cookie"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment