Jorge Lucangeli Obes | 68aac7f | 2016-04-13 11:01:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #include <base/at_exit.h> |
| 18 | #include <base/logging.h> |
| 19 | #include <base/message_loop/message_loop.h> |
| 20 | #include <binder/IServiceManager.h> |
| 21 | #include <binder/Status.h> |
| 22 | #include <brillo/binder_watcher.h> |
| 23 | #include <brillo/message_loops/base_message_loop.h> |
| 24 | #include <brillo/syslog_logging.h> |
| 25 | #include <utils/String16.h> |
| 26 | |
| 27 | #include "android/os/BnPermissionController.h" |
| 28 | |
| 29 | namespace { |
| 30 | static android::String16 serviceName("permission"); |
| 31 | } |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | class PermissionService : public android::os::BnPermissionController { |
| 36 | public: |
| 37 | ::android::binder::Status checkPermission( |
| 38 | const ::android::String16& permission, int32_t pid, int32_t uid, |
| 39 | bool* _aidl_return) { |
| 40 | (void)permission; |
| 41 | (void)pid; |
| 42 | (void)uid; |
| 43 | *_aidl_return = true; |
| 44 | return binder::Status::ok(); |
| 45 | } |
| 46 | |
| 47 | ::android::binder::Status getPackagesForUid( |
| 48 | int32_t uid, ::std::vector<::android::String16>* _aidl_return) { |
| 49 | (void)uid; |
| 50 | // Brillo doesn't currently have installable packages. |
| 51 | if (_aidl_return) { |
| 52 | _aidl_return->clear(); |
| 53 | } |
| 54 | return binder::Status::ok(); |
| 55 | } |
| 56 | |
| 57 | ::android::binder::Status isRuntimePermission( |
| 58 | const ::android::String16& permission, bool* _aidl_return) { |
| 59 | (void)permission; |
| 60 | // Brillo doesn't currently have runtime permissions. |
| 61 | *_aidl_return = false; |
| 62 | return binder::Status::ok(); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | } // namespace android |
| 67 | |
| 68 | int main() { |
| 69 | base::AtExitManager atExitManager; |
| 70 | brillo::InitLog(brillo::kLogToSyslog); |
| 71 | // Register the service with servicemanager. |
| 72 | android::status_t status = android::defaultServiceManager()->addService( |
| 73 | serviceName, new android::PermissionService()); |
| 74 | CHECK(status == android::OK) << "Failed to get IPermissionController " |
| 75 | "binder from servicemanager."; |
| 76 | |
| 77 | // Create a message loop. |
| 78 | base::MessageLoopForIO messageLoopForIo; |
| 79 | brillo::BaseMessageLoop messageLoop{&messageLoopForIo}; |
| 80 | |
| 81 | // Initialize a binder watcher. |
| 82 | brillo::BinderWatcher watcher(&messageLoop); |
| 83 | watcher.Init(); |
| 84 | |
| 85 | // Run the message loop. |
| 86 | messageLoop.Run(); |
| 87 | } |