Query only necessary columns in ChooserActivity.extractFileInfo().
ChooserActivity started querying the content URI with a null projection since Q, which means a default projection that includes all columns. However, ChooserActivity.extractFileInfo() actually only needs the file name and flags, so querying all columns usually means reading unnecessary information that may involve disk access, and it's called on the main thread. For example, ExternalStorageProvider returns the file size and last modified time when it sees a null projection, and it is calling File.length() and File.lastModified() for them. In other file providers, it is also possible for this to trigger a network request for such information, which will result in a NetworkOnMainThreadException that crashes the android:ui process. So to improve stability and performance, we should provide a projection that only contains the columns that we are actually interested in. Bug: 218105374 Test: ChooserActivityTest Change-Id: I91bbd397124f8e4f7d7bc597d59e278e6f54e8bb
Loading
Please register or sign in to comment