blob: f28bdf7cf55c8c78bda0ffbcb35987f84ad09991 [file] [log] [blame]
Peter Beverlooc0e3f8402017-08-31 16:08:301// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/android/build_info.h"
6#include "base/android/jni_android.h"
7#include "base/android/scoped_java_ref.h"
8#include "base/metrics/histogram_macros.h"
9#include "jni/DecoderService_jni.h"
10#include "sandbox/linux/seccomp-bpf-helpers/seccomp_starter_android.h"
11#include "sandbox/sandbox_features.h"
12
13#if BUILDFLAG(USE_SECCOMP_BPF)
Peter Beverlooc0e3f8402017-08-31 16:08:3014#include "sandbox/linux/seccomp-bpf-helpers/baseline_policy_android.h"
15#endif
16
Daniel Bratell7aacf952017-11-21 17:51:2517void JNI_DecoderService_InitializePhotoPickerSandbox(
Peter Beverlooc0e3f8402017-08-31 16:08:3018 JNIEnv* env,
19 const base::android::JavaParamRef<jclass>& jcaller) {
20 auto* info = base::android::BuildInfo::GetInstance();
21 sandbox::SeccompStarterAndroid starter(info->sdk_int(), info->device());
22
23#if BUILDFLAG(USE_SECCOMP_BPF)
24 // The policy compiler is only available if USE_SECCOMP_BPF is enabled.
Jinho Bang7fa90e872018-01-15 18:04:1225 starter.set_policy(std::make_unique<sandbox::BaselinePolicyAndroid>());
Peter Beverlooc0e3f8402017-08-31 16:08:3026#endif
27 starter.StartSandbox();
28
29 UMA_HISTOGRAM_ENUMERATION("Android.SeccompStatus.PhotoPickerSandbox",
30 starter.status(),
31 sandbox::SeccompSandboxStatus::STATUS_MAX);
32}