Skip to content

Commit

Permalink
Extras: Add dynamic theme shutdown and boot animation support
Browse files Browse the repository at this point in the history
Note: Custom boot animation will not work on encrypted device

Change-Id: I3b01953d0a69c033a98c0af49ee986b21652b725
Signed-off-by: Ivan Iskandar <ivan@prjkt.io>
Signed-off-by: Harsh Shandilya <harsh@prjkt.io>
Signed-off-by: VenkatVishalV <venkatvishal124@gmail.com>
  • Loading branch information
ivaniskandar authored and VenkatVishalV committed Nov 10, 2018
1 parent ffe2f8e commit 2986abb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmds/bootanimation/BootAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.z
static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip";
static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
static const char THEME_BOOTANIMATION_FILE[] = "/data/system/theme/bootanimation.zip";
static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip";
static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
static const char THEME_SHUTDOWNANIMATION_FILE[] = "/data/system/theme/shutdownanimation.zip";

static const char SYSTEM_DATA_DIR_PATH[] = "/data/system";
static const char SYSTEM_TIME_DIR_NAME[] = "time";
Expand Down Expand Up @@ -323,9 +325,9 @@ status_t BootAnimation::readyToRun() {
}
}
static const char* bootFiles[] =
{PRODUCT_BOOTANIMATION_FILE, OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE};
{THEME_BOOTANIMATION_FILE, PRODUCT_BOOTANIMATION_FILE, OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE};
static const char* shutdownFiles[] =
{PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE};
{THEME_SHUTDOWNANIMATION_FILE, PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE};

for (const char* f : (!mShuttingDown ? bootFiles : shutdownFiles)) {
if (access(f, R_OK) == 0) {
Expand Down
30 changes: 29 additions & 1 deletion services/core/java/com/android/server/power/ShutdownThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private static ProgressDialog showShutdownDialog(Context context) {
pd.setCancelable(false);
pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);

pd.show();
if (!themeShutdownAnimationExists()) pd.show();
return pd;
}

Expand Down Expand Up @@ -454,6 +454,10 @@ public void run() {
SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
}

if (themeShutdownAnimationExists()) {
startShutdownAnimation();
}

/*
* If we are rebooting into safe mode, write a system property
* indicating so.
Expand Down Expand Up @@ -674,6 +678,7 @@ public void run() {
*/
public static void rebootOrShutdown(final Context context, boolean reboot, String reason) {
if (reboot) {
stopShutdownAnimation();
Log.i(TAG, "Rebooting, reason: " + reason);
PowerManagerService.lowLevelReboot(reason);
Log.e(TAG, "Reboot failed, will attempt shutdown instead");
Expand All @@ -694,6 +699,9 @@ public static void rebootOrShutdown(final Context context, boolean reboot, Strin
} catch (InterruptedException unused) {
}
}

stopShutdownAnimation();

// Shutdown power
Log.i(TAG, "Performing low-level shutdown...");
PowerManagerService.lowLevelShutdown(reason);
Expand Down Expand Up @@ -786,4 +794,24 @@ public void run() {
}
}
}

private static boolean themeShutdownAnimationExists() {
return new File("/data/system/theme/shutdownanimation.zip").exists();
}

private static void startShutdownAnimation() {
SystemProperties.set("service.bootanim.exit", "0");
SystemProperties.set("sys.powerctl", "animate");
SystemProperties.set("ctl.start", "bootanim");
}

private static void stopShutdownAnimation() {
SystemProperties.set("service.bootanim.exit", "1");
while (SystemProperties.get("init.svc.bootanim").equals("running")) {
try {
Thread.sleep(10);
} catch (InterruptedException unused) {
}
}
}
}

0 comments on commit 2986abb

Please sign in to comment.