OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.content.ContentResolver; | 7 import android.content.ContentResolver; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.res.AssetFileDescriptor; | 9 import android.content.res.AssetFileDescriptor; |
10 import android.database.Cursor; | 10 import android.database.Cursor; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } else { | 151 } else { |
152 ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r")
; | 152 ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r")
; |
153 if (pfd != null) { | 153 if (pfd != null) { |
154 return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.U
NKNOWN_LENGTH); | 154 return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.U
NKNOWN_LENGTH); |
155 } | 155 } |
156 } | 156 } |
157 } catch (FileNotFoundException e) { | 157 } catch (FileNotFoundException e) { |
158 Log.w(TAG, "Cannot find content uri: " + uriString, e); | 158 Log.w(TAG, "Cannot find content uri: " + uriString, e); |
159 } catch (SecurityException e) { | 159 } catch (SecurityException e) { |
160 Log.w(TAG, "Cannot open content uri: " + uriString, e); | 160 Log.w(TAG, "Cannot open content uri: " + uriString, e); |
161 } catch (IllegalArgumentException | IllegalStateException e) { | 161 } catch (Exception e) { |
162 Log.w(TAG, "Unknown content uri: " + uriString, e); | 162 Log.w(TAG, "Unknown content uri: " + uriString, e); |
163 } | 163 } |
164 | |
165 return null; | 164 return null; |
166 } | 165 } |
167 | 166 |
168 /** | 167 /** |
169 * Method to resolve the display name of a content URI. | 168 * Method to resolve the display name of a content URI. |
170 * | 169 * |
171 * @param uri the content URI to be resolved. | 170 * @param uri the content URI to be resolved. |
172 * @param context {@link Context} in interest. | 171 * @param context {@link Context} in interest. |
173 * @param columnField the column field to query. | 172 * @param columnField the column field to query. |
174 * @return the display name of the @code uri if present in the database | 173 * @return the display name of the @code uri if present in the database |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 * @param cursor Cursor with COLUMN_FLAGS. | 252 * @param cursor Cursor with COLUMN_FLAGS. |
254 * @return True for virtual file, false for any other file. | 253 * @return True for virtual file, false for any other file. |
255 */ | 254 */ |
256 private static boolean hasVirtualFlag(Cursor cursor) { | 255 private static boolean hasVirtualFlag(Cursor cursor) { |
257 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false; | 256 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false; |
258 int index = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_FLAG
S); | 257 int index = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_FLAG
S); |
259 return index > -1 | 258 return index > -1 |
260 && (cursor.getLong(index) & DocumentsContract.Document.FLAG_VIRT
UAL_DOCUMENT) != 0; | 259 && (cursor.getLong(index) & DocumentsContract.Document.FLAG_VIRT
UAL_DOCUMENT) != 0; |
261 } | 260 } |
262 } | 261 } |
OLD | NEW |