Not crash when UI objects disappear during visible objects verification
Bug: 146785144 Change-Id: I5ccac4871c683413c27753774adc432e5e654e27
This commit is contained in:
1 parent
0fd48b51ba
commit
b856e48594
1 file changed
+12
-2
@@ -55,6 +55,7 @@ import androidx.test.uiautomator.By;
|
||||
import androidx.test.uiautomator.BySelector;
|
||||
import androidx.test.uiautomator.Configurator;
|
||||
import androidx.test.uiautomator.Direction;
|
||||
import androidx.test.uiautomator.StaleObjectException;
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
import androidx.test.uiautomator.Until;
|
||||
@@ -311,12 +312,21 @@ public final class LauncherInstrumentation {
|
||||
private String getVisiblePackages() {
|
||||
return mDevice.findObjects(By.textStartsWith(""))
|
||||
.stream()
|
||||
.map(object -> object.getApplicationPackage())
|
||||
.map(LauncherInstrumentation::getApplicationPackageSafe)
|
||||
.distinct()
|
||||
.filter(pkg -> !"com.android.systemui".equals(pkg))
|
||||
.filter(pkg -> pkg != null && !"com.android.systemui".equals(pkg))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private static String getApplicationPackageSafe(UiObject2 object) {
|
||||
try {
|
||||
return object.getApplicationPackage();
|
||||
} catch (StaleObjectException e) {
|
||||
// We are looking at all object in the system; external ones can suddenly go away.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getVisibleStateMessage() {
|
||||
if (hasLauncherObject(CONTEXT_MENU_RES_ID)) return "Context Menu";
|
||||
if (hasLauncherObject(WIDGETS_RES_ID)) return "Widgets";
|
||||
|
||||
Reference in new issue
Block a user