Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8016153 authored by Daniel Nicoara's avatar Daniel Nicoara Committed by android-build-merger
Browse files

Restrict VR HWC access to services with RESTRICTED_VR_ACCESS permission am: 0b4c80ac

am: 6ed8b503

Change-Id: If33d1a21ddc7444d6ff6a8972ffe9b44fff8c45a
parents c3c8e08a 6ed8b503
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
#include "vr_composer.h"

#include <binder/IPCThreadState.h>
#include <binder/PermissionCache.h>

namespace android {
namespace dvr {
namespace {

bool CheckPermission() {
  const android::IPCThreadState* ipc = android::IPCThreadState::self();
  const pid_t pid = ipc->getCallingPid();
  const uid_t uid = ipc->getCallingUid();
  const bool permission = PermissionCache::checkPermission(
      String16("android.permission.RESTRICTED_VR_ACCESS"), pid, uid);
  if (!permission)
    ALOGE("permission denied to pid=%d uid=%u", pid, uid);

  return permission;
}

}  // namespace

VrComposer::VrComposer() {}

@@ -11,6 +29,9 @@ binder::Status VrComposer::registerObserver(
    const sp<IVrComposerCallback>& callback) {
  std::lock_guard<std::mutex> guard(mutex_);

  if (!CheckPermission())
    return binder::Status::fromStatusT(PERMISSION_DENIED);

  if (callback_.get()) {
    ALOGE("Failed to register callback, already registered");
    return binder::Status::fromStatusT(ALREADY_EXISTS);