blob: fd914bc843ab060e167a8b3159eb876cbf363690 [file] [log] [blame]
Kenny Rootbe857d42010-08-18 15:59:25 -07001/*
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);
Jeff Sharkey7151a9a2015-04-04 15:22:37 -070078 final String path = data.readString();
79 final String oldState = data.readString();
80 final String newState = data.readString();
Kenny Rootbe857d42010-08-18 15:59:25 -070081 this.onStorageStateChanged(path, oldState, newState);
82 reply.writeNoException();
83 return true;
84 }
Jeff Sharkey7151a9a2015-04-04 15:22:37 -070085 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 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -070094 case TRANSACTION_onVolumeMetadataChanged: {
95 data.enforceInterface(DESCRIPTOR);
96 final VolumeInfo vol = (VolumeInfo) data.readParcelable(null);
97 onVolumeMetadataChanged(vol);
98 reply.writeNoException();
99 return true;
100 }
Kenny Rootbe857d42010-08-18 15:59:25 -0700101 }
102 return super.onTransact(code, data, reply, flags);
103 }
104
105 private static class Proxy implements IMountServiceListener {
106 private IBinder mRemote;
107
108 Proxy(IBinder remote) {
109 mRemote = remote;
110 }
111
112 public IBinder asBinder() {
113 return mRemote;
114 }
115
116 public String getInterfaceDescriptor() {
117 return DESCRIPTOR;
118 }
119
120 /**
121 * Detection state of USB Mass Storage has changed
122 *
123 * @param available true if a UMS host is connected.
124 */
125 public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException {
126 Parcel _data = Parcel.obtain();
127 Parcel _reply = Parcel.obtain();
128 try {
129 _data.writeInterfaceToken(DESCRIPTOR);
130 _data.writeInt(((connected) ? (1) : (0)));
131 mRemote.transact(Stub.TRANSACTION_onUsbMassStorageConnectionChanged, _data,
Jeff Sharkey7151a9a2015-04-04 15:22:37 -0700132 _reply, android.os.IBinder.FLAG_ONEWAY);
Kenny Rootbe857d42010-08-18 15:59:25 -0700133 _reply.readException();
134 } finally {
135 _reply.recycle();
136 _data.recycle();
137 }
138 }
139
140 /**
141 * Storage state has changed.
142 *
143 * @param path The volume mount path.
144 * @param oldState The old state of the volume.
145 * @param newState The new state of the volume. Note: State is one
146 * of the values returned by
147 * Environment.getExternalStorageState()
148 */
149 public void onStorageStateChanged(String path, String oldState, String newState)
150 throws RemoteException {
151 Parcel _data = Parcel.obtain();
152 Parcel _reply = Parcel.obtain();
153 try {
154 _data.writeInterfaceToken(DESCRIPTOR);
155 _data.writeString(path);
156 _data.writeString(oldState);
157 _data.writeString(newState);
Jeff Sharkey7151a9a2015-04-04 15:22:37 -0700158 mRemote.transact(Stub.TRANSACTION_onStorageStateChanged, _data, _reply,
159 android.os.IBinder.FLAG_ONEWAY);
160 _reply.readException();
161 } finally {
162 _reply.recycle();
163 _data.recycle();
164 }
165 }
166
167 @Override
168 public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
169 throws RemoteException {
170 Parcel _data = Parcel.obtain();
171 Parcel _reply = Parcel.obtain();
172 try {
173 _data.writeInterfaceToken(DESCRIPTOR);
174 _data.writeParcelable(vol, 0);
175 _data.writeInt(oldState);
176 _data.writeInt(newState);
177 mRemote.transact(Stub.TRANSACTION_onVolumeStateChanged, _data, _reply,
178 android.os.IBinder.FLAG_ONEWAY);
Kenny Rootbe857d42010-08-18 15:59:25 -0700179 _reply.readException();
180 } finally {
181 _reply.recycle();
182 _data.recycle();
183 }
184 }
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700185
186 @Override
187 public void onVolumeMetadataChanged(VolumeInfo vol) throws RemoteException {
188 Parcel _data = Parcel.obtain();
189 Parcel _reply = Parcel.obtain();
190 try {
191 _data.writeInterfaceToken(DESCRIPTOR);
192 _data.writeParcelable(vol, 0);
193 mRemote.transact(Stub.TRANSACTION_onVolumeMetadataChanged, _data, _reply,
194 android.os.IBinder.FLAG_ONEWAY);
195 _reply.readException();
196 } finally {
197 _reply.recycle();
198 _data.recycle();
199 }
200 }
Kenny Rootbe857d42010-08-18 15:59:25 -0700201 }
202
203 static final int TRANSACTION_onUsbMassStorageConnectionChanged = (IBinder.FIRST_CALL_TRANSACTION + 0);
204
205 static final int TRANSACTION_onStorageStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 1);
Jeff Sharkey7151a9a2015-04-04 15:22:37 -0700206
207 static final int TRANSACTION_onVolumeStateChanged = (IBinder.FIRST_CALL_TRANSACTION + 2);
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700208 static final int TRANSACTION_onVolumeMetadataChanged = (IBinder.FIRST_CALL_TRANSACTION + 3);
Kenny Rootbe857d42010-08-18 15:59:25 -0700209 }
210
211 /**
212 * Detection state of USB Mass Storage has changed
213 *
214 * @param available true if a UMS host is connected.
215 */
216 public void onUsbMassStorageConnectionChanged(boolean connected) throws RemoteException;
217
218 /**
219 * Storage state has changed.
220 *
221 * @param path The volume mount path.
222 * @param oldState The old state of the volume.
223 * @param newState The new state of the volume. Note: State is one of the
224 * values returned by Environment.getExternalStorageState()
225 */
226 public void onStorageStateChanged(String path, String oldState, String newState)
227 throws RemoteException;
Jeff Sharkey7151a9a2015-04-04 15:22:37 -0700228
229 public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
230 throws RemoteException;
Jeff Sharkeyd95d3bf2015-04-14 21:39:44 -0700231
232 public void onVolumeMetadataChanged(VolumeInfo vol) throws RemoteException;
Kenny Rootbe857d42010-08-18 15:59:25 -0700233}