Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74f094fe authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP: Add interface to MtpClient for receiving device added/removed events.

parent 0c330e26
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ public final class Mtp

        public static final Uri CONTENT_URI = Uri.parse(CONTENT_AUTHORITY_SLASH + "device");

        public static Uri getContentUri(int deviceID) {
            return Uri.parse(CONTENT_AUTHORITY_DEVICE_SLASH + deviceID);
        }

        /**
         * The manufacturer of the device
         * <P>Type: TEXT</P>
+19 −1
Original line number Diff line number Diff line
@@ -25,12 +25,18 @@ public class MtpClient {

    private static final String TAG = "MtpClient";

    private final Listener mListener;

    static {
        System.loadLibrary("media_jni");
    }

    public MtpClient() {
    public MtpClient(Listener listener) {
        native_setup();
        if (listener == null) {
            throw new NullPointerException("MtpClient: listener is null");
        }
        mListener = listener;
    }

    @Override
@@ -73,12 +79,24 @@ public class MtpClient {
        }
    }

    public interface Listener {
        // called when a new MTP device has been discovered
        void deviceAdded(int id);

        // called when an MTP device has been removed
        void deviceRemoved(int id);
    }

    // called from native code
    private void deviceAdded(int id) {
        Log.d(TAG, "deviceAdded " + id);
        mListener.deviceAdded(id);
    }

    // called from native code
    private void deviceRemoved(int id) {
        Log.d(TAG, "deviceRemoved " + id);
        mListener.deviceRemoved(id);
    }

    private MtpEventThread mEventThread;