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

Commit cdc0cfdc authored by Roman Birg's avatar Roman Birg
Browse files

add framework torch service



Change-Id: I0c7a055b33fdebe697f23d207b20408e06eb74a8
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
(cherry picked from commit 47efe1dc)
parent 4848ccb4
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -137,6 +137,7 @@ LOCAL_SRC_FILES += \
	core/java/android/hardware/IConsumerIrService.aidl \
	core/java/android/hardware/IConsumerIrService.aidl \
	core/java/android/hardware/IProCameraUser.aidl \
	core/java/android/hardware/IProCameraUser.aidl \
	core/java/android/hardware/IProCameraCallbacks.aidl \
	core/java/android/hardware/IProCameraCallbacks.aidl \
	core/java/android/hardware/ITorchService.aidl \
	core/java/android/hardware/camera2/ICameraDeviceUser.aidl \
	core/java/android/hardware/camera2/ICameraDeviceUser.aidl \
	core/java/android/hardware/camera2/ICameraDeviceCallbacks.aidl \
	core/java/android/hardware/camera2/ICameraDeviceCallbacks.aidl \
	core/java/android/hardware/ISerialManager.aidl \
	core/java/android/hardware/ISerialManager.aidl \
+10 −0
Original line number Original line Diff line number Diff line
@@ -2499,6 +2499,16 @@ public abstract class Context {
     */
     */
    public static final String THEME_SERVICE = "themes";
    public static final String THEME_SERVICE = "themes";


    /**
     * Use with {@link #getSystemService} to retrieve a
     * {@link com.android.server.TorchService} for accessing torch service.
     *
     * @see #getSystemService
     * @see com.android.server.TorchService
     * @hide
     */
    public static final String TORCH_SERVICE = "torch";

    /**
    /**
     * Determine whether the given permission is allowed for a particular
     * Determine whether the given permission is allowed for a particular
     * process and user ID running in the system.
     * process and user ID running in the system.
+13 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityThread;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.content.Context;
import android.hardware.ITorchService;
import android.graphics.ImageFormat;
import android.graphics.ImageFormat;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
@@ -326,6 +327,7 @@ public class Camera {
     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
     */
     */
    public static Camera open(int cameraId) {
    public static Camera open(int cameraId) {
        disableTorch();
        return new Camera(cameraId);
        return new Camera(cameraId);
    }
    }


@@ -336,6 +338,7 @@ public class Camera {
     * @see #open(int)
     * @see #open(int)
     */
     */
    public static Camera open() {
    public static Camera open() {
        disableTorch();
        int numberOfCameras = getNumberOfCameras();
        int numberOfCameras = getNumberOfCameras();
        CameraInfo cameraInfo = new CameraInfo();
        CameraInfo cameraInfo = new CameraInfo();
        for (int i = 0; i < numberOfCameras; i++) {
        for (int i = 0; i < numberOfCameras; i++) {
@@ -347,6 +350,16 @@ public class Camera {
        return null;
        return null;
    }
    }


    private static void disableTorch() {
        IBinder b = ServiceManager.getService(Context.TORCH_SERVICE);
        ITorchService torchService = ITorchService.Stub.asInterface(b);
        try {
            torchService.onCameraOpened();
        } catch (RemoteException e) {
            // Ignore
        }
    }

    Camera(int cameraId) {
    Camera(int cameraId) {
        mShutterCallback = null;
        mShutterCallback = null;
        mRawImageCallback = null;
        mRawImageCallback = null;
+26 −0
Original line number Original line Diff line number Diff line
/**
 * Copyright (c) 2014, The CyanogenMod 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 android.hardware;


/**
 * {@hide}
 */
interface ITorchService {
    void onCameraOpened();
    void onStartingTorch();
}
+9 −0
Original line number Original line Diff line number Diff line
@@ -503,6 +503,15 @@ class ServerThread {
                }
                }
            }
            }


            if (!disableNonCoreServices) {
                try {
                    Slog.i(TAG, "TorchService");
                    ServiceManager.addService(Context.TORCH_SERVICE, new TorchService(context));
                } catch (Throwable e) {
                    reportWtf("starting Torch Service", e);
                }
            }

            if (!disableNetwork) {
            if (!disableNetwork) {
                try {
                try {
                    Slog.i(TAG, "NetworkManagement Service");
                    Slog.i(TAG, "NetworkManagement Service");
Loading