IMountServiceListener.java revision 7151a9a887051542c6da9f380376f3b306184e5c
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            }
95            return super.onTransact(code, data, reply, flags);
96        }
97
98        private static class Proxy implements IMountServiceListener {
99            private IBinder mRemote;
100
101            Proxy(IBinder remote) {
102                mRemote = remote;
103            }
104
105            public IBinder asBinder() {
106                return mRemote;
107            }
108
109            public String getInterfaceDescriptor() {
110                return DESCRIPTOR;
111            }
112
113            /**
114             * Detection state of USB Mass Storage has changed
115             *
116             * @param available true if a UMS host is connected.
117             */
118            public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
119                Parcel _data = Parcel.obtain();
120                Parcel _reply = Parcel.obtain();
121                try {
122                    _data.writeInterfaceToken(DESCRIPTOR);
123                    _data.writeInt(((connected) ? (1) : (0)));
124                    mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
125                            _reply, android.os.IBinder.FLAG_ONEWAY);
126                    _reply.readException();
127                } finally {
128                    _reply.recycle();
129                    _data.recycle();
130                }
131            }
132
133            /**
134             * Storage state has changed.
135             *
136             * @param path The volume mount path.
137             * @param oldState The old state of the volume.
138             * @param newState The new state of the volume. Note: State is one
139             *            of the values returned by
140             *            Environment.getExternalStorageState()
141             */
142            public void onStorageStateChanged(String path, String oldState, String newState)
143                    throws RemoteException {
144                Parcel _data = Parcel.obtain();
145                Parcel _reply = Parcel.obtain();
146                try {
147                    _data.writeInterfaceToken(DESCRIPTOR);
148                    _data.writeString(path);
149                    _data.writeString(oldState);
150                    _data.writeString(newState);
151                    mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply,
152                            android.os.IBinder.FLAG_ONEWAY);
153                    _reply.readException();
154                } finally {
155                    _reply.recycle();
156                    _data.recycle();
157                }
158            }
159
160            @Override
161            public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
162                    throws RemoteException {
163                Parcel _data = Parcel.obtain();
164                Parcel _reply = Parcel.obtain();
165                try {
166                    _data.writeInterfaceToken(DESCRIPTOR);
167                    _data.writeParcelable(vol, 0);
168                    _data.writeInt(oldState);
169                    _data.writeInt(newState);
170                    mRemote.transact(Stub.TRANSACTION_onVolumeStateChanged, _data, _reply,
171                            android.os.IBinder.FLAG_ONEWAY);
172                    _reply.readException();
173                } finally {
174                    _reply.recycle();
175                    _data.recycle();
176                }
177            }
178        }
179
180        static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
181
182        static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
183
184        static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
185    }
186
187    /**
188     * Detection state of USB Mass Storage has changed
189     *
190     * @param available true if a UMS host is connected.
191     */
192    public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
193
194    /**
195     * Storage state has changed.
196     *
197     * @param path The volume mount path.
198     * @param oldState The old state of the volume.
199     * @param newState The new state of the volume. Note: State is one of the
200     *            values returned by Environment.getExternalStorageState()
201     */
202    public void onStorageStateChanged(String path, String oldState, String newState)
203            throws RemoteException;
204
205    public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
206            throws RemoteException;
207}
208