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

Commit 9d21ee5d authored by Ruben Brunk's avatar Ruben Brunk
Browse files

Add CameraService to system server.

- Adds a camera service to system server that forwards events to the
  mediaserver camera service.
- Notify the camera service when the device user changes.

Bug: 19186859
Change-Id: I172a2ce46c8e8a131ae7e8dd99d60c5f4f0d6668
parent 75e4f353
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -75,4 +75,11 @@ interface ICameraService
                    out BinderHolder device);

    int setTorchMode(String CameraId, boolean enabled, IBinder clientBinder);

    /**
     * Notify the camera service of a system event.  Should only be called from system_server.
     *
     * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
     */
    oneway void notifySystemEvent(int eventId, int arg0);
}
+8 −0
Original line number Diff line number Diff line
@@ -1220,6 +1220,14 @@
        android:label="@string/permlab_cameraDisableTransmitLed"
        android:description="@string/permdesc_cameraDisableTransmitLed" />

    <!-- Allows sending the camera service notifications about system-wide events.
        @hide -->
    <permission android:name="android.permission.CAMERA_SEND_SYSTEM_EVENTS"
        android:permissionGroup="android.permission-group.CAMERA"
        android:protectionLevel="signature|system"
        android:label="@string/permdesc_cameraSendSystemEvent"
        android:description="@string/permdesc_cameraSendSystemEvent" />

    <!-- =========================================== -->
    <!-- Permissions associated with telephony state -->
    <!-- =========================================== -->
+2 −0
Original line number Diff line number Diff line
@@ -1758,6 +1758,8 @@
    <string name="permlab_cameraDisableTransmitLed">disable transmit indicator LED when camera is in use</string>
    <!-- Description of a camera app permission, listed so the user can choose whether or not they want to allow it to disable the may-transmit light indicator. -->
    <string name="permdesc_cameraDisableTransmitLed">Allows a pre-installed system application to disable the camera use indicator LED.</string>
    <!-- Description of a camera app permission, listed so that the user can send the camera service notifications about system-wide events. -->
    <string name="permdesc_cameraSendSystemEvent">Allows a pre-installed system application to send the camera service system events.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_brick" product="tablet">permanently disable tablet</string>
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright 2015 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.
 */
package com.android.server.camera;

import android.content.Context;
import android.hardware.ICameraService;
import android.os.IBinder;
import android.os.RemoteException;

import com.android.server.SystemService;

/**
 * CameraService is the system_server analog to the camera service running in mediaserver.
 *
 * @hide
 */
public class CameraService extends SystemService {

    /**
     * This must match the ICameraService.aidl definition
     */
    private static final String CAMERA_SERVICE_BINDER_NAME = "media.camera";

    // Event arguments to use with the camera service notifySystemEvent call:
    public static final int NO_EVENT = 0; // NOOP
    public static final int USER_SWITCHED = 1; // User changed, argument is the new user handle

    public CameraService(Context context) {
        super(context);
    }

    @Override
    public void onStart() {}

    @Override
    public void onSwitchUser(int userHandle) {
        super.onSwitchUser(userHandle);

        /**
         * Forward the user switch event to the native camera service running in mediaserver.
         */
        IBinder cameraServiceBinder = getBinderService(CAMERA_SERVICE_BINDER_NAME);
        if (cameraServiceBinder == null) {
            return; // Camera service not active, there is no need to evict user clients.
        }
        ICameraService cameraServiceRaw = ICameraService.Stub.asInterface(cameraServiceBinder);
        try {
            cameraServiceRaw.notifySystemEvent(USER_SWITCHED, userHandle);
        } catch (RemoteException e) {
            // Do nothing, if camera service is dead, there is no need to evict user clients.
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accounts.AccountManagerService;
import com.android.server.am.ActivityManagerService;
import com.android.server.audio.AudioService;
import com.android.server.camera.CameraService;
import com.android.server.clipboard.ClipboardService;
import com.android.server.content.ContentService;
import com.android.server.devicepolicy.DevicePolicyManagerService;
@@ -408,6 +409,7 @@ public final class SystemServer {
        AudioService audioService = null;
        MmsServiceBroker mmsService = null;
        EntropyMixer entropyMixer = null;
        CameraService cameraService = null;

        boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
        boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
@@ -436,6 +438,9 @@ public final class SystemServer {

            mContentResolver = context.getContentResolver();

            Slog.i(TAG, "Camera Service");
            mSystemServiceManager.startService(CameraService.class);

            // The AccountManager must come before the ContentService
            try {
                // TODO: seems like this should be disable-able, but req'd by ContentService