Skip to content

Commit

Permalink
WIP Fix #875 - Implement user-travel-behavior tracking data collectio…
Browse files Browse the repository at this point in the history
…n feature
  • Loading branch information
cagryInside committed Jun 27, 2019
1 parent 2531a9a commit a3b8b42
Show file tree
Hide file tree
Showing 46 changed files with 3,019 additions and 279 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0'
classpath 'com.google.gms:google-services:4.1.0'
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31'
classpath 'com.google.gms:google-services:4.2.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#

android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jan 25 09:21:55 EST 2019
#Fri Jun 21 16:46:28 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
10 changes: 9 additions & 1 deletion onebusaway-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {
dexOptions {
preDexLibraries true
}
compileSdkVersion 28
compileSdkVersion 29
buildToolsVersion '28.0.3'

defaultConfig {
Expand Down Expand Up @@ -124,6 +124,7 @@ android {
buildConfigField "String", "FIXED_REGION_PAYMENT_ANDROID_APP_ID", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_TITLE", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_BODY", "null"
buildConfigField "boolean", "FIXED_TRAVEL_BEHAVIOR_DATA_COLLECTION", "false"
}

/**
Expand Down Expand Up @@ -168,6 +169,7 @@ android {
buildConfigField "String", "FIXED_REGION_PAYMENT_ANDROID_APP_ID", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_TITLE", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_BODY", "null"
buildConfigField "boolean", "FIXED_TRAVEL_BEHAVIOR_DATA_COLLECTION", "false"
}

agencyY {
Expand Down Expand Up @@ -208,6 +210,7 @@ android {
buildConfigField "String", "FIXED_REGION_PAYMENT_ANDROID_APP_ID", "\"co.bytemark.hart\""
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_TITLE", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_BODY", "null"
buildConfigField "boolean", "FIXED_TRAVEL_BEHAVIOR_DATA_COLLECTION", "false"
}
yrt {
// "YRT - York Region Transit - Canada" rebranding - https://play.google.com/store/apps/details?id=can.yrt.onebusaway
Expand Down Expand Up @@ -246,6 +249,7 @@ android {
buildConfigField "String", "FIXED_REGION_PAYMENT_ANDROID_APP_ID", "\"co.bytemark.york\""
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_TITLE", "null"
buildConfigField "String", "FIXED_REGION_PAYMENT_WARNING_BODY", "null"
buildConfigField "boolean", "FIXED_TRAVEL_BEHAVIOR_DATA_COLLECTION", "false"
}
/**
* Add more rebranding flavors here...
Expand Down Expand Up @@ -443,6 +447,10 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.1.0'
// WorkManager (Java only)
implementation 'androidx.work:work-runtime:2.0.0'
implementation "androidx.concurrent:concurrent-futures:1.0.0-beta01"
implementation "androidx.concurrent:concurrent-listenablefuture:1.0.0-beta01"
implementation "androidx.concurrent:concurrent-listenablefuture-callback:1.0.0-beta01"

}

apply plugin:'com.google.gms.google-services'
167 changes: 8 additions & 159 deletions onebusaway-android/google-services.json
Original file line number Diff line number Diff line change
@@ -1,186 +1,35 @@
{
"project_info": {
"project_number": "1083736323923",
"firebase_url": "https://api-project-1083736323923.firebaseio.com",
"project_id": "api-project-1083736323923",
"storage_bucket": "api-project-1083736323923.appspot.com"
"project_number": "893400419714",
"firebase_url": "https://oba-user-behavior.firebaseio.com",
"project_id": "oba-user-behavior",
"storage_bucket": "oba-user-behavior.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1083736323923:android:75ea84a920f3dd26",
"android_client_info": {
"package_name": "can.yrt.onebusaway"
}
},
"oauth_client": [
{
"client_id": "1083736323923-u9a12phc7p9s7kmlh6aerpdvu6cbjagg.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "can.yrt.onebusaway",
"certificate_hash": "d8d368095abbdf638318a74cce3f5f3c35ab34b2"
}
},
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAKhirldbMm7knvxq2lFoYiNxSCOesvnwk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1083736323923-a3abfviki4fcbm734vbfceejcivrvbv2.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "org.onebusaway.iphone",
"app_store_id": "329380089"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:1083736323923:android:e2ba0de76d8a138b",
"mobilesdk_app_id": "1:893400419714:android:e2ba0de76d8a138b",
"android_client_info": {
"package_name": "com.joulespersecond.seattlebusbot"
}
},
"oauth_client": [
{
"client_id": "1083736323923-0u4ns2rkmbar7taqetottco4oe0q36d5.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.joulespersecond.seattlebusbot",
"certificate_hash": "650f90e1ea8abee695865f3abaac9af968a99007"
}
},
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_id": "893400419714-do2ctm9psfdqt368vk5bsmr6la62sai3.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAKhirldbMm7knvxq2lFoYiNxSCOesvnwk"
"current_key": "AIzaSyBHl2hYUA8P6jd0DFo6jENr6Ty-Gladl_4"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_id": "893400419714-do2ctm9psfdqt368vk5bsmr6la62sai3.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1083736323923-a3abfviki4fcbm734vbfceejcivrvbv2.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "org.onebusaway.iphone",
"app_store_id": "329380089"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:1083736323923:android:0afb35895aeb0afe",
"android_client_info": {
"package_name": "org.agencyx.android"
}
},
"oauth_client": [
{
"client_id": "1083736323923-1db56fvaq7nt417bofvnf81hq1uc42e3.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "org.agencyx.android",
"certificate_hash": "650f90e1ea8abee695865f3abaac9af968a99007"
}
},
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAKhirldbMm7knvxq2lFoYiNxSCOesvnwk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1083736323923-a3abfviki4fcbm734vbfceejcivrvbv2.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "org.onebusaway.iphone",
"app_store_id": "329380089"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:1083736323923:android:5315b0708d7ce060",
"android_client_info": {
"package_name": "org.agencyy.android"
}
},
"oauth_client": [
{
"client_id": "1083736323923-8e01enil38smqtoc0fisqu57u57e26ie.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "org.agencyy.android",
"certificate_hash": "650f90e1ea8abee695865f3abaac9af968a99007"
}
},
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAKhirldbMm7knvxq2lFoYiNxSCOesvnwk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1083736323923-r9sj5jprq479c089eol4shq6q026tlv7.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1083736323923-a3abfviki4fcbm734vbfceejcivrvbv2.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "org.onebusaway.iphone",
"app_store_id": "329380089"
}
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions onebusaway-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
Expand All @@ -37,6 +38,7 @@
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="${applicationId}.permission.TRIP_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

<uses-sdk tools:overrideLibrary="net.openid.appauth,
android.support.customtabs,
Expand Down Expand Up @@ -296,6 +298,16 @@
</intent-filter>
</receiver>

<receiver
android:enabled="true" android:name=".travelbehavior.receiver.TransitionBroadcastReceiver">
</receiver>
<receiver
android:enabled="true" android:name=".travelbehavior.receiver.RecognitionBroadcastReceiver">
</receiver>
<receiver
android:enabled="true" android:name=".travelbehavior.receiver.LocationBroadcastReceiver">
</receiver>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
Expand All @@ -46,6 +47,7 @@
import org.onebusaway.android.io.elements.ObaRegion;
import org.onebusaway.android.provider.ObaContract;
import org.onebusaway.android.report.ui.util.SocialReportHandler;
import org.onebusaway.android.travelbehavior.TravelBehaviorManager;
import org.onebusaway.android.ui.social.SocialAppProfile;
import org.onebusaway.android.ui.social.SocialNavigationDrawerHandler;
import org.onebusaway.android.util.BuildFlavorUtils;
Expand Down Expand Up @@ -125,6 +127,8 @@ public void onStart(@NonNull LifecycleOwner owner) {
reportAnalytics();

createNotificationChannels();

TravelBehaviorManager.startCollectingData(getApplicationContext());
}

/**
Expand Down Expand Up @@ -623,4 +627,17 @@ private void createNotificationChannels() {
}
}

public static Boolean isIgnoringBatteryOptimizations(Context applicationContext) {
PowerManager pm = (PowerManager) applicationContext.getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
pm.isIgnoringBatteryOptimizations(applicationContext.getPackageName())) {
return true;
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return null;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.onebusaway.android.directions.util.TripRequestBuilder;
import org.opentripplanner.api.model.Itinerary;
import org.opentripplanner.api.model.Leg;
import org.opentripplanner.api.model.TripPlan;

import android.app.Activity;
import android.app.AlarmManager;
Expand Down Expand Up @@ -165,16 +166,16 @@ private void checkForItineraryChange(final Class<? extends Activity> source, fin

TripRequest.Callback callback = new TripRequest.Callback() {
@Override
public void onTripRequestComplete(List<Itinerary> itineraries, String url) {
if (itineraries == null || itineraries.isEmpty()) {
public void onTripRequestComplete(TripPlan tripPlan, String url) {
if (tripPlan == null || tripPlan.itineraries == null || tripPlan.itineraries.isEmpty()) {
onTripRequestFailure(-1, null);
return;
}

// Check each itinerary. Notify user if our *current* itinerary doesn't exist
// or has a lower rank.
for (int i = 0; i < itineraries.size(); i++) {
ItineraryDescription other = new ItineraryDescription(itineraries.get(i));
for (int i = 0; i < tripPlan.itineraries.size(); i++) {
ItineraryDescription other = new ItineraryDescription(tripPlan.itineraries.get(i));

if (itineraryDescription.itineraryMatches(other)) {

Expand All @@ -187,7 +188,7 @@ public void onTripRequestComplete(List<Itinerary> itineraries, String url) {
(delay > 0) ? R.string.trip_plan_delay
: R.string.trip_plan_early,
R.string.trip_plan_notification_new_plan_text,
source, builder.getBundle(), itineraries);
source, builder.getBundle(), tripPlan.itineraries);
disableListenForTripUpdates();
return;
}
Expand All @@ -203,7 +204,7 @@ public void onTripRequestComplete(List<Itinerary> itineraries, String url) {
showNotification(itineraryDescription,
R.string.trip_plan_notification_new_plan_title,
R.string.trip_plan_notification_new_plan_text, source,
builder.getBundle(), itineraries);
builder.getBundle(), tripPlan.itineraries);
disableListenForTripUpdates();
}

Expand Down
Loading

0 comments on commit a3b8b42

Please sign in to comment.