1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.internal.os;
17
18import android.os.BatteryStats;
19
20/**
21 * Power calculator for the camera subsystem, excluding the flashlight.
22 *
23 * Note: Power draw for the flash unit should be included in the FlashlightPowerCalculator.
24 */
25public class CameraPowerCalculator extends PowerCalculator {
26    private final double mCameraPowerOnAvg;
27
28    public CameraPowerCalculator(PowerProfile profile) {
29        mCameraPowerOnAvg = profile.getAveragePower(PowerProfile.POWER_CAMERA);
30    }
31
32    @Override
33    public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
34                             long rawUptimeUs, int statsType) {
35
36        // Calculate camera power usage.  Right now, this is a (very) rough estimate based on the
37        // average power usage for a typical camera application.
38        final BatteryStats.Timer timer = u.getCameraTurnedOnTimer();
39        if (timer != null) {
40            final long totalTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
41            app.cameraTimeMs = totalTime;
42            app.cameraPowerMah = (totalTime * mCameraPowerOnAvg) / (1000*60*60);
43        } else {
44            app.cameraTimeMs = 0;
45            app.cameraPowerMah = 0;
46        }
47    }
48}
49