From 6989ca9db3322faa8aa1a8da0eeee9853b4130f0 Mon Sep 17 00:00:00 2001 From: Alberto Date: Tue, 14 Mar 2017 21:37:16 +0100 Subject: [PATCH] Add privacy mode that hides the phone number (#588) --- .../gadgetbridge/impl/GBDeviceService.java | 18 ++++++++----- .../service/devices/hplus/HPlusSupport.java | 26 ++++++++++--------- app/src/main/res/values/arrays.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 29 insertions(+), 19 deletions(-) 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 ea2537e29..36ec75c20 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -73,9 +73,9 @@ public class GBDeviceService implements DeviceService { } protected void invokeService(Intent intent) { - if(LanguageUtils.transliterate()){ - for (String extra: transliterationExtras) { - if (intent.hasExtra(extra)){ + if (LanguageUtils.transliterate()) { + for (String extra : transliterationExtras) { + if (intent.hasExtra(extra)) { intent.putExtra(extra, LanguageUtils.transliterate(intent.getStringExtra(extra))); } } @@ -172,12 +172,15 @@ public class GBDeviceService implements DeviceService { String currentPrivacyMode = GBApplication.getPrefs().getString("pref_call_privacy_mode", GBApplication.getContext().getString(R.string.p_call_privacy_mode_off)); if (context.getString(R.string.p_call_privacy_mode_name).equals(currentPrivacyMode)) { callSpec.name = callSpec.number; - } - else if (context.getString(R.string.p_call_privacy_mode_complete).equals(currentPrivacyMode)) { + } else if (context.getString(R.string.p_call_privacy_mode_complete).equals(currentPrivacyMode)) { callSpec.number = null; callSpec.name = null; - } - else { + } else if (context.getString(R.string.pref_call_privacy_mode_number).equals(currentPrivacyMode)) { + callSpec.name = coalesce(callSpec.name, getContactDisplayNameByNumber(callSpec.number)); + if (!callSpec.name.equals(callSpec.number)) { + callSpec.number = null; + } + } else { callSpec.name = coalesce(callSpec.name, getContactDisplayNameByNumber(callSpec.number)); } @@ -372,6 +375,7 @@ public class GBDeviceService implements DeviceService { /** * Returns contact DisplayName by call number + * * @param number contact number * @return contact DisplayName, if found it */ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 2ed1dbf6d..18791908d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -669,18 +669,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { byte[] msg = new byte[13]; - //Show call number - for (int i = 0; i < msg.length; i++) - msg[i] = ' '; - - for (int i = 0; i < number.length() && i < (msg.length - 1); i++) - msg[i + 1] = (byte) number.charAt(i); - - msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER; - - builder.write(ctrlCharacteristic, msg); - builder.wait(200); - msg = msg.clone(); //Show call name @@ -697,6 +685,20 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME_CN; builder.write(ctrlCharacteristic, msg); + builder.wait(200); + msg = msg.clone(); + + //Show call number + for (int i = 0; i < msg.length; i++) + msg[i] = ' '; + + for (int i = 0; i < number.length() && i < (msg.length - 1); i++) + msg[i + 1] = (byte) number.charAt(i); + + msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER; + + builder.write(ctrlCharacteristic, msg); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 88685f63d..0bac667b8 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -158,12 +158,14 @@ @string/pref_call_privacy_mode_off @string/pref_call_privacy_mode_name + @string/pref_call_privacy_mode_number @string/pref_call_privacy_mode_complete @string/p_call_privacy_mode_off @string/p_call_privacy_mode_name + @string/pref_call_privacy_mode_number @string/p_call_privacy_mode_complete diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 145262648..61453fbe5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -99,8 +99,10 @@ Call Privacy Mode Display name and number Hide name but display number + Hide number but display name Hide name and number + Blacklist Apps Canned Messages