package android.mtp;
+import com.android.internal.util.Preconditions;
+
/**
* Java wrapper for MTP/PTP support as USB responder.
* {@hide}
private long mNativeContext; // accessed by native methods
private final MtpDatabase mDatabase;
+ private final Runnable mOnTerminate;
static {
System.loadLibrary("media_jni");
}
- public MtpServer(MtpDatabase database, boolean usePtp) {
- mDatabase = database;
+ public MtpServer(MtpDatabase database, boolean usePtp, Runnable onTerminate) {
+ mDatabase = Preconditions.checkNotNull(database);
+ mOnTerminate = Preconditions.checkNotNull(onTerminate);
native_setup(database, usePtp);
database.setServer(this);
}
native_run();
native_cleanup();
mDatabase.close();
+ mOnTerminate.run();
}
public void sendObjectAdded(int handle) {