Home | History | Annotate | Download | only in native
      1 /*
      2  * Copyright (C) 2015 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 
     18 
     19 #define LOG_TAG "VehicleMonitorListener"
     20 
     21 #include <memory>
     22 
     23 #include <utils/Errors.h>
     24 #include <utils/Log.h>
     25 
     26 #include <IVehicleMonitorListener.h>
     27 
     28 namespace android {
     29 
     30 enum {
     31     ON_APP_VIOLATION = IBinder::FIRST_CALL_TRANSACTION,
     32 };
     33 
     34 class BpVehicleMonitorListener : public BpInterface<IVehicleMonitorListener>
     35 {
     36   public:
     37     explicit BpVehicleMonitorListener(const sp<IBinder> & impl)
     38             : BpInterface<IVehicleMonitorListener>(impl) {
     39     }
     40 
     41     virtual void onAppViolation(
     42             int32_t pid, int32_t uid, int32_t action, int32_t violation) {
     43         Parcel data, reply;
     44         data.writeInterfaceToken(IVehicleMonitorListener::getInterfaceDescriptor());
     45         data.writeInt32(1);
     46         data.writeInt32(pid);
     47         data.writeInt32(uid);
     48         data.writeInt32(action);
     49         data.writeInt32(violation);
     50         remote()->transact(ON_APP_VIOLATION, data, &reply, IBinder::FLAG_ONEWAY);
     51     }
     52 };
     53 
     54 IMPLEMENT_META_INTERFACE(VehicleMonitorListener, "com.android.car.vehiclemonitor.IVehicleMonitorListener");
     55 
     56 // ----------------------------------------------------------------------
     57 
     58 status_t BnVehicleMonitorListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
     59                                               uint32_t flags) {
     60     status_t r;
     61     switch (code) {
     62         case ON_APP_VIOLATION: {
     63             CHECK_INTERFACE(IVehicleMonitorListener, data, reply);
     64             if (data.readInt32() == 0) { // java side allows passing null with this.
     65                 return BAD_VALUE;
     66             }
     67             int32_t pid = data.readInt32();
     68             int32_t uid = data.readInt32();
     69             int32_t action = data.readInt32();
     70             int32_t violation = data.readInt32();
     71             onAppViolation(pid, uid, action, violation);
     72             return NO_ERROR;
     73         } break;
     74         default:
     75             return BBinder::onTransact(code, data, reply, flags);
     76     }
     77 }
     78 
     79 }; // namespace android
     80