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 related to shutdown.
27 *
28 * @hide - For internal consumption only.
29 */
30public interface IMountShutdownObserver extends IInterface {
31    /** Local-side IPC implementation stub class. */
32    public static abstract class Stub extends Binder implements IMountShutdownObserver {
33        private static final java.lang.String DESCRIPTOR = "IMountShutdownObserver";
34
35        /** Construct the stub at attach it to the interface. */
36        public Stub() {
37            this.attachInterface(this, DESCRIPTOR);
38        }
39
40        /**
41         * Cast an IBinder object into an IMountShutdownObserver interface,
42         * generating a proxy if needed.
43         */
44        public static IMountShutdownObserver asInterface(IBinder obj) {
45            if ((obj == null)) {
46                return null;
47            }
48            IInterface iin = (IInterface) obj.queryLocalInterface(DESCRIPTOR);
49            if (((iin != null) && (iin instanceof IMountShutdownObserver))) {
50                return ((IMountShutdownObserver) iin);
51            }
52            return new IMountShutdownObserver.Stub.Proxy(obj);
53        }
54
55        public IBinder asBinder() {
56            return this;
57        }
58
59        @Override
60        public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
61                throws RemoteException {
62            switch (code) {
63                case INTERFACE_TRANSACTION: {
64                    reply.writeString(DESCRIPTOR);
65                    return true;
66                }
67                case TRANSACTION_onShutDownComplete: {
68                    data.enforceInterface(DESCRIPTOR);
69                    int statusCode;
70                    statusCode = data.readInt();
71                    this.onShutDownComplete(statusCode);
72                    reply.writeNoException();
73                    return true;
74                }
75            }
76            return super.onTransact(code, data, reply, flags);
77        }
78
79        private static class Proxy implements IMountShutdownObserver {
80            private IBinder mRemote;
81
82            Proxy(IBinder remote) {
83                mRemote = remote;
84            }
85
86            public IBinder asBinder() {
87                return mRemote;
88            }
89
90            public java.lang.String getInterfaceDescriptor() {
91                return DESCRIPTOR;
92            }
93
94            /**
95             * This method is called when the shutdown of MountService
96             * completed.
97             *
98             * @param statusCode indicates success or failure of the shutdown.
99             */
100            public void onShutDownComplete(int statusCode) throws RemoteException {
101                Parcel _data = Parcel.obtain();
102                Parcel _reply = Parcel.obtain();
103                try {
104                    _data.writeInterfaceToken(DESCRIPTOR);
105                    _data.writeInt(statusCode);
106                    mRemote.transact(Stub.TRANSACTION_onShutDownComplete, _data, _reply, 0);
107                    _reply.readException();
108                } finally {
109                    _reply.recycle();
110                    _data.recycle();
111                }
112            }
113        }
114
115        static final int TRANSACTION_onShutDownComplete = (IBinder.FIRST_CALL_TRANSACTION + 0);
116    }
117
118    /**
119     * This method is called when the shutdown of MountService completed.
120     *
121     * @param statusCode indicates success or failure of the shutdown.
122     */
123    public void onShutDownComplete(int statusCode) throws RemoteException;
124}
125