use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.
the class MiBandPairingActivity method pairingFinished.
private void pairingFinished(boolean pairedSuccessfully, GBDeviceCandidate candidate) {
LOG.debug("pairingFinished: " + pairedSuccessfully);
if (!isPairing) {
// already gone?
return;
}
isPairing = false;
AndroidUtils.safeUnregisterBroadcastReceiver(LocalBroadcastManager.getInstance(this), mPairingReceiver);
AndroidUtils.safeUnregisterBroadcastReceiver(this, mBondingReceiver);
if (pairedSuccessfully) {
// remember the device since we do not necessarily pair... temporary -- we probably need
// to query the db for available devices in ControlCenter. But only remember un-bonded
// devices, as bonded devices are displayed anyway.
String macAddress = deviceCandidate.getMacAddress();
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress);
if (device != null && device.getBondState() == BluetoothDevice.BOND_NONE) {
Prefs prefs = GBApplication.getPrefs();
prefs.getPreferences().edit().putString(MiBandConst.PREF_MIBAND_ADDRESS, macAddress).apply();
}
Intent intent = new Intent(this, ControlCenterv2.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
finish();
}
use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.
the class NotificationListener method onNotificationRemoved.
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
//FIXME: deduplicate code
String source = sbn.getPackageName();
Notification notification = sbn.getNotification();
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
return;
}
if (source.equals("android") || source.equals("com.android.systemui") || source.equals("com.android.dialer") || source.equals("com.cyanogenmod.eleven")) {
return;
}
Prefs prefs = GBApplication.getPrefs();
if (prefs.getBoolean("autoremove_notifications", false)) {
LOG.info("notification removed, will ask device to delete it");
//FIMXE: a truly unique id would be better
GBApplication.deviceService().onDeleteNotification((int) sbn.getPostTime());
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.
the class NotificationListener method onNotificationPosted.
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
/*
* return early if DeviceCommunicationService is not running,
* else the service would get started every time we get a notification.
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
* broadcast receivers because it seems to invalidate the permissions that are
* necessary for NotificationListenerService
*/
if (!isServiceRunning()) {
return;
}
switch(GBApplication.getGrantedInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
break;
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
case NotificationManager.INTERRUPTION_FILTER_NONE:
return;
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
// FIXME: Handle Reminders and Events if they are enabled in Do Not Disturb
return;
}
String source = sbn.getPackageName();
Notification notification = sbn.getNotification();
if (handleMediaSessionNotification(notification))
return;
Prefs prefs = GBApplication.getPrefs();
if (!prefs.getBoolean("notifications_generic_whenscreenon", false)) {
PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE);
if (powermanager.isScreenOn()) {
// LOG.info("Not forwarding notification, screen seems to be on and settings do not allow this");
return;
}
}
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
// LOG.info("Not forwarding notification, FLAG_ONGOING_EVENT is set. Notification flags: " + notification.flags);
return;
}
if (source.equals("android") || source.equals("com.android.systemui") || source.equals("com.android.dialer") || source.equals("com.cyanogenmod.eleven")) {
LOG.info("Not forwarding notification, is a system event");
return;
}
if (source.equals("com.moez.QKSMS") || source.equals("com.android.mms") || source.equals("com.sonyericsson.conversations") || source.equals("com.android.messaging") || source.equals("org.smssecure.smssecure")) {
if (!"never".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
return;
}
}
if (GBApplication.blacklist != null && GBApplication.blacklist.contains(source)) {
LOG.info("Not forwarding notification, application is blacklisted");
return;
}
NotificationSpec notificationSpec = new NotificationSpec();
// determinate Source App Name ("Label")
PackageManager pm = getPackageManager();
ApplicationInfo ai = null;
try {
ai = pm.getApplicationInfo(source, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (ai != null) {
notificationSpec.sourceName = (String) pm.getApplicationLabel(ai);
}
boolean preferBigText = false;
notificationSpec.type = AppNotificationType.getInstance().get(source);
if (source.startsWith("com.fsck.k9")) {
// we dont want group summaries at all for k9
if ((notification.flags & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY) {
return;
}
preferBigText = true;
}
if (notificationSpec.type == null) {
notificationSpec.type = NotificationType.UNKNOWN;
}
LOG.info("Processing notification from source " + source + " with flags: " + notification.flags);
dissectNotificationTo(notification, notificationSpec, preferBigText);
//FIMXE: a truly unique id would be better
notificationSpec.id = (int) sbn.getPostTime();
// ignore Gadgetbridge's very own notifications, except for those from the debug screen
if (getApplicationContext().getPackageName().equals(source)) {
if (!getApplicationContext().getString(R.string.test_notification).equals(notificationSpec.title)) {
return;
}
}
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(notification);
List<NotificationCompat.Action> actions = wearableExtender.getActions();
if (actions.isEmpty() && (notification.flags & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY) {
//this could cause #395 to come back
LOG.info("Not forwarding notification, FLAG_GROUP_SUMMARY is set and no wearable action present. Notification flags: " + notification.flags);
return;
}
for (NotificationCompat.Action act : actions) {
if (act != null && act.getRemoteInputs() != null) {
LOG.info("found wearable action: " + act.getTitle() + " " + sbn.getTag());
mActionLookup.add(notificationSpec.id, act);
notificationSpec.flags |= NotificationSpec.FLAG_WEARABLE_REPLY;
break;
}
}
GBApplication.deviceService().onNotification(notificationSpec);
}
use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.
the class PebbleReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Prefs prefs = GBApplication.getPrefs();
if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
return;
}
if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powermanager.isScreenOn()) {
return;
}
}
String messageType = intent.getStringExtra("messageType");
if (!messageType.equals("PEBBLE_ALERT")) {
LOG.info("non PEBBLE_ALERT message type not supported");
return;
}
if (!intent.hasExtra("notificationData")) {
LOG.info("missing notificationData extra");
return;
}
NotificationSpec notificationSpec = new NotificationSpec();
notificationSpec.id = -1;
String notificationData = intent.getStringExtra("notificationData");
try {
JSONArray notificationJSON = new JSONArray(notificationData);
notificationSpec.title = notificationJSON.getJSONObject(0).getString("title");
notificationSpec.body = notificationJSON.getJSONObject(0).getString("body");
} catch (JSONException e) {
e.printStackTrace();
return;
}
if (notificationSpec.title != null) {
notificationSpec.type = NotificationType.UNKNOWN;
String sender = intent.getStringExtra("sender");
if ("Conversations".equals(sender)) {
notificationSpec.type = NotificationType.CONVERSATIONS;
} else if ("OsmAnd".equals(sender)) {
notificationSpec.type = NotificationType.GENERIC_NAVIGATION;
}
GBApplication.deviceService().onNotification(notificationSpec);
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.
the class PhoneCallReceiver method onCallStateChanged.
public void onCallStateChanged(Context context, int state, String number) {
if (mLastState == state) {
return;
}
int callCommand = CallSpec.CALL_UNDEFINED;
switch(state) {
case TelephonyManager.CALL_STATE_RINGING:
mSavedNumber = number;
callCommand = CallSpec.CALL_INCOMING;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
callCommand = CallSpec.CALL_START;
} else {
callCommand = CallSpec.CALL_OUTGOING;
mSavedNumber = number;
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
//missed call would be correct here
callCommand = CallSpec.CALL_END;
} else {
callCommand = CallSpec.CALL_END;
}
break;
}
if (callCommand != CallSpec.CALL_UNDEFINED) {
Prefs prefs = GBApplication.getPrefs();
if ("never".equals(prefs.getString("notification_mode_calls", "always"))) {
return;
}
switch(GBApplication.getGrantedInterruptionFilter()) {
case NotificationManager.INTERRUPTION_FILTER_ALL:
break;
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
case NotificationManager.INTERRUPTION_FILTER_NONE:
return;
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_CALLS, mSavedNumber)) {
break;
}
// FIXME: Handle Repeat callers if it is enabled in Do Not Disturb
return;
}
CallSpec callSpec = new CallSpec();
callSpec.number = mSavedNumber;
callSpec.command = callCommand;
GBApplication.deviceService().onSetCallState(callSpec);
}
mLastState = state;
}
Aggregations