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

Commit 629698ec authored by Guillaume Jacquart's avatar Guillaume Jacquart Committed by Guillaume Jacquart
Browse files

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

parent 6193e019
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -142,7 +142,9 @@ public class OrbotService extends VpnService implements OrbotConstants {
    }

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

@@ -154,7 +156,7 @@ public class OrbotService extends VpnService implements OrbotConstants {

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

        if (mOrbotRawEventListener != null)
            mOrbotRawEventListener.getNodes().clear();
@@ -162,6 +164,8 @@ public class OrbotService extends VpnService implements OrbotConstants {

    @RequiresApi(api = Build.VERSION_CODES.O)
    private void createNotificationChannel() {
        if (!Prefs.isNotificationEnabled()) return;

        var mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        var mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, getString(R.string.app_name), NotificationManager.IMPORTANCE_LOW);
        mChannel.setDescription(getString(R.string.app_description));
@@ -174,6 +178,8 @@ public class OrbotService extends VpnService implements OrbotConstants {

    @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);

@@ -684,7 +690,9 @@ public class OrbotService extends VpnService implements OrbotConstants {
                return;
            }

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

            startTorService();
@@ -937,7 +945,9 @@ public class OrbotService extends VpnService implements OrbotConstants {
            if (notificationMessage.contains(LOG_NOTICE_BOOTSTRAPPED)) {
                var percent = notificationMessage.substring(LOG_NOTICE_BOOTSTRAPPED.length());
                percent = percent.substring(0, percent.indexOf('%')).trim();
                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
@@ -30,6 +30,8 @@ public class Prefs {
    private final static String PREF_HOST_ONION_SERVICES = "pref_host_onionservices";

    private final static String PREF_SNOWFLAKES_SERVED_COUNT = "pref_snowflakes_served";
    private final static String PREF_ENABLE_NOTIFICATION = "pref_enable_notification";


    private static SharedPreferences prefs;
    private static Context sContext;
@@ -144,6 +146,14 @@ public class Prefs {
        return prefs.getString(PREF_EXIT_NODES, "");
    }

    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);
    }