Commented out logging
parent
f80069b6e9
commit
71853902eb
|
@ -101,31 +101,31 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER);
|
connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER);
|
||||||
Log.d(TAG, "Priority and interval lowered due to low power");
|
// Log.d(TAG, "Priority and interval lowered due to low power");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
Log.d(TAG, "onCreate called");
|
// Log.d(TAG, "onCreate called");
|
||||||
|
|
||||||
// Get preferences
|
// Get preferences
|
||||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
setupNotifications(true);
|
setupNotifications(true);
|
||||||
showNotification(getText(R.string.connecting), false);
|
showNotification(getText(R.string.connecting), false);
|
||||||
Log.d(TAG, "Notification set up");
|
// Log.d(TAG, "Notification set up");
|
||||||
|
|
||||||
buildGoogleApiClient();
|
buildGoogleApiClient();
|
||||||
Log.d(TAG, "Google API Client built");
|
// Log.d(TAG, "Google API Client built");
|
||||||
mGoogleApiClient.connect();
|
mGoogleApiClient.connect();
|
||||||
Log.d(TAG, "Connected to Google API Client");
|
// Log.d(TAG, "Connected to Google API Client");
|
||||||
|
|
||||||
IntentFilter lowPowerFilter = new IntentFilter();
|
IntentFilter lowPowerFilter = new IntentFilter();
|
||||||
lowPowerFilter.addAction("android.intent.action.BATTERY_LOW");
|
lowPowerFilter.addAction("android.intent.action.BATTERY_LOW");
|
||||||
registerReceiver(LowPowerReceiver, lowPowerFilter);
|
registerReceiver(LowPowerReceiver, lowPowerFilter);
|
||||||
Log.d(TAG, "LowPowerReceiver activated");
|
// Log.d(TAG, "LowPowerReceiver activated");
|
||||||
|
|
||||||
mUserID = sharedPref.getString("loggedInUserId", null);
|
mUserID = sharedPref.getString("loggedInUserId", null);
|
||||||
mUserSK = sharedPref.getString("loggedInUserSk", null);
|
mUserSK = sharedPref.getString("loggedInUserSk", null);
|
||||||
|
@ -137,10 +137,10 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
mSocket.on("activate", onActivate);
|
mSocket.on("activate", onActivate);
|
||||||
mSocket.connect();
|
mSocket.connect();
|
||||||
mSocket.emit("room", "app-"+mUserID);
|
mSocket.emit("room", "app-"+mUserID);
|
||||||
Log.d(TAG, "Connected to socket.io server "+SERVER_ADDRESS);
|
// Log.d(TAG, "Connected to socket.io server "+SERVER_ADDRESS);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
showNotification(getText(R.string.server_connection_error), false);
|
showNotification(getText(R.string.server_connection_error), false);
|
||||||
Log.e(TAG, "Failed to connect to sockets server " + SERVER_ADDRESS, e);
|
// Log.e(TAG, "Failed to connect to sockets server " + SERVER_ADDRESS, e);
|
||||||
}
|
}
|
||||||
showNotification(getText(R.string.connected), false);
|
showNotification(getText(R.string.connected), false);
|
||||||
}
|
}
|
||||||
|
@ -171,10 +171,11 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
|
|
||||||
// Get permission
|
// Get permission
|
||||||
if (!checkLocationPermission(this)) {
|
if (!checkLocationPermission(this)) {
|
||||||
Log.d(TAG, "Location permission denied");
|
// Log.d(TAG, "Location permission denied");
|
||||||
|
//TODO: Turn off location updates
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Location permission granted");
|
// Log.d(TAG, "Location permission granted");
|
||||||
|
|
||||||
// Request location updates
|
// Request location updates
|
||||||
if (mGoogleApiClient.isConnected()) {
|
if (mGoogleApiClient.isConnected()) {
|
||||||
|
@ -190,14 +191,6 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
|
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
|
||||||
|
|
||||||
}
|
}
|
||||||
// if ( ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) {
|
|
||||||
// ActivityCompat.requestPermissions( this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION },
|
|
||||||
// LocationService.MY_FINE_LOCATION_PERMISSION );
|
|
||||||
// } else {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Set location if there is one
|
// Set location if there is one
|
||||||
if (mLastLocation != null) {
|
if (mLastLocation != null) {
|
||||||
|
@ -208,7 +201,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(Bundle bundle) {
|
public void onConnected(Bundle bundle) {
|
||||||
Log.d(TAG, "onConnected called");
|
// Log.d(TAG, "onConnected called");
|
||||||
|
|
||||||
mLocationRequest = LocationRequest.create();
|
mLocationRequest = LocationRequest.create();
|
||||||
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
||||||
|
@ -222,7 +215,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed(ConnectionResult connectionResult) {
|
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||||
Log.e(TAG, "onConnectionFailed: " + connectionResult);
|
// Log.e(TAG, "onConnectionFailed: " + connectionResult);
|
||||||
showNotification(getText(R.string.google_connection_error), false);
|
showNotification(getText(R.string.google_connection_error), false);
|
||||||
buildGoogleApiClient();
|
buildGoogleApiClient();
|
||||||
}
|
}
|
||||||
|
@ -231,11 +224,11 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
if (args[0].toString().equals("true")) {
|
if (args[0].toString().equals("true")) {
|
||||||
Log.d(TAG, "Activating realtime updates");
|
// Log.d(TAG, "Activating realtime updates");
|
||||||
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
||||||
showNotification(getString(R.string.realtime_updates), true);
|
showNotification(getString(R.string.realtime_updates), true);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Deactivating realtime updates");
|
// Log.d(TAG, "Deactivating realtime updates");
|
||||||
connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER);
|
connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER);
|
||||||
showNotification(getString(R.string.occasional_updates), false);
|
showNotification(getString(R.string.occasional_updates), false);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +246,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
mLocationView.put("dir", String.valueOf(location.getBearing()));
|
mLocationView.put("dir", String.valueOf(location.getBearing()));
|
||||||
mLocationView.put("spd", String.valueOf(location.getSpeed()));
|
mLocationView.put("spd", String.valueOf(location.getSpeed()));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "Failed to put JSON data");
|
// Log.e(TAG, "Failed to put JSON data");
|
||||||
}
|
}
|
||||||
mSocket.emit("app", mLocationView);
|
mSocket.emit("app", mLocationView);
|
||||||
// Log.v(TAG, "Location updated: " + mLocationView.toString());
|
// Log.v(TAG, "Location updated: " + mLocationView.toString());
|
||||||
|
@ -261,26 +254,26 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionSuspended(int i) {
|
public void onConnectionSuspended(int i) {
|
||||||
Log.d(TAG, "onConnectionSuspended called");
|
// Log.d(TAG, "onConnectionSuspended called");
|
||||||
showNotification(getText(R.string.google_connection_error), false);
|
showNotification(getText(R.string.google_connection_error), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
Log.d(TAG, "onDestroy executed");
|
// Log.d(TAG, "onDestroy executed");
|
||||||
|
|
||||||
mSocket.disconnect();
|
mSocket.disconnect();
|
||||||
Log.d(TAG, "Disconnected from sockets");
|
// Log.d(TAG, "Disconnected from sockets");
|
||||||
|
|
||||||
mGoogleApiClient.disconnect();
|
mGoogleApiClient.disconnect();
|
||||||
Log.d(TAG, "Google API disconnected");
|
// Log.d(TAG, "Google API disconnected");
|
||||||
|
|
||||||
unregisterReceiver(LowPowerReceiver);
|
unregisterReceiver(LowPowerReceiver);
|
||||||
Log.d(TAG, "LowPowerReceiver deactivated");
|
// Log.d(TAG, "LowPowerReceiver deactivated");
|
||||||
|
|
||||||
setupNotifications(false);
|
setupNotifications(false);
|
||||||
showNotification(getText(R.string.disconnected), false);
|
showNotification(getText(R.string.disconnected), false);
|
||||||
Log.d(TAG, "Notification changed");
|
// Log.d(TAG, "Notification changed");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.v(TAG, "Created...");
|
// Log.v(TAG, "Created...");
|
||||||
|
|
||||||
// Set up layout
|
// Set up layout
|
||||||
setContentView(R.layout.activity_login);
|
setContentView(R.layout.activity_login);
|
||||||
|
@ -77,20 +77,20 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Log.v(TAG, "Started. Checking for intent method");
|
// Log.v(TAG, "Started. Checking for intent method");
|
||||||
|
|
||||||
if (getIntent().hasExtra("method")) {
|
if (getIntent().hasExtra("method")) {
|
||||||
Log.v(TAG, "Intent has method extra");
|
// Log.v(TAG, "Intent has method extra");
|
||||||
if (getIntent().getStringExtra("method").equals("signOut")) {
|
if (getIntent().getStringExtra("method").equals("signOut")) {
|
||||||
Log.d(TAG, "Got intent to sign out");
|
// Log.d(TAG, "Got intent to sign out");
|
||||||
}
|
}
|
||||||
} else { // Try to sign in
|
} else { // Try to sign in
|
||||||
Log.v(TAG, "Trying to sign in...");
|
// Log.v(TAG, "Trying to sign in...");
|
||||||
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
|
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
|
||||||
if (opr.isDone()) {
|
if (opr.isDone()) {
|
||||||
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
|
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
|
||||||
// and the GoogleSignInResult will be available instantly.
|
// and the GoogleSignInResult will be available instantly.
|
||||||
Log.d(TAG, "Got cached sign-in");
|
// Log.d(TAG, "Got cached sign-in");
|
||||||
GoogleSignInResult result = opr.get();
|
GoogleSignInResult result = opr.get();
|
||||||
handleSignInResult(result);
|
handleSignInResult(result);
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,11 +128,11 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
.url(SERVER_ADDRESS+"auth/google/idtoken?id_token="+token)
|
.url(SERVER_ADDRESS+"auth/google/idtoken?id_token="+token)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Log.d(TAG, "Attempting Tracman signin with token: " + token);
|
// Log.d(TAG, "Attempting Tracman signin with token: " + token);
|
||||||
client.newCall(request).enqueue(new Callback() {
|
client.newCall(request).enqueue(new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Request request, IOException throwable) {
|
public void onFailure(Request request, IOException throwable) {
|
||||||
Log.e(TAG, "Failed to connect to server: " + SERVER_ADDRESS + "auth/google/idtoken?id_token=" + token);
|
// Log.e(TAG, "Failed to connect to server: " + SERVER_ADDRESS + "auth/google/idtoken?id_token=" + token);
|
||||||
showError(R.string.server_connection_error);
|
showError(R.string.server_connection_error);
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
res.body().close();
|
res.body().close();
|
||||||
throw new IOException("Unexpected code: " + res);
|
throw new IOException("Unexpected code: " + res);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Response code: " + res.code());
|
// Log.d(TAG, "Response code: " + res.code());
|
||||||
String userString = res.body().string();
|
String userString = res.body().string();
|
||||||
System.out.println("Full response: " + userString);
|
System.out.println("Full response: " + userString);
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
userID = user.getString("_id");
|
userID = user.getString("_id");
|
||||||
userName = user.getString("name");
|
userName = user.getString("name");
|
||||||
userSK = user.getString("sk32");
|
userSK = user.getString("sk32");
|
||||||
Log.v(TAG, "User retrieved with ID: " + userID);
|
// Log.v(TAG, "User retrieved with ID: " + userID);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "Unable to parse user JSON: ", e);
|
// Log.e(TAG, "Unable to parse user JSON: ", e);
|
||||||
Log.e(TAG, "JSON String used: " + userString);
|
// Log.e(TAG, "JSON String used: " + userString);
|
||||||
userID = null;
|
userID = null;
|
||||||
userName = null;
|
userName = null;
|
||||||
userSK = null;
|
userSK = null;
|
||||||
|
@ -179,18 +179,18 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSignInResult(GoogleSignInResult result) {
|
private void handleSignInResult(GoogleSignInResult result) {
|
||||||
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
|
// Log.d(TAG, "handleSignInResult:" + result.isSuccess());
|
||||||
if (result.isSuccess()) { // Signed in successfully
|
if (result.isSuccess()) { // Signed in successfully
|
||||||
GoogleSignInAccount acct = result.getSignInAccount();
|
GoogleSignInAccount acct = result.getSignInAccount();
|
||||||
String googleToken = acct.getIdToken();
|
String googleToken = acct.getIdToken();
|
||||||
Log.v(TAG, "Google token: " + googleToken);
|
// Log.v(TAG, "Google token: " + googleToken);
|
||||||
try {
|
try {
|
||||||
AuthenticateGoogle(acct.getIdToken());
|
AuthenticateGoogle(acct.getIdToken());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error sending ID token to backend.", e);
|
// Log.e(TAG, "Error sending ID token to backend.", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Failed to log in: "+result.getStatus().getStatusCode());
|
// Log.e(TAG, "Failed to log in: "+result.getStatus().getStatusCode());
|
||||||
if (result.getStatus().getStatusCode()!=4) {
|
if (result.getStatus().getStatusCode()!=4) {
|
||||||
showError(R.string.google_connection_error);
|
showError(R.string.google_connection_error);
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ public class LoginActivity extends AppCompatActivity implements
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed(ConnectionResult connectionResult) {
|
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||||
showError(R.string.disconnected);
|
showError(R.string.disconnected);
|
||||||
Log.d(TAG, "onConnectionFailed:" + connectionResult);
|
// Log.d(TAG, "onConnectionFailed:" + connectionResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgressDialog() {
|
private void showProgressDialog() {
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setupActionBar();
|
setupActionBar();
|
||||||
Log.d(TAG, "activity onCreate called");
|
// Log.d(TAG, "activity onCreate called");
|
||||||
|
|
||||||
// Get User ID
|
// Get User ID
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
@ -124,7 +124,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
|
||||||
Log.d(TAG, "onStop called");
|
// Log.d(TAG, "onStop called");
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
// Restart service so settings can take effect
|
// Restart service so settings can take effect
|
||||||
|
@ -136,7 +136,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||||
showLocationPermissionDialog();
|
showLocationPermissionDialog();
|
||||||
|
|
||||||
// Start location tracking service
|
// Start location tracking service
|
||||||
Log.d(TAG, "Starting LocationService");
|
// Log.d(TAG, "Starting LocationService");
|
||||||
startService(new Intent(this, LocationService.class));
|
startService(new Intent(this, LocationService.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue