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 17 package android.mtp; 18 19 /** 20 * Java wrapper for MTP/PTP support as USB responder. 21 * {@hide} 22 */ 23 public class MtpServer implements Runnable { 24 25 private long mNativeContext; // accessed by native methods 26 27 static { 28 System.loadLibrary("media_jni"); 29 } 30 MtpServer(MtpDatabase database, boolean usePtp)31 public MtpServer(MtpDatabase database, boolean usePtp) { 32 native_setup(database, usePtp); 33 database.setServer(this); 34 } 35 start()36 public void start() { 37 Thread thread = new Thread(this, "MtpServer"); 38 thread.start(); 39 } 40 41 @Override run()42 public void run() { 43 native_run(); 44 native_cleanup(); 45 } 46 sendObjectAdded(int handle)47 public void sendObjectAdded(int handle) { 48 native_send_object_added(handle); 49 } 50 sendObjectRemoved(int handle)51 public void sendObjectRemoved(int handle) { 52 native_send_object_removed(handle); 53 } 54 sendDevicePropertyChanged(int property)55 public void sendDevicePropertyChanged(int property) { 56 native_send_device_property_changed(property); 57 } 58 addStorage(MtpStorage storage)59 public void addStorage(MtpStorage storage) { 60 native_add_storage(storage); 61 } 62 removeStorage(MtpStorage storage)63 public void removeStorage(MtpStorage storage) { 64 native_remove_storage(storage.getStorageId()); 65 } 66 native_setup(MtpDatabase database, boolean usePtp)67 private native final void native_setup(MtpDatabase database, boolean usePtp); native_run()68 private native final void native_run(); native_cleanup()69 private native final void native_cleanup(); native_send_object_added(int handle)70 private native final void native_send_object_added(int handle); native_send_object_removed(int handle)71 private native final void native_send_object_removed(int handle); native_send_device_property_changed(int property)72 private native final void native_send_device_property_changed(int property); native_add_storage(MtpStorage storage)73 private native final void native_add_storage(MtpStorage storage); native_remove_storage(int storageId)74 private native final void native_remove_storage(int storageId); 75 } 76