Skip to content

Commit

Permalink
Bug 1757121 part 4: Acquire the Android lock while shutting down the …
Browse files Browse the repository at this point in the history
…accessibility service. r=eeejay

RemoteAccessibleBase::Attributes will soon use the service to query markup attributes.
Thus, the service must not shut down while a client call is being handled on the UI thread.

Differential Revision: https://phabricator.services.mozilla.com/D150722
  • Loading branch information
jcsteh committed Jul 12, 2022
1 parent d2615d1 commit d0d3ec2
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions accessible/base/nsAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,21 @@ LocalAccessible* nsAccessibilityService::CreateAccessible(
return newAcc;
}

#if defined(ANDROID)
# include "mozilla/Monitor.h"
# include "mozilla/Maybe.h"

static Maybe<Monitor> sAndroidMonitor;

mozilla::Monitor& nsAccessibilityService::GetAndroidMonitor() {
if (!sAndroidMonitor.isSome()) {
sAndroidMonitor.emplace("nsAccessibility::sAndroidMonitor");
}

return *sAndroidMonitor;
}
#endif

////////////////////////////////////////////////////////////////////////////////
// nsAccessibilityService private

Expand Down Expand Up @@ -1359,6 +1374,11 @@ void nsAccessibilityService::Shutdown() {
NS_IF_RELEASE(gXPCApplicationAccessible);
gXPCApplicationAccessible = nullptr;

#if defined(ANDROID)
// Don't allow the service to shut down while an a11y request is being handled
// in the UI thread, as the request may depend on state from the service.
MonitorAutoLock mal(GetAndroidMonitor());
#endif
NS_RELEASE(gAccessibilityService);
gAccessibilityService = nullptr;

Expand Down Expand Up @@ -1555,21 +1575,6 @@ void nsAccessibilityService::MarkupAttributes(
}
}

#if defined(ANDROID)
# include "mozilla/Monitor.h"
# include "mozilla/Maybe.h"

static Maybe<Monitor> sAndroidMonitor;

mozilla::Monitor& nsAccessibilityService::GetAndroidMonitor() {
if (!sAndroidMonitor.isSome()) {
sAndroidMonitor.emplace("nsAccessibility::sAndroidMonitor");
}

return *sAndroidMonitor;
}
#endif

LocalAccessible* nsAccessibilityService::AddNativeRootAccessible(
void* aAtkAccessible) {
#ifdef MOZ_ACCESSIBILITY_ATK
Expand Down

0 comments on commit d0d3ec2

Please sign in to comment.