Commit f3e1c4bc authored by Romain Hunault's avatar Romain Hunault

Merge branch 'cm-14.1' into eelo-0.1

parents 819dcd9d 04a3be40
......@@ -839,6 +839,7 @@ public class DownloadManager {
private long[] mIds = null;
private Integer mStatusFlags = null;
private String mFilterString = null;
private String mOrderByColumn = Downloads.Impl.COLUMN_LAST_MODIFICATION;
private int mOrderDirection = ORDER_DESCENDING;
private boolean mOnlyIncludeVisibleInDownloadsUi = false;
......@@ -852,6 +853,17 @@ public class DownloadManager {
return this;
}
/**
*
* Include only the downloads that contains the given string in its name.
* @return this object
* @hide
*/
public Query setFilterByString(@Nullable String filter) {
mFilterString = filter;
return this;
}
/**
* Include only downloads with status matching any the given status flags.
* @param flags any combination of the STATUS_* bit flags
......@@ -911,9 +923,20 @@ public class DownloadManager {
List<String> selectionParts = new ArrayList<String>();
String[] selectionArgs = null;
if (mIds != null) {
selectionParts.add(getWhereClauseForIds(mIds));
selectionArgs = getWhereArgsForIds(mIds);
int whereArgsCount = (mIds == null) ? 0 : mIds.length;
whereArgsCount = (mFilterString == null) ? whereArgsCount : whereArgsCount + 1;
selectionArgs = new String[whereArgsCount];
if (whereArgsCount > 0) {
if (mIds != null) {
selectionParts.add(getWhereClauseForIds(mIds));
getWhereArgsForIds(mIds, selectionArgs);
}
if (mFilterString != null) {
selectionParts.add(Downloads.Impl.COLUMN_TITLE + " LIKE ?");
selectionArgs[selectionArgs.length - 1] = "%" + mFilterString + "%";
}
}
if (mStatusFlags != null) {
......@@ -1486,12 +1509,22 @@ public class DownloadManager {
*/
static String[] getWhereArgsForIds(long[] ids) {
String[] whereArgs = new String[ids.length];
return getWhereArgsForIds(ids, whereArgs);
}
/**
* Get selection args for a clause returned by {@link #getWhereClauseForIds(long[])}
* and write it to the supplied args array.
*/
static String[] getWhereArgsForIds(long[] ids, String[] args) {
assert(args.length >= ids.length);
for (int i = 0; i < ids.length; i++) {
whereArgs[i] = Long.toString(ids[i]);
args[i] = Long.toString(ids[i]);
}
return whereArgs;
return args;
}
/**
* This class wraps a cursor returned by DownloadProvider -- the "underlying cursor" -- and
* presents a different set of columns, those defined in the DownloadManager.COLUMN_* constants.
......
......@@ -1658,7 +1658,8 @@ public final class SQLiteDatabase extends SQLiteClosable {
executeSql(sql, bindArgs);
}
private int executeSql(String sql, Object[] bindArgs) throws SQLException {
/** {@hide} */
public int executeSql(String sql, Object[] bindArgs) throws SQLException {
acquireReference();
try {
if (DatabaseUtils.getSqlStatementType(sql) == DatabaseUtils.STATEMENT_ATTACH) {
......
This diff is collapsed.
......@@ -338,6 +338,98 @@ class TextLine {
return h;
}
/**
* @see #measure(int, boolean, FontMetricsInt)
* @return The measure results for all possible offsets
*/
float[] measureAllOffsets(boolean[] trailing, FontMetricsInt fmi) {
float[] measurement = new float[mLen + 1];
int[] target = new int[mLen + 1];
for (int offset = 0; offset < target.length; ++offset) {
target[offset] = trailing[offset] ? offset - 1 : offset;
}
if (target[0] < 0) {
measurement[0] = 0;
}
float h = 0;
if (!mHasTabs) {
if (mDirections == Layout.DIRS_ALL_LEFT_TO_RIGHT) {
for (int offset = 0; offset <= mLen; ++offset) {
measurement[offset] = measureRun(0, offset, mLen, false, fmi);
}
return measurement;
}
if (mDirections == Layout.DIRS_ALL_RIGHT_TO_LEFT) {
for (int offset = 0; offset <= mLen; ++offset) {
measurement[offset] = measureRun(0, offset, mLen, true, fmi);
}
return measurement;
}
}
char[] chars = mChars;
int[] runs = mDirections.mDirections;
for (int i = 0; i < runs.length; i += 2) {
int runStart = runs[i];
int runLimit = runStart + (runs[i + 1] & Layout.RUN_LENGTH_MASK);
if (runLimit > mLen) {
runLimit = mLen;
}
boolean runIsRtl = (runs[i + 1] & Layout.RUN_RTL_FLAG) != 0;
int segstart = runStart;
for (int j = mHasTabs ? runStart : runLimit; j <= runLimit; ++j) {
int codept = 0;
if (mHasTabs && j < runLimit) {
codept = chars[j];
if (codept >= 0xD800 && codept < 0xDC00 && j + 1 < runLimit) {
codept = Character.codePointAt(chars, j);
if (codept > 0xFFFF) {
++j;
continue;
}
}
}
if (j == runLimit || codept == '\t') {
float oldh = h;
boolean advance = (mDir == Layout.DIR_RIGHT_TO_LEFT) == runIsRtl;
float w = measureRun(segstart, j, j, runIsRtl, fmi);
h += advance ? w : -w;
float baseh = advance ? oldh : h;
FontMetricsInt crtfmi = advance ? fmi : null;
for (int offset = segstart; offset <= j && offset <= mLen; ++offset) {
if (target[offset] >= segstart && target[offset] < j) {
measurement[offset] =
baseh + measureRun(segstart, offset, j, runIsRtl, crtfmi);
}
}
if (codept == '\t') {
if (target[j] == j) {
measurement[j] = h;
}
h = mDir * nextTab(h * mDir);
if (target[j + 1] == j) {
measurement[j + 1] = h;
}
}
segstart = j + 1;
}
}
}
if (target[mLen] == mLen) {
measurement[mLen] = h;
}
return measurement;
}
/**
* Draws a unidirectional (but possibly multi-styled) run of text.
*
......
......@@ -72,6 +72,32 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.assertSearchTextField(false, query);
}
public void testSearchDownloads() throws Exception {
initTestFiles();
bots.roots.openRoot(ROOT_0_ID);
bots.directory.copyFilesToClipboard(fileName1, fileName2);
device.waitForIdle();
bots.roots.openRoot("Downloads");
bots.directory.pasteFilesFromClipboard();
//TODO: linben Why do we need to click on Downloads again so this will work?
bots.roots.openRoot("Downloads");
device.waitForIdle();
String query = "file12";
bots.main.openSearchView();
bots.main.setSearchQuery(query);
device.pressEnter();
bots.directory.assertDocumentsCountOnList(true, 1);
bots.directory.assertDocumentsPresent(fileName2);
device.pressBack();
}
@Suppress
public void testSearchResultsFound_ClearsOnBack() throws Exception {
initTestFiles();
......@@ -151,4 +177,18 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
bots.main.assertSearchTextFiledAndIcon(false, false);
}
@Override
public void tearDown() throws Exception {
try {
// Proper clean up of #testSearchDownloads
bots.directory.clickDocument(fileName1 + ".txt");
bots.directory.clickDocument(fileName2);
device.waitForIdle();
bots.main.menuDelete().click();
bots.main.findDialogOkButton().click();
} catch (Exception e) {
} finally {
super.tearDown();
}
}
}
......@@ -30,6 +30,7 @@ import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.view.KeyEvent;
import android.view.MotionEvent;
import junit.framework.Assert;
......@@ -129,6 +130,17 @@ public class DirectoryListBot extends BaseBot {
return doc;
}
public void copyFilesToClipboard(String...labels) throws UiObjectNotFoundException {
for (String label: labels) {
clickDocument(label);
}
mDevice.pressKeyCode(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON);
}
public void pasteFilesFromClipboard() {
mDevice.pressKeyCode(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
}
public UiObject2 getSnackbar(String message) {
return mDevice.wait(Until.findObject(By.text(message)), mTimeout);
}
......
......@@ -8297,13 +8297,26 @@ public final class ActivityManagerService extends ActivityManagerNative
}
}
// Figure out the value returned when access is allowed
final int allowedResult;
if ((modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0) {
// If we're extending a persistable grant, then we need to return
// "targetUid" so that we always create a grant data structure to
// support take/release APIs
allowedResult = targetUid;
} else {
// Otherwise, we can return "-1" to indicate that no grant data
// structures need to be created
allowedResult = -1;
}
if (targetUid >= 0) {
// First... does the target actually need this permission?
if (checkHoldingPermissionsLocked(pm, pi, grantUri, targetUid, modeFlags)) {
// No need to grant the target this permission.
if (DEBUG_URI_PERMISSION) Slog.v(TAG_URI_PERMISSION,
"Target " + targetPkg + " already has full permission to " + grantUri);
return -1;
return allowedResult;
}
} else {
// First... there is no target package, so can anyone access it?
......@@ -8319,7 +8332,7 @@ public final class ActivityManagerService extends ActivityManagerNative
}
}
if (allowed) {
return -1;
return allowedResult;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment