Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/common/DockStateReader.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 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.wm.shell.common;
18
19 import static android.content.Intent.EXTRA_DOCK_STATE;
20
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.IntentFilter;
24
25 import com.android.wm.shell.dagger.WMSingleton;
26
27 import javax.inject.Inject;
28
29 /**
30 * Provides information about the docked state of the device.
31 */
32 @WMSingleton
33 public class DockStateReader {
34
35 private static final IntentFilter DOCK_INTENT_FILTER = new IntentFilter(
36 Intent.ACTION_DOCK_EVENT);
37
38 private final Context mContext;
39
40 @Inject
41 public DockStateReader(Context context) {
42 mContext = context;
43 }
44
45 /**
46 * @return True if the device is docked and false otherwise.
47 */
48 public boolean isDocked() {
49 Intent dockStatus = mContext.registerReceiver(/* receiver */ null, DOCK_INTENT_FILTER);
50 if (dockStatus != null) {
51 int dockState = dockStatus.getIntExtra(EXTRA_DOCK_STATE,
52 Intent.EXTRA_DOCK_STATE_UNDOCKED);
53 return dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
54 }
55 return false;
56 }
57 }