Skip to content

Commit

Permalink
Merge pull request #9920 from brave/pr9901_fix_crash_a5_17735_1.29.x
Browse files Browse the repository at this point in the history
Fix wrong cast exception on Android 5; fixes brave/brave-browser#17735 (uplift to 1.29.x)
  • Loading branch information
kjozwiak authored Sep 1, 2021
2 parents 2fb2fd4 + 934339f commit ca07200
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ else if (cont instanceof ContextWrapper)
* @param context Context that is using the BraveShieldsMenu.
*/
public BraveShieldsHandler(Context context) {
mContext = scanForActivity(context);
Context contextCandidate = scanForActivity(context);
mHardwareButtonMenuAnchor = null;
mContext = (contextCandidate != null && (contextCandidate instanceof Activity))
? contextCandidate
: null;

if (mContext != null) {
mHardwareButtonMenuAnchor = ((Activity)mContext).findViewById(R.id.menu_anchor_stub);
}
Expand Down Expand Up @@ -215,6 +219,8 @@ public void show(View anchorView, Tab tab) {
}

public PopupWindow showPopupMenu(View anchorView) {
if (mContext == null) return null;

int rotation = ((Activity)mContext).getWindowManager().getDefaultDisplay().getRotation();
// This fixes the bug where the bottom of the menu starts at the top of
// the keyboard, instead of overlapping the keyboard as it should.
Expand Down Expand Up @@ -399,6 +405,8 @@ private void initViews() {
}

private void setUpMainLayout() {
if (mContext == null) return;

String favIconURL = mBraveRewardsNativeWorker.GetPublisherFavIconURL(mTabId);
Tab currentActiveTab = mIconFetcher.getTab();
String url = currentActiveTab.getUrl().getSpec();
Expand Down Expand Up @@ -491,6 +499,8 @@ private void setUpSecondaryLayout() {
}

private void setupDetailsLayouts() {
if (mContext == null) return;

ArrayList<String> detailsLayouts = new ArrayList<>();
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_TRACKERS);
detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING);
Expand Down Expand Up @@ -678,6 +688,8 @@ public void onClick(View view) {
}

private void setUpMainSwitchLayout(boolean isChecked) {
if (mContext == null) return;

TextView mShieldDownText = mMainLayout.findViewById(R.id.shield_down_text);
Button mReportBrokenSiteButton = mMainLayout.findViewById(R.id.btn_report_broken_site);
mReportBrokenSiteButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -867,7 +879,7 @@ public void onLargeIconReady(Bitmap icon) {


private void SetFavIcon(Bitmap bmp) {
if (bmp != null) {
if (bmp != null && mContext != null) {
((Activity)mContext).runOnUiThread(
new Runnable() {
@Override
Expand Down

0 comments on commit ca07200

Please sign in to comment.