Dropping some required permissions. Smarter microphone permission.

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

@ -26,8 +26,6 @@
#endif
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
@interface AppDelegate ()
@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 {
[self setupAppearance];
if (getenv("runningTests_dontStartApp")) {
@ -82,6 +79,7 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
[Environment setCurrent:[Release releaseEnvironmentWithLogging:logger]];
[Environment.getCurrent.phoneDirectoryManager startUntilCancelled:nil];
[Environment.getCurrent.contactsManager doAfterEnvironmentInitSetup];
[Environment.getCurrent initCallListener];
[[TSStorageManager sharedManager] setupDatabase];
@ -120,16 +118,6 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
[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]) {
[TSSocketManager becomeActive];
[self refreshContacts];
@ -236,9 +224,6 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
-(void) applicationDidBecomeActive:(UIApplication *)application {
if ([TSAccountManager isRegistered]) {
[TSSocketManager becomeActive];
[AppAudioManager.sharedInstance awake];
[PushManager.sharedManager verifyPushPermissions];
[AppAudioManager.sharedInstance requestRequiredPermissionsIfNeeded];
}
// Hacky way to clear notification center after processed push
[UIApplication.sharedApplication setApplicationIconBadgeNumber:1];

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

@ -1,7 +1,5 @@
#import "AppAudioManager.h"
#import <AVFoundation/AVAudioSession.h>
#import "AudioRouter.h"
#import "SoundBoard.h"
#import "SoundPlayer.h"
@ -13,7 +11,7 @@
AppAudioManager* sharedAppAudioManager;
@interface AppAudioManager (){
@interface AppAudioManager () <UIAlertViewDelegate>{
enum AudioProfile _audioProfile;
BOOL isSpeakerphoneActive;
}
@ -79,7 +77,6 @@ AppAudioManager* sharedAppAudioManager;
switch (progressType){
case CallProgressType_Connecting:
[sharedAppAudioManager setAudioEnabled:YES];
[_soundPlayer stopAllAudio];
case CallProgressType_Ringing:
(initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing];
break;
@ -160,15 +157,27 @@ AppAudioManager* sharedAppAudioManager;
return [self changeAudioSessionCategoryTo:DEFAULT_CATEGORY];
}
-(void) requestRequiredPermissionsIfNeeded {
-(void) requestRequiredPermissionsIfNeededWithCompletion:(PermissionBlock)permissionBlock incoming:(BOOL)isIncoming {
[AVAudioSession.sharedInstance requestRecordPermission:^(BOOL 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];
}
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 {
NSError* e;
[AVAudioSession.sharedInstance setCategory:category error:&e];

@ -90,7 +90,9 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
CFErrorRef creationError = nil;
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &creationError);
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]];
}

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

@ -13,6 +13,7 @@
#import "SignalsViewController.h"
#import "TSStorageManager.h"
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
#define isRegisteredUserDefaultString @"isRegistered"
static Environment* environment = nil;
@ -158,6 +159,19 @@ phoneDirectoryManager;
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{
return [PropertyListPreferences new];
}

@ -28,13 +28,6 @@ typedef void(^failedPushRegistrationBlock)(NSError *error);
+ (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
*

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

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

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

Loading…
Cancel
Save