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

Commit 29bcb287 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MTP: Add support of ObjectInfoChanged Event"

parents 40236796 e4f680e0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -266,6 +266,12 @@ public class MtpDatabase implements AutoCloseable {
                if (MtpDatabase.this.mServer != null)
                    MtpDatabase.this.mServer.sendObjectRemoved(id);
            }

            @Override
            public void sendObjectInfoChanged(int id) {
                if (MtpDatabase.this.mServer != null)
                    MtpDatabase.this.mServer.sendObjectInfoChanged(id);
            }
        }, subDirectories == null ? null : Sets.newHashSet(subDirectories));

        initDeviceProperties(context);
+5 −0
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ public class MtpServer implements Runnable {
        native_send_object_removed(handle);
    }

    public void sendObjectInfoChanged(int handle) {
        native_send_object_info_changed(handle);
    }

    public void sendDevicePropertyChanged(int property) {
        native_send_device_property_changed(property);
    }
@@ -106,6 +110,7 @@ public class MtpServer implements Runnable {
    private native final void native_cleanup();
    private native final void native_send_object_added(int handle);
    private native final void native_send_object_removed(int handle);
    private native final void native_send_object_info_changed(int handle);
    private native final void native_send_device_property_changed(int property);
    private native final void native_add_storage(MtpStorage storage);
    private native final void native_remove_storage(int storageId);
+30 −1
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ public class MtpStorageManager {

        MtpObjectObserver(MtpObject object) {
            super(object.getPath().toString(),
                    MOVED_FROM | MOVED_TO | DELETE | CREATE | IN_ONLYDIR);
                    MOVED_FROM | MOVED_TO | DELETE | CREATE | IN_ONLYDIR
                  | CLOSE_WRITE);
            mObject = object;
        }

@@ -85,6 +86,10 @@ public class MtpStorageManager {
                    if (mObject.mObserver != null)
                        mObject.mObserver.stopWatching();
                    mObject.mObserver = null;
                } else if ((event & CLOSE_WRITE) != 0) {
                    if (sDebug)
                        Log.i(TAG, "inotify for " + mObject.getPath() + " CLOSE_WRITE: " + path);
                    handleChangedObject(mObject, path);
                } else {
                    Log.w(TAG, "Got unrecognized event " + path + " " + event);
                }
@@ -302,6 +307,11 @@ public class MtpStorageManager {
         * Called when an object is deleted.
         */
        public abstract void sendObjectRemoved(int id);

        /**
         * Called when an object info is changed.
         */
        public abstract void sendObjectInfoChanged(int id);
    }

    private MtpNotifier mMtpNotifier;
@@ -733,6 +743,25 @@ public class MtpStorageManager {
            Log.i(TAG, state + " transitioned to " + obj.getState() + " in op " + op);
    }

    private synchronized void handleChangedObject(MtpObject parent, String path) {
        MtpOperation op = MtpOperation.NONE;
        MtpObject obj = parent.getChild(path);
        if (obj != null) {
            // Only handle files for size change notification event
            if ((!obj.isDir()) && (obj.getSize() > 0))
            {
                MtpObjectState state = obj.getState();
                op = obj.getOperation();
                MtpStorageManager.this.mMtpNotifier.sendObjectInfoChanged(obj.getId());
                if (sDebug)
                    Log.d(TAG, "sendObjectInfoChanged: id=" + obj.getId() + ",size=" + obj.getSize());
            }
        } else {
            if (sDebug)
                Log.w(TAG, "object " + path + " null");
        }
    }

    /**
     * Block the caller until all events currently in the event queue have been
     * read and processed. Used for testing purposes.
+13 −0
Original line number Diff line number Diff line
@@ -134,6 +134,18 @@ android_mtp_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint handle
        ALOGE("server is null in send_object_removed");
}

static void
android_mtp_MtpServer_send_object_info_changed(JNIEnv *env, jobject thiz, jint handle)
{
    Mutex::Autolock autoLock(sMutex);

    MtpServer* server = getMtpServer(env, thiz);
    if (server)
        server->sendObjectInfoChanged(handle);
    else
        ALOGE("server is null in send_object_info_changed");
}

static void
android_mtp_MtpServer_send_device_property_changed(JNIEnv *env, jobject thiz, jint property)
{
@@ -202,6 +214,7 @@ static const JNINativeMethod gMethods[] = {
    {"native_cleanup",              "()V",  (void *)android_mtp_MtpServer_cleanup},
    {"native_send_object_added",    "(I)V", (void *)android_mtp_MtpServer_send_object_added},
    {"native_send_object_removed",  "(I)V", (void *)android_mtp_MtpServer_send_object_removed},
    {"native_send_object_info_changed",  "(I)V", (void *)android_mtp_MtpServer_send_object_info_changed},
    {"native_send_device_property_changed",  "(I)V",
                                    (void *)android_mtp_MtpServer_send_device_property_changed},
    {"native_add_storage",          "(Landroid/mtp/MtpStorage;)V",
+140 −56

File changed.

Preview size limit exceeded, changes collapsed.