Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +20 −0 Original line number Diff line number Diff line Loading @@ -342,6 +342,26 @@ class MtpDatabase { } } String getDeviceDocumentId(int deviceId) throws FileNotFoundException { try (final Cursor cursor = mDatabase.query( TABLE_DOCUMENTS, strings(Document.COLUMN_DOCUMENT_ID), COLUMN_DEVICE_ID + " = ? AND " + COLUMN_DOCUMENT_TYPE + " = ? AND " + COLUMN_ROW_STATE + " != ?", strings(deviceId, DOCUMENT_TYPE_DEVICE, ROW_STATE_DISCONNECTED), null, null, null, "1")) { if (cursor.getCount() > 0) { cursor.moveToNext(); return cursor.getString(0); } else { throw new FileNotFoundException("The device ID not found: " + deviceId); } } } /** * Adds new document under the parent. * The method does not affect invalidated and pending documents because we know the document is Loading packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +10 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,16 @@ public class MtpDocumentsProvider extends DocumentsProvider { } } /** * Obtains document ID for the given device ID. * @param deviceId * @return document ID * @throws FileNotFoundException device ID has not been build. */ public String getDeviceDocumentId(int deviceId) throws FileNotFoundException { return mDatabase.getDeviceDocumentId(deviceId); } /** * Resumes root scanner to handle the update of device list. */ Loading packages/MtpDocumentsProvider/src/com/android/mtp/ReceiverActivity.java +21 −9 Original line number Diff line number Diff line Loading @@ -17,10 +17,15 @@ package com.android.mtp; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.net.Uri; import android.os.Bundle; import android.provider.DocumentsContract; import android.util.Log; import java.io.IOException; /** * Invisible activity to receive intents. Loading @@ -33,14 +38,21 @@ public class ReceiverActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(getIntent().getAction())) { // TODO: To obtain data URI for the attached device, we need to wait until RootScanner // found the device and add it to database. Set correct root URI, and use ACTION_BROWSE // to launch Documents UI. final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName( "com.android.documentsui", "com.android.documentsui.LauncherActivity")); final UsbDevice device = getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE); try { final MtpDocumentsProvider provider = MtpDocumentsProvider.getInstance(); provider.openDevice(device.getDeviceId()); final String deviceRootId = provider.getDeviceDocumentId(device.getDeviceId()); final Uri uri = DocumentsContract.buildRootUri( MtpDocumentsProvider.AUTHORITY, deviceRootId); final Intent intent = new Intent(DocumentsContract.ACTION_BROWSE); intent.setData(uri); intent.addCategory(Intent.CATEGORY_DEFAULT); this.startActivity(intent); } catch (IOException exception) { Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exception); } } finish(); } Loading Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +20 −0 Original line number Diff line number Diff line Loading @@ -342,6 +342,26 @@ class MtpDatabase { } } String getDeviceDocumentId(int deviceId) throws FileNotFoundException { try (final Cursor cursor = mDatabase.query( TABLE_DOCUMENTS, strings(Document.COLUMN_DOCUMENT_ID), COLUMN_DEVICE_ID + " = ? AND " + COLUMN_DOCUMENT_TYPE + " = ? AND " + COLUMN_ROW_STATE + " != ?", strings(deviceId, DOCUMENT_TYPE_DEVICE, ROW_STATE_DISCONNECTED), null, null, null, "1")) { if (cursor.getCount() > 0) { cursor.moveToNext(); return cursor.getString(0); } else { throw new FileNotFoundException("The device ID not found: " + deviceId); } } } /** * Adds new document under the parent. * The method does not affect invalidated and pending documents because we know the document is Loading
packages/MtpDocumentsProvider/src/com/android/mtp/MtpDocumentsProvider.java +10 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,16 @@ public class MtpDocumentsProvider extends DocumentsProvider { } } /** * Obtains document ID for the given device ID. * @param deviceId * @return document ID * @throws FileNotFoundException device ID has not been build. */ public String getDeviceDocumentId(int deviceId) throws FileNotFoundException { return mDatabase.getDeviceDocumentId(deviceId); } /** * Resumes root scanner to handle the update of device list. */ Loading
packages/MtpDocumentsProvider/src/com/android/mtp/ReceiverActivity.java +21 −9 Original line number Diff line number Diff line Loading @@ -17,10 +17,15 @@ package com.android.mtp; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; import android.net.Uri; import android.os.Bundle; import android.provider.DocumentsContract; import android.util.Log; import java.io.IOException; /** * Invisible activity to receive intents. Loading @@ -33,14 +38,21 @@ public class ReceiverActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(getIntent().getAction())) { // TODO: To obtain data URI for the attached device, we need to wait until RootScanner // found the device and add it to database. Set correct root URI, and use ACTION_BROWSE // to launch Documents UI. final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName( "com.android.documentsui", "com.android.documentsui.LauncherActivity")); final UsbDevice device = getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE); try { final MtpDocumentsProvider provider = MtpDocumentsProvider.getInstance(); provider.openDevice(device.getDeviceId()); final String deviceRootId = provider.getDeviceDocumentId(device.getDeviceId()); final Uri uri = DocumentsContract.buildRootUri( MtpDocumentsProvider.AUTHORITY, deviceRootId); final Intent intent = new Intent(DocumentsContract.ACTION_BROWSE); intent.setData(uri); intent.addCategory(Intent.CATEGORY_DEFAULT); this.startActivity(intent); } catch (IOException exception) { Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exception); } } finish(); } Loading