1 /* 2 * Copyright (C) 2010 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 17 package android.os.storage; 18 19 import android.os.Binder; 20 import android.os.IBinder; 21 import android.os.IInterface; 22 import android.os.Parcel; 23 import android.os.RemoteException; 24 25 /** 26 * Callback class for receiving events from MountService about Opaque Binary 27 * Blobs (OBBs). 28 * 29 * @hide - Applications should use StorageManager to interact with OBBs. 30 */ 31 public interface IObbActionListener extends IInterface { 32 /** Local-side IPC implementation stub class. */ 33 public static abstract class Stub extends Binder implements IObbActionListener { 34 private static final String DESCRIPTOR = "IObbActionListener"; 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 IObbActionListener interface, 43 * generating a proxy if needed. 44 */ 45 public static IObbActionListener asInterface(IBinder obj) { 46 if ((obj == null)) { 47 return null; 48 } 49 IInterface iin = (IInterface) obj.queryLocalInterface(DESCRIPTOR); 50 if (((iin != null) && (iin instanceof IObbActionListener))) { 51 return ((IObbActionListener) iin); 52 } 53 return new IObbActionListener.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_onObbResult: { 69 data.enforceInterface(DESCRIPTOR); 70 String filename; 71 filename = data.readString(); 72 int nonce; 73 nonce = data.readInt(); 74 int status; 75 status = data.readInt(); 76 this.onObbResult(filename, nonce, status); 77 reply.writeNoException(); 78 return true; 79 } 80 } 81 return super.onTransact(code, data, reply, flags); 82 } 83 84 private static class Proxy implements IObbActionListener { 85 private IBinder mRemote; 86 87 Proxy(IBinder remote) { 88 mRemote = remote; 89 } 90 91 public IBinder asBinder() { 92 return mRemote; 93 } 94 95 public String getInterfaceDescriptor() { 96 return DESCRIPTOR; 97 } 98 99 /** 100 * Return from an OBB action result. 101 * 102 * @param filename the path to the OBB the operation was performed 103 * on 104 * @param returnCode status of the operation 105 */ 106 public void onObbResult(String filename, int nonce, int status) 107 throws RemoteException { 108 Parcel _data = Parcel.obtain(); 109 Parcel _reply = Parcel.obtain(); 110 try { 111 _data.writeInterfaceToken(DESCRIPTOR); 112 _data.writeString(filename); 113 _data.writeInt(nonce); 114 _data.writeInt(status); 115 mRemote.transact(Stub.TRANSACTION_onObbResult, _data, _reply, 116 android.os.IBinder.FLAG_ONEWAY); 117 _reply.readException(); 118 } finally { 119 _reply.recycle(); 120 _data.recycle(); 121 } 122 } 123 } 124 125 static final int TRANSACTION_onObbResult = (IBinder.FIRST_CALL_TRANSACTION + 0); 126 } 127 128 /** 129 * Return from an OBB action result. 130 * 131 * @param filename the path to the OBB the operation was performed on 132 * @param nonce identifier that is meaningful to the receiver 133 * @param status status code as defined in {@link OnObbStateChangeListener} 134 */ 135 public void onObbResult(String filename, int nonce, int status) throws RemoteException; 136 } 137