Skip to content

Commit

Permalink
Remove MtpService bindings from MediaProvider
Browse files Browse the repository at this point in the history
Any usage of MtpService from MediaProvider has
been removed, so we can also remove the interfacing
code.

Test: Mtp still works
Change-Id: I167daa1a28d4f1f98c52f6436b999fd15e940ad4
  • Loading branch information
Jerry Zhang committed Jul 18, 2018
1 parent 9446158 commit 191df0e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 59 deletions.
55 changes: 2 additions & 53 deletions src/com/android/providers/media/MediaProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,25 +507,6 @@ public void onOpen(SQLiteDatabase db) {
}
}

// synchronize on mMtpServiceConnection when accessing mMtpService
private IMtpService mMtpService;

private final ServiceConnection mMtpServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, android.os.IBinder service) {
synchronized (this) {
mMtpService = IMtpService.Stub.asInterface(service);
}
}

@Override
public void onServiceDisconnected(ComponentName className) {
synchronized (this) {
mMtpService = null;
}
}
};

private static final String[] sDefaultFolderNames = {
Environment.DIRECTORY_MUSIC,
Environment.DIRECTORY_PODCASTS,
Expand Down Expand Up @@ -2514,13 +2495,12 @@ private Uri insertInternal(Uri uri, int match, ContentValues initialValues,

Uri newUri = null;
DatabaseHelper helper = getDatabaseForUri(uri);
if (helper == null && match != VOLUMES && match != MTP_CONNECTED) {
if (helper == null && match != VOLUMES) {
throw new UnsupportedOperationException(
"Unknown URI: " + uri);
}

SQLiteDatabase db = ((match == VOLUMES || match == MTP_CONNECTED) ? null
: helper.getWritableDatabase());
SQLiteDatabase db = match == VOLUMES ? null : helper.getWritableDatabase();

switch (match) {
case IMAGES_MEDIA: {
Expand Down Expand Up @@ -2694,19 +2674,6 @@ private Uri insertInternal(Uri uri, int match, ContentValues initialValues,
return attachedVolume;
}

case MTP_CONNECTED:
synchronized (mMtpServiceConnection) {
if (mMtpService == null) {
Context context = getContext();
// MTP is connected, so grab a connection to MtpService
context.bindService(new Intent(context, MtpService.class),
mMtpServiceConnection, Context.BIND_AUTO_CREATE);
}
}
fixParentIdIfNeeded();

break;

case FILES:
rowId = insertFile(helper, uri, initialValues,
FileColumns.MEDIA_TYPE_NONE, true, notifyRowIds);
Expand Down Expand Up @@ -3215,19 +3182,6 @@ public int delete(Uri uri, String userWhere, String[] userWhereArgs) {
if (match == VOLUMES_ID) {
detachVolume(uri);
count = 1;
} else if (match == MTP_CONNECTED) {
synchronized (mMtpServiceConnection) {
if (mMtpService != null) {
// MTP has disconnected, so release our connection to MtpService
getContext().unbindService(mMtpServiceConnection);
count = 1;
// mMtpServiceConnection.onServiceDisconnected might not get called,
// so set mMtpService = null here
mMtpService = null;
} else {
count = 0;
}
}
} else {
final String volumeName = getVolumeName(uri);
final boolean isExternal = "external".equals(volumeName);
Expand Down Expand Up @@ -5004,9 +4958,6 @@ private void detachVolume(Uri uri) {
private static final int MTP_OBJECTS = 702;
private static final int MTP_OBJECTS_ID = 703;
private static final int MTP_OBJECT_REFERENCES = 704;
// UsbReceiver calls insert() and delete() with this URI to tell us
// when MTP is connected and disconnected
private static final int MTP_CONNECTED = 705;

// Used only to invoke special logic for directories
private static final int FILES_DIRECTORY = 706;
Expand Down Expand Up @@ -5110,8 +5061,6 @@ private int matchUri(Uri uri, boolean allowHidden) {
// NOTE: technically hidden, since Uri is never exposed
publicMatcher.addURI(AUTHORITY, "*/version", VERSION);

hiddenMatcher.addURI(AUTHORITY, "*/mtp_connected", MTP_CONNECTED);

hiddenMatcher.addURI(AUTHORITY, "*", VOLUMES_ID);
hiddenMatcher.addURI(AUTHORITY, null, VOLUMES);

Expand Down
6 changes: 0 additions & 6 deletions src/com/android/providers/media/MtpReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
Expand Down Expand Up @@ -57,8 +56,6 @@ private void handleUsbState(Context context, Intent intent) {
if (configured && (mtpEnabled || ptpEnabled)) {
if (!isCurrentUser)
return;
context.getContentResolver().insert(Uri.parse(
"content://media/none/mtp_connected"), null);
intent = new Intent(context, MtpService.class);
intent.putExtra(UsbManager.USB_DATA_UNLOCKED, unlocked);
if (ptpEnabled) {
Expand All @@ -70,9 +67,6 @@ private void handleUsbState(Context context, Intent intent) {
// Only unbind if disconnected or disabled.
boolean status = context.stopService(new Intent(context, MtpService.class));
if (DEBUG) { Log.d(TAG, "handleUsbState stopService status=" + status); }
// tell MediaProvider MTP is disconnected so it can unbind from the service
context.getContentResolver().delete(Uri.parse(
"content://media/none/mtp_connected"), null, null);
}
}
}

0 comments on commit 191df0e

Please sign in to comment.