IMountServiceListener.java revision b36586a7c9b7718f33961406537e27bbd9b16211
1/*
2 * Copyright (C) 2009 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
17package android.os.storage;
18
19import android.os.Binder;
20import android.os.IBinder;
21import android.os.IInterface;
22import android.os.Parcel;
23import android.os.RemoteException;
24
25/**
26 * Callback class for receiving events from MountService.
27 *
28 * @hide - Applications should use IStorageEventListener for storage event
29 *       callbacks.
30 */
31public interface IMountServiceListener extends IInterface {
32    /** Local-side IPC implementation stub class. */
33    public static abstract class Stub extends Binder implements IMountServiceListener {
34        private static final String DESCRIPTOR = "IMountServiceListener";
35
36        /** Construct the stub at attach it to the interface. */
37        public Stub() {
38            this.attachInterface(this, DESCRIPTOR);
39        }
40
41        /**
42         * Cast an IBinder object into an IMountServiceListener interface,
43         * generating a proxy if needed.
44         */
45        public static IMountServiceListener asInterface(IBinder obj) {
46            if ((obj == null)) {
47                return null;
48            }
49            IInterface iin = (IInterface) obj.queryLocalInterface(DESCRIPTOR);
50            if (((iin != null) && (iin instanceof IMountServiceListener))) {
51                return ((IMountServiceListener) iin);
52            }
53            return new IMountServiceListener.Stub.Proxy(obj);
54        }
55
56        public IBinder asBinder() {
57            return this;
58        }
59
60        @Override
61        public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
62                throws RemoteException {
63            switch (code) {
64                case INTERFACE_TRANSACTION: {
65                    reply.writeString(DESCRIPTOR);
66                    return true;
67                }
68                case TRANSACTION_onUsbMassStorageConnectionChanged: {
69                    data.enforceInterface(DESCRIPTOR);
70                    boolean connected;
71                    connected = (0 != data.readInt());
72                    this.onUsbMassStorageConnectionChanged(connected);
73                    reply.writeNoException();
74                    return true;
75                }
76                case TRANSACTION_onStorageStateChanged: {
77                    data.enforceInterface(DESCRIPTOR);
78                    final String path = data.readString();
79                    final String oldState = data.readString();
80                    final String newState = data.readString();
81                    this.onStorageStateChanged(path, oldState, newState);
82                    reply.writeNoException();
83                    return true;
84                }
85                case TRANSACTION_onVolumeStateChanged: {
86                    data.enforceInterface(DESCRIPTOR);
87                    final VolumeInfo vol = (VolumeInfo) data.readParcelable(null);
88                    final int oldState = data.readInt();
89                    final int newState = data.readInt();
90                    onVolumeStateChanged(vol, oldState, newState);
91                    reply.writeNoException();
92                    return true;
93                }
94                case TRANSACTION_onVolumeMetadataChanged: {
95                    data.enforceInterface(DESCRIPTOR);
96                    final String fsUuid = data.readString();
97                    onVolumeMetadataChanged(fsUuid);
98                    reply.writeNoException();
99                    return true;
100                }
101                case TRANSACTION_onDiskScanned: {
102                    data.enforceInterface(DESCRIPTOR);
103                    final DiskInfo disk = (DiskInfo) data.readParcelable(null);
104                    final int volumeCount = data.readInt();
105                    onDiskScanned(disk, volumeCount);
106                    reply.writeNoException();
107                    return true;
108                }
109            }
110            return super.onTransact(code, data, reply, flags);
111        }
112
113        private static class Proxy implements IMountServiceListener {
114            private IBinder mRemote;
115
116            Proxy(IBinder remote) {
117                mRemote = remote;
118            }
119
120            public IBinder asBinder() {
121                return mRemote;
122            }
123
124            public String getInterfaceDescriptor() {
125                return DESCRIPTOR;
126            }
127
128            /**
129             * Detection state of USB Mass Storage has changed
130             *
131             * @param available true if a UMS host is connected.
132             */
133            public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
134                Parcel _data = Parcel.obtain();
135                Parcel _reply = Parcel.obtain();
136                try {
137                    _data.writeInterfaceToken(DESCRIPTOR);
138                    _data.writeInt(((connected) ? (1) : (0)));
139                    mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
140                            _reply, android.os.IBinder.FLAG_ONEWAY);
141                    _reply.readException();
142                } finally {
143                    _reply.recycle();
144                    _data.recycle();
145                }
146            }
147
148            /**
149             * Storage state has changed.
150             *
151             * @param path The volume mount path.
152             * @param oldState The old state of the volume.
153             * @param newState The new state of the volume. Note: State is one
154             *            of the values returned by
155             *            Environment.getExternalStorageState()
156             */
157            public void onStorageStateChanged(String path, String oldState, String newState)
158                    throws RemoteException {
159                Parcel _data = Parcel.obtain();
160                Parcel _reply = Parcel.obtain();
161                try {
162                    _data.writeInterfaceToken(DESCRIPTOR);
163                    _data.writeString(path);
164                    _data.writeString(oldState);
165                    _data.writeString(newState);
166                    mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply,
167                            android.os.IBinder.FLAG_ONEWAY);
168                    _reply.readException();
169                } finally {
170                    _reply.recycle();
171                    _data.recycle();
172                }
173            }
174
175            @Override
176            public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
177                    throws RemoteException {
178                Parcel _data = Parcel.obtain();
179                Parcel _reply = Parcel.obtain();
180                try {
181                    _data.writeInterfaceToken(DESCRIPTOR);
182                    _data.writeParcelable(vol, 0);
183                    _data.writeInt(oldState);
184                    _data.writeInt(newState);
185                    mRemote.transact(Stub.TRANSACTION_onVolumeStateChanged, _data, _reply,
186                            android.os.IBinder.FLAG_ONEWAY);
187                    _reply.readException();
188                } finally {
189                    _reply.recycle();
190                    _data.recycle();
191                }
192            }
193
194            @Override
195            public void onVolumeMetadataChanged(String fsUuid) throws RemoteException {
196                Parcel _data = Parcel.obtain();
197                Parcel _reply = Parcel.obtain();
198                try {
199                    _data.writeInterfaceToken(DESCRIPTOR);
200                    _data.writeString(fsUuid);
201                    mRemote.transact(Stub.TRANSACTION_onVolumeMetadataChanged, _data, _reply,
202                            android.os.IBinder.FLAG_ONEWAY);
203                    _reply.readException();
204                } finally {
205                    _reply.recycle();
206                    _data.recycle();
207                }
208            }
209
210            @Override
211            public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException {
212                Parcel _data = Parcel.obtain();
213                Parcel _reply = Parcel.obtain();
214                try {
215                    _data.writeInterfaceToken(DESCRIPTOR);
216                    _data.writeParcelable(disk, 0);
217                    _data.writeInt(volumeCount);
218                    mRemote.transact(Stub.TRANSACTION_onDiskScanned, _data, _reply,
219                            android.os.IBinder.FLAG_ONEWAY);
220                    _reply.readException();
221                } finally {
222                    _reply.recycle();
223                    _data.recycle();
224                }
225            }
226        }
227
228        static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
229        static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
230        static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
231        static final int TRANSACTION_onVolumeMetadataChanged = (IBinder.FIRST_CALL_TRANSACTION + 3);
232        static final int TRANSACTION_onDiskScanned = (IBinder.FIRST_CALL_TRANSACTION + 4);
233    }
234
235    /**
236     * Detection state of USB Mass Storage has changed
237     *
238     * @param available true if a UMS host is connected.
239     */
240    public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
241
242    /**
243     * Storage state has changed.
244     *
245     * @param path The volume mount path.
246     * @param oldState The old state of the volume.
247     * @param newState The new state of the volume. Note: State is one of the
248     *            values returned by Environment.getExternalStorageState()
249     */
250    public void onStorageStateChanged(String path, String oldState, String newState)
251            throws RemoteException;
252
253    public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
254            throws RemoteException;
255
256    public void onVolumeMetadataChanged(String fsUuid) throws RemoteException;
257
258    public void onDiskScanned(DiskInfo disk, int volumeCount) throws RemoteException;
259}
260