Fixing A11yServiceInfo.packageNames set to Null not work

When setting new package names from A11y services, these package names
only added into the old ones, but didn't be removed old package names
and cleared if the updated package names is Null. Doing the clear
operation for old package names and adding the new ones if there's
any new package names.

Bug: 158314907
Test: a11y CTS & unit tests
Test: manual testing with reporter's test APK
Change-Id: I753a1a2c8909f767a1f7089e6e98e8ad856c09af
This commit is contained in:
Jacky Kao
2020-07-02 08:59:34 +08:00
parent c5caed0cd0
commit 2580b4375c
2 changed files with 21 additions and 0 deletions

View File

@@ -295,6 +295,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
mEventTypes = info.eventTypes;
mFeedbackType = info.feedbackType;
String[] packageNames = info.packageNames;
mPackageNames.clear();
if (packageNames != null) {
mPackageNames.addAll(Arrays.asList(packageNames));
}

View File

@@ -51,6 +51,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -270,6 +271,25 @@ public class AbstractAccessibilityServiceConnectionTest {
verify(mMockSystemSupport).onClientChangeLocked(true);
}
@Test
public void setServiceInfo_ChangePackageNames_updateSuccess() {
assertTrue(mServiceConnection.mPackageNames.isEmpty());
final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo();
updateServiceInfo(serviceInfo, 0, 0, A11Y_SERVICE_FLAG,
new String[] {PACKAGE_NAME1, PACKAGE_NAME2},
1000);
mServiceConnection.setServiceInfo(serviceInfo);
assertEquals(serviceInfo.packageNames.length, mServiceConnection.mPackageNames.size());
assertTrue(mServiceConnection.mPackageNames.containsAll(
Arrays.asList(mServiceConnection.getServiceInfo().packageNames)));
updateServiceInfo(serviceInfo, 0, 0, A11Y_SERVICE_FLAG, null, 1000);
mServiceConnection.setServiceInfo(serviceInfo);
assertTrue(mServiceConnection.mPackageNames.isEmpty());
}
@Test
public void canReceiveEvents_hasEventType_returnTrue() {
final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo();