forked from e-mission/e-mission-data-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implmentation of the status screen
- End-to-end implementation of the "check" parts of the interface - Code structure similar to the existing android code for simplicity - checks defined in `TripDiarySensorControlChecks` - interface with the plugin in `SensorControlForegroundDelegate` - interface with the background code to generate error notifications in `SensorControlBackgroundChecker` Testing done: With the UI changes in: e-mission/e-mission-phone@d69f3a5 the plugin -> foreground delegate -> checks pipeline works e-mission/e-mission-phone#812 (comment) TO DO: - Background checks need to be tested - Implement the "fix" methods in addition to the "check" methods
- Loading branch information
Showing
13 changed files
with
307 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
#import <UIKit/UIKit.h> | ||
#import <CoreMotion/CoreMotion.h> | ||
|
||
@interface SensorControlBackgroundChecker: NSObject | ||
|
||
+(void)restartFSMIfStartState; | ||
+(void)checkAppState; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#import "SensorControlBackgroundChecker.h" | ||
#import "TripDiarySensorControlChecks.h" | ||
#import "TripDiaryStateMachine.h" | ||
#import "LocalNotificationManager.h" | ||
#import "BEMAppDelegate.h" | ||
#import "BEMActivitySync.h" | ||
|
||
#import <CoreMotion/CoreMotion.h> | ||
#define OPEN_APP_STATUS_PAGE_ID @362253744 | ||
|
||
@implementation SensorControlBackgroundChecker | ||
|
||
+(NSDictionary*)OPEN_APP_STATUS_PAGE | ||
{ | ||
NSDictionary* config = @{ | ||
@"id": OPEN_APP_STATUS_PAGE_ID, | ||
@"title": NSLocalizedStringFromTable(@"fix_app_status_title", @"DCLocalizable", nil), | ||
@"text": NSLocalizedStringFromTable(@"fix_app_status_text", @"DCLocalizable", nil), | ||
@"data": @{ | ||
@"redirectTo": @"root.main.control", | ||
@"redirectParams": @{ | ||
@"launchAppStatusModal": @true | ||
} | ||
} | ||
}; | ||
return config; | ||
} | ||
|
||
+(void)restartFSMIfStartState | ||
{ | ||
NSUInteger currState = [TripDiaryStateMachine instance].currState; | ||
if (currState == kStartState) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Still in start state, sending initialize..."] showUI:TRUE]; | ||
[[NSNotificationCenter defaultCenter] postNotificationName:CFCTransitionNotificationName | ||
object:CFCTransitionInitialize]; | ||
} else { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"In valid state %@, nothing to do...", [TripDiaryStateMachine getStateName:currState]] showUI:FALSE]; | ||
} | ||
} | ||
|
||
+(void)checkAppState | ||
{ | ||
[LocalNotificationManager cancelNotification:OPEN_APP_STATUS_PAGE_ID]; | ||
|
||
NSArray* allChecks = @[ | ||
@([TripDiarySensorControlChecks checkLocationSettings]), | ||
@([TripDiarySensorControlChecks checkLocationPermissions]), | ||
@([TripDiarySensorControlChecks checkMotionActivitySettings]), | ||
@([TripDiarySensorControlChecks checkMotionActivityPermissions]), | ||
@([TripDiarySensorControlChecks checkNotificationsEnabled]) | ||
]; | ||
BOOL allChecksPass = true; | ||
for (id check in allChecks) { | ||
allChecksPass = allChecksPass && check; | ||
} | ||
|
||
BOOL locChecksPass = allChecks[0] && allChecks[1]; | ||
|
||
if (allChecksPass) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"All settings valid, nothing to prompt"]]; | ||
[self restartFSMIfStartState]; | ||
} | ||
else if (locChecksPass) { | ||
/* | ||
Log.i(ctxt, TAG, "all checks = "+allOtherChecksPass+" but location permission status "+allOtherChecks[0]+" should be true "+ | ||
" so one of the non-location checks must be false: loc permission, motion permission, notification, unused apps" + Arrays.toString(allOtherChecks)); | ||
Log.i(ctxt, TAG, "a non-local check failed, generating only user visible notification"); | ||
*/ | ||
[self generateOpenAppSettingsNotification]; | ||
} | ||
else { | ||
/* | ||
Log.i(ctxt, TAG, "location settings are valid, but location permission is not, generating tracking error and visible notification"); | ||
Log.i(ctxt, TAG, "curr status check results = " + | ||
" loc permission, motion permission, notification, unused apps "+ Arrays.toString(allOtherChecks)); | ||
*/ | ||
// Should replace with TRACKING_ERROR but looks like we | ||
// don't have any | ||
[[NSNotificationCenter defaultCenter] | ||
postNotificationName:CFCTransitionNotificationName | ||
object:CFCTransitionGeofenceCreationError]; | ||
[self generateOpenAppSettingsNotification]; | ||
} | ||
} | ||
|
||
+(void)generateOpenAppSettingsNotification | ||
{ | ||
[LocalNotificationManager schedulePluginCompatibleNotification:[self OPEN_APP_STATUS_PAGE] withNewData:NULL]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#import <Cordova/CDV.h> | ||
#import <Foundation/Foundation.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
#import <UIKit/UIKit.h> | ||
#import <CoreMotion/CoreMotion.h> | ||
|
||
@interface SensorControlForegroundDelegate: NSObject | ||
|
||
+(void)checkLocationSettings:(id<CDVCommandDelegate>)delegate forCommand:(CDVInvokedUrlCommand*)command; | ||
+(void)checkLocationPermissions:(id<CDVCommandDelegate>)delegate forCommand:(CDVInvokedUrlCommand*)command; | ||
+(void)checkMotionActivitySettings:(id<CDVCommandDelegate>)delegate | ||
forCommand:(CDVInvokedUrlCommand*)command; | ||
+(void)checkMotionActivityPermissions:(id<CDVCommandDelegate>)delegate forCommand:(CDVInvokedUrlCommand*)command; | ||
+(void)checkNotificationsEnabled:(id<CDVCommandDelegate>)delegate forCommand:(CDVInvokedUrlCommand*)command; | ||
@end |
Oops, something went wrong.