Skip to content

Commit

Permalink
GetLocales might crash, lint says. Lets prevent it.
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Dec 1, 2017
1 parent 0ca216f commit 603bc3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
}
lintOptions {
warning 'MissingTranslation'
disable 'GoogleAppIndexingWarning','GoogleAppIndexingApiWarning','TrulyRandom','BadHostnameVerifier','IconMissingDensityFolder','IconLocation','UnusedAttribute'
disable 'GoogleAppIndexingWarning','GoogleAppIndexingApiWarning','TrulyRandom','BadHostnameVerifier','IconMissingDensityFolder','IconLocation','UnusedAttribute','GetLocales'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

public class NativeDeviceInfoProvider implements DeviceInfoProvider {
Expand Down Expand Up @@ -198,8 +199,16 @@ static public List<String> getFeatures(Context context) {
}

static public List<String> getLocales(Context context) {
List<String> rawLocales = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
rawLocales.addAll(Arrays.asList(context.getAssets().getLocales()));
} else {
for (Locale locale: Locale.getAvailableLocales()) {
rawLocales.add(locale.toString());
}
}
List<String> locales = new ArrayList<>();
for (String locale: context.getAssets().getLocales()) {
for (String locale: rawLocales) {
if (TextUtils.isEmpty(locale)) {
continue;
}
Expand Down

0 comments on commit 603bc3a

Please sign in to comment.