Add and honor the “CallKit Privacy” setting.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent f5004b27ab
commit 01d2582074

@ -18,6 +18,7 @@
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "TSMessagesManager.h" #import "TSMessagesManager.h"
#import "TSSocketManager.h" #import "TSSocketManager.h"
#import "TSStorageManager+Calling.h"
#import "TextSecureKitEnv.h" #import "TextSecureKitEnv.h"
#import "VersionMigrations.h" #import "VersionMigrations.h"
#import <AxolotlKit/SessionCipher.h> #import <AxolotlKit/SessionCipher.h>
@ -377,6 +378,15 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) {
DDLogWarn(@"%@ ignoring attempt to initiate video call to unknown anonymous signal user.", self.tag);
return NO;
}
}
// This intent can be received from more than one user interaction. // This intent can be received from more than one user interaction.
// //
// * It can be received if the user taps the "video" button in the CallKit UI for an // * It can be received if the user taps the "video" button in the CallKit UI for an
@ -386,7 +396,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// contacts app. If so, the correct response is to try to initiate a new call // contacts app. If so, the correct response is to try to initiate a new call
// to that user - unless there already is another call in progress. // to that user - unless there already is another call in progress.
if ([Environment getCurrent].callService.call != nil) { if ([Environment getCurrent].callService.call != nil) {
if ([handle isEqualToString:[Environment getCurrent].callService.call.remotePhoneNumber]) { if ([phoneNumber isEqualToString:[Environment getCurrent].callService.call.remotePhoneNumber]) {
DDLogWarn(@"%@ trying to upgrade ongoing call to video.", self.tag); DDLogWarn(@"%@ trying to upgrade ongoing call to video.", self.tag);
[[Environment getCurrent].callService handleCallKitStartVideo]; [[Environment getCurrent].callService handleCallKitStartVideo];
return YES; return YES;
@ -399,7 +409,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator;
OWSAssert(outboundCallInitiator); OWSAssert(outboundCallInitiator);
return [outboundCallInitiator initiateCallWithHandle:handle]; return [outboundCallInitiator initiateCallWithHandle:phoneNumber];
} else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) { } else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) {
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) { if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) {
@ -423,6 +433,15 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
NSString *_Nullable phoneNumber = handle;
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
phoneNumber = [[TSStorageManager sharedManager] phoneNumberForCallKitId:handle];
if (phoneNumber.length < 1) {
DDLogWarn(@"%@ ignoring attempt to initiate audio call to unknown anonymous signal user.", self.tag);
return NO;
}
}
if ([Environment getCurrent].phoneManager.hasOngoingRedphoneCall) { if ([Environment getCurrent].phoneManager.hasOngoingRedphoneCall) {
DDLogWarn(@"%@ ignoring INStartAudioCallIntent due to ongoing RedPhone call.", self.tag); DDLogWarn(@"%@ ignoring INStartAudioCallIntent due to ongoing RedPhone call.", self.tag);
return NO; return NO;
@ -434,7 +453,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator;
OWSAssert(outboundCallInitiator); OWSAssert(outboundCallInitiator);
return [outboundCallInitiator initiateCallWithHandle:handle]; return [outboundCallInitiator initiateCallWithHandle:phoneNumber];
} else { } else {
DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.", DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.",
self.tag, self.tag,

@ -21,6 +21,7 @@
#import "PushManager.h" #import "PushManager.h"
#import "RPAccountManager.h" #import "RPAccountManager.h"
#import "TSSocketManager.h" #import "TSSocketManager.h"
#import "TSStorageManager+Calling.h"
#import "UIColor+OWS.h" #import "UIColor+OWS.h"
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
#import "UIUtil.h" #import "UIUtil.h"

@ -23,9 +23,15 @@ final class CallKitCallManager: NSObject {
// MARK: Actions // MARK: Actions
func startCall(_ call: SignalCall) { func startCall(_ call: SignalCall) {
let handle = (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() var handle: CXHandle
? CXHandle(type: .generic, value: CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString) if Environment.getCurrent().preferences.isCallKitPrivacyEnabled() {
: CXHandle(type: .phoneNumber, value: call.remotePhoneNumber)) let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString
handle = CXHandle(type: .generic, value: callKitId)
TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId:callKitId)
} else {
handle = CXHandle(type: .phoneNumber, value: call.remotePhoneNumber)
}
let startCallAction = CXStartCallAction(call: call.localId, handle: handle) let startCallAction = CXStartCallAction(call: call.localId, handle: handle)
startCallAction.isVideo = call.hasLocalVideo startCallAction.isVideo = call.hasLocalVideo

@ -100,9 +100,14 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
// Construct a CXCallUpdate describing the incoming call, including the caller. // Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate() let update = CXCallUpdate()
update.remoteHandle = (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() if Environment.getCurrent().preferences.isCallKitPrivacyEnabled() {
? CXHandle(type: .generic, value: CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString) let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString
: CXHandle(type: .phoneNumber, value: call.remotePhoneNumber)) update.remoteHandle = CXHandle(type: .generic, value: callKitId)
TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId:callKitId)
} else {
update.remoteHandle = CXHandle(type: .phoneNumber, value: call.remotePhoneNumber)
}
update.hasVideo = call.hasLocalVideo update.hasVideo = call.hasLocalVideo
// Update the name used in the CallKit UI for incoming calls. // Update the name used in the CallKit UI for incoming calls.
update.localizedCallerName = NSLocalizedString("CALLKIT_ANONYMOUS_CONTACT_NAME", comment: "The generic name used for calls if CallKit privacy is enabled") update.localizedCallerName = NSLocalizedString("CALLKIT_ANONYMOUS_CONTACT_NAME", comment: "The generic name used for calls if CallKit privacy is enabled")
@ -241,9 +246,9 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
ensureCallName(call:call) ensureCallName(call:call)
} }
func ensureCallName(call : SignalCall) { func ensureCallName(call: SignalCall) {
guard Environment.getCurrent().preferences.isCallKitPrivacyEnabled() else { guard Environment.getCurrent().preferences.isCallKitPrivacyEnabled() else {
return; return
} }
// Update the name used in the CallKit UI for outgoing calls. // Update the name used in the CallKit UI for outgoing calls.

Loading…
Cancel
Save