Commit 1127bd12 authored by Dmitry Skiba's avatar Dmitry Skiba Committed by Commit Bot

Handle ResourceNotFound in TabbedModeFRA.

TabbedModeFirstRunActivity introduced in 9c6253e4 doesn't properly
handle Resources.NotFoundException from Resources.getValue(), which
can result in a crash (see the bug).

This CL adds necessary Resources.NotFoundException handling.

Bug: 780459
Change-Id: Ib56c9e7be3ddb6aff6ab84621a089ace004b2eee
Reviewed-on: https://chromium-review.googlesource.com/748707Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Dmitry Skiba <dskiba@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513289}
parent 98b579c1
......@@ -531,4 +531,10 @@
<!-- Reader Mode dimensions -->
<!-- Padding surrounding the message. -->
<dimen name="reader_mode_infobar_text_padding">8dp</dimen>
<!-- Defaults for TabbedModeFirstRunActivity values. -->
<item type="dimen" name="dialog_fixed_width_major">100%</item>
<item type="dimen" name="dialog_fixed_width_minor">100%</item>
<item type="dimen" name="dialog_fixed_height_major">100%</item>
<item type="dimen" name="dialog_fixed_height_minor">100%</item>
</resources>
......@@ -5,6 +5,8 @@
package org.chromium.chrome.browser.firstrun;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.AnyRes;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
......@@ -59,6 +61,19 @@ public class TabbedModeFirstRunActivity extends FirstRunActivity {
fetchConstraints();
}
/**
* Wrapper around Resources.getValue() that translates Resources.NotFoundException
* into false return value. Otherwise the function returns true.
*/
private boolean safeGetResourceValue(@AnyRes int id, TypedValue value) {
try {
getContext().getResources().getValue(id, value, true);
return true;
} catch (Resources.NotFoundException e) {
return false;
}
}
private void fetchConstraints() {
// Fetch size constraints. These are copies of corresponding abc_* AppCompat values,
// because abc_* values are private, and even though corresponding theme attributes
......@@ -67,14 +82,10 @@ public class TabbedModeFirstRunActivity extends FirstRunActivity {
// system DialogWhenLarge theme.
// Note that we don't care about the return values, because onMeasure() handles null
// constraints (and they will be null when the device is not considered "large").
getContext().getResources().getValue(
R.dimen.dialog_fixed_width_minor, mFixedWidthMinor, true);
getContext().getResources().getValue(
R.dimen.dialog_fixed_width_major, mFixedWidthMajor, true);
getContext().getResources().getValue(
R.dimen.dialog_fixed_height_minor, mFixedHeightMinor, true);
getContext().getResources().getValue(
R.dimen.dialog_fixed_height_major, mFixedHeightMajor, true);
safeGetResourceValue(R.dimen.dialog_fixed_width_minor, mFixedWidthMinor);
safeGetResourceValue(R.dimen.dialog_fixed_width_major, mFixedWidthMajor);
safeGetResourceValue(R.dimen.dialog_fixed_height_minor, mFixedHeightMinor);
safeGetResourceValue(R.dimen.dialog_fixed_height_major, mFixedHeightMajor);
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment