blob: b8a6846ced76d74f903380dc0b85c7f8826ab27b [file] [log] [blame]
Eino-Ville Talvalae91012b2017-07-10 15:27:24 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE2.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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.server.camera;
18
19import android.app.job.JobInfo;
20import android.app.job.JobParameters;
21import android.app.job.JobScheduler;
22import android.app.job.JobService;
23import android.content.ComponentName;
24import android.content.ContentResolver;
25import android.content.Context;
26import android.util.Slog;
27
28import java.util.concurrent.TimeUnit;
29
30import com.android.server.LocalServices;
31
32/**
33 * A JobService to periodically collect camera usage stats.
34 */
35public class CameraStatsJobService extends JobService {
36 private static final String TAG = "CameraStatsJobService";
37
38 // Must be unique within UID (system service)
39 private static final int CAMERA_REPORTING_JOB_ID = 0xCA3E7A;
40
41 private static ComponentName sCameraStatsJobServiceName = new ComponentName(
42 "android",
43 CameraStatsJobService.class.getName());
44
45 @Override
46 public boolean onStartJob(JobParameters params) {
47 CameraServiceProxy serviceProxy = LocalServices.getService(CameraServiceProxy.class);
48 if (serviceProxy == null) {
49 Slog.w(TAG, "Can't collect camera usage stats - no camera service proxy found");
50 return false;
51 }
52
53 serviceProxy.dumpUsageEvents();
54 return false;
55 }
56
57 @Override
58 public boolean onStopJob(JobParameters params) {
59 // All work is done in onStartJob, so nothing to stop here
60 return false;
61 }
62
63 public static void schedule(Context context) {
64
65 JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
66 if (js == null) {
67 Slog.e(TAG, "Can't collect camera usage stats - no Job Scheduler");
68 return;
69 }
70 js.schedule(new JobInfo.Builder(CAMERA_REPORTING_JOB_ID, sCameraStatsJobServiceName)
71 .setMinimumLatency(TimeUnit.DAYS.toMillis(1))
72 .setRequiresDeviceIdle(true)
73 .build());
74
75 }
76
77}