| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 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 |
} |