diff options
author | cyberta <cyberta@riseup.net> | 2022-12-26 14:12:10 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2022-12-26 14:12:10 +0000 |
commit | 9d64ea1f6274ca66c4e44f7bd24698a1f64c3ffe (patch) | |
tree | 1bf433d5363a437d388851e7368ee143a226f6b7 /app/src/main/java/se | |
parent | 6334225050f02901119812b807c29a4a07ebe182 (diff) | |
parent | 35bd57e5399e8bec5102338c7f0900fbc18970b2 (diff) |
Merge branch 'rc_fixes' into 'master'
Rc fixes
See merge request leap/bitmask_android!235
Diffstat (limited to 'app/src/main/java/se')
6 files changed, 53 insertions, 88 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java index d5bbd2c5..d57d725e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java @@ -174,19 +174,17 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh } private void initExcludeAppsEntry(View rootView) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - IconTextEntry excludeApps = rootView.findViewById(R.id.exclude_apps); - excludeApps.setVisibility(VISIBLE); - Set<String> apps = PreferenceHelper.getExcludedApps(this.getContext()); - if (apps != null) { - updateExcludeAppsSubtitle(excludeApps, apps.size()); - } - FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); - excludeApps.setOnClickListener((buttonView) -> { - Fragment fragment = new ExcludeAppsFragment(); - fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); - }); + IconTextEntry excludeApps = rootView.findViewById(R.id.exclude_apps); + excludeApps.setVisibility(VISIBLE); + Set<String> apps = PreferenceHelper.getExcludedApps(this.getContext()); + if (apps != null) { + updateExcludeAppsSubtitle(excludeApps, apps.size()); } + FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); + excludeApps.setOnClickListener((buttonView) -> { + Fragment fragment = new ExcludeAppsFragment(); + fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); + }); } private void updateExcludeAppsSubtitle(IconTextEntry excludeApps, int number) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java index 675f1a61..e747d5b4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java @@ -209,10 +209,18 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer int endIndex = 0; if (matcher.matches()) { startIndex = matcher.start(2); - endIndex = startIndex + matcher.group(3).length(); + try { + endIndex = startIndex + matcher.group(3).length(); + } catch (NullPointerException npe) { + endIndex = -1; + } } systemSettingsMessage = systemSettingsMessage.replace("<b>", "").replace("</b>", ""); String wholeMessage = systemSettingsMessage + "\n\n" + tetheringMessage; + if (startIndex == -1 || endIndex == -1) { + Log.e(TAG, "Tethering string has wrong formatting!"); + return wholeMessage; + } Spannable spannable = new SpannableString(wholeMessage); spannable.setSpan(new ClickableSpan() { @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java index 8f4d7862..51bcb2b1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java @@ -96,12 +96,10 @@ public class ViewHelper { } int color = ContextCompat.getColor(activity, secondaryColor); bar.setBackgroundDrawable(new ColorDrawable(color)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Window window = activity.getWindow(); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(ContextCompat.getColor(activity, primaryColor)); - } + Window window = activity.getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(ContextCompat.getColor(activity, primaryColor)); int actionBarTextColor; if (textColor == 0) { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 645d7b26..79876d50 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -91,7 +91,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat } }); thread.run(); - } else if (action.equals("android.net.VpnService") && Build.VERSION.SDK_INT >= ALWAYS_ON_MIN_API_LEVEL) { + } else if (intent == null || action.equals("android.net.VpnService") && Build.VERSION.SDK_INT >= ALWAYS_ON_MIN_API_LEVEL) { //only always-on feature triggers this startWithForegroundNotification(); thread = new Thread(new Runnable() { @@ -154,15 +154,12 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat builder.addRoute("::",0); builder.addAddress("fc00::", 7); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - allowAllAFFamilies(builder); - } + allowAllAFFamilies(builder); return builder; } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void allowAllAFFamilies(Builder builder) { builder.allowFamily(OsConstants.AF_INET); builder.allowFamily(OsConstants.AF_INET6); @@ -174,9 +171,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat VpnStatus.updateStateString(STATE_ESTABLISH, "", R.string.void_vpn_establish, ConnectionStatus.LEVEL_BLOCKING); Builder builder = prepareBlockingVpnProfile(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - builder.addDisallowedApplication(getPackageName()); - } + builder.addDisallowedApplication(getPackageName()); fd = builder.establish(); } catch (Exception e) { @@ -208,7 +203,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat blockingMessage, blockingMessage, eipStatus.getLevel(), - this + null ); } else { stopForeground(true); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java index 31893fb1..b4d11f26 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnNotificationManager.java @@ -16,6 +16,18 @@ */ package se.leap.bitmaskclient.eip; +import static android.os.Build.VERSION_CODES.O; +import static android.text.TextUtils.isEmpty; +import static androidx.core.app.NotificationCompat.PRIORITY_DEFAULT; +import static androidx.core.app.NotificationCompat.PRIORITY_MAX; +import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK; +import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT; +import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; +import static se.leap.bitmaskclient.base.models.Constants.ASK_TO_CANCEL_VPN; +import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_START; +import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_STOP_BLOCKING_VPN; +import static se.leap.bitmaskclient.base.utils.ConfigHelper.getPendingIntentFlags; + import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationChannel; @@ -31,7 +43,6 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.text.style.StyleSpan; -import android.widget.RemoteViews; import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; @@ -45,18 +56,6 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.StartActivity; -import static android.os.Build.VERSION_CODES.O; -import static android.text.TextUtils.isEmpty; -import static androidx.core.app.NotificationCompat.PRIORITY_DEFAULT; -import static androidx.core.app.NotificationCompat.PRIORITY_MAX; -import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK; -import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.ASK_TO_CANCEL_VPN; -import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_START; -import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_STOP_BLOCKING_VPN; -import static se.leap.bitmaskclient.base.utils.ConfigHelper.getPendingIntentFlags; - /** * Created by cyberta on 14.01.18. */ @@ -129,7 +128,7 @@ public class VpnNotificationManager { public void buildOpenVpnNotification(String profileName, boolean isObfuscated, String msg, String tickerText, ConnectionStatus status, long when, - String notificationChannelNewstatusId, VpnServiceCallback vpnServiceCallback) { + String channelId, VpnServiceCallback vpnServiceCallback) { String cancelString; CharSequence bigmessage = null; String bridgeIcon = new String(Character.toChars(0x1f309)); @@ -141,7 +140,7 @@ public class VpnNotificationManager { case LEVEL_CONNECTING_SERVER_REPLIED: case LEVEL_CONNECTING_NO_SERVER_REPLY_YET: cancelString = context.getString(R.string.cancel); - if (isObfuscated && Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { + if (isObfuscated) { Spannable spannable = new SpannableString(context.getString(R.string.obfuscated_connection_try)); spannable.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannable.length() -1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); bigmessage = TextUtils.concat(spannable, " " + bridgeIcon + "\n" + msg); @@ -150,7 +149,7 @@ public class VpnNotificationManager { // show disconnect if connection exists case LEVEL_CONNECTED: - if (isObfuscated && Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { + if (isObfuscated) { Spannable spannable = new SpannableString(context.getString(R.string.obfuscated_connection)); spannable.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannable.length() -1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); bigmessage = TextUtils.concat(spannable, " " + bridgeIcon + "\n" + msg); @@ -184,7 +183,7 @@ public class VpnNotificationManager { bigmessage, tickerText, status, - notificationChannelNewstatusId, + channelId, PRIORITY_DEFAULT, when, contentIntent, @@ -245,40 +244,16 @@ public class VpnNotificationManager { } } - /** - * @return a custom remote view for notifications for API 16 - 19 - */ - private RemoteViews getKitkatCustomRemoteView(ConnectionStatus status, String title, String message) { - int iconResource = getIconByConnectionStatus(status); - RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.v_custom_notification); - remoteViews.setImageViewResource(R.id.image_icon, iconResource); - remoteViews.setTextViewText(R.id.message, message); - remoteViews.setTextViewText(R.id.title, title); - - return remoteViews; - } - private void buildVpnNotification(String title, String message, CharSequence bigMessage, String tickerText, - ConnectionStatus status, String notificationChannelNewstatusId, int priority, + ConnectionStatus status, String channelId, int priority, long when, PendingIntent contentIntent, NotificationCompat.Action notificationAction, VpnServiceCallback vpnServiceCallback) { - NotificationCompat.Builder nCompatBuilder = new NotificationCompat.Builder(context, notificationChannelNewstatusId); + NotificationCompat.Builder nCompatBuilder = new NotificationCompat.Builder(context, channelId); int icon = getIconByConnectionStatus(status); - // this is a workaround to avoid confusion between the Android's system vpn notification - // showing a filled out key icon and the bitmask icon indicating a different state. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT && - notificationChannelNewstatusId.equals(OpenVPNService.NOTIFICATION_CHANNEL_NEWSTATUS_ID)) { - if (status != LEVEL_NONETWORK) { - // removes the icon from the system status bar - icon = android.R.color.transparent; - // adds the icon to the notification in the notification drawer - nCompatBuilder.setContent(getKitkatCustomRemoteView(status, title, message)); - } - } else { - nCompatBuilder.setStyle(new NotificationCompat.BigTextStyle(). - setBigContentTitle(title). - bigText(bigMessage)); - } + nCompatBuilder.setStyle(new NotificationCompat.BigTextStyle(). + setBigContentTitle(title). + bigText(bigMessage)); + nCompatBuilder.addAction(notificationAction); nCompatBuilder.setContentTitle(title); nCompatBuilder.setCategory(NotificationCompat.CATEGORY_SERVICE); @@ -296,11 +271,13 @@ public class VpnNotificationManager { } Notification notification = nCompatBuilder.build(); - int notificationId = notificationChannelNewstatusId.hashCode(); + int notificationId = channelId.hashCode(); - compatNotificationManager.notify(notificationId, notification); if (vpnServiceCallback != null) { vpnServiceCallback.onNotificationBuild(notificationId, notification); + } else { + compatNotificationManager.notify(notificationId, notification); + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java index aaf20647..5cfefb2e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java @@ -161,7 +161,6 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity imple if (provider != null) { setProviderHeaderText(provider.getName()); } - setProgressbarColorForPreLollipop(); setDefaultGuidelineValues(); setGlobalLayoutChangeListener(); } @@ -173,16 +172,6 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity imple } } - private void setProgressbarColorForPreLollipop() { - if (progressBar == null || Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return; - } - progressBar.getIndeterminateDrawable().setColorFilter( - ContextCompat.getColor(this, R.color.colorPrimary), - PorterDuff.Mode.SRC_IN); - } - - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); |