Merge "Move shutdown UI to sysui (when possible)" into oc-dr1-dev

This commit is contained in:
Jason Monk
2017-08-08 16:49:25 +00:00
committed by Android (Google) Code Review
12 changed files with 143 additions and 58 deletions

View File

@@ -115,4 +115,6 @@ oneway interface IStatusBar
void remQsTile(in ComponentName tile);
void clickQsTile(in ComponentName tile);
void handleSystemKey(in int key);
void showShutdownUi(boolean isReboot, String reason);
}

View File

@@ -39,4 +39,7 @@
<!-- Whether the device uses the default focus highlight when focus state isn't specified. -->
<bool name="config_useDefaultFocusHighlight">false</bool>
<!-- Allow SystemUI to show the shutdown dialog -->
<bool name="config_showSysuiShutdown">false</bool>
</resources>

View File

@@ -3000,4 +3000,7 @@
<!-- Enable the RingtonePickerActivity in 'com.android.providers.media'. -->
<bool name="config_defaultRingtonePickerEnabled">true</bool>
<!-- Allow SystemUI to show the shutdown dialog -->
<bool name="config_showSysuiShutdown">true</bool>
</resources>

View File

@@ -3067,4 +3067,5 @@
<java-symbol type="bool" name="config_showAreaUpdateInfoSettings" />
<java-symbol type="layout" name="shutdown_dialog" />
<java-symbol type="dimen" name="chooser_service_spacing" />
<java-symbol type="bool" name="config_showSysuiShutdown" />
</resources>

View File

@@ -26,6 +26,8 @@ public interface GlobalActions extends Plugin {
int VERSION = 1;
void showGlobalActions(GlobalActionsManager manager);
default void showShutdownUi(boolean isReboot, String reason) {
}
@ProvidesInterface(version = GlobalActionsManager.VERSION)
public interface GlobalActionsManager {

View File

@@ -45,6 +45,11 @@ public class GlobalActionsComponent extends SystemUI implements Callbacks, Globa
SysUiServiceProvider.getComponent(mContext, CommandQueue.class).addCallbacks(this);
}
@Override
public void handleShowShutdownUi(boolean isReboot, String reason) {
mExtension.get().showShutdownUi(isReboot, reason);
}
@Override
public void handleShowGlobalActionsMenu() {
mExtension.get().showGlobalActions(this);

View File

@@ -116,8 +116,6 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
private final Context mContext;
private final GlobalActionsManager mWindowManagerFuncs;
private final AudioManager mAudioManager;
@@ -682,10 +680,7 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
/** {@inheritDoc} */
public void onClick(DialogInterface dialog, int which) {
Action item = mAdapter.getItem(which);
if ((item instanceof PowerAction)
|| (item instanceof RestartAction)) {
if (mDialog != null) mDialog.fadeOut();
} else if (!(item instanceof SilentModeTriStateAction)) {
if (!(item instanceof SilentModeTriStateAction)) {
dialog.dismiss();
}
item.onPress();
@@ -1325,23 +1320,6 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
.start();
}
public void fadeOut() {
mHardwareLayout.setTranslationX(0);
mHardwareLayout.setAlpha(1);
mListView.animate()
.alpha(0)
.translationX(getAnimTranslation())
.setDuration(300)
.setInterpolator(new LogAccelerateInterpolator())
.setUpdateListener(animation -> {
float frac = animation.getAnimatedFraction();
float alpha = NotificationUtils.interpolate(
ScrimController.GRADIENT_SCRIM_ALPHA, SHUTDOWN_SCRIM_ALPHA, frac);
mGradientDrawable.setAlpha((int) (alpha * 255));
})
.start();
}
private float getAnimTranslation() {
return getContext().getResources().getDimension(
com.android.systemui.R.dimen.global_actions_panel_width) / 2;

View File

@@ -14,17 +14,33 @@
package com.android.systemui.globalactions;
import android.app.Dialog;
import android.app.KeyguardManager;
import android.app.WallpaperColors;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.colorextraction.drawable.GradientDrawable;
import com.android.settingslib.Utils;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.GlobalActions;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import android.content.Context;
import android.support.v7.view.ContextThemeWrapper;
public class GlobalActionsImpl implements GlobalActions {
private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
private final Context mContext;
private final KeyguardMonitor mKeyguardMonitor;
private final DeviceProvisionedController mDeviceProvisionedController;
@@ -44,4 +60,51 @@ public class GlobalActionsImpl implements GlobalActions {
mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
mDeviceProvisionedController.isDeviceProvisioned());
}
@Override
public void showShutdownUi(boolean isReboot, String reason) {
GradientDrawable background = new GradientDrawable(mContext);
background.setAlpha((int) (SHUTDOWN_SCRIM_ALPHA * 255));
Dialog d = new Dialog(mContext,
com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
// Window initialization
Window window = d.getWindow();
window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
window.requestFeature(Window.FEATURE_NO_TITLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
window.addFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
window.setBackgroundDrawable(background);
window.setWindowAnimations(R.style.Animation_Toast);
d.setContentView(R.layout.shutdown_dialog);
d.setCancelable(false);
int color = Utils.getColorAttr(mContext, com.android.systemui.R.attr.wallpaperTextColor);
boolean onKeyguard = mContext.getSystemService(
KeyguardManager.class).isKeyguardLocked();
ProgressBar bar = d.findViewById(R.id.progress);
bar.getIndeterminateDrawable().setTint(color);
TextView message = d.findViewById(R.id.text1);
message.setTextColor(color);
if (isReboot) message.setText(R.string.reboot_to_reset_message);
Point displaySize = new Point();
mContext.getDisplay().getRealSize(displaySize);
GradientColors colors = Dependency.get(SysuiColorExtractor.class).getColors(
onKeyguard ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
background.setColors(colors, false);
background.setScreenSize(displaySize.x, displaySize.y);
d.show();
}
}

View File

@@ -79,6 +79,7 @@ public class CommandQueue extends IStatusBar.Stub {
private static final int MSG_DISMISS_KEYBOARD_SHORTCUTS = 32 << MSG_SHIFT;
private static final int MSG_HANDLE_SYSTEM_KEY = 33 << MSG_SHIFT;
private static final int MSG_SHOW_GLOBAL_ACTIONS = 34 << MSG_SHIFT;
private static final int MSG_SHOW_SHUTDOWN_UI = 35 << MSG_SHIFT;
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@@ -136,6 +137,7 @@ public class CommandQueue extends IStatusBar.Stub {
default void handleSystemKey(int arg1) { }
default void handleShowGlobalActionsMenu() { }
default void handleShowShutdownUi(boolean isReboot, String reason) { }
}
@VisibleForTesting
@@ -429,6 +431,15 @@ public class CommandQueue extends IStatusBar.Stub {
}
}
@Override
public void showShutdownUi(boolean isReboot, String reason) {
synchronized (mLock) {
mHandler.removeMessages(MSG_SHOW_SHUTDOWN_UI);
mHandler.obtainMessage(MSG_SHOW_SHUTDOWN_UI, isReboot ? 1 : 0, 0, reason)
.sendToTarget();
}
}
private final class H extends Handler {
private H(Looper l) {
super(l);
@@ -610,6 +621,11 @@ public class CommandQueue extends IStatusBar.Stub {
mCallbacks.get(i).handleShowGlobalActionsMenu();
}
break;
case MSG_SHOW_SHUTDOWN_UI:
for (int i = 0; i < mCallbacks.size(); i++) {
mCallbacks.get(i).handleShowShutdownUi(msg.arg1 != 0, (String) msg.obj);
}
break;
}
}
}

View File

@@ -57,7 +57,9 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.internal.telephony.ITelephony;
import com.android.server.LocalServices;
import com.android.server.pm.PackageManagerService;
import com.android.server.statusbar.StatusBarManagerInternal;
import java.io.File;
import java.io.IOException;
@@ -288,6 +290,9 @@ public final class ShutdownThread extends Thread {
pd.setMessage(context.getText(
com.android.internal.R.string.reboot_to_update_prepare));
} else {
if (showSysuiReboot()) {
return null;
}
pd.setIndeterminate(true);
pd.setMessage(context.getText(
com.android.internal.R.string.reboot_to_update_reboot));
@@ -296,39 +301,12 @@ public final class ShutdownThread extends Thread {
// Factory reset path. Set the dialog message accordingly.
pd.setTitle(context.getText(com.android.internal.R.string.reboot_to_reset_title));
pd.setMessage(context.getText(
com.android.internal.R.string.reboot_to_reset_message));
com.android.internal.R.string.reboot_to_reset_message));
pd.setIndeterminate(true);
} else if (mReason != null && mReason.equals(PowerManager.SHUTDOWN_USER_REQUESTED)) {
Dialog d = new Dialog(context);
d.setContentView(com.android.internal.R.layout.shutdown_dialog);
d.setCancelable(false);
int color;
try {
boolean onKeyguard = context.getSystemService(
KeyguardManager.class).isKeyguardLocked();
WallpaperColors currentColors = context.getSystemService(WallpaperManager.class)
.getWallpaperColors(onKeyguard ?
WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
color = currentColors != null &&
(currentColors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT)
!= 0 ?
Color.BLACK : Color.WHITE;
} catch (Exception e) {
color = Color.WHITE;
}
ProgressBar bar = d.findViewById(com.android.internal.R.id.progress);
bar.getIndeterminateDrawable().setTint(color);
((TextView) d.findViewById(com.android.internal.R.id.text1)).setTextColor(color);
d.getWindow().getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
d.show();
return null;
} else {
if (showSysuiReboot()) {
return null;
}
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
pd.setIndeterminate(true);
@@ -340,6 +318,23 @@ public final class ShutdownThread extends Thread {
return pd;
}
private static boolean showSysuiReboot() {
Log.d(TAG, "Attempting to use SysUI shutdown UI");
try {
StatusBarManagerInternal service = LocalServices.getService(
StatusBarManagerInternal.class);
if (service.showShutdownUi(mReboot, mReason)) {
// Sysui will handle shutdown UI.
Log.d(TAG, "SysUI handling shutdown UI");
return true;
}
} catch (Exception e) {
// If anything went wrong, ignore it and use fallback ui
}
Log.d(TAG, "SysUI is unavailable");
return false;
}
private static void beginShutdownSequence(Context context) {
synchronized (sIsStartedGuard) {
if (sIsStarted) {

View File

@@ -80,6 +80,8 @@ public interface StatusBarManagerInternal {
void setGlobalActionsListener(GlobalActionsListener listener);
void showGlobalActions();
boolean showShutdownUi(boolean isReboot, String requestString);
public interface GlobalActionsListener {
/**
* Called when sysui starts and connects its status bar, or when the status bar binder

View File

@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Slog;
import com.android.internal.R;
import com.android.internal.statusbar.IStatusBar;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
@@ -329,6 +330,20 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
} catch (RemoteException ex) {}
}
}
@Override
public boolean showShutdownUi(boolean isReboot, String reason) {
if (!mContext.getResources().getBoolean(R.bool.config_showSysuiShutdown)) {
return false;
}
if (mBar != null) {
try {
mBar.showShutdownUi(isReboot, reason);
return true;
} catch (RemoteException ex) {}
}
return false;
}
};
// ================================================================================