From 77c3f9d48e664b83919d52a005b238ca9c43f9af Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Wed, 9 Jan 2019 23:43:00 +0000 Subject: [PATCH] Tidying up log messages - in particular using Log.i for more important ones, and keeping Log.v for regular messages. --- .../uk/org/openseizuredetector/OsdUtil.java | 24 +++++---- .../uk/org/openseizuredetector/SdServer.java | 54 +++++++++---------- .../openseizuredetector/StartupActivity.java | 17 +++--- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java index 2255096..1132bcc 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java @@ -134,7 +134,8 @@ public class OsdUtil { public boolean isServerRunning() { - //Log.v(TAG,"isServerRunning()................"); + int nServers = 0; + /* Log.v(TAG,"isServerRunning()...."); */ ActivityManager manager = (ActivityManager) mContext.getSystemService(mContext.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : @@ -142,12 +143,15 @@ public class OsdUtil { //Log.v(TAG,"Service: "+service.service.getClassName()); if ("uk.org.openseizuredetector.SdServer" .equals(service.service.getClassName())) { - //Log.v(TAG,"Yes!"); - return true; + nServers = nServers + 1; } } - //Log.v(TAG,"No!"); - return false; + if (nServers != 0) { + Log.v(TAG, "isServerRunning() - " + nServers + " instances are running"); + return true; + } + else + return false; } /** @@ -155,7 +159,7 @@ public class OsdUtil { */ public void startServer() { // Start the server - Log.v(TAG,"startServer()"); + Log.i(TAG,"OsdUtil.startServer()"); writeToSysLogFile("startServer() - starting server"); Intent sdServerIntent; sdServerIntent = new Intent(mContext, SdServer.class); @@ -167,7 +171,7 @@ public class OsdUtil { * Stop the SdServer service */ public void stopServer() { - Log.v(TAG, "stopping Server..."); + Log.i(TAG, "OsdUtil.stopServer() - stopping Server..."); writeToSysLogFile("stopserver() - stopping server"); // then send an Intent to stop the service. @@ -182,7 +186,7 @@ public class OsdUtil { * bind an activity to to an already running server. */ public void bindToServer(Activity activity, SdServiceConnection sdServiceConnection) { - Log.v(TAG, "bindToServer() - binding to SdServer"); + Log.i(TAG, "OsdUtil.bindToServer() - binding to SdServer"); writeToSysLogFile("bindToServer() - binding to SdServer"); Intent intent = new Intent(sdServiceConnection.mContext, SdServer.class); activity.bindService(intent, sdServiceConnection, Context.BIND_AUTO_CREATE); @@ -194,7 +198,7 @@ public class OsdUtil { public void unbindFromServer(Activity activity, SdServiceConnection sdServiceConnection) { // unbind this activity from the service if it is bound. if (sdServiceConnection.mBound) { - Log.v(TAG, "unbindFromServer() - unbinding"); + Log.i(TAG, "unbindFromServer() - unbinding"); writeToSysLogFile("unbindFromServer() - unbinding"); try { activity.unbindService(sdServiceConnection); @@ -204,7 +208,7 @@ public class OsdUtil { writeToSysLogFile("unbindFromServer() - error unbinding service - " +ex.toString()); } } else { - Log.v(TAG, "unbindFromServer() - not bound to server - ignoring"); + Log.i(TAG, "unbindFromServer() - not bound to server - ignoring"); writeToSysLogFile("unbindFromServer() - not bound to server - ignoring"); } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index c159b28..c208925 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -390,7 +390,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei // Show the main activity on the user's screen. private void showMainActivity() { - Log.v(TAG, "showMainActivity()"); + Log.i(TAG, "showMainActivity()"); mUtil.writeToSysLogFile("SdServer.showMainActivity()"); ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); @@ -398,10 +398,10 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei ComponentName componentInfo = runningTaskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals("uk.org.openseizuredetector")) { - Log.v(TAG, "showMainActivity(): OpenSeizureDetector Activity is already shown on top - not doing anything"); + Log.i(TAG, "showMainActivity(): OpenSeizureDetector Activity is already shown on top - not doing anything"); mUtil.writeToSysLogFile("SdServer.showMainActivity - Activity is already shown on top, not doing anything"); } else { - Log.v(TAG, "showMainActivity(): Showing Main Activity"); + Log.i(TAG, "showMainActivity(): Showing Main Activity"); Intent i = new Intent(getApplicationContext(), MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(i); @@ -526,7 +526,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei // Called by SdDataSource when a fault condition is detected. public void onSdDataFault(SdData sdData) { - Log.v(TAG, "onSdDataFault()"); + Log.i(TAG, "onSdDataFault()"); mSdData = sdData; mSdData.alarmState = 4; // set fault alarm state. mSdData.alarmStanding = false; @@ -665,16 +665,16 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei + loc.getLongitude() + "," + loc.getLatitude()); } else { - Log.v(TAG, "sendSMSAlarm() - Last Location is Null so sending first SMS without location."); + Log.i(TAG, "sendSMSAlarm() - Last Location is Null so sending first SMS without location."); } - Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers"); + Log.i(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers"); mUtil.writeToSysLogFile("SdServer.sendSMSAlarm()"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%H:%M:%S %d/%m/%Y"); // SmsManager sm = SmsManager.getDefault(); for (int i = 0; i < mSMSNumbers.length; i++) { - Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); + Log.i(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); // sm.sendTextMessage(mSMSNumbers[i], null, mSMSMsgStr + " - " + dateStr, null, null); Intent intent = new Intent(Intent.ACTION_SEND); intent.setDataAndType(Uri.parse("smsto:"), "vnd.android-dir/mms-sms"); @@ -683,11 +683,11 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { - Log.v(TAG, "sendSMSAlarm() - Failed to send SMS."); + Log.e(TAG, "sendSMSAlarm() - Failed to send SMS."); } } } else { - Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); + Log.i(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!", Toast.LENGTH_SHORT); @@ -705,12 +705,12 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei public void onSdLocationReceived(Location ll) { if (ll == null) { mUtil.showToast("onSdLocationReceived() - NULL LOCATION RECEIVED"); - Log.v(TAG, "onSdLocationReceived() - NULL LOCATION RECEIVED"); + Log.w(TAG, "onSdLocationReceived() - NULL LOCATION RECEIVED"); } else { //mUtil.showToast("onSdLocationReceived() - found location" + ll.toString()); - Log.v(TAG, "onSdLocationReceived() - found location" + ll.toString()); + Log.i(TAG, "onSdLocationReceived() - found location" + ll.toString()); if (mSMSAlarm) { - Log.v(TAG, "onSdLocationReceived() - Sending to " + mSMSNumbers.length + " Numbers"); + Log.i(TAG, "onSdLocationReceived() - Sending to " + mSMSNumbers.length + " Numbers"); mUtil.writeToSysLogFile("SdServer.sendSMSAlarm()"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); @@ -726,17 +726,17 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei + ll.getLatitude() + "%2C" + ll.getLongitude(); String messageStr = mSMSMsgStr + " - " + dateStr + " - " + googleUrl; - Log.v(TAG, "onSdLocationReceived() - Message is " + messageStr); + Log.i(TAG, "onSdLocationReceived() - Message is " + messageStr); mUtil.showToast(messageStr); SmsManager sm = SmsManager.getDefault(); for (int i = 0; i < mSMSNumbers.length; i++) { - Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); + Log.i(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); sm.sendTextMessage(mSMSNumbers[i], null, messageStr, null, null); } } else { - Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); + Log.i(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!", Toast.LENGTH_SHORT); @@ -782,7 +782,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei * set the alarm standing flags to false to allow alarm phase to reset to current value. */ public void acceptAlarm() { - Log.v(TAG, "acceptAlarm()"); + Log.i(TAG, "acceptAlarm()"); mSdData.alarmStanding = false; mSdData.fallAlarmStanding = false; mSdDataSource.acceptAlarm(); @@ -794,12 +794,12 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei // Start timer to remove the cancel audible flag // after the required period. if (mCancelAudibleTimer != null) { - Log.v(TAG, "cancelAudible(): cancel audible timer already running - cancelling it."); + Log.i(TAG, "cancelAudible(): cancel audible timer already running - cancelling it."); mCancelAudibleTimer.cancel(); mCancelAudibleTimer = null; mCancelAudible = false; } else { - Log.v(TAG, "cancelAudible(): starting cancel audible timer"); + Log.i(TAG, "cancelAudible(): starting cancel audible timer"); mCancelAudible = true; mCancelAudibleTimer = // conver to ms. @@ -826,18 +826,18 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei * problems. */ protected void startWebServer() { - Log.v(TAG, "startWebServer()"); + Log.i(TAG, "startWebServer()"); mUtil.writeToSysLogFile("SdServer.Start Web Server."); if (webServer == null) { webServer = new SdWebServer(getApplicationContext(), mUtil.getDataStorageDir(), mSdData, this); try { webServer.start(); } catch (IOException ioe) { - Log.w(TAG, "startWebServer(): Error: " + ioe.toString()); + Log.e(TAG, "startWebServer(): Error: " + ioe.toString()); } - Log.w(TAG, "startWebServer(): Web server initialized."); + Log.i(TAG, "startWebServer(): Web server initialized."); } else { - Log.v(TAG, "startWebServer(): server already running???"); + Log.i(TAG, "startWebServer(): server already running???"); } mNetworkBroadcastReceiver = new NetworkBroadcastReceiver(); @@ -851,11 +851,11 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei * And de-register for network connectivity events. */ protected void stopWebServer() { - Log.v(TAG, "SdServer.stopWebServer()"); + Log.i(TAG, "SdServer.stopWebServer()"); if (webServer != null) { webServer.stop(); if (webServer.isAlive()) { - Log.v(TAG, "stopWebServer() - server still alive???"); + Log.w(TAG, "stopWebServer() - server still alive???"); } else { Log.v(TAG, "stopWebServer() - server died ok"); } @@ -878,9 +878,9 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei try { activeNetwork = cm.getActiveNetworkInfo(); } catch (Exception e) { - Log.v(TAG, "NetworkBroadcastReceiver - failed to retrieve active network info"); + Log.e(TAG, "NetworkBroadcastReceiver - failed to retrieve active network info"); mUtil.writeToSysLogFile("NetworkBroadcastReceiver - failed to retrieve active network info"); - Log.v(TAG, e.toString()); + Log.e(TAG, e.toString()); } boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); @@ -920,7 +920,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei * - defined in res/xml/prefs.xml */ public void updatePrefs() { - Log.v(TAG, "updatePrefs()"); + Log.i(TAG, "updatePrefs()"); mUtil.writeToSysLogFile("SdServer.updatePrefs()"); SharedPreferences SP = PreferenceManager diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index 01f3992..ccc02b1 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -79,6 +79,7 @@ public class StartupActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Log.i(TAG,"onCreate()"); // Set our custom uncaught exception handler to report issues. Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(StartupActivity.this)); @@ -168,6 +169,7 @@ public class StartupActivity extends Activity { @Override protected void onStart() { super.onStart(); + Log.i(TAG,"onStart()"); mUtil.writeToSysLogFile("StartupActivity.onStart()"); TextView tv; @@ -227,7 +229,7 @@ public class StartupActivity extends Activity { @Override protected void onStop() { super.onStop(); - Log.v(TAG, "onStop()"); + Log.i(TAG, "onStop()"); mUtil.writeToSysLogFile("StartupActivity.onStop() - unbinding from server"); mUtil.unbindFromServer(this, mConnection); mUiTimer.cancel(); @@ -246,6 +248,8 @@ public class StartupActivity extends Activity { TextView tv; ProgressBar pb; + Log.v(TAG,"serverStatusRunnable()"); + // Service Running tv = (TextView) findViewById(R.id.textItem1); pb = (ProgressBar) findViewById(R.id.progressBar1); @@ -390,7 +394,7 @@ public class StartupActivity extends Activity { if (allOk) { if (!mDialogDisplayed) { if (!mStartedMainActivity) { - Log.v(TAG, "starting main activity..."); + Log.i(TAG, "serverStatusRunnable() - starting main activity..."); mUtil.writeToSysLogFile("StartupActivity.serverStatusRunnable - all checks ok - starting main activity."); try { Intent intent = new Intent( @@ -402,7 +406,7 @@ public class StartupActivity extends Activity { finish(); } catch (Exception ex) { mStartedMainActivity = false; - Log.v(TAG, "exception starting main activity " + ex.toString()); + Log.e(TAG, "exception starting main activity " + ex.toString()); mUtil.writeToSysLogFile("StartupActivity.serverStatusRunnable - exception starting main activity " + ex.toString()); } } else { @@ -445,6 +449,7 @@ public class StartupActivity extends Activity { AlertDialog UpdateDialog; AlertDialog FirstRunDialog; SharedPreferences prefs; + Log.i(TAG,"checkFirstRun()"); versionName = this.getVersionName(this, StartupActivity.class); prefs = PreferenceManager.getDefaultSharedPreferences(this); storedVersionName = (prefs.getString("AppVersionName", null)); @@ -481,7 +486,7 @@ public class StartupActivity extends Activity { } }); FirstRunDialog = alertDialogBuilder.create(); - Log.v(TAG, "Displaying First Run Dialog"); + Log.i(TAG, "Displaying First Run Dialog"); FirstRunDialog.show(); mDialogDisplayed = true; } else if (!storedVersionName.equals(versionName)) { @@ -512,13 +517,13 @@ public class StartupActivity extends Activity { } }); UpdateDialog = alertDialogBuilder.create(); - Log.v(TAG, "Displaying Update Dialog"); + Log.i(TAG, "Displaying Update Dialog"); UpdateDialog.show(); mDialogDisplayed = true; } else { Log.v(TAG, "App has already been run - not showing dialog."); } - Log.v(TAG, "Setting AppVersionName to" + versionName); + Log.i(TAG, "Setting Stored AppVersionName to" + versionName); prefs.edit().putString("AppVersionName", versionName).commit(); }