Skip to content

Commit

Permalink
Null array bug fix in Accelerometer.
Browse files Browse the repository at this point in the history
* Moved data saving to separate thread in ForegroundApplication.
  • Loading branch information
audaciouscode committed Aug 17, 2017
1 parent 90258c2 commit 5f8f7e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Expand Up @@ -103,35 +103,43 @@ private void startGenerator() {
this.mAppChecker = new AppChecker();
this.mAppChecker.other(new AppChecker.Listener() {
@Override
public void onForeground(String process) {
long now = System.currentTimeMillis();
public void onForeground(final String process) {
final long now = System.currentTimeMillis();

WindowManager window = (WindowManager) me.mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = window.getDefaultDisplay();
final Display display = window.getDefaultDisplay();

boolean screenActive = true;
Runnable r = new Runnable() {
@Override
public void run() {
boolean screenActive = true;

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
if (display.getState() != Display.STATE_ON) {
screenActive = false;
}
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
if (display.getState() != Display.STATE_ON) {
screenActive = false;
}
}

ContentValues values = new ContentValues();
values.put(ForegroundApplication.HISTORY_OBSERVED, now);
values.put(ForegroundApplication.HISTORY_APPLICATION, process);
values.put(ForegroundApplication.HISTORY_DURATION, me.mSampleInterval);
values.put(ForegroundApplication.HISTORY_SCREEN_ACTIVE, screenActive);

ContentValues values = new ContentValues();
values.put(ForegroundApplication.HISTORY_OBSERVED, now);
values.put(ForegroundApplication.HISTORY_APPLICATION, process);
values.put(ForegroundApplication.HISTORY_DURATION, me.mSampleInterval);
values.put(ForegroundApplication.HISTORY_SCREEN_ACTIVE, screenActive);
me.mDatabase.insert(ForegroundApplication.TABLE_HISTORY, null, values);

me.mDatabase.insert(ForegroundApplication.TABLE_HISTORY, null, values);
Bundle update = new Bundle();
update.putLong(ForegroundApplication.HISTORY_OBSERVED, now);
update.putString(ForegroundApplication.HISTORY_APPLICATION, process);
update.putLong(ForegroundApplication.HISTORY_DURATION, me.mSampleInterval);
update.putBoolean(ForegroundApplication.HISTORY_SCREEN_ACTIVE, screenActive);

Bundle update = new Bundle();
update.putLong(ForegroundApplication.HISTORY_OBSERVED, now);
update.putString(ForegroundApplication.HISTORY_APPLICATION, process);
update.putLong(ForegroundApplication.HISTORY_DURATION, me.mSampleInterval);
update.putBoolean(ForegroundApplication.HISTORY_SCREEN_ACTIVE, screenActive);
Generators.getInstance(me.mContext).notifyGeneratorUpdated(ForegroundApplication.GENERATOR_IDENTIFIER, update);
}
};

Generators.getInstance(me.mContext).notifyGeneratorUpdated(ForegroundApplication.GENERATOR_IDENTIFIER, update);
Thread t = new Thread(r);
t.start();
}
});

Expand Down
Expand Up @@ -685,6 +685,10 @@ public Cursor queryHistory(String[] cols, String where, String[] args, String or

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.values == null) {
return;
}

long rawTimestamp = sensorEvent.timestamp;

if (this.mBaseTimestamp == 0) {
Expand Down

0 comments on commit 5f8f7e5

Please sign in to comment.