Files
frameworks_base/media/java/android/media/MtpClient.java
Mike Lockwood d0e1a9f40e MTP: Remove an unnecessary thread from the MtpClient class.
Now a single thread is used for passing USB host events up to MtpClient.

Change-Id: I0e3a277956cb3d1036da122ea10acb03a27844d6
Signed-off-by: Mike Lockwood <lockwood@android.com>
2010-07-01 11:39:42 -04:00

98 lines
2.6 KiB
Java

/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.media;
import android.util.Log;
/**
* {@hide}
*/
public class MtpClient {
private static final String TAG = "MtpClient";
private final Listener mListener;
static {
System.loadLibrary("media_jni");
}
public MtpClient(Listener listener) {
native_setup();
if (listener == null) {
throw new NullPointerException("MtpClient: listener is null");
}
mListener = listener;
}
@Override
protected void finalize() {
native_finalize();
}
public boolean start() {
return native_start();
}
public void stop() {
native_stop();
}
public boolean deleteObject(int deviceID, int objectID) {
return native_delete_object(deviceID, objectID);
}
public int getParent(int deviceID, int objectID) {
return native_get_parent(deviceID, objectID);
}
public int getStorageID(int deviceID, int objectID) {
return native_get_storage_id(deviceID, objectID);
}
public interface Listener {
// called when a new MTP device has been discovered
void deviceAdded(int id);
// called when an MTP device has been removed
void deviceRemoved(int id);
}
// called from native code
private void deviceAdded(int id) {
Log.d(TAG, "deviceAdded " + id);
mListener.deviceAdded(id);
}
// called from native code
private void deviceRemoved(int id) {
Log.d(TAG, "deviceRemoved " + id);
mListener.deviceRemoved(id);
}
// used by the JNI code
private int mNativeContext;
private native final void native_setup();
private native final void native_finalize();
private native boolean native_start();
private native void native_stop();
private native boolean native_delete_object(int deviceID, int objectID);
private native int native_get_parent(int deviceID, int objectID);
private native int native_get_storage_id(int deviceID, int objectID);
}