Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 877d857c authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

/e/ add Pref to enable/disable service notification.

(cherry picked from commit 629698ec)
parent 590a205f
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -114,17 +114,21 @@ public class OrbotService extends VpnService {
    }

    private void showConnectedToTorNetworkNotification() {
        if (mNotifyBuilder != null) {
            mNotifyBuilder.setProgress(0, 0, false);
        }
        showToolbarNotification(getString(R.string.status_activated), NOTIFY_ID, R.drawable.ic_stat_tor);
    }

    private void clearNotifications() {
        if (mNotificationManager != null) mNotificationManager.cancelAll();
        if (mNotificationManager != null) mNotificationManager.cancel(NOTIFY_ID);
        if (mOrbotRawEventListener != null) mOrbotRawEventListener.getNodes().clear();
    }

    @SuppressLint({"NewApi", "RestrictedApi"})
    protected void showToolbarNotification(String notifyMsg, int notifyType, int icon) {
        if (!Prefs.isNotificationEnabled()) return;

        var intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        var pendIntent = PendingIntent.getActivity(OrbotService.this, 0, intent, PendingIntent.FLAG_IMMUTABLE);

@@ -382,7 +386,7 @@ public class OrbotService extends VpnService {
                mActionBroadcastReceiver = new ActionBroadcastReceiver();
                ContextCompat.registerReceiver(this, mActionBroadcastReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Prefs.isNotificationEnabled())
                    Notifications.createNotificationChannel(this);

                var hasGeoip = new File(appBinHome, GEOIP_ASSET_KEY).exists();
@@ -562,7 +566,10 @@ public class OrbotService extends VpnService {
                showConnectedToTorNetworkNotification();
                return;
            }

            if (mNotifyBuilder != null) {
                mNotifyBuilder.setProgress(100, 0, false);
            }
            showToolbarNotification("", NOTIFY_ID, R.drawable.ic_stat_tor);

            if (Prefs.getTorConnectionPathway().equals(Prefs.CONNECTION_PATHWAY_SMART))
@@ -822,7 +829,9 @@ public class OrbotService extends VpnService {
                percent = percent.substring(0, percent.indexOf('%')).trim();
                localIntent.putExtra(LOCAL_EXTRA_BOOTSTRAP_PERCENT, percent);
                var prog = Integer.parseInt(percent);
                mNotifyBuilder.setProgress(100, prog, false);
                if (mNotifyBuilder != null) {
                    mNotifyBuilder.setProgress(100, Integer.parseInt(percent), false);
                }
                notificationMessage = notificationMessage.substring(notificationMessage.indexOf(':') + 1).trim();
            }
        }
+10 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ public class Prefs {
    });

    public static final String PREF_SECURE_WINDOW_FLAG = "pref_flag_secure";
    private final static String PREF_ENABLE_NOTIFICATION = "pref_enable_notification";


    private static SharedPreferences prefs;

@@ -234,6 +236,14 @@ public class Prefs {
        putString(PREF_EXIT_NODES, country);
    }

    public static void enableNotification(boolean value) {
        putBoolean(PREF_ENABLE_NOTIFICATION, value);
    }

    public static boolean isNotificationEnabled() {
        return prefs.getBoolean(PREF_ENABLE_NOTIFICATION, true);
    }

    public static SharedPreferences getSharedPrefs(Context context) {
        //   return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS, Context.MODE_MULTI_PROCESS);
        return PreferenceManager.getDefaultSharedPreferences(context);