Search in sources :

Example 1 with Event

use of com.secupwn.aimsicd.data.model.Event in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class EventAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        convertView = inflater.inflate(R.layout.eventlog_items, parent, false);
        holder = new ViewHolder(convertView);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Event event = getItem(position);
    holder.updateDisplay(event, position);
    return convertView;
}
Also used : LayoutInflater(android.view.LayoutInflater) Event(com.secupwn.aimsicd.data.model.Event)

Example 2 with Event

use of com.secupwn.aimsicd.data.model.Event in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class RealmHelper method toEventLog.

/**
     * Defining a new simpler version of insertEventLog for use in CellTracker.
     */
public void toEventLog(Realm realm, final int DF_id, final String DF_desc) {
    final Date timestamp = new Date();
    final int lac = CellTracker.monitorCell.getLocationAreaCode();
    final int cid = CellTracker.monitorCell.getCellId();
    //[UMTS,LTE]
    final int psc = CellTracker.monitorCell.getPrimaryScramblingCode();
    final double gpsd_lat = CellTracker.monitorCell.getLat();
    final double gpsd_lon = CellTracker.monitorCell.getLon();
    final double gpsd_accu = CellTracker.monitorCell.getAccuracy();
    realm.executeTransactionAsync(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            // skip CID/LAC of "-1" (due to crappy API, Roaming or Air-Plane Mode)
            if (cid != -1 || lac != -1) {
                // Check if LAST entry is the same!
                RealmResults<Event> events = realm.where(Event.class).findAllSorted("timestamp");
                boolean insertData;
                if (events.isEmpty()) {
                    insertData = true;
                } else {
                    Event lastEvent = events.last();
                    insertData = !(lastEvent.getCellId() == cid && lastEvent.getLocationAreaCode() == lac && lastEvent.getPrimaryScramblingCode() == psc && lastEvent.getDfId() == DF_id);
                }
                if (insertData) {
                    Event event = realm.createObject(Event.class);
                    event.setTimestamp(timestamp);
                    event.setLocationAreaCode(lac);
                    event.setCellId(cid);
                    event.setPrimaryScramblingCode(psc);
                    GpsLocation gpsLocation = realm.createObject(GpsLocation.class);
                    gpsLocation.setLatitude(gpsd_lat);
                    gpsLocation.setLongitude(gpsd_lon);
                    gpsLocation.setAccuracy(gpsd_accu);
                    event.setGpsLocation(gpsLocation);
                    event.setDfId(DF_id);
                    event.setDfDescription(DF_desc);
                }
            }
        }
    }, new Realm.Transaction.OnSuccess() {

        @Override
        public void onSuccess() {
            log.info("ToEventLog(): Added new event: id=" + DF_id + " time=" + timestamp + " cid=" + cid);
            // Short 100 ms Vibration
            // TODO not elegant solution, vibrator invocation should be moved somewhere else imho
            boolean vibrationEnabled = mPreferences.getBoolean(mContext.getString(R.string.pref_notification_vibrate_enable), true);
            int thresholdLevel = Integer.valueOf(mPreferences.getString(mContext.getString(R.string.pref_notification_vibrate_min_level), String.valueOf(Status.MEDIUM.ordinal())));
            boolean higherLevelThanThreshold = Status.MEDIUM.ordinal() <= thresholdLevel;
            if (vibrationEnabled && higherLevelThanThreshold) {
                Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(100);
            }
        // Short sound:
        // TODO see issue #15
        }
    });
}
Also used : Event(com.secupwn.aimsicd.data.model.Event) GpsLocation(com.secupwn.aimsicd.data.model.GpsLocation) Vibrator(android.os.Vibrator) Realm(io.realm.Realm) Date(java.util.Date) RealmResults(io.realm.RealmResults)

Aggregations

Event (com.secupwn.aimsicd.data.model.Event)2 Vibrator (android.os.Vibrator)1 LayoutInflater (android.view.LayoutInflater)1 GpsLocation (com.secupwn.aimsicd.data.model.GpsLocation)1 Realm (io.realm.Realm)1 RealmResults (io.realm.RealmResults)1 Date (java.util.Date)1