lineage-sdk: Import power menu related classes
Different parts of the system need to check if advanced reboot is enabled, so just move the method here and include it in said different parts. The global actions constants also used to live in the frameworks, but as they include our own additions and are also accessible by LineageParts, place them here from now on. Change-Id: Ic5a02b8118c702dced5a25d775a4cc84c92a3fc2
This commit is contained in:
committed by
Michael Bestas
parent
e861b1d7f1
commit
a0e29562a2
@@ -240,4 +240,11 @@
|
||||
<!-- Timeout in MS for how long you have to long-press the back key to
|
||||
kill the foreground app. -->
|
||||
<integer name="config_backKillTimeout">2000</integer>
|
||||
|
||||
<!-- Defines the actions shown in advanced reboot submenu -->
|
||||
<string-array name="config_restartActionsList">
|
||||
<item>restart</item>
|
||||
<item>restart_recovery</item>
|
||||
<item>restart_bootloader</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -151,4 +151,7 @@
|
||||
<!-- Back kill -->
|
||||
<java-symbol type="string" name="app_killed_message" />
|
||||
<java-symbol type="integer" name="config_backKillTimeout" />
|
||||
|
||||
<!-- Power menu -->
|
||||
<java-symbol type="array" name="config_restartActionsList" />
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The CyanogenMod Project
|
||||
* Copyright (C) 2017-2018 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.lineageos.internal.util;
|
||||
|
||||
/* Master list of all actions for the power menu */
|
||||
public class PowerMenuConstants {
|
||||
public static final String GLOBAL_ACTION_KEY_POWER = "power";
|
||||
public static final String GLOBAL_ACTION_KEY_RESTART = "restart";
|
||||
public static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
|
||||
public static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
|
||||
public static final String GLOBAL_ACTION_KEY_USERS = "users";
|
||||
public static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
|
||||
public static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
|
||||
public static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
|
||||
public static final String GLOBAL_ACTION_KEY_SILENT = "silent";
|
||||
public static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
|
||||
public static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
|
||||
|
||||
/**
|
||||
* Advanced restart menu actions
|
||||
*/
|
||||
public static final String GLOBAL_ACTION_KEY_RESTART_RECOVERY = "restart_recovery";
|
||||
public static final String GLOBAL_ACTION_KEY_RESTART_BOOTLOADER = "restart_bootloader";
|
||||
public static final String GLOBAL_ACTION_KEY_RESTART_DOWNLOAD = "restart_download";
|
||||
|
||||
private static String[] ALL_ACTIONS = {
|
||||
GLOBAL_ACTION_KEY_POWER,
|
||||
GLOBAL_ACTION_KEY_RESTART,
|
||||
GLOBAL_ACTION_KEY_SCREENSHOT,
|
||||
GLOBAL_ACTION_KEY_AIRPLANE,
|
||||
GLOBAL_ACTION_KEY_USERS,
|
||||
GLOBAL_ACTION_KEY_SETTINGS,
|
||||
GLOBAL_ACTION_KEY_LOCKDOWN,
|
||||
GLOBAL_ACTION_KEY_BUGREPORT,
|
||||
GLOBAL_ACTION_KEY_SILENT,
|
||||
GLOBAL_ACTION_KEY_VOICEASSIST,
|
||||
GLOBAL_ACTION_KEY_ASSIST
|
||||
};
|
||||
|
||||
public static String[] getAllActions() {
|
||||
return ALL_ACTIONS;
|
||||
}
|
||||
}
|
||||
35
sdk/src/java/org/lineageos/internal/util/PowerMenuUtils.java
Normal file
35
sdk/src/java/org/lineageos/internal/util/PowerMenuUtils.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.lineageos.internal.util;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
|
||||
public final class PowerMenuUtils {
|
||||
public static boolean isAdvancedRestartPossible(final Context context) {
|
||||
KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
boolean keyguardLocked = km.inKeyguardRestrictedInputMode() && km.isKeyguardSecure();
|
||||
boolean advancedRestartEnabled = LineageSettings.Secure.getInt(context.getContentResolver(),
|
||||
LineageSettings.Secure.ADVANCED_REBOOT, 0) == 1;
|
||||
boolean isPrimaryUser = UserHandle.getCallingUserId() == UserHandle.USER_OWNER;
|
||||
|
||||
return advancedRestartEnabled && !keyguardLocked && isPrimaryUser;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user