mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-04-30 17:36:22 +00:00
Notify the user (once) if during a video call the battery level goes below 10%
This commit is contained in:
parent
e0c46d1ba7
commit
bbc4e348f1
5 changed files with 64 additions and 2 deletions
|
|
@ -24,7 +24,8 @@ enum CallDelegateType {
|
||||||
CD_UNDEFINED = 0,
|
CD_UNDEFINED = 0,
|
||||||
CD_NEW_CALL,
|
CD_NEW_CALL,
|
||||||
CD_ZRTP,
|
CD_ZRTP,
|
||||||
CD_VIDEO_UPDATE
|
CD_VIDEO_UPDATE,
|
||||||
|
CD_STOP_VIDEO_ON_LOW_BATTERY
|
||||||
};
|
};
|
||||||
|
|
||||||
@protocol UIActionSheetCustomDelegate
|
@protocol UIActionSheetCustomDelegate
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,38 @@ void addAnimationFadeTransition(UIView* view, float duration) {
|
||||||
hideControlsTimer = nil;
|
hideControlsTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) batteryLevelChanged: (NSNotification*) notif {
|
||||||
|
LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]);
|
||||||
|
if (!call || !linphone_call_params_video_enabled(linphone_call_get_current_params(call)))
|
||||||
|
return;
|
||||||
|
LinphoneCallAppData* appData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call);
|
||||||
|
if ([UIDevice currentDevice].batteryState == UIDeviceBatteryStateUnplugged) {
|
||||||
|
float level = [UIDevice currentDevice].batteryLevel;
|
||||||
|
ms_message("Video call is running. Battery level: %.2f", level);
|
||||||
|
if (level < 0.1 && !appData->batteryWarningShown) {
|
||||||
|
// notify user
|
||||||
|
CallDelegate* cd = [[CallDelegate alloc] init];
|
||||||
|
cd.eventType = CD_STOP_VIDEO_ON_LOW_BATTERY;
|
||||||
|
cd.delegate = self;
|
||||||
|
cd.call = call;
|
||||||
|
|
||||||
|
if (visibleActionSheet != nil) {
|
||||||
|
[visibleActionSheet dismissWithClickedButtonIndex:visibleActionSheet.cancelButtonIndex animated:TRUE];
|
||||||
|
}
|
||||||
|
NSString* title = NSLocalizedString(@"Battery is running low. Stop video ?",nil);
|
||||||
|
visibleActionSheet = [[UIActionSheet alloc] initWithTitle:title
|
||||||
|
delegate:cd
|
||||||
|
cancelButtonTitle:NSLocalizedString(@"Continue video",nil)
|
||||||
|
destructiveButtonTitle:NSLocalizedString(@"Stop video",nil)
|
||||||
|
otherButtonTitles:nil];
|
||||||
|
|
||||||
|
visibleActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
|
||||||
|
[visibleActionSheet showInView:self.view];
|
||||||
|
appData->batteryWarningShown = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-(void) enableVideoDisplay {
|
-(void) enableVideoDisplay {
|
||||||
[self orientationChanged:nil];
|
[self orientationChanged:nil];
|
||||||
|
|
||||||
|
|
@ -233,6 +265,8 @@ void addAnimationFadeTransition(UIView* view, float duration) {
|
||||||
NSLog(@"new center: %f %f", videoView.center.x, videoView.center.y);
|
NSLog(@"new center: %f %f", videoView.center.x, videoView.center.y);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self batteryLevelChanged:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) disableVideoDisplay {
|
-(void) disableVideoDisplay {
|
||||||
|
|
@ -392,7 +426,9 @@ void addAnimationFadeTransition(UIView* view, float duration) {
|
||||||
|
|
||||||
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryLevelChanged:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
|
||||||
|
|
||||||
|
|
||||||
[videoCameraSwitch setPreview:videoPreview];
|
[videoCameraSwitch setPreview:videoPreview];
|
||||||
addVideo.videoUpdateIndicator = videoUpdateIndicator;
|
addVideo.videoUpdateIndicator = videoUpdateIndicator;
|
||||||
|
|
||||||
|
|
@ -976,6 +1012,16 @@ void addAnimationFadeTransition(UIView* view, float duration) {
|
||||||
visibleActionSheet = nil;
|
visibleActionSheet = nil;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CD_STOP_VIDEO_ON_LOW_BATTERY: {
|
||||||
|
LinphoneCall* call = (LinphoneCall*)datas;
|
||||||
|
LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call));
|
||||||
|
if ([visibleActionSheet destructiveButtonIndex] == buttonIndex) {
|
||||||
|
// stop video
|
||||||
|
linphone_call_params_enable_video(paramsCopy, FALSE);
|
||||||
|
linphone_core_update_call([LinphoneManager getLc], call, paramsCopy);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ms_error("Unhandled CallDelegate event of type: %d received - ignoring", type);
|
ms_error("Unhandled CallDelegate event of type: %d received - ignoring", type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,8 @@ int __aeabi_idiv(int a, int b) {
|
||||||
[window makeKeyAndVisible];
|
[window makeKeyAndVisible];
|
||||||
|
|
||||||
[[LinphoneManager instance] setCallDelegate:myPhoneViewController];
|
[[LinphoneManager instance] setCallDelegate:myPhoneViewController];
|
||||||
|
|
||||||
|
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) setupGSMInteraction {
|
-(void) setupGSMInteraction {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ struct NetworkReachabilityContext {
|
||||||
void (*networkStateChanged) (Connectivity newConnectivity);
|
void (*networkStateChanged) (Connectivity newConnectivity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct _LinphoneCallAppData {
|
||||||
|
bool_t batteryWarningShown;
|
||||||
|
} LinphoneCallAppData;
|
||||||
|
|
||||||
|
|
||||||
@interface LinphoneManager : NSObject <AVAudioSessionDelegate> {
|
@interface LinphoneManager : NSObject <AVAudioSessionDelegate> {
|
||||||
@protected
|
@protected
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,12 @@ extern void libmsbcg729_init();
|
||||||
|
|
||||||
bool canHideInCallView = (linphone_core_get_calls([LinphoneManager getLc]) == NULL);
|
bool canHideInCallView = (linphone_core_get_calls([LinphoneManager getLc]) == NULL);
|
||||||
|
|
||||||
|
if (!linphone_call_get_user_pointer(call)) {
|
||||||
|
LinphoneCallAppData* data = (LinphoneCallAppData*) malloc(sizeof(LinphoneCallAppData));
|
||||||
|
data->batteryWarningShown = FALSE;
|
||||||
|
linphone_call_set_user_pointer(call, data);
|
||||||
|
}
|
||||||
|
|
||||||
switch (new_state) {
|
switch (new_state) {
|
||||||
case LinphoneCallIncomingReceived:
|
case LinphoneCallIncomingReceived:
|
||||||
[callDelegate displayIncomingCall:call
|
[callDelegate displayIncomingCall:call
|
||||||
|
|
@ -262,6 +268,9 @@ extern void libmsbcg729_init();
|
||||||
[callDelegate displayInCall:call FromUI:mCurrentViewController forUser:lUserName withDisplayName:lDisplayName];
|
[callDelegate displayInCall:call FromUI:mCurrentViewController forUser:lUserName withDisplayName:lDisplayName];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case LinphoneCallReleased:
|
||||||
|
free (linphone_call_get_user_pointer(call));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue