use of dev.ukanth.ufirewall.log.LogPreference in project afwall by ukanth.
the class AppDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(getString(R.string.traffic_detail_title));
setContentView(R.layout.app_detail);
int appid = getIntent().getIntExtra("appid", -1);
String packageName = getIntent().getStringExtra("package");
try {
CheckBox logOption = (CheckBox) findViewById(R.id.notification_p);
LogPreference logPreference = SQLite.select().from(LogPreference.class).where(LogPreference_Table.uid.eq(appid)).querySingle();
if (logPreference != null) {
logOption.setChecked(logPreference.isDisable());
}
logOption.setOnCheckedChangeListener((buttonView, isChecked) -> {
// only use when triggered by user
if (buttonView.isPressed()) {
// write the logic here
G.updateLogNotification(appid, isChecked);
}
});
} catch (Exception e) {
}
Toolbar toolbar = (Toolbar) findViewById(R.id.app_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final Context ctx = getApplicationContext();
ImageView image = (ImageView) findViewById(R.id.app_icon);
TextView textView = (TextView) findViewById(R.id.app_title);
TextView textView2 = (TextView) findViewById(R.id.app_package);
TextView up = (TextView) findViewById(R.id.up);
TextView down = (TextView) findViewById(R.id.down);
/**/
final PackageManager packageManager = getApplicationContext().getPackageManager();
final String[] packageNameList = ctx.getPackageManager().getPackagesForUid(appid);
final String pName = packageName;
Button button = findViewById(R.id.app_settings);
button.setOnClickListener(v -> Api.showInstalledAppDetails(getApplicationContext(), pName));
ApplicationInfo applicationInfo;
try {
if (!packageName.startsWith("dev.afwall.special.")) {
applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
if (applicationInfo != null) {
image.setImageDrawable(applicationInfo.loadIcon(packageManager));
String name = packageManager.getApplicationLabel(applicationInfo).toString();
textView.setText(name);
setTotalBytesManual(down, up, applicationInfo.uid);
}
} else {
image.setImageDrawable(getApplicationContext().getResources().getDrawable(R.drawable.ic_android_white_24dp));
if (appid >= 0) {
textView.setText(Api.getSpecialDescription(getApplicationContext(), packageName.replace("dev.afwall.special.", "")));
} else {
textView.setText(Api.getSpecialDescriptionSystem(getApplicationContext(), packageName.replace("dev.afwall.special.", "")));
}
down.setText(" : " + humanReadableByteCount(0, false));
up.setText(" : " + humanReadableByteCount(0, false));
button.setEnabled(false);
}
if (packageNameList != null && packageNameList.length > 1) {
textView2.setText(Arrays.toString(packageNameList));
button.setEnabled(false);
} else {
textView2.setText(packageName);
}
} catch (final NameNotFoundException e) {
down.setText(" : " + humanReadableByteCount(0, false));
up.setText(" : " + humanReadableByteCount(0, false));
button.setEnabled(false);
}
}
use of dev.ukanth.ufirewall.log.LogPreference in project afwall by ukanth.
the class G method storeBlockedApps.
public static void storeBlockedApps(List<Integer> list) {
// store to DB
for (Integer uid : list) {
LogPreference preference = new LogPreference();
preference.setUid(uid);
preference.setTimestamp(System.currentTimeMillis());
preference.setDisable(true);
FlowManager.getDatabase(LogPreferenceDB.class).beginTransactionAsync(databaseWrapper -> preference.save(databaseWrapper)).build().execute();
}
}
use of dev.ukanth.ufirewall.log.LogPreference in project afwall by ukanth.
the class G method updateLogNotification.
public static void updateLogNotification(int uid, boolean isChecked) {
// update logic here
LogPreference preference = new LogPreference();
preference.setUid(uid);
preference.setTimestamp(System.currentTimeMillis());
preference.setDisable(isChecked);
FlowManager.getDatabase(LogPreferenceDB.class).beginTransactionAsync(databaseWrapper -> preference.save(databaseWrapper)).build().execute();
}
use of dev.ukanth.ufirewall.log.LogPreference in project afwall by ukanth.
the class G method readBlockedApps.
public static List<Integer> readBlockedApps() {
List<LogPreference> list = SQLite.select().from(LogPreference.class).queryList();
List<Integer> listSelected = new ArrayList<>();
for (LogPreference pref : list) {
if (pref.isDisable()) {
listSelected.add(pref.getUid());
}
}
return listSelected;
}
use of dev.ukanth.ufirewall.log.LogPreference in project afwall by ukanth.
the class MainActivity method migrateNotification.
private void migrateNotification() {
try {
if (!G.isNotificationMigrated()) {
List<Integer> idList = G.getBlockedNotifyList();
for (Integer uid : idList) {
LogPreference preference = new LogPreference();
preference.setUid(uid);
preference.setTimestamp(System.currentTimeMillis());
preference.setDisable(true);
FlowManager.getDatabase(LogPreferenceDB.class).beginTransactionAsync(databaseWrapper -> preference.save(databaseWrapper)).build().execute();
}
G.isNotificationMigrated(true);
}
} catch (Exception e) {
Log.e(G.TAG, "Unable to migrate notification", e);
}
}
Aggregations