use of android.os.Vibrator 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
}
});
}
use of android.os.Vibrator in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class CellTracker method vibrate.
/**
* Vibrator helper method, will check current preferences (vibrator enabled, min threat level to vibrate)
* and act appropriately
* */
private void vibrate(int msec, Status threatLevel) {
if (vibrateEnabled && (threatLevel == null || threatLevel.ordinal() >= vibrateMinThreatLevel)) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(msec);
}
}
use of android.os.Vibrator in project adbWireless by Skywriter-se.
the class adbWireless method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = new ProgressDialog(adbWireless.this);
this.iv_button = (ImageView) findViewById(R.id.iv_button);
this.tv_footer_1 = (TextView) findViewById(R.id.tv_footer_1);
this.tv_footer_2 = (TextView) findViewById(R.id.tv_footer_2);
this.tv_footer_3 = (TextView) findViewById(R.id.tv_footer_3);
this.mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
this.mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (!hasRootPermission()) {
// Log.d(MSG_TAG, "Not Root!");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.no_root)).setCancelable(true).setPositiveButton(getString(R.string.button_close), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
adbWireless.this.finish();
}
});
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.create();
builder.setTitle(R.string.no_root_title);
builder.show();
}
if (!checkWifiState()) {
// Log.d(MSG_TAG, "Not Wifi!");
wifiState = false;
saveWiFiState(wifiState);
if (prefsWiFiOn()) {
enableWiFi(true);
} else {
WiFidialog();
}
} else {
wifiState = true;
saveWiFiState(wifiState);
}
this.iv_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (prefsHaptic())
vib.vibrate(35);
try {
if (!mState) {
spinner.setMessage(getString(R.string.Turning_on));
spinner.show();
adbStart();
} else {
spinner.setMessage(getString(R.string.Turning_off));
spinner.show();
adbStop();
}
updateState();
spinner.cancel();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of android.os.Vibrator in project platform_frameworks_base by android.
the class VibratorService method updateInputDeviceVibrators.
private void updateInputDeviceVibrators() {
synchronized (mVibrations) {
doCancelVibrateLocked();
synchronized (mInputDeviceVibrators) {
mVibrateInputDevicesSetting = false;
try {
mVibrateInputDevicesSetting = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0;
} catch (SettingNotFoundException snfe) {
}
mLowPowerMode = mPowerManagerInternal.getLowPowerModeEnabled();
if (mVibrateInputDevicesSetting) {
if (!mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = true;
mIm.registerInputDeviceListener(this, mH);
}
} else {
if (mInputDeviceListenerRegistered) {
mInputDeviceListenerRegistered = false;
mIm.unregisterInputDeviceListener(this);
}
}
mInputDeviceVibrators.clear();
if (mVibrateInputDevicesSetting) {
int[] ids = mIm.getInputDeviceIds();
for (int i = 0; i < ids.length; i++) {
InputDevice device = mIm.getInputDevice(ids[i]);
Vibrator vibrator = device.getVibrator();
if (vibrator.hasVibrator()) {
mInputDeviceVibrators.add(vibrator);
}
}
}
}
startNextVibrationLocked();
}
}
use of android.os.Vibrator in project zxingfragmentlib by mitoyarzun.
the class BeepManager method playBeepSoundAndVibrate.
public synchronized void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
if (vibrate) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
Aggregations