summaryrefslogtreecommitdiff
path: root/libs/binder/PermissionController.cpp
diff options
context:
space:
mode:
author Svet Ganov <svetoslavganov@google.com> 2018-01-15 17:14:20 -0800
committer Svet Ganov <svetoslavganov@google.com> 2018-01-16 21:38:32 -0800
commite752a5cc64b78f799525aa4e44e5f74e8c402465 (patch)
treefaac395cc63bde42799bfea8d6c018ee1963ad2e /libs/binder/PermissionController.cpp
parent98da46b723d515420261a4c04225cdec135ca98d (diff)
No sensor access to idle UIDs - native framework
Idle UIDs are ones that were in the background for long enough time. Currently such apps can access sensor data even though they have no user perceptible components running. This affects the user's privacy since an app in the background can use sensor data to infer location, activity, habits, etc. The goal is to restrict sensor access for all apps in the ecosystem regardless of target SDK which means the solution should be backwards compatible. At the high level the sesnor service observes UID state changes and applies policy like this: Continuous sensors: for sensros in this reporting mode when the UID goes in the background we will stop dispatching events. Once the UID goes active we will start reporting the events. While this is an app visible behavior change we would rather do that vs delivering fake events. Flush events: there is no change in behavior based on the UID state. Hence, idle apps can request a flush and would get the completion callback. From an app perspective flushing works at any point. Trigger events: for sensors in this reporting mode when the UID goes in the background we will not report any trigger events. From an app perspective the sensor just did not pick up any events. On-change events: for sensors in this reporting mode when the UID goes in the background we will not report any change events. From an app perspective the sensor just did not pick up any events. Wake locks: since UIDs in idle state cannot acquire wakelocks we will not be grabbing a wakelock on behalf of apps in that state. Test: Added - SensorTest#testSanitizedContinuousEventsUidIdle Added - SensorTest#testBatchAndFlushUidIdle Pass - cts-tradefed run cts-dev -m CtsSensorTestCases bug:63938985 Change-Id: I156803610ad6d86afaae641ebbb0e84f16d2344b
Diffstat (limited to 'libs/binder/PermissionController.cpp')
-rw-r--r--libs/binder/PermissionController.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/binder/PermissionController.cpp b/libs/binder/PermissionController.cpp
new file mode 100644
index 0000000000..25748cadbb
--- /dev/null
+++ b/libs/binder/PermissionController.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <mutex>
+#include <binder/PermissionController.h>
+#include <binder/Binder.h>
+#include <binder/IServiceManager.h>
+
+#include <utils/SystemClock.h>
+
+namespace android {
+
+PermissionController::PermissionController()
+{
+}
+
+sp<IPermissionController> PermissionController::getService()
+{
+ std::lock_guard<Mutex> scoped_lock(mLock);
+ int64_t startTime = 0;
+ sp<IPermissionController> service = mService;
+ while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
+ sp<IBinder> binder = defaultServiceManager()->checkService(String16("permission"));
+ if (binder == nullptr) {
+ // Wait for the activity service to come back...
+ if (startTime == 0) {
+ startTime = uptimeMillis();
+ ALOGI("Waiting for permission service");
+ } else if ((uptimeMillis() - startTime) > 10000) {
+ ALOGW("Waiting too long for permission service, giving up");
+ service = NULL;
+ break;
+ }
+ sleep(1);
+ } else {
+ service = interface_cast<IPermissionController>(binder);
+ mService = service;
+ }
+ }
+ return service;
+}
+
+bool PermissionController::checkPermission(const String16& permission, int32_t pid, int32_t uid)
+{
+ sp<IPermissionController> service = getService();
+ return service != NULL ? service->checkPermission(permission, pid, uid) : false;
+}
+
+void PermissionController::getPackagesForUid(const uid_t uid, Vector<String16> &packages)
+{
+ sp<IPermissionController> service = getService();
+ if (service != nullptr) {
+ service->getPackagesForUid(uid, packages);
+ }
+}
+
+bool PermissionController::isRuntimePermission(const String16& permission)
+{
+ sp<IPermissionController> service = getService();
+ return service != nullptr ? service->isRuntimePermission(permission) : false;
+}
+
+int PermissionController::getPackageUid(const String16& package, int flags)
+{
+ sp<IPermissionController> service = getService();
+ return service != nullptr ? service->getPackageUid(package, flags) : -1;
+}
+
+}; // namespace android