synchronized (mLock) {
UserState userState = mUserStateWeakReference.get();
if (userState == null) return;
- if (userState.mEnabledServices.remove(mComponentName)) {
+ if (userState.getEnabledServicesLocked().remove(mComponentName)) {
final long identity = Binder.clearCallingIdentity();
try {
mSystemSupport.persistComponentNamesToSettingLocked(
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
- userState.mEnabledServices, userState.mUserId);
+ userState.getEnabledServicesLocked(), userState.mUserId);
} finally {
Binder.restoreCallingIdentity(identity);
}
mWasConnectedAndDied = false;
serviceInterface = mServiceInterface;
}
+ // There's a chance that service is removed from enabled_accessibility_services setting
+ // key, but skip unbinding because of it's in binding state. Unbinds it if it's
+ // not in enabled service list.
+ if (serviceInterface != null
+ && !userState.getEnabledServicesLocked().contains(mComponentName)) {
+ mSystemSupport.onClientChangeLocked(false);
+ return;
+ }
}
if (serviceInterface == null) {
binderDied();
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.accessibilityservice.AccessibilityServiceInfo;
+import android.accessibilityservice.IAccessibilityServiceClient;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import org.mockito.MockitoAnnotations;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
assertTrue(mConnection.getServiceInfo().crashed);
verify(mMockKeyEventDispatcher).flush(mConnection);
}
+
+ @Test
+ public void connectedService_notInEnabledServiceList_doNotInitClient()
+ throws RemoteException {
+ IBinder mockBinder = mock(IBinder.class);
+ IAccessibilityServiceClient mockClient = mock(IAccessibilityServiceClient.class);
+ when(mockBinder.queryLocalInterface(any())).thenReturn(mockClient);
+ when(mMockUserState.getEnabledServicesLocked())
+ .thenReturn(Collections.emptySet());
+ setServiceBinding(COMPONENT_NAME);
+
+ mConnection.bindLocked();
+ mConnection.onServiceConnected(COMPONENT_NAME, mockBinder);
+ mHandler.sendAllMessages();
+ verify(mMockSystemSupport, times(2)).onClientChangeLocked(false);
+ verify(mockClient, times(0)).init(any(), anyInt(), any());
+ }
}