Changed lots of log entries to debug start-stop problems and (I think) fixed the problem with permissions on Android 8 - alpha test version of V2.6
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="uk.org.openseizuredetector"
|
package="uk.org.openseizuredetector"
|
||||||
android:versionCode="42"
|
android:versionCode="42"
|
||||||
android:versionName="2.6.0">
|
android:versionName="2.6.0"
|
||||||
|
android:allowBackup="false"
|
||||||
|
>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.v(TAG,"onCreate()");
|
Log.i(TAG,"onCreate()");
|
||||||
|
|
||||||
// Set our custom uncaught exception handler to report issues.
|
// Set our custom uncaught exception handler to report issues.
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this));
|
Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this));
|
||||||
@@ -187,6 +187,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Log.i(TAG, "Starting Server");
|
Log.i(TAG, "Starting Server");
|
||||||
startServer();
|
startServer();
|
||||||
// and bind to it so we can see its data
|
// and bind to it so we can see its data
|
||||||
|
Log.i(TAG, "Binding to Server");
|
||||||
mUtil.bindToServer(this, mConnection);
|
mUtil.bindToServer(this, mConnection);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -269,7 +270,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
String versionName = mUtil.getAppVersionName();
|
String versionName = mUtil.getAppVersionName();
|
||||||
tv.setText("OpenSeizureDetector Android App Version " + versionName);
|
tv.setText("OpenSeizureDetector Android App Version " + versionName);
|
||||||
|
|
||||||
Log.v(TAG,"onStart() - binding to server");
|
Log.i(TAG,"onStart() - binding to server");
|
||||||
mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server");
|
mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server");
|
||||||
mUtil.bindToServer(this, mConnection);
|
mUtil.bindToServer(this, mConnection);
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class OsdUncaughtExceptionHandler implements Thread.UncaughtExceptionHand
|
|||||||
"\n"+errorContent.toString());
|
"\n"+errorContent.toString());
|
||||||
Dialog dialog = builder.create();
|
Dialog dialog = builder.create();
|
||||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
dialog.show();
|
//dialog.show();
|
||||||
Looper.loop();
|
Looper.loop();
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package uk.org.openseizuredetector;
|
package uk.org.openseizuredetector;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -57,6 +58,8 @@ import android.os.UserHandle;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.format.Time;
|
import android.text.format.Time;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -80,11 +83,16 @@ import java.util.concurrent.RunnableFuture;
|
|||||||
* OsdUtil - OpenSeizureDetector Utilities
|
* OsdUtil - OpenSeizureDetector Utilities
|
||||||
* Deals with starting and stopping the background service and binding to it to receive data.
|
* Deals with starting and stopping the background service and binding to it to receive data.
|
||||||
*/
|
*/
|
||||||
public class OsdUtil {
|
public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||||
private final String SYSLOG = "SysLog";
|
private final String SYSLOG = "SysLog";
|
||||||
private final String ALARMLOG = "AlarmLog";
|
private final String ALARMLOG = "AlarmLog";
|
||||||
private final String DATALOG = "DataLog";
|
private final String DATALOG = "DataLog";
|
||||||
|
|
||||||
|
private final String[] REQUIRED_PERMISSIONS = {
|
||||||
|
Manifest.permission.SEND_SMS,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on http://stackoverflow.com/questions/7440473/android-how-to-check-if-the-intent-service-is-still-running-or-has-stopped-running
|
* Based on http://stackoverflow.com/questions/7440473/android-how-to-check-if-the-intent-service-is-still-running-or-has-stopped-running
|
||||||
*/
|
*/
|
||||||
@@ -94,6 +102,7 @@ public class OsdUtil {
|
|||||||
private boolean mLogAlarms = true;
|
private boolean mLogAlarms = true;
|
||||||
private boolean mLogSystem = true;
|
private boolean mLogSystem = true;
|
||||||
private boolean mLogData = true;
|
private boolean mLogData = true;
|
||||||
|
private boolean mPermissionsRequested = false;
|
||||||
|
|
||||||
public OsdUtil(Context context, Handler handler) {
|
public OsdUtil(Context context, Handler handler) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -404,4 +413,42 @@ public class OsdUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean arePermissionsOK() {
|
||||||
|
boolean allOk = true;
|
||||||
|
Log.v(TAG,"arePermissionsOK");
|
||||||
|
for (int i = 0; i< REQUIRED_PERMISSIONS.length; i++) {
|
||||||
|
if (ContextCompat.checkSelfPermission(mContext, REQUIRED_PERMISSIONS[i])
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.i(TAG, REQUIRED_PERMISSIONS[i] + " Permission Not Granted");
|
||||||
|
allOk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestPermissions(Activity activity) {
|
||||||
|
if (mPermissionsRequested) {
|
||||||
|
Log.i(TAG,"requestPermissions() - request already sent - not doing anything");
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "requestPermissions() - requesting permissions");
|
||||||
|
for (int i = 0; i < REQUIRED_PERMISSIONS.length; i++) {
|
||||||
|
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
|
||||||
|
REQUIRED_PERMISSIONS[i])) {
|
||||||
|
Log.i(TAG, "shouldShowRationale for permission" + REQUIRED_PERMISSIONS[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActivityCompat.requestPermissions(activity,
|
||||||
|
REQUIRED_PERMISSIONS,
|
||||||
|
42);
|
||||||
|
mPermissionsRequested = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
|
String permissions[], int[] grantResults) {
|
||||||
|
Log.i(TAG,"onequestPermissionsResult - Permission" + permissions + " = " + grantResults);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
SharedPreferences SP = PreferenceManager
|
SharedPreferences SP = PreferenceManager
|
||||||
.getDefaultSharedPreferences(this.getApplicationContext());
|
.getDefaultSharedPreferences(this.getApplicationContext());
|
||||||
String dataSourceStr = SP.getString("DataSource", "Pebble");
|
String dataSourceStr = SP.getString("DataSource", "Pebble");
|
||||||
Log.v(TAG, "onBuildHeaders DataSource = " + dataSourceStr);
|
Log.i(TAG, "onBuildHeaders DataSource = " + dataSourceStr);
|
||||||
|
|
||||||
//Boolean cameraEnabled = SP.getBoolean("UseIpCamera", false);
|
//Boolean cameraEnabled = SP.getBoolean("UseIpCamera", false);
|
||||||
//Log.v(TAG, "onBuildHeaders cameraEnabled = " + cameraEnabled);
|
//Log.v(TAG, "onBuildHeaders cameraEnabled = " + cameraEnabled);
|
||||||
@@ -111,12 +111,12 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
super.onStart();
|
super.onStart();
|
||||||
mUtil.writeToSysLogFile("PrefActvity.onStart()");
|
mUtil.writeToSysLogFile("PrefActvity.onStart()");
|
||||||
invalidateHeaders();
|
invalidateHeaders();
|
||||||
Log.v(TAG, "onStart()");
|
Log.i(TAG, "onStart()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||||
Log.v(TAG, "SharedPreference " + s + " Changed.");
|
Log.i(TAG, "SharedPreference " + s + " Changed.");
|
||||||
//mUtil.showToast("Shared Preference " + s + " Changed.");
|
//mUtil.showToast("Shared Preference " + s + " Changed.");
|
||||||
mPrefChanged = true;
|
mPrefChanged = true;
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mUtil.writeToSysLogFile("PrefActvity.onResume()");
|
mUtil.writeToSysLogFile("PrefActvity.onResume()");
|
||||||
Log.v(TAG, "onResume()");
|
Log.i(TAG, "onResume()");
|
||||||
SharedPreferences SP = PreferenceManager
|
SharedPreferences SP = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
.getDefaultSharedPreferences(getBaseContext());
|
||||||
SP.registerOnSharedPreferenceChangeListener(this);
|
SP.registerOnSharedPreferenceChangeListener(this);
|
||||||
@@ -135,6 +135,7 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
Log.i(TAG, "onPause()");
|
||||||
mUtil.writeToSysLogFile("PrefActvity.onPause()");
|
mUtil.writeToSysLogFile("PrefActvity.onPause()");
|
||||||
SharedPreferences SP = PreferenceManager
|
SharedPreferences SP = PreferenceManager
|
||||||
.getDefaultSharedPreferences(getBaseContext());
|
.getDefaultSharedPreferences(getBaseContext());
|
||||||
@@ -142,12 +143,13 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onStop() {
|
||||||
super.onDestroy();
|
super.onStop();
|
||||||
mUtil.writeToSysLogFile("PrefActvity.onDestroy()");
|
mUtil.writeToSysLogFile("PrefActvity.onStop()");
|
||||||
Log.v(TAG, "onDestroy. mPrefChanged=" + mPrefChanged);
|
Log.i(TAG, "onStop. mPrefChanged=" + mPrefChanged);
|
||||||
if (mPrefChanged) {
|
if (mPrefChanged) {
|
||||||
mUtil.writeToSysLogFile("PrefActvity.onDestroy() - settings changed - re-starting....");
|
Log.i(TAG,"PrefActivity.onStop() - settings changed - restarting server");
|
||||||
|
mUtil.writeToSysLogFile("PrefActvity.onStop() - settings changed - re-starting server....");
|
||||||
mUtil.showToast("Settings Changed - re-starting OpenSeizureDetector....");
|
mUtil.showToast("Settings Changed - re-starting OpenSeizureDetector....");
|
||||||
Intent intent = new Intent(getApplicationContext(), StartupActivity.class);
|
Intent intent = new Intent(getApplicationContext(), StartupActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public class SdDataSourceGarmin extends SdDataSource {
|
|||||||
public SdDataSourceGarmin(Context context, Handler handler,
|
public SdDataSourceGarmin(Context context, Handler handler,
|
||||||
SdDataReceiver sdDataReceiver) {
|
SdDataReceiver sdDataReceiver) {
|
||||||
super(context, handler, sdDataReceiver);
|
super(context, handler, sdDataReceiver);
|
||||||
mName = "NetworkPassive";
|
mName = "Garmin";
|
||||||
// Set default settings from XML files (mContext is set by super().
|
// Set default settings from XML files (mContext is set by super().
|
||||||
PreferenceManager.setDefaultValues(mContext,
|
PreferenceManager.setDefaultValues(mContext,
|
||||||
R.xml.network_passive_datasource_prefs, true);
|
R.xml.network_passive_datasource_prefs, true);
|
||||||
@@ -126,7 +126,7 @@ public class SdDataSourceGarmin extends SdDataSource {
|
|||||||
* make sure any changes to preferences are taken into account.
|
* make sure any changes to preferences are taken into account.
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
Log.v(TAG, "start()");
|
Log.i(TAG, "start()");
|
||||||
mUtil.writeToSysLogFile("SdDataSourceGarmin.start()");
|
mUtil.writeToSysLogFile("SdDataSourceGarmin.start()");
|
||||||
updatePrefs();
|
updatePrefs();
|
||||||
// Start timer to check status of watch regularly.
|
// Start timer to check status of watch regularly.
|
||||||
@@ -188,7 +188,7 @@ public class SdDataSourceGarmin extends SdDataSource {
|
|||||||
* Stop the datasource from updating
|
* Stop the datasource from updating
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
Log.v(TAG, "stop()");
|
Log.i(TAG, "stop()");
|
||||||
mUtil.writeToSysLogFile("SdDataSourceGarmin.stop()");
|
mUtil.writeToSysLogFile("SdDataSourceGarmin.stop()");
|
||||||
try {
|
try {
|
||||||
// Stop the status timer
|
// Stop the status timer
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class SdDataSourcePebble extends SdDataSource {
|
|||||||
// use a timer to check the status of the pebble app on the same frequency
|
// use a timer to check the status of the pebble app on the same frequency
|
||||||
// as we get app data.
|
// as we get app data.
|
||||||
if (mStatusTimer == null) {
|
if (mStatusTimer == null) {
|
||||||
Log.v(TAG, "start(): starting status timer");
|
Log.v(TAG, "start(): starting status timer with period "+mDataUpdatePeriod*1000 + " ms");
|
||||||
mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting status timer");
|
mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting status timer");
|
||||||
mStatusTimer = new Timer();
|
mStatusTimer = new Timer();
|
||||||
mStatusTimer.schedule(new TimerTask() {
|
mStatusTimer.schedule(new TimerTask() {
|
||||||
@@ -190,7 +190,7 @@ public class SdDataSourcePebble extends SdDataSource {
|
|||||||
getPebbleSdSettings();
|
getPebbleSdSettings();
|
||||||
if (mSettingsTimer == null) {
|
if (mSettingsTimer == null) {
|
||||||
Log.v(TAG, "start(): starting settings timer");
|
Log.v(TAG, "start(): starting settings timer");
|
||||||
mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting settings timer");
|
mUtil.writeToSysLogFile("SdDataSourcePebble.start() - starting settings timer with period "+1000*mSettingsPeriod);
|
||||||
mSettingsTimer = new Timer();
|
mSettingsTimer = new Timer();
|
||||||
mSettingsTimer.schedule(new TimerTask() {
|
mSettingsTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
@@ -244,6 +244,8 @@ public class SdDataSourcePebble extends SdDataSource {
|
|||||||
* - defined in res/xml/SdDataSourcePebblePrefs.xml
|
* - defined in res/xml/SdDataSourcePebblePrefs.xml
|
||||||
*/
|
*/
|
||||||
public void updatePrefs() {
|
public void updatePrefs() {
|
||||||
|
String prefStr = "null";
|
||||||
|
|
||||||
Log.v(TAG, "updatePrefs()");
|
Log.v(TAG, "updatePrefs()");
|
||||||
//mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs()");
|
//mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs()");
|
||||||
SharedPreferences SP = PreferenceManager
|
SharedPreferences SP = PreferenceManager
|
||||||
@@ -273,7 +275,6 @@ public class SdDataSourcePebble extends SdDataSource {
|
|||||||
|
|
||||||
|
|
||||||
// Watch Settings
|
// Watch Settings
|
||||||
String prefStr;
|
|
||||||
|
|
||||||
prefStr = SP.getString("PebbleDebug", "SET_FROM_XML");
|
prefStr = SP.getString("PebbleDebug", "SET_FROM_XML");
|
||||||
mDebug = (short) Integer.parseInt(prefStr);
|
mDebug = (short) Integer.parseInt(prefStr);
|
||||||
@@ -347,7 +348,7 @@ public class SdDataSourcePebble extends SdDataSource {
|
|||||||
Log.v(TAG, "updatePrefs() FallWindow = " + mFallWindow);
|
Log.v(TAG, "updatePrefs() FallWindow = " + mFallWindow);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.v(TAG, "updatePrefs() - Problem parsing preferences!");
|
Log.v(TAG, "updatePrefs() - Problem parsing preferences! - prefStr="+prefStr);
|
||||||
mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs() - ERROR "+ex.toString());
|
mUtil.writeToSysLogFile("SdDataSourcePebble.updatePrefs() - ERROR "+ex.toString());
|
||||||
Toast toast = Toast.makeText(mContext, "Problem Parsing Preferences - Something won't work - Please go back to Settings and correct it!", Toast.LENGTH_SHORT);
|
Toast toast = Toast.makeText(mContext, "Problem Parsing Preferences - Something won't work - Please go back to Settings and correct it!", Toast.LENGTH_SHORT);
|
||||||
toast.show();
|
toast.show();
|
||||||
|
|||||||
@@ -139,14 +139,14 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
*/
|
*/
|
||||||
public SdServer() {
|
public SdServer() {
|
||||||
super();
|
super();
|
||||||
Log.v(TAG, "SdServer Created");
|
Log.i(TAG, "SdServer Created");
|
||||||
mSdData = new SdData();
|
mSdData = new SdData();
|
||||||
mToneGenerator = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
|
mToneGenerator = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
Log.v(TAG, "sdServer.onBind()");
|
Log.i(TAG, "sdServer.onBind()");
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Log.v(TAG, "onCreate()");
|
Log.i(TAG, "onCreate()");
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mUtil = new OsdUtil(getApplicationContext(), mHandler);
|
mUtil = new OsdUtil(getApplicationContext(), mHandler);
|
||||||
mUtil.writeToSysLogFile("SdServer.onCreate()");
|
mUtil.writeToSysLogFile("SdServer.onCreate()");
|
||||||
@@ -186,7 +186,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Log.v(TAG, "onStartCommand() - SdServer service starting");
|
Log.i(TAG, "onStartCommand() - SdServer service starting");
|
||||||
mUtil.writeToSysLogFile("SdServer.onStartCommand()");
|
mUtil.writeToSysLogFile("SdServer.onStartCommand()");
|
||||||
|
|
||||||
// Update preferences.
|
// Update preferences.
|
||||||
@@ -216,10 +216,11 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
mSdDataSource = new SdDataSourceGarmin(this.getApplicationContext(), mHandler, this);
|
mSdDataSource = new SdDataSourceGarmin(this.getApplicationContext(), mHandler, this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.v(TAG, "Datasource " + mSdDataSourceName + " not recognised - Exiting");
|
Log.e(TAG, "Datasource " + mSdDataSourceName + " not recognised - Defaulting to Pebble");
|
||||||
mUtil.writeToSysLogFile("SdServer.onStartCommand() - Datasource " + mSdDataSourceName + " not recognised - exiting");
|
mUtil.writeToSysLogFile("SdServer.onStartCommand() - Datasource " + mSdDataSourceName + " not recognised - exiting");
|
||||||
mUtil.showToast("Datasource " + mSdDataSourceName + " not recognised - Exiting");
|
mUtil.showToast("Datasource " + mSdDataSourceName + " not recognised - Defaulting to Pebble");
|
||||||
return 1;
|
mUtil.writeToSysLogFile("SdServer.onStartCommand() - creating SdDataSourcePebble");
|
||||||
|
mSdDataSource = new SdDataSourcePebble(this.getApplicationContext(), mHandler, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSMSAlarm) {
|
if (mSMSAlarm) {
|
||||||
@@ -295,7 +296,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Log.v(TAG, "onDestroy(): SdServer Service stopping");
|
Log.i(TAG, "onDestroy(): SdServer Service stopping");
|
||||||
mUtil.writeToSysLogFile("SdServer.onDestroy() - releasing wakelock");
|
mUtil.writeToSysLogFile("SdServer.onDestroy() - releasing wakelock");
|
||||||
// release the wake lock to allow CPU to sleep and reduce
|
// release the wake lock to allow CPU to sleep and reduce
|
||||||
// battery drain.
|
// battery drain.
|
||||||
@@ -314,7 +315,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mSdDataSource != null) {
|
if (mSdDataSource != null) {
|
||||||
Log.v(TAG, "stopping mSdDataSource");
|
Log.i(TAG, "stopping mSdDataSource");
|
||||||
mUtil.writeToSysLogFile("SdServer.onDestroy() - stopping mSdDataSource");
|
mUtil.writeToSysLogFile("SdServer.onDestroy() - stopping mSdDataSource");
|
||||||
mSdDataSource.stop();
|
mSdDataSource.stop();
|
||||||
} else {
|
} else {
|
||||||
@@ -574,7 +575,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
|
|
||||||
// Called by SdDataSource when a fault condition is detected.
|
// Called by SdDataSource when a fault condition is detected.
|
||||||
public void onSdDataFault(SdData sdData) {
|
public void onSdDataFault(SdData sdData) {
|
||||||
Log.i(TAG, "onSdDataFault()");
|
Log.v(TAG, "onSdDataFault()");
|
||||||
mSdData = sdData;
|
mSdData = sdData;
|
||||||
mSdData.alarmState = 4; // set fault alarm state.
|
mSdData.alarmState = 4; // set fault alarm state.
|
||||||
mSdData.alarmStanding = false;
|
mSdData.alarmStanding = false;
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ public class StartupActivity extends Activity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mConnection = new SdServiceConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -198,16 +199,17 @@ public class StartupActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mUtil.isServerRunning()) {
|
if (mUtil.isServerRunning()) {
|
||||||
Log.v(TAG, "onStart() - server running - stopping it");
|
Log.i(TAG, "onStart() - server running - stopping it");
|
||||||
mUtil.writeToSysLogFile("StartupActivity.onStart() - server already running - stopping it.");
|
mUtil.writeToSysLogFile("StartupActivity.onStart() - server already running - stopping it.");
|
||||||
mUtil.stopServer();
|
mUtil.stopServer();
|
||||||
}
|
}
|
||||||
mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server");
|
mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server");
|
||||||
|
Log.i(TAG,"onStart() - starting server");
|
||||||
mUtil.startServer();
|
mUtil.startServer();
|
||||||
|
|
||||||
// Bind to the service.
|
// Bind to the service.
|
||||||
|
Log.i(TAG,"onStart() - binding to server");
|
||||||
mUtil.writeToSysLogFile("StartupActivity.onStart() - binding to server");
|
mUtil.writeToSysLogFile("StartupActivity.onStart() - binding to server");
|
||||||
mConnection = new SdServiceConnection(this);
|
|
||||||
mUtil.bindToServer(this, mConnection);
|
mUtil.bindToServer(this, mConnection);
|
||||||
|
|
||||||
// Check to see if this is the first time the app has been run, and display welcome dialog if it is.
|
// Check to see if this is the first time the app has been run, and display welcome dialog if it is.
|
||||||
@@ -229,7 +231,7 @@ public class StartupActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
Log.i(TAG, "onStop()");
|
Log.i(TAG, "onStop() - unbinding from server");
|
||||||
mUtil.writeToSysLogFile("StartupActivity.onStop() - unbinding from server");
|
mUtil.writeToSysLogFile("StartupActivity.onStop() - unbinding from server");
|
||||||
mUtil.unbindFromServer(this, mConnection);
|
mUtil.unbindFromServer(this, mConnection);
|
||||||
mUiTimer.cancel();
|
mUiTimer.cancel();
|
||||||
@@ -250,21 +252,22 @@ public class StartupActivity extends Activity {
|
|||||||
|
|
||||||
Log.v(TAG,"serverStatusRunnable()");
|
Log.v(TAG,"serverStatusRunnable()");
|
||||||
|
|
||||||
// Service Running
|
// Settings ok
|
||||||
tv = (TextView) findViewById(R.id.textItem1);
|
tv = (TextView) findViewById(R.id.textItem1);
|
||||||
pb = (ProgressBar) findViewById(R.id.progressBar1);
|
pb = (ProgressBar) findViewById(R.id.progressBar1);
|
||||||
if (mUtil.isServerRunning()) {
|
if (mUtil.arePermissionsOK()) {
|
||||||
tv.setText("Background Service Running OK");
|
tv.setText("App Permissions OK");
|
||||||
tv.setBackgroundColor(okColour);
|
tv.setBackgroundColor(okColour);
|
||||||
tv.setTextColor(okTextColour);
|
tv.setTextColor(okTextColour);
|
||||||
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||||
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||||
} else {
|
} else {
|
||||||
tv.setText("Waiting for Background Service...");
|
tv.setText("Problem with App Permissions");
|
||||||
tv.setBackgroundColor(alarmColour);
|
tv.setBackgroundColor(alarmColour);
|
||||||
tv.setTextColor(alarmTextColour);
|
tv.setTextColor(alarmTextColour);
|
||||||
pb.setIndeterminate(true);
|
pb.setIndeterminate(true);
|
||||||
allOk = false;
|
allOk = false;
|
||||||
|
mUtil.requestPermissions(StartupActivity.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we Bound to the Service
|
// Are we Bound to the Service
|
||||||
|
|||||||
Reference in New Issue
Block a user