Option to manage system applications

This commit is contained in:
M66B 2015-10-31 18:07:21 +01:00
parent 81e2bd058a
commit fd7c1dc561
13 changed files with 44 additions and 19 deletions

View File

@ -215,7 +215,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
new AsyncTask<Object, Object, List<Rule>>() {
@Override
protected List<Rule> doInBackground(Object... arg) {
return Rule.getRules(ActivityMain.this);
return Rule.getRules(false, ActivityMain.this);
}
@Override
@ -300,6 +300,9 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
MenuItem menuOther = menu.findItem(R.id.menu_whitelist_other);
menuOther.setChecked(prefs.getBoolean("whitelist_other", true));
MenuItem menuSystem = menu.findItem(R.id.menu_system);
menuSystem.setChecked(prefs.getBoolean("manage_system", false));
MenuItem menuTheme = menu.findItem(R.id.menu_theme);
menuTheme.setChecked(prefs.getBoolean("dark_theme", false));
@ -324,6 +327,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
menu_whitelist_other(prefs);
return true;
case R.id.menu_system:
menu_system(prefs);
return true;
case R.id.menu_theme:
menu_theme(prefs);
return true;
@ -366,6 +373,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
SinkholeService.reload("other", this);
}
private void menu_system(SharedPreferences prefs) {
prefs.edit().putBoolean("manage_system", !prefs.getBoolean("manage_system", true)).apply();
updateApplicationList();
SinkholeService.reload(null, this);
}
private void menu_theme(SharedPreferences prefs) {
prefs.edit().putBoolean("dark_theme", !prefs.getBoolean("dark_theme", false)).apply();
recreate();

View File

@ -21,43 +21,42 @@ public class Rule implements Comparable<Rule> {
public boolean other_blocked;
public boolean unused;
public boolean changed;
public boolean attributes = false;
private Rule(PackageInfo info, boolean wifi_blocked, boolean other_blocked, boolean unused, boolean changed, Context context) {
private Rule(PackageInfo info, Context context) {
PackageManager pm = context.getPackageManager();
this.info = info;
this.name = info.applicationInfo.loadLabel(pm).toString();
this.system = ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
int setting = pm.getApplicationEnabledSetting(info.packageName);
if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
this.disabled = !info.applicationInfo.enabled;
else
this.disabled = (setting != PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
this.wifi_blocked = wifi_blocked;
this.other_blocked = other_blocked;
this.unused = unused;
this.changed = changed;
}
public static List<Rule> getRules(Context context) {
public static List<Rule> getRules(boolean all, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
SharedPreferences other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
SharedPreferences punused = context.getSharedPreferences("unused", Context.MODE_PRIVATE);
SharedPreferences unused = context.getSharedPreferences("unused", Context.MODE_PRIVATE);
boolean wlWifi = prefs.getBoolean("whitelist_wifi", true);
boolean wlOther = prefs.getBoolean("whitelist_other", true);
boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", true);
boolean whitelist_other = prefs.getBoolean("whitelist_other", true);
boolean manage_system = prefs.getBoolean("manage_system", false);
List<Rule> listRules = new ArrayList<>();
for (PackageInfo info : context.getPackageManager().getInstalledPackages(0)) {
boolean blWifi = wifi.getBoolean(info.packageName, wlWifi);
boolean blOther = other.getBoolean(info.packageName, wlOther);
boolean unused = punused.getBoolean(info.packageName, false);
boolean changed = (blWifi != wlWifi || blOther != wlOther);
listRules.add(new Rule(info, blWifi, blOther, unused, changed, context));
boolean system = ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
if (!system || manage_system || all) {
Rule rule = new Rule(info, context);
rule.system = system;
rule.wifi_blocked = (system && !manage_system ? false : wifi.getBoolean(info.packageName, whitelist_wifi));
rule.other_blocked = (system && !manage_system ? false : other.getBoolean(info.packageName, whitelist_other));
rule.unused = unused.getBoolean(info.packageName, false);
rule.changed = (rule.wifi_blocked != whitelist_wifi || rule.other_blocked != whitelist_other);
listRules.add(rule);
}
}
Collections.sort(listRules);

View File

@ -100,7 +100,7 @@ public class SinkholeService extends VpnService {
builder.addRoute("0:0:0:0:0:0:0:0", 0);
// Add list of allowed applications
for (Rule rule : Rule.getRules(this))
for (Rule rule : Rule.getRules(true, this))
if (!(wifi ? rule.wifi_blocked : rule.other_blocked) || (rule.unused && interactive)) {
Log.i(TAG, "Allowing " + rule.info.packageName);
try {

View File

@ -19,6 +19,10 @@
android:id="@+id/menu_whitelist_other"
android:checkable="true"
android:title="@string/menu_whitelist_other" />
<item
android:id="@+id/menu_system"
android:checkable="true"
android:title="@string/menu_system" />
<item
android:id="@+id/menu_theme"
android:checkable="true"

View File

@ -5,6 +5,7 @@
<string name="menu_network">فتح إعدادات الشبكة</string>
<string name="menu_whitelist_wifi">حظر الواي فاي بشكل افتراضي</string>
<string name="menu_whitelist_other">حظر الشبكة بشكل افتراضي</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">استخدام الثيم الداكن</string>
<string name="menu_vpn_settings">فتح إعدادات الـVPN</string>
<string name="menu_support">الدعم</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">Ouvrir les paramètres réseaux</string>
<string name="menu_whitelist_wifi">Blocage Wi-Fi par défaut</string>
<string name="menu_whitelist_other">Blocage données mobiles par défaut</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">Utiliser le thème sombre</string>
<string name="menu_vpn_settings">Ouvrir les paramètres VPN</string>
<string name="menu_support">Support</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">Apri impostazioni di rete</string>
<string name="menu_whitelist_wifi">Blocca Wi-Fi di default</string>
<string name="menu_whitelist_other">Block rete di dati di default</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">Usa il tema scuro</string>
<string name="menu_vpn_settings">Apri impostazioni VPN</string>
<string name="menu_support">Supporto</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">네트워크 설정 열기</string>
<string name="menu_whitelist_wifi">Wi-Fi 차단을 기본 설정으로</string>
<string name="menu_whitelist_other">모바일 데이터 차단을 기본 설정으로</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">어두운 테마 사용</string>
<string name="menu_vpn_settings">Android VPN 설정 열기</string>
<string name="menu_support">지원</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">Open netwerkinstellingen</string>
<string name="menu_whitelist_wifi">Blokkeer Wi-Fi standaard</string>
<string name="menu_whitelist_other">Blokkeer mobiel standaard</string>
<string name="menu_system">Beheer systeem applicaties</string>
<string name="menu_dark">Gebruik donker thema</string>
<string name="menu_vpn_settings">Open Android VPN-instellingen</string>
<string name="menu_support">Ondersteuning</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">Deschide setari retea</string>
<string name="menu_whitelist_wifi">Blocheaza implicit Wi-Fi</string>
<string name="menu_whitelist_other">Blocheaza implicit date mobile</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">Foloseste tema intunecata</string>
<string name="menu_vpn_settings">Deschide setari VPN Android</string>
<string name="menu_support">Asistenta</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">Otvoriť nastavenia sietí</string>
<string name="menu_whitelist_wifi">Predvolene blokovať Wi-Fi</string>
<string name="menu_whitelist_other">Predvolene blokovať mobilné dáta</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">Použiť tmavú tému</string>
<string name="menu_vpn_settings">Otvoriť nastavenia VPN</string>
<string name="menu_support">Podpora</string>

View File

@ -5,6 +5,7 @@
<string name="menu_network">打开网络设置</string>
<string name="menu_whitelist_wifi">默认阻止Wi-Fi网络</string>
<string name="menu_whitelist_other">默认阻止移动网络</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">使用暗色主题</string>
<string name="menu_vpn_settings">打开安卓VPN设置</string>
<string name="menu_support">软件支持</string>

View File

@ -6,6 +6,7 @@
<string name="menu_network">Open network settings</string>
<string name="menu_whitelist_wifi">Block Wi-Fi by default</string>
<string name="menu_whitelist_other">Block mobile by default</string>
<string name="menu_system">Manage system applications</string>
<string name="menu_dark">Use dark theme</string>
<string name="menu_vpn_settings">Open Android VPN settings</string>
<string name="menu_support">Support</string>