Commit d7f63203 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

Ignore #setInitialA11yFocus before view created

Calls to FirstRunFragment#setInitialA11yFocus can be triggered when
view is not initialized yet for the fragment and cause NPE with current
implementations. This CL simply ignores the calls if it is made too
early.

More context on why #setInitialA11yFocus is introduced and why this
fix might be sufficient can be found in the crbug.com/1140174#c2.


Bug: 1140174
Change-Id: Ie7771e73a46bd30d1c0e0fa3e2e56c0e886c4d54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2487580
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819064}
parent d5126f6a
...@@ -94,6 +94,9 @@ public class DataReductionProxyFirstRunFragment extends Fragment implements Firs ...@@ -94,6 +94,9 @@ public class DataReductionProxyFirstRunFragment extends Fragment implements Firs
@Override @Override
public void setInitialA11yFocus() { public void setInitialA11yFocus() {
// Ignore calls before view is created.
if (getView() == null) return;
final View title = getView().findViewById(R.id.title); final View title = getView().findViewById(R.id.title);
title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
} }
......
...@@ -71,6 +71,9 @@ public class DefaultSearchEngineFirstRunFragment extends Fragment implements Fir ...@@ -71,6 +71,9 @@ public class DefaultSearchEngineFirstRunFragment extends Fragment implements Fir
@Override @Override
public void setInitialA11yFocus() { public void setInitialA11yFocus() {
// Ignore calls before view is created.
if (getView() == null) return;
final View title = getView().findViewById(R.id.chooser_title); final View title = getView().findViewById(R.id.chooser_title);
title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
} }
......
...@@ -31,9 +31,11 @@ public interface FirstRunFragment { ...@@ -31,9 +31,11 @@ public interface FirstRunFragment {
* Set the a11y focus when the fragment is shown on the screen. * Set the a11y focus when the fragment is shown on the screen.
* *
* Android ViewPager cannot always assign the correct a11y focus automatically when switching * Android ViewPager cannot always assign the correct a11y focus automatically when switching
* between pages. * between pages. See https://crbug.com/1094064 for more detail.
* *
* See https://crbug.com/1094064 for more detail. * Note that this function can be called before views for the fragment is created. To avoid NPE,
* it is suggested to add null checker inside this function implementation. See
* https://crbug.com/1140174 for more detail.
*/ */
void setInitialA11yFocus(); void setInitialA11yFocus();
......
...@@ -88,6 +88,9 @@ public class SigninFirstRunFragment extends SigninFragmentBase implements FirstR ...@@ -88,6 +88,9 @@ public class SigninFirstRunFragment extends SigninFragmentBase implements FirstR
@Override @Override
public void setInitialA11yFocus() { public void setInitialA11yFocus() {
// Ignore calls before view is created.
if (getView() == null) return;
final View title = getView().findViewById(R.id.signin_title); final View title = getView().findViewById(R.id.signin_title);
title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); title.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
} }
......
...@@ -138,6 +138,8 @@ public class ToSAndUMAFirstRunFragment extends Fragment implements FirstRunFragm ...@@ -138,6 +138,8 @@ public class ToSAndUMAFirstRunFragment extends Fragment implements FirstRunFragm
@Override @Override
public void setInitialA11yFocus() { public void setInitialA11yFocus() {
// Ignore calls before view is created.
if (mTitle == null) return;
mTitle.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); mTitle.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
} }
......
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