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 | |
| 19 | import android.util.Log; |
| 20 | |
| 21 | /** |
| 22 | * Java wrapper for MTP/PTP support as USB responder. |
| 23 | * {@hide} |
| 24 | */ |
| 25 | public class MtpServer { |
| 26 | |
Mike Lockwood | a3f8514 | 2011-03-17 09:43:50 -0400 | [diff] [blame] | 27 | private final Object mLock = new Object(); |
| 28 | private boolean mStarted; |
| 29 | |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 30 | private static final String TAG = "MtpServer"; |
| 31 | |
| 32 | static { |
| 33 | System.loadLibrary("media_jni"); |
| 34 | } |
| 35 | |
Mike Lockwood | 7d40d42 | 2011-06-21 08:27:06 -0400 | [diff] [blame^] | 36 | public MtpServer(MtpDatabase database, boolean usePtp) { |
| 37 | native_setup(database, usePtp); |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 40 | public void start() { |
Mike Lockwood | a3f8514 | 2011-03-17 09:43:50 -0400 | [diff] [blame] | 41 | synchronized (mLock) { |
| 42 | native_start(); |
| 43 | mStarted = true; |
| 44 | } |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | public void stop() { |
Mike Lockwood | a3f8514 | 2011-03-17 09:43:50 -0400 | [diff] [blame] | 48 | synchronized (mLock) { |
| 49 | if (mStarted) { |
| 50 | native_stop(); |
| 51 | mStarted = false; |
| 52 | } |
| 53 | } |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Mike Lockwood | be125a5 | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 56 | public void sendObjectAdded(int handle) { |
| 57 | native_send_object_added(handle); |
| 58 | } |
| 59 | |
| 60 | public void sendObjectRemoved(int handle) { |
| 61 | native_send_object_removed(handle); |
| 62 | } |
| 63 | |
Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 64 | public void addStorage(MtpStorage storage) { |
| 65 | native_add_storage(storage); |
Mike Lockwood | 66e57f6 | 2011-02-18 13:24:01 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 68 | public void removeStorage(MtpStorage storage) { |
| 69 | native_remove_storage(storage.getStorageId()); |
| 70 | } |
| 71 | |
Mike Lockwood | 7d40d42 | 2011-06-21 08:27:06 -0400 | [diff] [blame^] | 72 | private native final void native_setup(MtpDatabase database, boolean usePtp); |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 73 | private native final void native_start(); |
| 74 | private native final void native_stop(); |
Mike Lockwood | be125a5 | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 75 | private native final void native_send_object_added(int handle); |
| 76 | private native final void native_send_object_removed(int handle); |
Mike Lockwood | b239b683 | 2011-04-05 10:21:27 -0400 | [diff] [blame] | 77 | private native final void native_add_storage(MtpStorage storage); |
| 78 | private native final void native_remove_storage(int storageId); |
Mike Lockwood | 98ef64e | 2010-06-29 16:42:13 -0400 | [diff] [blame] | 79 | } |