| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the Adblock Plus, | 2 * This file is part of the Adblock Plus, |
| 3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 import android.app.NotificationManager; | 33 import android.app.NotificationManager; |
| 34 import android.app.PendingIntent; | 34 import android.app.PendingIntent; |
| 35 import android.app.Service; | 35 import android.app.Service; |
| 36 import android.content.BroadcastReceiver; | 36 import android.content.BroadcastReceiver; |
| 37 import android.content.Context; | 37 import android.content.Context; |
| 38 import android.content.Intent; | 38 import android.content.Intent; |
| 39 import android.content.IntentFilter; | 39 import android.content.IntentFilter; |
| 40 import android.content.SharedPreferences; | 40 import android.content.SharedPreferences; |
| 41 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; | 41 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
| 42 import android.content.pm.PackageManager.NameNotFoundException; | 42 import android.content.pm.PackageManager.NameNotFoundException; |
| 43 import android.content.res.Resources; |
| 43 import android.net.ConnectivityManager; | 44 import android.net.ConnectivityManager; |
| 44 import android.net.NetworkInfo; | 45 import android.net.NetworkInfo; |
| 45 import android.os.Binder; | 46 import android.os.Binder; |
| 46 import android.os.Build; | 47 import android.os.Build; |
| 47 import android.os.Handler; | 48 import android.os.Handler; |
| 48 import android.os.IBinder; | 49 import android.os.IBinder; |
| 49 import android.preference.PreferenceManager; | 50 import android.preference.PreferenceManager; |
| 50 import android.util.Log; | 51 import android.util.Log; |
| 51 import android.widget.Toast; | 52 import android.widget.Toast; |
| 52 | 53 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 109 |
| 109 private String iptables = null; | 110 private String iptables = null; |
| 110 | 111 |
| 111 @Override | 112 @Override |
| 112 public void onCreate() | 113 public void onCreate() |
| 113 { | 114 { |
| 114 super.onCreate(); | 115 super.onCreate(); |
| 115 | 116 |
| 116 // Get port for local proxy | 117 // Get port for local proxy |
| 117 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
); | 118 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
); |
| 119 Resources resources = getResources(); |
| 120 |
| 118 String p = prefs.getString(getString(R.string.pref_port), null); | 121 String p = prefs.getString(getString(R.string.pref_port), null); |
| 119 try | 122 try |
| 120 { | 123 { |
| 121 port = p != null ? Integer.valueOf(p) : getResources().getInteger(R.intege
r.def_port); | 124 port = p != null ? Integer.valueOf(p) : resources.getInteger(R.integer.def
_port); |
| 122 } | 125 } |
| 123 catch (NumberFormatException e) | 126 catch (NumberFormatException e) |
| 124 { | 127 { |
| 125 Toast.makeText(this, getString(R.string.msg_badport) + ": " + p, Toast.LEN
GTH_LONG).show(); | 128 Toast.makeText(this, getString(R.string.msg_badport) + ": " + p, Toast.LEN
GTH_LONG).show(); |
| 126 port = getResources().getInteger(R.integer.def_port); | 129 port = resources.getInteger(R.integer.def_port); |
| 127 } | 130 } |
| 128 | 131 |
| 129 // Try to read user proxy settings | 132 // Try to read user proxy settings |
| 130 String proxyHost = null; | 133 String proxyHost = null; |
| 131 String proxyPort = null; | 134 String proxyPort = null; |
| 132 String proxyExcl = null; | 135 String proxyExcl = null; |
| 133 String proxyUser = null; | 136 String proxyUser = null; |
| 134 String proxyPass = null; | 137 String proxyPass = null; |
| 135 | 138 |
| 136 if (hasNativeProxy) | 139 if (hasNativeProxy) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 prefs.registerOnSharedPreferenceChangeListener(this); | 258 prefs.registerOnSharedPreferenceChangeListener(this); |
| 256 | 259 |
| 257 String msg = getString(transparent ? R.string.notif_all : nativeProxy ? R.st
ring.notif_wifi : R.string.notif_waiting); | 260 String msg = getString(transparent ? R.string.notif_all : nativeProxy ? R.st
ring.notif_wifi : R.string.notif_waiting); |
| 258 if (!transparent && !nativeProxy) | 261 if (!transparent && !nativeProxy) |
| 259 { | 262 { |
| 260 // Initiate no traffic check | 263 // Initiate no traffic check |
| 261 notrafficHandler = new Handler(); | 264 notrafficHandler = new Handler(); |
| 262 notrafficHandler.postDelayed(noTraffic, NO_TRAFFIC_TIMEOUT); | 265 notrafficHandler.postDelayed(noTraffic, NO_TRAFFIC_TIMEOUT); |
| 263 } | 266 } |
| 264 // Lock service | 267 // Lock service |
| 268 boolean hideIcon = prefs.getBoolean(getString(R.string.pref_hideicon), resou
rces.getBoolean(R.bool.def_hideicon)); |
| 265 ongoingNotification = new Notification(); | 269 ongoingNotification = new Notification(); |
| 266 ongoingNotification.when = 0; | 270 ongoingNotification.when = 0; |
| 267 contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Preferen
ces.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TA
SK), 0); | 271 contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Preferen
ces.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TA
SK), 0); |
| 268 ongoingNotification.icon = R.drawable.ic_stat_blocking; | 272 ongoingNotification.icon = hideIcon ? R.drawable.transparent : R.drawable.ic
_stat_blocking; |
| 269 ongoingNotification.setLatestEventInfo(getApplicationContext(), getText(R.st
ring.app_name), msg, contentIntent); | 273 ongoingNotification.setLatestEventInfo(getApplicationContext(), getText(R.st
ring.app_name), msg, contentIntent); |
| 270 startForeground(ONGOING_NOTIFICATION_ID, ongoingNotification); | 274 startForeground(ONGOING_NOTIFICATION_ID, ongoingNotification); |
| 271 | 275 |
| 272 sendBroadcast(new Intent(BROADCAST_STATE_CHANGED).putExtra("enabled", true).
putExtra("port", port).putExtra("manual", isManual())); | 276 sendBroadcast(new Intent(BROADCAST_STATE_CHANGED).putExtra("enabled", true).
putExtra("port", port).putExtra("manual", isManual())); |
| 273 Log.i(TAG, "Service started"); | 277 Log.i(TAG, "Service started"); |
| 274 } | 278 } |
| 275 | 279 |
| 276 @Override | 280 @Override |
| 277 public int onStartCommand(Intent intent, int flags, int startId) | 281 public int onStartCommand(Intent intent, int flags, int startId) |
| 278 { | 282 { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 notrafficHandler.removeCallbacks(noTraffic); | 586 notrafficHandler.removeCallbacks(noTraffic); |
| 583 if (changeStatus) | 587 if (changeStatus) |
| 584 { | 588 { |
| 585 NotificationManager notificationManager = (NotificationManager) getSyste
mService(NOTIFICATION_SERVICE); | 589 NotificationManager notificationManager = (NotificationManager) getSyste
mService(NOTIFICATION_SERVICE); |
| 586 ongoingNotification.setLatestEventInfo(ProxyService.this, getText(R.stri
ng.app_name), getText(R.string.notif_wifi), contentIntent); | 590 ongoingNotification.setLatestEventInfo(ProxyService.this, getText(R.stri
ng.app_name), getText(R.string.notif_wifi), contentIntent); |
| 587 notificationManager.notify(ONGOING_NOTIFICATION_ID, ongoingNotification)
; | 591 notificationManager.notify(ONGOING_NOTIFICATION_ID, ongoingNotification)
; |
| 588 } | 592 } |
| 589 } | 593 } |
| 590 notrafficHandler = null; | 594 notrafficHandler = null; |
| 591 } | 595 } |
| 596 |
| 597 public void setEmptyIcon(boolean empty) |
| 598 { |
| 599 ongoingNotification.icon = empty ? R.drawable.transparent : R.drawable.ic_st
at_blocking; |
| 600 NotificationManager notificationManager = (NotificationManager) getSystemSer
vice(NOTIFICATION_SERVICE); |
| 601 notificationManager.notify(ONGOING_NOTIFICATION_ID, ongoingNotification); |
| 602 } |
| 592 | 603 |
| 593 private final IBinder binder = new LocalBinder(); | 604 private final IBinder binder = new LocalBinder(); |
| 594 | 605 |
| 595 public final class LocalBinder extends Binder | 606 public final class LocalBinder extends Binder |
| 596 { | 607 { |
| 597 public ProxyService getService() | 608 public ProxyService getService() |
| 598 { | 609 { |
| 599 return ProxyService.this; | 610 return ProxyService.this; |
| 600 } | 611 } |
| 601 } | 612 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 @Override | 739 @Override |
| 729 public void log(int level, Object obj, String message) | 740 public void log(int level, Object obj, String message) |
| 730 { | 741 { |
| 731 if (level <= logLevel) | 742 if (level <= logLevel) |
| 732 { | 743 { |
| 733 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); | 744 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); |
| 734 } | 745 } |
| 735 } | 746 } |
| 736 } | 747 } |
| 737 } | 748 } |
| OLD | NEW |