diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 80451121d..c962a80df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -114,7 +114,7 @@ android:parentActivityName=".activities.ControlCenterv2" /> + = Build.VERSION_CODES.O; } + public static boolean isRunningTenOrLater() { + return VERSION.SDK_INT >= Build.VERSION_CODES.Q; + } + + public static boolean isRunningPieOrLater() { return VERSION.SDK_INT >= Build.VERSION_CODES.P; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java index 840c488db..4a0cd1c5b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppBlacklistActivity.java @@ -79,11 +79,11 @@ public class AppBlacklistActivity extends AbstractGBActivity { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; - case R.id.blacklist_all_notif: - appBlacklistAdapter.blacklistAllNotif(); + case R.id.check_all_applications: + appBlacklistAdapter.checkAllApplications(); return true; - case R.id.whitelist_all_notif: - appBlacklistAdapter.whitelistAllNotif(); + case R.id.uncheck_all_applications: + appBlacklistAdapter.uncheckAllApplications(); return true; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index 33b8df34d..fb33c3a43 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -307,8 +307,8 @@ public class ControlCenterv2 extends AppCompatActivity Intent dbIntent = new Intent(this, DataManagementActivity.class); startActivity(dbIntent); return true; - case R.id.action_blacklist: - Intent blIntent = new Intent(this, AppBlacklistActivity.class); + case R.id.action_notification_management: + Intent blIntent = new Intent(this, NotificationManagementActivity.class); startActivity(blIntent); return true; case R.id.device_action_discover: diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 5ee666508..476931254 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -410,6 +410,15 @@ public class DebugActivity extends AbstractGBActivity { } }); + Button runDebugFunction = findViewById(R.id.runDebugFunction); + runDebugFunction.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit(); + //editor.remove("notification_list_is_blacklist").apply(); + } + }); + Button addDeviceButtonDebug = findViewById(R.id.addDeviceButtonDebug); addDeviceButtonDebug.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java new file mode 100644 index 000000000..a007fb5d2 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java @@ -0,0 +1,144 @@ +/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo, + vanous + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo, + vanous + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.activities; + +import android.content.Intent; +import android.media.Ringtone; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceCategory; +import android.preference.PreferenceManager; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter; +import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; +import nodomain.freeyourgadget.gadgetbridge.util.Prefs; + +public class NotificationManagementActivity extends AbstractSettingsActivity { + private static final Logger LOG = LoggerFactory.getLogger(NotificationManagementActivity.class); + private static final int RINGTONE_REQUEST_CODE = 4712; + private static final String DEFAULT_RINGTONE_URI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.notifications_preferences); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + + Prefs prefs = GBApplication.getPrefs(); + Preference pref = findPreference("notifications_generic"); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); + startActivity(enableIntent); + return true; + } + }); + + + pref = findPreference(GBPrefs.PING_TONE); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Set Ping tone"); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL); + startActivityForResult(intent, RINGTONE_REQUEST_CODE); + return true; + } + }); + pref.setSummary(RingtoneManager.getRingtone(this, Uri.parse(prefs.getString(GBPrefs.PING_TONE, DEFAULT_RINGTONE_URI))).getTitle(this)); + + pref = findPreference("pref_key_blacklist"); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + Intent enableIntent = new Intent(NotificationManagementActivity.this, AppBlacklistActivity.class); + startActivity(enableIntent); + return true; + } + }); + + if (!GBApplication.isRunningMarshmallowOrLater()) { + pref = findPreference("notification_filter"); + PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications"); + category.removePreference(pref); + } + + if (GBApplication.isRunningTenOrLater()) { + pref = findPreference("minimize_priority"); + PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications"); + category.removePreference(pref); + } + } + + + @Override + protected String[] getPreferenceKeysWithSummary() { + return new String[]{ + }; + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + if (requestCode == RINGTONE_REQUEST_CODE && intent != null) { + if (intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) != null) { + Uri uri = intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); + Ringtone r = RingtoneManager.getRingtone(this, uri); + findPreference(GBPrefs.PING_TONE).setSummary(r.toString()); + + PreferenceManager + .getDefaultSharedPreferences(this) + .edit() + .putString(GBPrefs.PING_TONE, uri.toString()) + .apply(); + findPreference(GBPrefs.PING_TONE).setSummary(r.getTitle(this)); + } + } + } + + +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java index f0d453834..4c249c9ec 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -73,8 +73,6 @@ public class SettingsActivity extends AbstractSettingsActivity { public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system"; private static final int FILE_REQUEST_CODE = 4711; - private static final int RINGTONE_REQUEST_CODE = 4712; - private static final String DEFAULT_RINGTONE_URI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -87,17 +85,7 @@ public class SettingsActivity extends AbstractSettingsActivity { super.onPostCreate(savedInstanceState); Prefs prefs = GBApplication.getPrefs(); - - Preference pref = findPreference("notifications_generic"); - pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference preference) { - Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); - startActivity(enableIntent); - return true; - } - }); - - pref = findPreference("pref_category_activity_personal"); + Preference pref = findPreference("pref_category_activity_personal"); pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent enableIntent = new Intent(SettingsActivity.this, AboutUserPreferencesActivity.class); @@ -143,15 +131,6 @@ public class SettingsActivity extends AbstractSettingsActivity { } }); - pref = findPreference("pref_key_blacklist"); - pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - public boolean onPreferenceClick(Preference preference) { - Intent enableIntent = new Intent(SettingsActivity.this, AppBlacklistActivity.class); - startActivity(enableIntent); - return true; - } - }); - pref = findPreference("pref_key_blacklist_calendars"); pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { @@ -244,12 +223,6 @@ public class SettingsActivity extends AbstractSettingsActivity { } }); - if (!GBApplication.isRunningMarshmallowOrLater()) { - pref = findPreference("notification_filter"); - PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications"); - category.removePreference(pref); - } - pref = findPreference("location_aquire"); pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { @@ -309,20 +282,6 @@ public class SettingsActivity extends AbstractSettingsActivity { } }); - pref = findPreference(GBPrefs.PING_TONE); - pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Set Ping tone"); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL); - startActivityForResult(intent, RINGTONE_REQUEST_CODE); - return true; - } - }); - pref.setSummary(RingtoneManager.getRingtone(this, Uri.parse(prefs.getString(GBPrefs.PING_TONE, DEFAULT_RINGTONE_URI))).getTitle(this)); pref = findPreference(GBPrefs.AUTO_EXPORT_LOCATION); pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @@ -455,20 +414,6 @@ public class SettingsActivity extends AbstractSettingsActivity { .getPrefs().getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0); PeriodicExporter.sheduleAlarm(getApplicationContext(), autoExportPeriod, autoExportEnabled); } - if (requestCode == RINGTONE_REQUEST_CODE && intent != null) { - if(intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)!= null){ - Uri uri = intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); - Ringtone r = RingtoneManager.getRingtone(this ,uri); - findPreference(GBPrefs.PING_TONE).setSummary(r.toString()); - - PreferenceManager - .getDefaultSharedPreferences(this) - .edit() - .putString(GBPrefs.PING_TONE, uri.toString()) - .apply(); - findPreference(GBPrefs.PING_TONE).setSummary(r.getTitle(this)); - } - } } /* diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java index ad2eb3a4f..91ac84724 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AppBlacklistAdapter.java @@ -137,18 +137,28 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter apps_blacklist = new HashSet<>(); List allApps = mPm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo ai : allApps) { @@ -158,7 +168,7 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter apps_blacklist = new HashSet<>(); GBApplication.setAppsNotifBlackList(apps_blacklist); notifyDataSetChanged(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index baf198ae3..45c14acb7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -168,9 +168,12 @@ public class NotificationListener extends NotificationListenerService { LOG.info("could not lookup handle for mute action"); break; } - LOG.info("going to mute " + packageName); - GBApplication.addAppToNotifBlacklist(packageName); + if (GBApplication.getPrefs().getString("notification_list_is_blacklist", "true").equals("true")) { + GBApplication.addAppToNotifBlacklist(packageName); + } else { + GBApplication.removeFromAppsNotifBlacklist(packageName); + } break; case ACTION_DISMISS: { StatusBarNotification[] sbns = NotificationListener.this.getActiveNotifications(); @@ -263,11 +266,13 @@ public class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { logNotification(sbn, true); + LOG.debug("notificationAppListIsBlackList: " + GBApplication.getPrefs().getString("notification_list_is_blacklist","true")); + notificationStack.remove(sbn.getPackageName()); notificationStack.add(sbn.getPackageName()); - if (shouldIgnoreNotifications()) return; + if (isServiceNotRunningAndShouldIgnoreNotifications()) return; if (shouldIgnoreSource(sbn)) { LOG.debug("Ignoring notification source"); @@ -716,7 +721,7 @@ public class NotificationListener extends NotificationListenerService { notificationStack.remove(sbn.getPackageName()); - if (shouldIgnoreNotifications()) return; + if (isServiceNotRunningAndShouldIgnoreNotifications()) return; if (shouldIgnoreSource(sbn)) return; if (handleMediaSessionNotification(sbn)) return; @@ -790,7 +795,7 @@ public class NotificationListener extends NotificationListenerService { } - private boolean shouldIgnoreNotifications() { + private boolean isServiceNotRunningAndShouldIgnoreNotifications() { /* * return early if DeviceCommunicationService is not running, * else the service would get started every time we get a notification. @@ -834,9 +839,19 @@ public class NotificationListener extends NotificationListenerService { } } - if (GBApplication.appIsNotifBlacklisted(source)) { - LOG.info("Ignoring notification, application is blacklisted"); - return true; + if (GBApplication.getPrefs().getString("notification_list_is_blacklist", "true").equals("true")) { + if (GBApplication.appIsNotifBlacklisted(source)) { + LOG.info("Ignoring notification, application is blacklisted"); + return true; + } + } else { + if (GBApplication.appIsNotifBlacklisted(source)) { + LOG.info("Allowing notification, application is whitelisted"); + return false; + } else { + LOG.info("Ignoring notification, application is not whitelisted"); + return true; + } } return false; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java index eb75fb952..081539bd0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java @@ -76,9 +76,16 @@ public class PebbleReceiver extends BroadcastReceiver { if (notificationSpec.title != null) { notificationSpec.type = NotificationType.UNKNOWN; String sender = intent.getStringExtra("sender"); - if (GBApplication.appIsPebbleBlacklisted(sender)) { - LOG.info("Ignoring Pebble message, application "+ sender +" is blacklisted"); - return; + if (GBApplication.getPrefs().getString("notification_list_is_blacklist", "true").equals("true")) { + if (GBApplication.appIsPebbleBlacklisted(sender)) { + LOG.info("Ignoring Pebble message, application " + sender + " is blacklisted"); + return; + } + } else { + if (!GBApplication.appIsPebbleBlacklisted(sender)) { + LOG.info("Ignoring Pebble message, application " + sender + " is not whitelisted"); + return; + } } if ("Conversations".equals(sender)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java index 6c568a27d..fef80c875 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -138,13 +138,17 @@ public class GBDeviceService implements DeviceService { @Override public void onNotification(NotificationSpec notificationSpec) { + boolean hideMessageDetails = GBApplication.getPrefs().getString("pref_message_privacy_mode", + GBApplication.getContext().getString(R.string.p_message_privacy_mode_off)) + .equals(GBApplication.getContext().getString(R.string.p_message_privacy_mode_complete)); + Intent intent = createIntent().setAction(ACTION_NOTIFICATION) .putExtra(EXTRA_NOTIFICATION_FLAGS, notificationSpec.flags) - .putExtra(EXTRA_NOTIFICATION_PHONENUMBER, notificationSpec.phoneNumber) - .putExtra(EXTRA_NOTIFICATION_SENDER, coalesce(notificationSpec.sender, getContactDisplayNameByNumber(notificationSpec.phoneNumber))) - .putExtra(EXTRA_NOTIFICATION_SUBJECT, notificationSpec.subject) - .putExtra(EXTRA_NOTIFICATION_TITLE, notificationSpec.title) - .putExtra(EXTRA_NOTIFICATION_BODY, notificationSpec.body) + .putExtra(EXTRA_NOTIFICATION_PHONENUMBER, hideMessageDetails ? null : notificationSpec.phoneNumber) + .putExtra(EXTRA_NOTIFICATION_SENDER, hideMessageDetails ? null : coalesce(notificationSpec.sender, getContactDisplayNameByNumber(notificationSpec.phoneNumber))) + .putExtra(EXTRA_NOTIFICATION_SUBJECT, hideMessageDetails ? null : notificationSpec.subject) + .putExtra(EXTRA_NOTIFICATION_TITLE, hideMessageDetails ? null : notificationSpec.title) + .putExtra(EXTRA_NOTIFICATION_BODY, hideMessageDetails ? null : notificationSpec.body) .putExtra(EXTRA_NOTIFICATION_ID, notificationSpec.getId()) .putExtra(EXTRA_NOTIFICATION_TYPE, notificationSpec.type) .putExtra(EXTRA_NOTIFICATION_ACTIONS, notificationSpec.attachedActions) diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index bd7c24b7b..0530ac90c 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -225,6 +225,14 @@ grid:layout_columnSpan="2" grid:layout_gravity="fill_horizontal" /> +