| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.hidedisplaycutout; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.res.Configuration; |
| 21 |
import android.os.SystemProperties; |
| 22 |
|
| 23 |
import androidx.annotation.NonNull; |
| 24 |
import androidx.annotation.Nullable; |
| 25 |
import androidx.annotation.VisibleForTesting; |
| 26 |
|
| 27 |
import com.android.wm.shell.common.DisplayController; |
| 28 |
import com.android.wm.shell.common.ShellExecutor; |
| 29 |
import com.android.wm.shell.sysui.ConfigurationChangeListener; |
| 30 |
import com.android.wm.shell.sysui.ShellCommandHandler; |
| 31 |
import com.android.wm.shell.sysui.ShellController; |
| 32 |
import com.android.wm.shell.sysui.ShellInit; |
| 33 |
|
| 34 |
import java.io.PrintWriter; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class HideDisplayCutoutController implements ConfigurationChangeListener { |
| 40 |
private static final String TAG = "HideDisplayCutoutController"; |
| 41 |
|
| 42 |
private final Context mContext; |
| 43 |
private final ShellCommandHandler mShellCommandHandler; |
| 44 |
private final ShellController mShellController; |
| 45 |
private final HideDisplayCutoutOrganizer mOrganizer; |
| 46 |
@VisibleForTesting |
| 47 |
boolean mEnabled; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@Nullable |
| 54 |
public static HideDisplayCutoutController create(Context context, |
| 55 |
ShellInit shellInit, |
| 56 |
ShellCommandHandler shellCommandHandler, |
| 57 |
ShellController shellController, |
| 58 |
DisplayController displayController, |
| 59 |
ShellExecutor mainExecutor) { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if (!SystemProperties.getBoolean("ro.support_hide_display_cutout", false)) { |
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
HideDisplayCutoutOrganizer organizer = |
| 68 |
new HideDisplayCutoutOrganizer(context, displayController, mainExecutor); |
| 69 |
return new HideDisplayCutoutController(context, shellInit, shellCommandHandler, |
| 70 |
shellController, organizer); |
| 71 |
} |
| 72 |
|
| 73 |
HideDisplayCutoutController(Context context, |
| 74 |
ShellInit shellInit, |
| 75 |
ShellCommandHandler shellCommandHandler, |
| 76 |
ShellController shellController, |
| 77 |
HideDisplayCutoutOrganizer organizer) { |
| 78 |
mContext = context; |
| 79 |
mShellCommandHandler = shellCommandHandler; |
| 80 |
mShellController = shellController; |
| 81 |
mOrganizer = organizer; |
| 82 |
shellInit.addInitCallback(this::onInit, this); |
| 83 |
} |
| 84 |
|
| 85 |
private void onInit() { |
| 86 |
mShellCommandHandler.addDumpCallback(this::dump, this); |
| 87 |
updateStatus(); |
| 88 |
mShellController.addConfigurationChangeListener(this); |
| 89 |
} |
| 90 |
|
| 91 |
@VisibleForTesting |
| 92 |
void updateStatus() { |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
final boolean enabled = mContext.getResources().getBoolean( |
| 97 |
com.android.internal.R.bool.config_hideDisplayCutoutWithDisplayArea); |
| 98 |
if (enabled == mEnabled) { |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
mEnabled = enabled; |
| 103 |
if (enabled) { |
| 104 |
mOrganizer.enableHideDisplayCutout(); |
| 105 |
} else { |
| 106 |
mOrganizer.disableHideDisplayCutout(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public void onConfigurationChanged(Configuration newConfig) { |
| 112 |
updateStatus(); |
| 113 |
} |
| 114 |
|
| 115 |
public void dump(@NonNull PrintWriter pw, String prefix) { |
| 116 |
final String innerPrefix = " "; |
| 117 |
pw.print(TAG); |
| 118 |
pw.println(" states: "); |
| 119 |
pw.print(innerPrefix); |
| 120 |
pw.print("mEnabled="); |
| 121 |
pw.println(mEnabled); |
| 122 |
mOrganizer.dump(pw); |
| 123 |
} |
| 124 |
} |