Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brave notification permission issue fix (uplift to 1.47.x) #16781

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,12 @@ public void onRequestPermissionsResult(
@Override
public void onResume() {
super.onResume();
if (BravePermissionUtils.hasPermission(
getContext(), PermissionConstants.NOTIFICATION_PERMISSION)) {
statsNotificationView.setVisibility(View.GONE);
} else {
if (!BravePermissionUtils.hasPermission(
getContext(), PermissionConstants.NOTIFICATION_PERMISSION)
|| BravePermissionUtils.isGeneralNotificationPermissionBlocked(getActivity())) {
statsNotificationView.setVisibility(View.VISIBLE);
} else {
statsNotificationView.setVisibility(View.GONE);
}
}

Expand All @@ -224,8 +225,9 @@ private void updateNotificationView(View view) {
btnDismiss.setOnClickListener(v -> { statsNotificationView.setVisibility(View.GONE); });
View notificationOnButton = view.findViewById(R.id.notification_on_button);
notificationOnButton.setOnClickListener(v -> {
if (getActivity().shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
if (BravePermissionUtils.isGeneralNotificationPermissionBlocked(getActivity())
|| getActivity().shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
|| (!BuildInfo.isAtLeastT() || !BuildInfo.targetsAtLeastT())) {
// other than android 13 redirect to
// setting page and for android 13 Last time don't allow selected in permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public static boolean shouldShowNotificationWarningDialog(Context context) {
return false;
}

private static boolean shouldShowRewardWarningDialog(Context context) {
public static boolean shouldShowRewardWarningDialog(Context context) {
return BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(context)
&& isBraveRewardsEnabled();
}

private static boolean shouldShowPrivacyWarningDialog(Context context) {
public static boolean shouldShowPrivacyWarningDialog(Context context) {
return BravePermissionUtils.isGeneralNotificationPermissionBlocked(context)
&& isPrivacyReportsEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,9 @@ public void onClick(View v) {
}

private void requestNotificationPermission() {
if (mActivity.shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
if (BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(mAnchorView.getContext())
|| mActivity.shouldShowRequestPermissionRationale(
PermissionConstants.NOTIFICATION_PERMISSION)
|| (!BuildInfo.isAtLeastT() || !BuildInfo.targetsAtLeastT())) {
// other than android 13 redirect to
// setting page and for android 13 Last time don't allow selected in permission
Expand Down Expand Up @@ -1009,16 +1010,16 @@ public void onNothingSelected(AdapterView<?> arg0) {}
btnContinue.setOnClickListener((new View.OnClickListener() {
@Override
public void onClick(View v) {
if (BravePermissionUtils.hasPermission(mAnchorView.getContext(),
PermissionConstants.NOTIFICATION_PERMISSION)) {
if (countrySpinner != null) {
mBraveRewardsNativeWorker.CreateRewardsWallet(sortedCountryMap.get(
countrySpinner.getSelectedItem().toString()));
}
} else {
// else request notification permission
if (!BravePermissionUtils.hasPermission(mAnchorView.getContext(),
PermissionConstants.NOTIFICATION_PERMISSION)
|| BravePermissionUtils.isBraveAdsNotificationPermissionBlocked(
mAnchorView.getContext())) {
requestNotificationPermission();
}
if (countrySpinner != null) {
mBraveRewardsNativeWorker.CreateRewardsWallet(
sortedCountryMap.get(countrySpinner.getSelectedItem().toString()));
}
}
}));
}
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
Turn notifications back on if you'd like to keep earning BAT and receiving weekly privacy reports.
</message>
<message name="IDS_NOTIFICATION_BRAVE_DIALOG_DESCRIPTION_ONLY_REWARDS" desc="Text description for When ONLY Brave Rewards is TURNED ON.">
Turn notifications back on if you'd like to keep earning BAT
Turn notifications back on if you'd like to keep earning BAT.
</message>
<message name="IDS_NOTIFICATION_BRAVE_DIALOG_DESCRIPTION_ONLY_PRIVACY" desc="Text description for When ONLY Privacy Report is TURNED ON.">
Turn notifications back on if you'd like to keep receiving weekly privacy reports.
Expand Down