| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2005 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 "PermissionController" | 
|  | 18 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 19 | #include <binder/IPermissionController.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 |  | 
|  | 21 | #include <utils/Debug.h> | 
|  | 22 | #include <utils/Log.h> | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/Parcel.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <utils/String8.h> | 
|  | 25 |  | 
| Mathias Agopian | 208059f | 2009-05-18 15:08:03 -0700 | [diff] [blame] | 26 | #include <private/binder/Static.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 | // ---------------------------------------------------------------------- | 
|  | 31 |  | 
|  | 32 | class BpPermissionController : public BpInterface<IPermissionController> | 
|  | 33 | { | 
|  | 34 | public: | 
|  | 35 | BpPermissionController(const sp<IBinder>& impl) | 
|  | 36 | : BpInterface<IPermissionController>(impl) | 
|  | 37 | { | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | virtual bool checkPermission(const String16& permission, int32_t pid, int32_t uid) | 
|  | 41 | { | 
|  | 42 | Parcel data, reply; | 
|  | 43 | data.writeInterfaceToken(IPermissionController::getInterfaceDescriptor()); | 
|  | 44 | data.writeString16(permission); | 
|  | 45 | data.writeInt32(pid); | 
|  | 46 | data.writeInt32(uid); | 
|  | 47 | remote()->transact(CHECK_PERMISSION_TRANSACTION, data, &reply); | 
|  | 48 | // fail on exception | 
|  | 49 | if (reply.readInt32() != 0) return 0; | 
|  | 50 | return reply.readInt32() != 0; | 
|  | 51 | } | 
|  | 52 | }; | 
|  | 53 |  | 
|  | 54 | IMPLEMENT_META_INTERFACE(PermissionController, "android.os.IPermissionController"); | 
|  | 55 |  | 
|  | 56 | // ---------------------------------------------------------------------- | 
|  | 57 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | status_t BnPermissionController::onTransact( | 
|  | 59 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 60 | { | 
|  | 61 | //printf("PermissionController received: "); data.print(); | 
|  | 62 | switch(code) { | 
|  | 63 | case CHECK_PERMISSION_TRANSACTION: { | 
|  | 64 | CHECK_INTERFACE(IPermissionController, data, reply); | 
|  | 65 | String16 permission = data.readString16(); | 
|  | 66 | int32_t pid = data.readInt32(); | 
|  | 67 | int32_t uid = data.readInt32(); | 
|  | 68 | bool res = checkPermission(permission, pid, uid); | 
|  | 69 | // write exception | 
|  | 70 | reply->writeInt32(0); | 
|  | 71 | reply->writeInt32(res ? 1 : 0); | 
|  | 72 | return NO_ERROR; | 
|  | 73 | } break; | 
|  | 74 | default: | 
|  | 75 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 76 | } | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | }; // namespace android | 
|  | 80 |  |