Debian Codegraph @

apex/jobscheduler/service/java/com/android/server/deviceidle/TvConstraintController.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 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 */
16
17 package com.android.server.deviceidle;
18
19 import android.annotation.Nullable;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.os.Handler;
23
24 import com.android.server.DeviceIdleInternal;
25 import com.android.server.LocalServices;
26
27 /**
28 * Device idle constraints for television devices.
29 *
30 * <p>Televisions are devices with {@code FEATURE_LEANBACK_ONLY}. Other devices might support
31 * some kind of leanback mode but they should not follow the same rules for idle state.
32 */
33 public class TvConstraintController implements ConstraintController {
34 private final Context mContext;
35 private final Handler mHandler;
36 private final DeviceIdleInternal mDeviceIdleService;
37
38 @Nullable
39 private final BluetoothConstraint mBluetoothConstraint;
40
41 public TvConstraintController(Context context, Handler handler) {
42 mContext = context;
43 mHandler = handler;
44 mDeviceIdleService = LocalServices.getService(DeviceIdleInternal.class);
45
46 final PackageManager pm = context.getPackageManager();
47 mBluetoothConstraint = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
48 ? new BluetoothConstraint(mContext, mHandler, mDeviceIdleService)
49 : null;
50 }
51
52 @Override
53 public void start() {
54 if (mBluetoothConstraint != null) {
55 mDeviceIdleService.registerDeviceIdleConstraint(
56 mBluetoothConstraint, "bluetooth", IDeviceIdleConstraint.SENSING_OR_ABOVE);
57 }
58 }
59
60 @Override
61 public void stop() {
62 if (mBluetoothConstraint != null) {
63 mDeviceIdleService.unregisterDeviceIdleConstraint(mBluetoothConstraint);
64 }
65 }
66 }