Home | History | Annotate | Download | only in utils
      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 #define LOG_TAG "ISchedulingPolicyService"
     18 //#define LOG_NDEBUG 0
     19 
     20 #include <binder/Parcel.h>
     21 #include "ISchedulingPolicyService.h"
     22 
     23 namespace android {
     24 
     25 // Keep in sync with frameworks/base/core/java/android/os/ISchedulingPolicyService.aidl
     26 enum {
     27     REQUEST_PRIORITY_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
     28 };
     29 
     30 // ----------------------------------------------------------------------
     31 
     32 class BpSchedulingPolicyService : public BpInterface<ISchedulingPolicyService>
     33 {
     34 public:
     35     explicit BpSchedulingPolicyService(const sp<IBinder>& impl)
     36         : BpInterface<ISchedulingPolicyService>(impl)
     37     {
     38     }
     39 
     40     virtual int requestPriority(int32_t pid, int32_t tid,
     41                                 int32_t prio, bool isForApp, bool asynchronous)
     42     {
     43         Parcel data, reply;
     44         data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor());
     45         data.writeInt32(pid);
     46         data.writeInt32(tid);
     47         data.writeInt32(prio);
     48         data.writeBool(isForApp);
     49         uint32_t flags = asynchronous ? IBinder::FLAG_ONEWAY : 0;
     50         status_t status = remote()->transact(REQUEST_PRIORITY_TRANSACTION, data, &reply, flags);
     51         if (status != NO_ERROR) {
     52             return status;
     53         }
     54         if (asynchronous) {
     55             return NO_ERROR;
     56         }
     57         // fail on exception: force binder reconnection
     58         if (reply.readExceptionCode() != 0) {
     59             return DEAD_OBJECT;
     60         }
     61         return reply.readInt32();
     62     }
     63 };
     64 
     65 IMPLEMENT_META_INTERFACE(SchedulingPolicyService, "android.os.ISchedulingPolicyService");
     66 
     67 // ----------------------------------------------------------------------
     68 
     69 status_t BnSchedulingPolicyService::onTransact(
     70     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     71 {
     72     switch (code) {
     73     case REQUEST_PRIORITY_TRANSACTION:
     74         // Not reached
     75         return NO_ERROR;
     76         break;
     77     default:
     78         return BBinder::onTransact(code, data, reply, flags);
     79     }
     80 }
     81 
     82 }   // namespace android
     83