| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 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 | |
| Mike Lockwood | 0cd0136 | 2010-12-30 11:54:33 -0500 | [diff] [blame] | 17 | package android.mtp; |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 18 | |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 19 | /** |
| 20 | * Java wrapper for MTP/PTP support as USB responder. |
| 21 | * {@hide} |
| 22 | */ |
| Mike Lockwood | dcc3194 | 2011-07-11 15:04:38 -0400 | [diff] [blame] | 23 | public class MtpServer implements Runnable { |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 24 | |
| Mike Lockwood | dcc3194 | 2011-07-11 15:04:38 -0400 | [diff] [blame] | 25 | private int mNativeContext; // accessed by native methods |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 26 | |
| 27 | static { |
| 28 | System.loadLibrary("media_jni"); |
| 29 | } |
| 30 | |
| Mike Lockwood | 7d40d42 | 2011-06-21 08:27:06 -0400 | [diff] [blame] | 31 | public MtpServer(MtpDatabase database, boolean usePtp) { |
| 32 | native_setup(database, usePtp); |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 33 | } |
| 34 | |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 35 | public void start() { |
| Mike Lockwood | dcc3194 | 2011-07-11 15:04:38 -0400 | [diff] [blame] | 36 | Thread thread = new Thread(this, "MtpServer"); |
| 37 | thread.start(); |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| Mike Lockwood | dcc3194 | 2011-07-11 15:04:38 -0400 | [diff] [blame] | 40 | @Override |
| 41 | public void run() { |
| 42 | native_run(); |
| 43 | native_cleanup(); |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| Mike Lockwood | be125a5 | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 46 | public void sendObjectAdded(int handle) { |
| 47 | native_send_object_added(handle); |
| 48 | } |
| 49 | |
| 50 | public void sendObjectRemoved(int handle) { |
| 51 | native_send_object_removed(handle); |
| 52 | } |
| 53 | |
| Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 54 | public void addStorage(MtpStorage storage) { |
| 55 | native_add_storage(storage); |
| Mike Lockwood | 66e57f6 | 2011-02-18 13:24:01 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 58 | public void removeStorage(MtpStorage storage) { |
| 59 | native_remove_storage(storage.getStorageId()); |
| 60 | } |
| 61 | |
| Mike Lockwood | 7d40d42 | 2011-06-21 08:27:06 -0400 | [diff] [blame] | 62 | private native final void native_setup(MtpDatabase database, boolean usePtp); |
| Mike Lockwood | dcc3194 | 2011-07-11 15:04:38 -0400 | [diff] [blame] | 63 | private native final void native_run(); |
| 64 | private native final void native_cleanup(); |
| Mike Lockwood | be125a5 | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 65 | private native final void native_send_object_added(int handle); |
| 66 | private native final void native_send_object_removed(int handle); |
| Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 67 | private native final void native_add_storage(MtpStorage storage); |
| 68 | private native final void native_remove_storage(int storageId); |
| Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 69 | } |