MtpServer.java revision 0cd0136d440cf6ad9d5fab430269116786e671ec
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.mtp; 18 19import android.util.Log; 20 21/** 22 * Java wrapper for MTP/PTP support as USB responder. 23 * {@hide} 24 */ 25public class MtpServer { 26 27 private static final String TAG = "MtpServer"; 28 29 static { 30 System.loadLibrary("media_jni"); 31 } 32 33 public MtpServer(MtpDatabase database, String storagePath, long reserveSpace) { 34 native_setup(database, storagePath, reserveSpace); 35 } 36 37 @Override 38 protected void finalize() throws Throwable { 39 try { 40 native_finalize(); 41 } finally { 42 super.finalize(); 43 } 44 } 45 46 public void start() { 47 native_start(); 48 } 49 50 public void stop() { 51 native_stop(); 52 } 53 54 public void sendObjectAdded(int handle) { 55 native_send_object_added(handle); 56 } 57 58 public void sendObjectRemoved(int handle) { 59 native_send_object_removed(handle); 60 } 61 62 public void setPtpMode(boolean usePtp) { 63 native_set_ptp_mode(usePtp); 64 } 65 66 // used by the JNI code 67 private int mNativeContext; 68 69 private native final void native_setup(MtpDatabase database, String storagePath, 70 long reserveSpace); 71 private native final void native_finalize(); 72 private native final void native_start(); 73 private native final void native_stop(); 74 private native final void native_send_object_added(int handle); 75 private native final void native_send_object_removed(int handle); 76 private native final void native_set_ptp_mode(boolean usePtp); 77} 78