Merge "Avoid null pointer when in getAmbientBrightnessStats" into pi-dev
am: a43cedbf25
Change-Id: Ia06d7cb7a5585a3f0865cb3500e48a4f02b082ea
This commit is contained in:
@@ -686,10 +686,15 @@ public class BrightnessTracker {
|
||||
}
|
||||
|
||||
public ParceledListSlice<AmbientBrightnessDayStats> getAmbientBrightnessStats(int userId) {
|
||||
ArrayList<AmbientBrightnessDayStats> stats = mAmbientBrightnessStatsTracker.getUserStats(
|
||||
userId);
|
||||
return (stats != null) ? new ParceledListSlice<>(stats) : new ParceledListSlice<>(
|
||||
Collections.EMPTY_LIST);
|
||||
if (mAmbientBrightnessStatsTracker != null) {
|
||||
ArrayList<AmbientBrightnessDayStats> stats =
|
||||
mAmbientBrightnessStatsTracker.getUserStats(
|
||||
userId);
|
||||
if (stats != null) {
|
||||
return new ParceledListSlice<>(stats);
|
||||
}
|
||||
}
|
||||
return ParceledListSlice.emptyList();
|
||||
}
|
||||
|
||||
// Not allowed to keep the SensorEvent so used to copy the data we care about.
|
||||
|
||||
@@ -30,9 +30,11 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.display.AmbientBrightnessDayStats;
|
||||
import android.hardware.display.BrightnessChangeEvent;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Handler;
|
||||
@@ -571,6 +573,19 @@ public class BrightnessTrackerTest {
|
||||
assertEquals(event.batteryLevel, event2.batteryLevel, FLOAT_DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonNullAmbientStats() {
|
||||
// getAmbientBrightnessStats should return an empty list rather than null when
|
||||
// tracker isn't started or hasn't collected any data.
|
||||
ParceledListSlice<AmbientBrightnessDayStats> slice = mTracker.getAmbientBrightnessStats(0);
|
||||
assertNotNull(slice);
|
||||
assertTrue(slice.getList().isEmpty());
|
||||
startTracker(mTracker);
|
||||
slice = mTracker.getAmbientBrightnessStats(0);
|
||||
assertNotNull(slice);
|
||||
assertTrue(slice.getList().isEmpty());
|
||||
}
|
||||
|
||||
private InputStream getInputStream(String data) {
|
||||
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user