blob: 61fbfb902d0d93284791519ab105aad7358240d5 [file] [log] [blame]
Mike Lockwood98ef64e2010-06-29 16:42:13 -04001/*
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 Lockwood0cd01362010-12-30 11:54:33 -050017package android.mtp;
Mike Lockwood98ef64e2010-06-29 16:42:13 -040018
Mike Lockwood98ef64e2010-06-29 16:42:13 -040019/**
20 * Java wrapper for MTP/PTP support as USB responder.
21 * {@hide}
22 */
Mike Lockwooddcc31942011-07-11 15:04:38 -040023public class MtpServer implements Runnable {
Mike Lockwood98ef64e2010-06-29 16:42:13 -040024
Ashok Bhate2e59322013-12-17 19:04:19 +000025 private long mNativeContext; // accessed by native methods
Daichi Hironofe259312016-04-06 13:00:22 +090026 private final MtpDatabase mDatabase;
Mike Lockwood98ef64e2010-06-29 16:42:13 -040027
28 static {
29 System.loadLibrary("media_jni");
30 }
31
Mike Lockwood7d40d422011-06-21 08:27:06 -040032 public MtpServer(MtpDatabase database, boolean usePtp) {
Daichi Hironofe259312016-04-06 13:00:22 +090033 mDatabase = database;
Mike Lockwood7d40d422011-06-21 08:27:06 -040034 native_setup(database, usePtp);
Mike Lockwood56c85242014-03-07 13:29:08 -080035 database.setServer(this);
Mike Lockwood98ef64e2010-06-29 16:42:13 -040036 }
37
Mike Lockwood98ef64e2010-06-29 16:42:13 -040038 public void start() {
Mike Lockwooddcc31942011-07-11 15:04:38 -040039 Thread thread = new Thread(this, "MtpServer");
40 thread.start();
Mike Lockwood98ef64e2010-06-29 16:42:13 -040041 }
42
Mike Lockwooddcc31942011-07-11 15:04:38 -040043 @Override
44 public void run() {
45 native_run();
46 native_cleanup();
Daichi Hironofe259312016-04-06 13:00:22 +090047 mDatabase.close();
Mike Lockwood98ef64e2010-06-29 16:42:13 -040048 }
49
Mike Lockwoodbe125a52010-07-12 18:54:16 -040050 public void sendObjectAdded(int handle) {
51 native_send_object_added(handle);
52 }
53
54 public void sendObjectRemoved(int handle) {
55 native_send_object_removed(handle);
56 }
57
Mike Lockwood56c85242014-03-07 13:29:08 -080058 public void sendDevicePropertyChanged(int property) {
59 native_send_device_property_changed(property);
60 }
61
Mike Lockwoodb239b6832011-04-05 10:21:27 -040062 public void addStorage(MtpStorage storage) {
63 native_add_storage(storage);
Mike Lockwood66e57f62011-02-18 13:24:01 -050064 }
65
Mike Lockwoodb239b6832011-04-05 10:21:27 -040066 public void removeStorage(MtpStorage storage) {
67 native_remove_storage(storage.getStorageId());
68 }
69
Mike Lockwood7d40d422011-06-21 08:27:06 -040070 private native final void native_setup(MtpDatabase database, boolean usePtp);
Mike Lockwooddcc31942011-07-11 15:04:38 -040071 private native final void native_run();
72 private native final void native_cleanup();
Mike Lockwoodbe125a52010-07-12 18:54:16 -040073 private native final void native_send_object_added(int handle);
74 private native final void native_send_object_removed(int handle);
Mike Lockwood56c85242014-03-07 13:29:08 -080075 private native final void native_send_device_property_changed(int property);
Mike Lockwoodb239b6832011-04-05 10:21:27 -040076 private native final void native_add_storage(MtpStorage storage);
77 private native final void native_remove_storage(int storageId);
Mike Lockwood98ef64e2010-06-29 16:42:13 -040078}