#
#  Copyright 2023 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.
#

description    "Start daemon for Minijailed Media Codec (MMC) Service"
author         "ChromeOS BT <chromeos-bt-team@google.com>"

# Mmc Codec Manager can recover by restarting.
oom score -100

# This service is started by D-Bus service activation through
# org.chromium.mmc.CodecManager.service
stop on stopping boot-services

#  Minijail forks off the desired process and exits after forking.
expect fork

pre-start script
  # Check if Boot-services is still running before starting mmc_service.
  # This is to prevent new dbus-activated instances from getting
  # started once the system is beginning to shut down.
  if ! initctl status boot-services | grep -q running; then
    stop
    exit 0
  fi
end script

exec minijail0 --config /usr/share/minijail/mmc.conf \
  -- /usr/bin/mmc_service

# Wait until DBus service becomes available.
post-start exec minijail0 -u mmc_service -g mmc_service /usr/bin/gdbus \
    wait --system --timeout 15 org.chromium.mmc.CodecManager
