blob: 6f13b03c3b6b3cdad9b59d695aba87a563979a44 [file] [log] [blame]
Kelvin Zhang596969b2023-10-05 10:21:13 -07001//
2// Copyright (C) 2023 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#include <update_engine/aosp/permission.h>
17
18#include <array>
19#include <algorithm>
20#include <android-base/stringprintf.h>
21#include <android-base/logging.h>
22
23namespace chromeos_update_engine {
24
25android::binder::Status CheckCallingUid() {
26 const auto calling_uid = android::BinderWrapper::Get()->GetCallingUid();
27 if (!Contains(kAllowedUids, calling_uid)) {
28 LOG(ERROR) << "Calling UID " << calling_uid
29 << " is not allowed to access update_engine APIs";
30 auto message =
31 android::base::StringPrintf("UID %d is not allowed", calling_uid);
32 return android::binder::Status::fromExceptionCode(
33 android::binder::Status::EX_SECURITY,
34 android::String8(message.c_str()));
35 }
36 return android::binder::Status::ok();
37}
38
39} // namespace chromeos_update_engine