Search in sources :

Example 1 with LogPreference

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);
    }
}
Also used : LogPreference(dev.ukanth.ufirewall.log.LogPreference) Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) Button(android.widget.Button) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with LogPreference

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();
    }
}
Also used : LogPreference(dev.ukanth.ufirewall.log.LogPreference) LogPreferenceDB(dev.ukanth.ufirewall.log.LogPreferenceDB)

Example 3 with LogPreference

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();
}
Also used : LogPreference(dev.ukanth.ufirewall.log.LogPreference) LogPreferenceDB(dev.ukanth.ufirewall.log.LogPreferenceDB)

Example 4 with LogPreference

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;
}
Also used : LogPreference(dev.ukanth.ufirewall.log.LogPreference) ArrayList(java.util.ArrayList)

Example 5 with LogPreference

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);
    }
}
Also used : LogPreference(dev.ukanth.ufirewall.log.LogPreference) LogPreferenceDB(dev.ukanth.ufirewall.log.LogPreferenceDB) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

LogPreference (dev.ukanth.ufirewall.log.LogPreference)5 LogPreferenceDB (dev.ukanth.ufirewall.log.LogPreferenceDB)3 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Toolbar (android.support.v7.widget.Toolbar)1 Button (android.widget.Button)1 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1