Dropping some required permissions. Smarter microphone permission.

pull/1/head
Frederic Jacobs 10 years ago
parent 7a5f9f1413
commit 788aa8cb4f

@ -26,8 +26,6 @@
#endif #endif
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
@interface AppDelegate () @interface AppDelegate ()
@property (nonatomic, retain) UIWindow *blankWindow; @property (nonatomic, retain) UIWindow *blankWindow;
@ -68,7 +66,6 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
} }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setupAppearance]; [self setupAppearance];
if (getenv("runningTests_dontStartApp")) { if (getenv("runningTests_dontStartApp")) {
@ -82,6 +79,7 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
[Environment setCurrent:[Release releaseEnvironmentWithLogging:logger]]; [Environment setCurrent:[Release releaseEnvironmentWithLogging:logger]];
[Environment.getCurrent.phoneDirectoryManager startUntilCancelled:nil]; [Environment.getCurrent.phoneDirectoryManager startUntilCancelled:nil];
[Environment.getCurrent.contactsManager doAfterEnvironmentInitSetup]; [Environment.getCurrent.contactsManager doAfterEnvironmentInitSetup];
[Environment.getCurrent initCallListener];
[[TSStorageManager sharedManager] setupDatabase]; [[TSStorageManager sharedManager] setupDatabase];
@ -120,16 +118,6 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
[self prepareScreenshotProtection]; [self prepareScreenshotProtection];
[Environment.phoneManager.currentCallObservable watchLatestValue:^(CallState* latestCall) {
if (latestCall == nil){
return;
}
SignalsViewController *vc = [[Environment getCurrent] signalsViewController];
[vc dismissViewControllerAnimated:NO completion:nil];
vc.latestCall = latestCall;
[vc performSegueWithIdentifier:kCallSegue sender:self];
} onThread:NSThread.mainThread untilCancelled:nil];
if ([TSAccountManager isRegistered]) { if ([TSAccountManager isRegistered]) {
[TSSocketManager becomeActive]; [TSSocketManager becomeActive];
[self refreshContacts]; [self refreshContacts];
@ -236,9 +224,6 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
-(void) applicationDidBecomeActive:(UIApplication *)application { -(void) applicationDidBecomeActive:(UIApplication *)application {
if ([TSAccountManager isRegistered]) { if ([TSAccountManager isRegistered]) {
[TSSocketManager becomeActive]; [TSSocketManager becomeActive];
[AppAudioManager.sharedInstance awake];
[PushManager.sharedManager verifyPushPermissions];
[AppAudioManager.sharedInstance requestRequiredPermissionsIfNeeded];
} }
// Hacky way to clear notification center after processed push // Hacky way to clear notification center after processed push
[UIApplication.sharedApplication setApplicationIconBadgeNumber:1]; [UIApplication.sharedApplication setApplicationIconBadgeNumber:1];

@ -1,5 +1,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioSession.h>
#import "CallProgress.h" #import "CallProgress.h"
#import "CallTermination.h" #import "CallTermination.h"
#import "SoundPlayer.h" #import "SoundPlayer.h"
@ -33,7 +34,7 @@ enum AudioProfile {
-(BOOL) toggleSpeakerPhone; -(BOOL) toggleSpeakerPhone;
-(void) cancellAllAudio; -(void) cancellAllAudio;
-(void) requestRequiredPermissionsIfNeeded; -(void) requestRequiredPermissionsIfNeededWithCompletion:(PermissionBlock)permissionBlock incoming:(BOOL)isIncoming;
-(BOOL) requestRecordingPrivilege; -(BOOL) requestRecordingPrivilege;
-(BOOL) releaseRecordingPrivilege; -(BOOL) releaseRecordingPrivilege;

@ -1,7 +1,5 @@
#import "AppAudioManager.h" #import "AppAudioManager.h"
#import <AVFoundation/AVAudioSession.h>
#import "AudioRouter.h" #import "AudioRouter.h"
#import "SoundBoard.h" #import "SoundBoard.h"
#import "SoundPlayer.h" #import "SoundPlayer.h"
@ -13,7 +11,7 @@
AppAudioManager* sharedAppAudioManager; AppAudioManager* sharedAppAudioManager;
@interface AppAudioManager (){ @interface AppAudioManager () <UIAlertViewDelegate>{
enum AudioProfile _audioProfile; enum AudioProfile _audioProfile;
BOOL isSpeakerphoneActive; BOOL isSpeakerphoneActive;
} }
@ -79,7 +77,6 @@ AppAudioManager* sharedAppAudioManager;
switch (progressType){ switch (progressType){
case CallProgressType_Connecting: case CallProgressType_Connecting:
[sharedAppAudioManager setAudioEnabled:YES]; [sharedAppAudioManager setAudioEnabled:YES];
[_soundPlayer stopAllAudio];
case CallProgressType_Ringing: case CallProgressType_Ringing:
(initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing]; (initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing];
break; break;
@ -160,15 +157,27 @@ AppAudioManager* sharedAppAudioManager;
return [self changeAudioSessionCategoryTo:DEFAULT_CATEGORY]; return [self changeAudioSessionCategoryTo:DEFAULT_CATEGORY];
} }
-(void) requestRequiredPermissionsIfNeeded { -(void) requestRequiredPermissionsIfNeededWithCompletion:(PermissionBlock)permissionBlock incoming:(BOOL)isIncoming {
[AVAudioSession.sharedInstance requestRecordPermission:^(BOOL granted) { [AVAudioSession.sharedInstance requestRecordPermission:^(BOOL granted) {
if (!granted) { if (!granted) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ACTION_REQUIRED_TITLE", @"") message:NSLocalizedString(@"AUDIO_PERMISSION_MESSAGE", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ACTION_REQUIRED_TITLE", @"") message:NSLocalizedString(@"AUDIO_PERMISSION_MESSAGE", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") otherButtonTitles:NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE",nil), nil];
[alertView setDelegate:self];
[alertView show]; [alertView show];
} }
permissionBlock(granted);
}]; }];
} }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) { // Tapped the Settings button
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
}
}
-(BOOL) changeAudioSessionCategoryTo:(NSString*) category { -(BOOL) changeAudioSessionCategoryTo:(NSString*) category {
NSError* e; NSError* e;
[AVAudioSession.sharedInstance setCategory:category error:&e]; [AVAudioSession.sharedInstance setCategory:category error:&e];

@ -90,7 +90,9 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
CFErrorRef creationError = nil; CFErrorRef creationError = nil;
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &creationError); ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &creationError);
checkOperationDescribe(nil == creationError, [((__bridge NSError *)creationError) localizedDescription]) ; checkOperationDescribe(nil == creationError, [((__bridge NSError *)creationError) localizedDescription]) ;
ABAddressBookRequestAccessWithCompletion(addressBookRef, nil); ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// TO DO: DISPLAY ALERT
});
[observableContactsController updateValue:[self getContactsFromAddressBook:addressBookRef]]; [observableContactsController updateValue:[self getContactsFromAddressBook:addressBookRef]];
} }

@ -80,6 +80,8 @@ andCurrentRegionCodeForPhoneNumbers:(NSString*)currentRegionCodeForPhoneNumbers
+(BOOL)isRedPhoneRegistered; +(BOOL)isRedPhoneRegistered;
+(void)resetAppData; +(void)resetAppData;
- (void)initCallListener;
- (void)setSignalsViewController:(SignalsViewController *)signalsViewController; - (void)setSignalsViewController:(SignalsViewController *)signalsViewController;
- (void)setSignUpFlowNavigationController:(UINavigationController *)signUpFlowNavigationController; - (void)setSignUpFlowNavigationController:(UINavigationController *)signUpFlowNavigationController;

@ -13,6 +13,7 @@
#import "SignalsViewController.h" #import "SignalsViewController.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
#define isRegisteredUserDefaultString @"isRegistered" #define isRegisteredUserDefaultString @"isRegistered"
static Environment* environment = nil; static Environment* environment = nil;
@ -158,6 +159,19 @@ phoneDirectoryManager;
return signalingKey && macKey && extra && serverAuth; return signalingKey && macKey && extra && serverAuth;
} }
- (void)initCallListener {
[self.phoneManager.currentCallObservable watchLatestValue:^(CallState* latestCall) {
if (latestCall == nil){
return;
}
SignalsViewController *vc = [[Environment getCurrent] signalsViewController];
[vc dismissViewControllerAnimated:NO completion:nil];
vc.latestCall = latestCall;
[vc performSegueWithIdentifier:kCallSegue sender:self];
} onThread:NSThread.mainThread untilCancelled:nil];
}
+(PropertyListPreferences*)preferences{ +(PropertyListPreferences*)preferences{
return [PropertyListPreferences new]; return [PropertyListPreferences new];
} }

@ -28,13 +28,6 @@ typedef void(^failedPushRegistrationBlock)(NSError *error);
+ (PushManager*)sharedManager; + (PushManager*)sharedManager;
/**
* Push notification token is always registered during signup. User can however revoke notifications.
* Therefore, we check on startup if mandatory permissions are granted.
*/
- (void)verifyPushPermissions;
/** /**
* Push notification registration method * Push notification registration method
* *

@ -16,8 +16,7 @@
@interface PushManager () @interface PushManager ()
@property TOCFutureSource *registerWithServerFutureSource; @property TOCFutureSource *registerWithServerFutureSource;
@property UIAlertView *missingPermissionsAlertView; @property UIAlertView *missingPermissionsAlertView;
@end @end
@ -44,18 +43,7 @@
return self; return self;
} }
- (void)verifyPushPermissions{
if (self.isMissingMandatoryNotificationTypes || self.needToRegisterForRemoteNotifications){
[self registrationWithSuccess:^{
DDLogInfo(@"Re-enabled push succesfully");
} failure:^(NSError *error) {
DDLogError(@"Failed to re-register for push");
}];
}
}
- (void)registrationWithSuccess:(void (^)())success failure:(failedPushRegistrationBlock)failure{ - (void)registrationWithSuccess:(void (^)())success failure:(failedPushRegistrationBlock)failure{
if (!self.wantRemoteNotifications) { if (!self.wantRemoteNotifications) {
success(); success();
return; return;
@ -69,7 +57,6 @@
} failure:failure]; } failure:failure];
} }
#pragma mark Private Methods #pragma mark Private Methods
#pragma mark Register Push Notification Token with server #pragma mark Register Push Notification Token with server
@ -128,7 +115,6 @@
}]; }];
} }
- (void)registrationAndRedPhoneTokenRequestWithSuccess:(void (^)(NSData* pushToken, NSString* signupToken))success failure:(failedPushRegistrationBlock)failure{ - (void)registrationAndRedPhoneTokenRequestWithSuccess:(void (^)(NSData* pushToken, NSString* signupToken))success failure:(failedPushRegistrationBlock)failure{
[self registrationForPushWithSuccess:^(NSData *pushToken) { [self registrationForPushWithSuccess:^(NSData *pushToken) {
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall requestTextSecureVerificationCode] success:^(NSURLSessionDataTask *task, id responseObject) { [RPServerRequestsManager.sharedInstance performRequest:[RPAPICall requestTextSecureVerificationCode] success:^(NSURLSessionDataTask *task, id responseObject) {
@ -165,11 +151,7 @@
}]; }];
[registrerUserNotificationFuture thenDo:^(id types) { [registrerUserNotificationFuture thenDo:^(id types) {
if (self.isMissingMandatoryNotificationTypes) { success();
failure();
} else{
success();
}
}]; }];
} }
@ -188,20 +170,8 @@
return YES; return YES;
} }
-(BOOL)isMissingMandatoryNotificationTypes {
int mandatoryTypes = self.mandatoryNotificationTypes;
int currentTypes = UIApplication.sharedApplication.currentUserNotificationSettings.types;
return (mandatoryTypes & currentTypes) != mandatoryTypes;
}
-(int)allNotificationTypes{ -(int)allNotificationTypes{
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge; return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
} }
-(int)mandatoryNotificationTypes{
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
}
@end @end

@ -1,3 +1,4 @@
#import "AppAudioManager.h"
#import "CallAudioManager.h" #import "CallAudioManager.h"
#import "PhoneManager.h" #import "PhoneManager.h"
#import "ThreadManager.h" #import "ThreadManager.h"
@ -52,22 +53,30 @@
-(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact { -(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact {
require(remoteNumber != nil); require(remoteNumber != nil);
[[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) {
if (granted) {
[self callToRemoteNumber:remoteNumber withOptionallyKnownContact:contact];
}
} incoming:NO];
}
- (void)callToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact {
CallController* callController = [self cancelExistingCallAndInitNewCallWork:true CallController* callController = [self cancelExistingCallAndInitNewCallWork:true
remote:remoteNumber remote:remoteNumber
optionalContact:contact]; optionalContact:contact];
[callController acceptCall]; // initiator implicitly accepts call [callController acceptCall]; // initiator implicitly accepts call
TOCCancelToken* lifetime = [callController untilCancelledToken]; TOCCancelToken* lifetime = [callController untilCancelledToken];
TOCFuture* futureConnected = [CallConnectUtil asyncInitiateCallToRemoteNumber:remoteNumber TOCFuture* futureConnected = [CallConnectUtil asyncInitiateCallToRemoteNumber:remoteNumber
andCallController:callController]; andCallController:callController];
TOCFuture* futureCalling = [futureConnected thenTry:^id(CallConnectResult* connectResult) { TOCFuture* futureCalling = [futureConnected thenTry:^id(CallConnectResult* connectResult) {
[callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString]; [callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
CallAudioManager *cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket CallAudioManager *cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket
andErrorHandler:callController.errorHandler andErrorHandler:callController.errorHandler
untilCancelled:lifetime]; untilCancelled:lifetime];
[callController setCallAudioManager:cam]; [callController setCallAudioManager:cam];
return nil; return nil;
}]; }];
@ -96,28 +105,32 @@
return; return;
} }
Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber]; [[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) {
CallController* callController = [self cancelExistingCallAndInitNewCallWork:false if (granted) {
remote:session.initiatorNumber Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber];
optionalContact:callingContact]; CallController* callController = [self cancelExistingCallAndInitNewCallWork:false
remote:session.initiatorNumber
TOCCancelToken* lifetime = [callController untilCancelledToken]; optionalContact:callingContact];
TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session TOCCancelToken* lifetime = [callController untilCancelledToken];
andCallController:callController];
TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session
TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) { andCallController:callController];
[callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) {
andErrorHandler:callController.errorHandler [callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
untilCancelled:lifetime]; CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket
[callController setCallAudioManager:cam]; andErrorHandler:callController.errorHandler
return nil; untilCancelled:lifetime];
}]; [callController setCallAudioManager:cam];
return nil;
[futureStarted catchDo:^(id error) { }];
callController.errorHandler(error, nil, true);
}]; [futureStarted catchDo:^(id error) {
callController.errorHandler(error, nil, true);
}];
}
} incoming:YES];
} }
-(CallController*) curCallController { -(CallController*) curCallController {
return currentCallControllerObservable.currentValue; return currentCallControllerObservable.currentValue;

@ -49,6 +49,7 @@ static NSString *const kCodeSentSegue = @"codeSent";
[_countryNameButton setTitle:NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"") forState:UIControlStateNormal]; [_countryNameButton setTitle:NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"") forState:UIControlStateNormal];
_phoneNumberTextField.placeholder = NSLocalizedString(@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @""); _phoneNumberTextField.placeholder = NSLocalizedString(@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"");
[_phoneNumberButton setTitle:NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON",@"") forState:UIControlStateNormal]; [_phoneNumberButton setTitle:NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON",@"") forState:UIControlStateNormal];
[_phoneNumberButton.titleLabel setAdjustsFontSizeToFitWidth:YES];
[_sendCodeButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal]; [_sendCodeButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal];
} }

Loading…
Cancel
Save