Dirk Vogt | f96bec8 | 2016-10-27 17:24:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 com.fairphone.hiccup; |
| 18 | import android.util.Log; |
| 19 | |
| 20 | |
| 21 | |
| 22 | import android.os.Binder; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.IInterface; |
| 25 | import android.os.Parcel; |
| 26 | import android.os.RemoteException; |
| 27 | import com.fairphone.hiccup.LogFile; |
| 28 | import java.io.FileDescriptor; |
| 29 | import java.util.List; |
| 30 | import java.util.ArrayList; |
| 31 | import android.os.ParcelFileDescriptor; |
| 32 | /** |
| 33 | * @hide |
| 34 | */ |
| 35 | public interface IHiccupdService extends IInterface { |
| 36 | public static abstract class Stub extends Binder implements IHiccupdService { |
| 37 | private static class Proxy implements IHiccupdService { |
| 38 | private final IBinder mRemote; |
| 39 | |
| 40 | Proxy(IBinder remote) { |
| 41 | mRemote = remote; |
| 42 | } |
| 43 | |
| 44 | public IBinder asBinder() { |
| 45 | return mRemote; |
| 46 | } |
| 47 | |
| 48 | public String getInterfaceDescriptor() { |
| 49 | return DESCRIPTOR; |
| 50 | } |
| 51 | |
| 52 | public List<LogFile> getLogs() throws RemoteException { |
| 53 | Parcel _data = Parcel.obtain(); |
| 54 | Parcel _reply = Parcel.obtain(); |
| 55 | ArrayList<LogFile> logFiles = null; |
| 56 | try { |
| 57 | _data.writeInterfaceToken(DESCRIPTOR); |
| 58 | mRemote.transact(Stub.TRANSACTION_get_logs, _data, _reply, 0); |
| 59 | int nLogFiles = _reply.readInt(); |
| 60 | logFiles = new ArrayList<LogFile>(nLogFiles); |
| 61 | for (int i = 0; i < nLogFiles ; i++ ) { |
| 62 | String fileName = _reply.readString(); |
| 63 | if(fileName == null) { |
| 64 | fileName="UNKNOWN_FILE"; |
| 65 | } |
| 66 | ParcelFileDescriptor pfd = _reply.readFileDescriptor(); |
| 67 | FileDescriptor fileDescriptor = (pfd != null)?pfd.getFileDescriptor():null; |
| 68 | |
| 69 | logFiles.add(new LogFile(fileName, fileDescriptor)); |
| 70 | } |
| 71 | } finally { |
| 72 | _reply.recycle(); |
| 73 | _data.recycle(); |
| 74 | } |
| 75 | return logFiles; |
| 76 | } |
| 77 | |
| 78 | public List<LogFile> getLastKmsg() throws RemoteException { |
| 79 | Parcel _data = Parcel.obtain(); |
| 80 | Parcel _reply = Parcel.obtain(); |
| 81 | ArrayList<LogFile> logFiles = null; |
| 82 | try { |
| 83 | _data.writeInterfaceToken(DESCRIPTOR); |
| 84 | mRemote.transact(Stub.TRANSACTION_get_last_kmesg, _data, _reply, 0); |
| 85 | int nLogFiles = _reply.readInt(); |
| 86 | logFiles = new ArrayList<LogFile>(nLogFiles); |
| 87 | for (int i = 0; i < nLogFiles ; i++ ) { |
| 88 | String fileName = _reply.readString(); |
| 89 | if(fileName == null) { |
| 90 | fileName="UNKNOWN_FILE"; |
| 91 | } |
| 92 | ParcelFileDescriptor pfd = _reply.readFileDescriptor(); |
| 93 | FileDescriptor fileDescriptor = (pfd != null)?pfd.getFileDescriptor():null; |
| 94 | logFiles.add(new LogFile(fileName, fileDescriptor)); |
| 95 | } |
| 96 | } finally { |
| 97 | _reply.recycle(); |
| 98 | _data.recycle(); |
| 99 | } |
| 100 | return logFiles; |
| 101 | } |
| 102 | |
| 103 | public void cleanLogs() throws RemoteException { |
| 104 | Parcel _data = Parcel.obtain(); |
| 105 | Parcel _reply = Parcel.obtain(); |
| 106 | try { |
| 107 | _data.writeInterfaceToken(DESCRIPTOR); |
| 108 | mRemote.transact(Stub.TRANSACTION_clean_logs, _data, _reply, 0); |
| 109 | } finally { |
| 110 | _reply.recycle(); |
| 111 | _data.recycle(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | public void startLogging() throws RemoteException { |
| 116 | Parcel _data = Parcel.obtain(); |
| 117 | Parcel _reply = Parcel.obtain(); |
| 118 | try { |
| 119 | _data.writeInterfaceToken(DESCRIPTOR); |
| 120 | mRemote.transact(Stub.TRANSACTION_start_logging, _data, _reply, 0); |
| 121 | } finally { |
| 122 | _reply.recycle(); |
| 123 | _data.recycle(); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | public void stopLogging() throws RemoteException { |
| 128 | Parcel _data = Parcel.obtain(); |
| 129 | Parcel _reply = Parcel.obtain(); |
| 130 | try { |
| 131 | _data.writeInterfaceToken(DESCRIPTOR); |
| 132 | mRemote.transact(Stub.TRANSACTION_stop_logging, _data, _reply, 0); |
| 133 | } finally { |
| 134 | _reply.recycle(); |
| 135 | _data.recycle(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | public String getBootReason() throws RemoteException { |
| 140 | Parcel _data = Parcel.obtain(); |
| 141 | Parcel _reply = Parcel.obtain(); |
| 142 | try { |
| 143 | _data.writeInterfaceToken(DESCRIPTOR); |
| 144 | mRemote.transact(Stub.TRANSACTION_get_bootreason, _data, _reply, 0); |
| 145 | return _reply.readString(); |
| 146 | } finally { |
| 147 | _reply.recycle(); |
| 148 | _data.recycle(); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | public String getPowerOnReason() throws RemoteException { |
| 153 | Parcel _data = Parcel.obtain(); |
| 154 | Parcel _reply = Parcel.obtain(); |
| 155 | try { |
| 156 | _data.writeInterfaceToken(DESCRIPTOR); |
| 157 | mRemote.transact(Stub.TRANSACTION_get_poweronreason, _data, _reply, 0); |
| 158 | return _reply.readString(); |
| 159 | } finally { |
| 160 | _reply.recycle(); |
| 161 | _data.recycle(); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | public String getPowerOffReason() throws RemoteException { |
| 166 | Parcel _data = Parcel.obtain(); |
| 167 | Parcel _reply = Parcel.obtain(); |
| 168 | try { |
| 169 | _data.writeInterfaceToken(DESCRIPTOR); |
| 170 | mRemote.transact(Stub.TRANSACTION_get_poweroffreason, _data, _reply, 0); |
| 171 | return _reply.readString(); |
| 172 | } finally { |
| 173 | _reply.recycle(); |
| 174 | _data.recycle(); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | public int getApiVersion() throws RemoteException { |
| 179 | Parcel _data = Parcel.obtain(); |
| 180 | Parcel _reply = Parcel.obtain(); |
| 181 | try { |
| 182 | _data.writeInterfaceToken(DESCRIPTOR); |
| 183 | mRemote.transact(Stub.TRANSACTION_get_api_version, _data, _reply, 0); |
| 184 | return _reply.readInt(); |
| 185 | } finally { |
| 186 | _reply.recycle(); |
| 187 | _data.recycle(); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | private static final String DESCRIPTOR = "com.fairphone.IHiccupd"; |
| 193 | |
| 194 | static final int TRANSACTION_get_logs = IBinder.FIRST_CALL_TRANSACTION + 0; |
| 195 | static final int TRANSACTION_clean_logs = IBinder.FIRST_CALL_TRANSACTION + 1; |
| 196 | static final int TRANSACTION_start_logging = IBinder.FIRST_CALL_TRANSACTION + 2; |
| 197 | static final int TRANSACTION_stop_logging = IBinder.FIRST_CALL_TRANSACTION + 3; |
| 198 | static final int TRANSACTION_get_bootreason = IBinder.FIRST_CALL_TRANSACTION + 4; |
| 199 | static final int TRANSACTION_get_poweronreason = IBinder.FIRST_CALL_TRANSACTION + 5; |
| 200 | static final int TRANSACTION_get_poweroffreason = IBinder.FIRST_CALL_TRANSACTION + 6; |
| 201 | static final int TRANSACTION_get_last_kmesg = IBinder.FIRST_CALL_TRANSACTION + 7; |
| 202 | static final int TRANSACTION_get_api_version = IBinder.FIRST_CALL_TRANSACTION + 8; |
| 203 | |
| 204 | /** |
| 205 | * Cast an IBinder object into an IHiccupdService interface, generating |
| 206 | * a proxy if needed. |
| 207 | */ |
| 208 | public static IHiccupdService asInterface(IBinder obj) { |
| 209 | if (obj == null) { |
| 210 | return null; |
| 211 | } |
| 212 | IInterface iin = obj.queryLocalInterface(DESCRIPTOR); |
| 213 | if (iin != null && iin instanceof IHiccupdService) { |
| 214 | return (IHiccupdService) iin; |
| 215 | } |
| 216 | return new IHiccupdService.Stub.Proxy(obj); |
| 217 | } |
| 218 | |
| 219 | /** Construct the stub at attach it to the interface. */ |
| 220 | public Stub() { |
| 221 | attachInterface(this, DESCRIPTOR); |
| 222 | } |
| 223 | |
| 224 | public IBinder asBinder() { |
| 225 | return this; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 230 | throws RemoteException { |
| 231 | switch (code) { |
| 232 | case INTERFACE_TRANSACTION: { |
| 233 | reply.writeString(DESCRIPTOR); |
| 234 | return true; |
| 235 | } |
| 236 | } |
| 237 | return super.onTransact(code, data, reply, flags); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | public List<LogFile> getLogs() throws RemoteException; |
| 242 | public List<LogFile> getLastKmsg() throws RemoteException; |
| 243 | public void cleanLogs() throws RemoteException; |
| 244 | public void startLogging() throws RemoteException; |
| 245 | public void stopLogging() throws RemoteException; |
| 246 | public String getBootReason() throws RemoteException; |
| 247 | public String getPowerOnReason() throws RemoteException; |
| 248 | public String getPowerOffReason() throws RemoteException; |
| 249 | public int getApiVersion() throws RemoteException; |
| 250 | |
| 251 | } |