Merge "Add Compat framework flag to restrict SAF" into rvc-dev
diff --git a/res/layout/item_doc_list.xml b/res/layout/item_doc_list.xml
index 8e73b7f..7c1b28f 100644
--- a/res/layout/item_doc_list.xml
+++ b/res/layout/item_doc_list.xml
@@ -34,7 +34,7 @@
android:orientation="horizontal" >
<FrameLayout
- android:id="@android:id/icon"
+ android:id="@+id/icon"
android:pointerIcon="hand"
android:layout_width="@dimen/list_item_width"
android:layout_height="@dimen/list_item_height"
diff --git a/src/com/android/documentsui/dirlist/ListDocumentHolder.java b/src/com/android/documentsui/dirlist/ListDocumentHolder.java
index f4ec86b..7590609 100644
--- a/src/com/android/documentsui/dirlist/ListDocumentHolder.java
+++ b/src/com/android/documentsui/dirlist/ListDocumentHolder.java
@@ -66,7 +66,7 @@
Lookup<String, String> fileTypeLookup) {
super(context, parent, R.layout.item_doc_list);
- mIconLayout = itemView.findViewById(android.R.id.icon);
+ mIconLayout = itemView.findViewById(R.id.icon);
mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime);
mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb);
mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check);
diff --git a/tests/common/com/android/documentsui/bots/DirectoryListBot.java b/tests/common/com/android/documentsui/bots/DirectoryListBot.java
index 97db4de..08d2995 100644
--- a/tests/common/com/android/documentsui/bots/DirectoryListBot.java
+++ b/tests/common/com/android/documentsui/bots/DirectoryListBot.java
@@ -34,13 +34,13 @@
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
-import android.widget.ImageView;
import java.util.ArrayList;
import java.util.Arrays;
@@ -62,6 +62,7 @@
private final String mDirListId;
private final String mItemRootId;
private final String mPreviewId;
+ private final String mIconId;
private UiAutomation mAutomation;
@@ -73,6 +74,7 @@
mDirListId = mTargetPackage + ":id/dir_list";
mItemRootId = mTargetPackage + ":id/item_root";
mPreviewId = mTargetPackage + ":id/preview_icon";
+ mIconId = mTargetPackage + ":id/icon";
}
public void assertDocumentsCount(int count) throws UiObjectNotFoundException {
@@ -182,7 +184,7 @@
public void openDocument(String label) throws UiObjectNotFoundException {
int toolType = Configurator.getInstance().getToolType();
Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
- UiObject doc = findDocument(label);
+ UiObject doc = findDocument(label, true);
doc.click();
Configurator.getInstance().setToolType(toolType);
}
@@ -212,20 +214,22 @@
.equals(mTargetPackage + ":id/icon_check");
}
- public UiObject2 findSelectionHotspot(String label) {
+ public UiObject2 findSelectionHotspot(String label) throws UiObjectNotFoundException {
final BySelector list = By.res(mDirListId);
BySelector selector = By.hasChild(By.text(label));
+
+ final UiSelector docList = findDocumentsListSelector();
+ new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
+
UiObject2 parent = mDevice.findObject(list).findObject(selector);
- if (parent.getClassName().equals("android.widget.LinearLayout")
- || parent.getClassName().equals("android.widget.RelativeLayout")) {
- // For list mode and doc grid, the parent of the textView does not contain the selector
- // icon, but the grandparent of the textView does
- // Gotta go one more level up
- selector = By.hasDescendant(By.text(label).depth(2));
- parent = mDevice.findObject(list).findObject(selector);
+ for (int i = 1; i <= MAX_LAYOUT_LEVEL; i++) {
+ parent = parent.getParent();
+ if (mItemRootId.equals(parent.getResourceName())) {
+ break;
+ }
}
- return parent.findObject(By.clazz(ImageView.class));
+ return parent.findObject(By.res(mIconId));
}
public void copyFilesToClipboard(String...labels) throws UiObjectNotFoundException {
@@ -263,14 +267,19 @@
}
public UiObject findDocument(String label) throws UiObjectNotFoundException {
- final UiSelector docList = new UiSelector().resourceId(
- mDirContainerId).childSelector(
- new UiSelector().resourceId(mDirListId));
+ return findDocument(label, false);
+ }
+
+ public UiObject findDocument(String label, boolean withScroll)
+ throws UiObjectNotFoundException {
+ final UiSelector docList = findDocumentsListSelector();
// Wait for the first list item to appear
new UiObject(docList.childSelector(new UiSelector())).waitForExists(mTimeout);
- // new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
+ if (withScroll) {
+ new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
+ }
return mDevice.findObject(docList.childSelector(new UiSelector().text(label)));
}
@@ -299,9 +308,7 @@
}
public void assertFirstDocumentHasFocus() throws UiObjectNotFoundException {
- final UiSelector docList = new UiSelector().resourceId(
- mDirContainerId).childSelector(
- new UiSelector().resourceId(mDirListId));
+ final UiSelector docList = findDocumentsListSelector();
// Wait for the first list item to appear
UiObject doc = new UiObject(docList.childSelector(new UiSelector()));
@@ -316,6 +323,12 @@
mDirListId);
}
+ private UiSelector findDocumentsListSelector() {
+ return new UiSelector().resourceId(
+ mDirContainerId).childSelector(
+ new UiSelector().resourceId(mDirListId));
+ }
+
public void assertHasFocus() {
assertHasFocus(mDirListId);
}
@@ -342,7 +355,7 @@
}
public void rightClickDocument(String label) throws UiObjectNotFoundException {
- Rect startCoord = findDocument(label).getBounds();
+ Rect startCoord = findDocument(label, true).getBounds();
rightClickDocument(new Point(startCoord.centerX(), startCoord.centerY()));
}
diff --git a/tests/functional/com/android/documentsui/CancelFromNotificationUiTest.java b/tests/functional/com/android/documentsui/CancelFromNotificationUiTest.java
index 1c125c9..e2bc292 100644
--- a/tests/functional/com/android/documentsui/CancelFromNotificationUiTest.java
+++ b/tests/functional/com/android/documentsui/CancelFromNotificationUiTest.java
@@ -87,6 +87,8 @@
// So, reset the storage size again to 500MB.
Bundle bundle = new Bundle();
bundle.putLong(EXTRA_SIZE, 500L);
+ // Set a flag to prevent many refreshes.
+ bundle.putBoolean(StubProvider.EXTRA_ENABLE_ROOT_NOTIFICATION, false);
mDocsHelper.configure(null, bundle);
try {
diff --git a/tests/common/com/android/documentsui/DialogFragmentTest.java b/tests/functional/com/android/documentsui/DialogUiTest.java
similarity index 97%
rename from tests/common/com/android/documentsui/DialogFragmentTest.java
rename to tests/functional/com/android/documentsui/DialogUiTest.java
index 1fe2c32..2413602 100644
--- a/tests/common/com/android/documentsui/DialogFragmentTest.java
+++ b/tests/functional/com/android/documentsui/DialogUiTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package com.android.documentsui;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -29,7 +31,7 @@
import android.os.ParcelFileDescriptor;
import androidx.fragment.app.FragmentManager;
-import androidx.test.filters.MediumTest;
+import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
@@ -54,9 +56,9 @@
import java.io.FileInputStream;
import java.io.IOException;
-@MediumTest
+@LargeTest
@RunWith(AndroidJUnit4.class)
-public class DialogFragmentTest {
+public class DialogUiTest {
private static final String CREATE_FRAGEMENT_TAG = "create_directory";
CreateDirectoryFragment mCreateDirectoryFragment;
@@ -81,7 +83,7 @@
mCreateDirectoryFragment = null;
}
-/* @Test
+ @Test
public void testCreateDialogShows() throws Throwable {
mActivityTestRule.runOnUiThread(() -> CreateDirectoryFragment.show(mFragmentManager));
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
@@ -216,7 +218,7 @@
// called, so test pass means it skip.
CreateDirectoryFragment.show(mFragmentManager);
}
-*/
+
@Test
public void testDeleteDocumentFragmentShows_skipWhenStateSaved() {
mFragmentManager = Mockito.mock(FragmentManager.class);
diff --git a/tests/unit/com/android/documentsui/theme/ThemeOverlayManagerTest.java b/tests/unit/com/android/documentsui/theme/ThemeOverlayManagerTest.java
index 2c5d9da..2e5e1a7 100644
--- a/tests/unit/com/android/documentsui/theme/ThemeOverlayManagerTest.java
+++ b/tests/unit/com/android/documentsui/theme/ThemeOverlayManagerTest.java
@@ -46,7 +46,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -91,17 +90,6 @@
}
@Test
- public void testOverlayPackagesForDocumentsUI_shouldBeMutable() {
- final String docsuiPkgId = mContext.getPackageName();
- final OverlayManager manager = mContext.getSystemService(OverlayManager.class);
- final List<OverlayInfo> infos = manager.getOverlayInfosForTarget(docsuiPkgId, mUserHandle);
-
- for (OverlayInfo info : infos) {
- assertThat(info.isMutable).isTrue();
- }
- }
-
- @Test
public void testApplyOverlays_shouldSetEnabled() throws Exception {
final boolean enabled = true;