Fix a crash in Storage Settings.

This prevents a NullPtrException when the DonutView attempts to shrink
the percentage sign. By gracefully falling back when we don't understand
the percentage sign, we can avoid a crash.

Change-Id: I0b0770ce4b51eb30817dc556636f86476f4cd1bf
Fixes: 77653937
Test: Robotest -- screenshot attached
This commit is contained in:
Daniel Nishi
2018-04-06 13:05:35 -07:00
parent c2ec26b4ac
commit f5ba67dc40
2 changed files with 46 additions and 8 deletions

View File

@@ -0,0 +1,19 @@
package com.android.settings.widget;
import android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class DonutViewTest {
@Test
public void getPercentageStringSpannable_doesntCrashForMissingPercentage() {
Context context = RuntimeEnvironment.application;
DonutView.getPercentageStringSpannable(context.getResources(), "50%", "h");
}
}