Loading src/main/java/org/torproject/android/service/OrbotService.java +14 −4 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading @@ -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)); Loading @@ -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); Loading Loading @@ -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(); Loading Loading @@ -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(); } } Loading src/main/java/org/torproject/android/service/util/Prefs.java +10 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading
src/main/java/org/torproject/android/service/OrbotService.java +14 −4 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading @@ -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)); Loading @@ -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); Loading Loading @@ -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(); Loading Loading @@ -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(); } } Loading
src/main/java/org/torproject/android/service/util/Prefs.java +10 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading