Skip to content

Commit

Permalink
Merge pull request #195 from shankari/native_upgrade_2021
Browse files Browse the repository at this point in the history
Native upgrade 2021
  • Loading branch information
shankari authored Feb 23, 2022
2 parents 650965f + a081e06 commit 8dcd9b4
Show file tree
Hide file tree
Showing 35 changed files with 1,611 additions and 483 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-em-datacollection",
"version": "1.6.0",
"version": "1.7.0",
"description": "The main tracking for the e-mission platform",
"license": "BSD-3-clause",
"cordova": {
Expand Down
29 changes: 22 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-em-datacollection"
version="1.6.1">
version="1.7.0">

<name>DataCollection</name>
<description>Background data collection FTW! This is the part that I really
Expand Down Expand Up @@ -117,9 +117,13 @@
</service>
</config-file>

<framework src="com.google.code.gson:gson:2.8.5"/>
<framework src="com.google.code.gson:gson:2.8.8"/>
<framework src="com.google.android.gms:play-services-location:$LOCATION_VERSION"/>
<preference name="LOCATION_VERSION" default="17.0.0"/>
<preference name="LOCATION_VERSION" default="18.0.0"/>
<framework src="androidx.core:core:$ANDROIDX_CORE_VERSION"/>
<preference name="ANDROIDX_CORE_VERSION" default="1.7.0"/>

<framework src="src/android/enable_api_31.gradle" custom="true" type="gradleReference" />

<source-file src="src/android/DataCollectionPlugin.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker"/>
<source-file src="src/android/BootReceiver.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker"/>
Expand All @@ -144,6 +148,7 @@
<source-file src="src/android/sensors/PollSensor.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/sensors"/>
<source-file src="src/android/sensors/PollSensorManager.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/sensors"/>
<source-file src="src/android/verification/SensorControlConstants.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/verification"/>
<source-file src="src/android/verification/SensorControlChecks.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/verification"/>
<source-file src="src/android/verification/SensorControlBackgroundChecker.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/verification"/>
<source-file src="src/android/verification/SensorControlForegroundDelegate.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/verification"/>
<source-file src="src/android/wrapper/Metadata.java" target-dir="src/edu/berkeley/eecs/emission/cordova/tracker/wrapper"/>
Expand Down Expand Up @@ -196,10 +201,16 @@
<false/>
</config-file>

<framework src="Bolts/Tasks" type="podspec" spec="~> 1.9.0"/>
<podspec>
<config>
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="Bolts/Tasks" spec="~> 1.9.1" />
</pods>
</podspec>

<framework src="CoreLocation.framework"/>
<framework src="Accounts.framework"/>

<header-file src="src/ios/BEMDataCollection.h"/>
<header-file src="src/ios/BEMAppDelegate.h"/>
Expand All @@ -210,7 +221,9 @@
<header-file src="src/ios/Location/TripDiaryActions.h" target-dir="Location"/>
<header-file src="src/ios/Location/TripDiaryDelegate.h" target-dir="Location"/>
<header-file src="src/ios/Location/TripDiaryStateMachine.h" target-dir="Location"/>
<header-file src="src/ios/Location/TripDiarySettingsCheck.h" target-dir="Location"/>
<header-file src="src/ios/Verification/TripDiarySensorControlChecks.h" target-dir="Verification"/>
<header-file src="src/ios/Verification/SensorControlForegroundDelegate.h" target-dir="Verification"/>
<header-file src="src/ios/Verification/SensorControlBackgroundChecker.h" target-dir="Verification"/>
<header-file src="src/ios/Wrapper/Metadata.h" target-dir="Wrapper"/>
<header-file src="src/ios/Wrapper/MotionActivity.h" target-dir="Wrapper"/>
<header-file src="src/ios/Wrapper/SimpleLocation.h" target-dir="Wrapper"/>
Expand All @@ -230,7 +243,9 @@
<source-file src="src/ios/Location/TripDiaryActions.m" target-dir="Location"/>
<source-file src="src/ios/Location/TripDiaryDelegate.m" target-dir="Location"/>
<source-file src="src/ios/Location/TripDiaryStateMachine.m" target-dir="Location"/>
<source-file src="src/ios/Location/TripDiarySettingsCheck.m" target-dir="Location"/>
<source-file src="src/ios/Verification/TripDiarySensorControlChecks.m" target-dir="Verification"/>
<source-file src="src/ios/Verification/SensorControlForegroundDelegate.m" target-dir="Verification"/>
<source-file src="src/ios/Verification/SensorControlBackgroundChecker.m" target-dir="Verification"/>
<source-file src="src/ios/Wrapper/Metadata.m" target-dir="Wrapper"/>
<source-file src="src/ios/Wrapper/MotionActivity.m" target-dir="Wrapper"/>
<source-file src="src/ios/Wrapper/SimpleLocation.m" target-dir="Wrapper"/>
Expand Down
10 changes: 10 additions & 0 deletions res/android/values/dc_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
<!-- TripDiaryStateMachineService and Ongoing-->
<string name="success_moving_new_state">Success moving to %1$s</string>
<string name="failed_moving_new_state">Failed moving to %1$s</string>
<string name="location_permission_off">Insufficient location permissions, please fix</string>
<string name="location_permission_off_app_open">Insufficient location permissions, please fix in app settings</string>
<string name="location_permission_off_enable">Location permission off, click to enable</string>
<string name="background_loc_permission_off_enable">Background location permission off, click to enable</string>
<string name="activity_permission_off">Activity permission off, please fix</string>
<string name="activity_permission_off_app_open">Activity permission off, please fix in app settings</string>
<string name="activity_permission_off_enable">Activity permission off, click to enable</string>
<string name="notifications_blocked">Notifications blocked, please enable</string>
<string name="notifications_paused">Notifications paused. This can only be fixed by the app developer. Please report to your admin.</string>
<string name="unused_apps_restricted">Please allow this app to read sensor data even if you launch it infrequently.</string>
<string name="fix_app_status_title">Incorrect app settings</string>
<string name="fix_app_status_text">Click to view and fix app status</string>
<string name="error_location_settings">Error in location settings, click to resolve</string>
<string name="unknown_error_location_settings">Unknown error while reading location, please check your settings</string>
<string name="notify_curr_state">In state %1$s</string>
Expand All @@ -28,6 +37,7 @@
<!-- ConfigManager -->
<string name="error_reading_stored_config">Error reading stored tracking config, reset to defaults</string>
<!-- DataCollectionPlugin -->
<string name="user_rejected_setting">It looks like you canceled the requested change. Please accept it instead.</string>
<string name="unable_resolve_issue">Unrecoverable error in tracking, report at Profile -> Upload Log</string>
<!-- State notification displays-->
<string name="local.state.waiting_for_trip_start">Ready for your next trip</string>
Expand Down
18 changes: 14 additions & 4 deletions res/ios/en.lproj/DCLocalizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
"new-data-collections-terms" = "New data collection terms - collection paused until consent";
"error-reading-activities" = "Error while reading activities";
"travel-mode-unavailable" = "Travel mode detection may be unavailable.";
"activity-detection-unsupported" = "Activity detection unsupported";
"activity-permission-problem" = "No 'Motion & Fitness' permission - automatic mode detection will not work. Turn it on (Settings -> app)";
"activity-turned-off-problem" = "Motion & Fitness Service disabled - automatic mode detection will not work. Turn it on (Settings -> Privacy)";
"activity-detection-unsupported" = "Activity detection unsupported. Please uninstall.";
"activity-permission-problem" = "'Motion & Fitness' permission off, please fix in app settings";
"activity-turned-off-problem" = "Motion & Fitness Service disabled. Turn it on (Phone Settings -> Privacy) and *restart the app*";
"travel-mode-unknown" = "Travel mode detection unavailable - all trips will be UNKNOWN.";
"bad-loc-tracking-problem" = "Background location accuracy is consistently poor - trip tracking may not work. Report problem.";
"location-turned-off-problem" = "Location Services are turned off - trip tracking will not work. Turn it on (Settings -> Privacy)";
"location-turned-off-problem" = "Location Services are turned off. Turn it on (Settings -> Privacy)";
"fix-service-action-button" = "Launch Settings";
"permission-problem-title" = "Incorrect permission";
"location-permission-problem" = "The app does not have the 'always' permission - background trip tracking will not work.";
"fix-permission-action-button" = "Fix permission";
"precise-location-problem" = "The app does not have permission to read 'precise' location - background trip tracking will not work.";
"notifications_blocked" = "Notifications blocked, please enable";
"notifications_blocked_app_open" = "Notifications blocked, please fix in app settings and then refresh";
"location_not_enabled" = "Location turned off, please turn on";
"location_permission_off" = "Insufficient location permissions, please fix";
"location_permission_off_app_open" = "Insufficient location permissions, please fix in app settings";
"location_permission_off_enable" = "Insufficient location permissions, please enable";
"activity_permission_off" = "Motion and Fitness permission off, please enable";
"activity_permission_off_app_open" = "Motion and Fitness permission off, please fix in app settings";
"fix_app_status_title" = "Incorrect app settings";
"fix_app_status_text" = "Click to view and fix app status";
2 changes: 1 addition & 1 deletion src/android/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static LocationTrackingConfig getConfig(Context context) {
} catch(JsonParseException e) {
Log.e(context, TAG, "Found error " + e + "parsing sync config json, resetting to defaults");
NotificationHelper.createNotification(context, Constants.TRACKING_ERROR_ID,
context.getString(R.string.error_reading_stored_config));
null, context.getString(R.string.error_reading_stored_config));
cachedConfig = new LocationTrackingConfig();
updateConfig(context, cachedConfig);
}
Expand Down
52 changes: 49 additions & 3 deletions src/android/DataCollectionPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.berkeley.eecs.emission.cordova.tracker;

import edu.berkeley.eecs.emission.R;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CallbackContext;
Expand Down Expand Up @@ -62,15 +64,59 @@ public boolean execute(String action, JSONArray data, final CallbackContext call
JSONObject newConsent = data.getJSONObject(0);
ConsentConfig cfg = new Gson().fromJson(newConsent.toString(), ConsentConfig.class);
ConfigManager.setConsented(ctxt, cfg);
TripDiaryStateMachineForegroundService.startProperly(cordova.getActivity().getApplication());
// TripDiaryStateMachineForegroundService.startProperly(cordova.getActivity().getApplication());
// Now, really initialize the state machine
// Note that we don't call initOnUpgrade so that we can handle the case where the
// user deleted the consent and re-consented, but didn't upgrade the app
mControlDelegate.checkAndPromptPermissions();
// ctxt.sendBroadcast(new ExplicitIntent(ctxt, R.string.transition_initialize));
// mControlDelegate.checkAndPromptPermissions();
ctxt.sendBroadcast(new ExplicitIntent(ctxt, R.string.transition_initialize));
// TripDiaryStateMachineReceiver.restartCollection(ctxt);
callbackContext.success();
return true;
} else if (action.equals("fixLocationSettings")) {
Log.d(cordova.getActivity(), TAG, "fixing location settings");
mControlDelegate.checkAndPromptLocationSettings(callbackContext);
return true;
} else if (action.equals("isValidLocationSettings")) {
Log.d(cordova.getActivity(), TAG, "checking location settings");
mControlDelegate.checkLocationSettings(callbackContext);
return true;
} else if (action.equals("fixLocationPermissions")) {
Log.d(cordova.getActivity(), TAG, "fixing location permissions");
mControlDelegate.checkAndPromptLocationPermissions(callbackContext);
return true;
} else if (action.equals("isValidLocationPermissions")) {
Log.d(cordova.getActivity(), TAG, "checking location permissions");
mControlDelegate.checkLocationPermissions(callbackContext);
return true;
} else if (action.equals("fixFitnessPermissions")) {
Log.d(cordova.getActivity(), TAG, "fixing fitness permissions");
mControlDelegate.checkAndPromptMotionActivityPermissions(callbackContext);
return true;
} else if (action.equals("isValidFitnessPermissions")) {
Log.d(cordova.getActivity(), TAG, "checking fitness permissions");
mControlDelegate.checkMotionActivityPermissions(callbackContext);
return true;
} else if (action.equals("fixShowNotifications")) {
Log.d(cordova.getActivity(), TAG, "fixing notification enable");
mControlDelegate.checkAndPromptShowNotificationsEnabled(callbackContext);
return true;
} else if (action.equals("isValidShowNotifications")) {
Log.d(cordova.getActivity(), TAG, "checking notification enable");
mControlDelegate.checkShowNotificationsEnabled(callbackContext);
return true;
} else if (action.equals("isNotificationsUnpaused")) {
Log.d(cordova.getActivity(), TAG, "checking notification unpause");
mControlDelegate.checkPausedNotifications(callbackContext);
return true;
} else if (action.equals("fixUnusedAppRestrictions")) {
Log.d(cordova.getActivity(), TAG, "fixing unused app restrictions");
mControlDelegate.checkAndPromptUnusedAppsUnrestricted(callbackContext);
return true;
} else if (action.equals("isUnusedAppUnrestricted")) {
Log.d(cordova.getActivity(), TAG, "checking unused app restrictions");
mControlDelegate.checkUnusedAppsUnrestricted(callbackContext);
return true;
} else if (action.equals("storeBatteryLevel")) {
Context ctxt = cordova.getActivity();
TripDiaryStateMachineReceiver.saveBatteryAndSimulateUser(ctxt);
Expand Down
7 changes: 7 additions & 0 deletions src/android/enable_api_31.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ext.postBuildExtras = {
android {
defaultConfig {
compileSdkVersion 31
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void onHandleIntent(Intent intent) {
DetectedActivity mostProbableActivity = result.getMostProbableActivity();
Log.i(this, TAG, "Detected new activity "+mostProbableActivity);
if (ConfigManager.getConfig(this).isSimulateUserInteraction()) {
NotificationHelper.createNotification(this, ACTIVITY_IN_NUMBERS,this.getString(R.string.detected_new_activity, activityType2Name(mostProbableActivity.getType(), this)));
NotificationHelper.createNotification(this, ACTIVITY_IN_NUMBERS, null, this.getString(R.string.detected_new_activity, activityType2Name(mostProbableActivity.getType(), this)));
}
// TODO: Do we want to compare activity and only store when different?
// Can easily do that by getting the last activity
Expand Down
2 changes: 1 addition & 1 deletion src/android/location/ForegroundServiceComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void setNewState(String newState) {
mCtxt.bindService(fsi, connection, 0);
} else {
NotificationHelper.createNotification(mCtxt, Constants.TRACKING_ERROR_ID,
mCtxt.getString(R.string.unable_resolve_issue));
null, mCtxt.getString(R.string.unable_resolve_issue));
Log.e(mCtxt, TAG, "Too many recursions, generating notification");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
" flags = " + flags + " and startId = " + startId);
String message = humanizeState(this, TripDiaryStateMachineService.getState(this));
if (intent == null) {
SensorControlBackgroundChecker.checkLocationSettingsAndPermissions(this);
SensorControlBackgroundChecker.checkAppState(this);
message = humanizeState(this, TripDiaryStateMachineService.getState(this));
}
handleStart(message, intent, flags, startId);
Expand Down Expand Up @@ -133,8 +133,8 @@ public void setStateMessage(String newState) {

private Notification getNotification(String msg) {
NotificationManager nMgr = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = NotificationHelper.getNotificationBuilderForApp(this,
nMgr, msg);
Notification.Builder builder = NotificationHelper.getNotificationBuilderForApp(this, null,
msg);
builder.setOngoing(true);

Intent activityIntent = new Intent(this, MainActivity.class);
Expand Down Expand Up @@ -172,7 +172,7 @@ private static Intent getForegroundServiceIntent(Context ctxt) {
}

public static void checkForegroundNotification(Context ctxt) {
if(Build.VERSION.SDK_INT >Build.VERSION_CODES.O) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager mgr = (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] activeNotifications = mgr.getActiveNotifications();
Log.d(ctxt, TAG, "In checkForegroundNotification, found " + activeNotifications.length + " active notifications");
Expand Down
6 changes: 3 additions & 3 deletions src/android/location/TripDiaryStateMachineReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void onReceive(Context context, Intent intent) {
if (introDoneResult != null) {
Log.i(context, TAG, reqConsent + " is not the current consented version, skipping init...");
NotificationHelper.createNotification(context, STARTUP_IN_NUMBERS,
context.getString(R.string.new_data_collection_terms));
null, context.getString(R.string.new_data_collection_terms));
return;
} else {
Log.i(context, TAG, "onboarding is not complete, skipping prompt");
Expand Down Expand Up @@ -129,7 +129,7 @@ public static void performPeriodicActivity(Context ctxt) {
}

public static void checkLocationStillAvailable(Context ctxt) {
SensorControlBackgroundChecker.checkLocationSettingsAndPermissions(ctxt);
SensorControlBackgroundChecker.checkAppState(ctxt);
}

public static void validateAndCleanupState(Context ctxt) {
Expand Down Expand Up @@ -173,7 +173,7 @@ public static void saveBatteryAndSimulateUser(Context ctxt) {
Battery currInfo = BatteryUtils.getBatteryInfo(ctxt);
UserCacheFactory.getUserCache(ctxt).putSensorData(R.string.key_usercache_battery, currInfo);
if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) {
NotificationHelper.createNotification(ctxt, 1234, ctxt.getString(R.string.battery_level,
NotificationHelper.createNotification(ctxt, 1234, null, ctxt.getString(R.string.battery_level,
currInfo.getBatteryLevelPct()));
}
}
Expand Down
Loading

0 comments on commit 8dcd9b4

Please sign in to comment.