Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebd3af3c authored by Ameya Thakur's avatar Ameya Thakur Committed by Linux Build Service Account
Browse files

ShutdownThread: Add hook to call into oem shutdown function.

We now invoke a oem specific function as part of the device shutdown.

Change-Id: I71643064130c606562ad21f61db937b508d43f41
parent 0ad56325
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import com.android.server.pm.PackageManagerService;

import android.util.Log;
import android.view.WindowManager;
import java.lang.reflect.Method;
import dalvik.system.PathClassLoader;

import java.io.BufferedReader;
import java.io.File;
@@ -619,6 +621,7 @@ public final class ShutdownThread extends Thread {
     * @param reason reason for reboot
     */
    public static void rebootOrShutdown(final Context context, boolean reboot, String reason) {
        deviceRebootOrShutdown(reboot, reason);
        if (reboot) {
            Log.i(TAG, "Rebooting, reason: " + reason);
            PowerManagerService.lowLevelReboot(reason);
@@ -722,4 +725,27 @@ public final class ShutdownThread extends Thread {
            Log.w(TAG, "Timed out waiting for uncrypt.");
        }
    }

    private static void deviceRebootOrShutdown(boolean reboot, String reason) {
        Class<?> cl;
        PathClassLoader oemClassLoader = new PathClassLoader("/system/framework/oem-services.jar",
                                                             ClassLoader.getSystemClassLoader());
        String deviceShutdownClassName = "com.qti.server.power.ShutdownOem";
        try {
            cl = Class.forName(deviceShutdownClassName);
            Method m;
                try {
                    m = cl.getMethod("rebootOrShutdown", new Class[] {boolean.class, String.class});
                    m.invoke(cl.newInstance(), reboot, reason);
                } catch (NoSuchMethodException ex) {
                    Log.e(TAG, "rebootOrShutdown method not found in class " + deviceShutdownClassName);
                } catch (Exception ex) {
                    Log.e(TAG, "Unknown exception hit while trying to invode rebootOrShutdown");
                }
        } catch (ClassNotFoundException e) {
            Log.e(TAG, "Unable to find class " + deviceShutdownClassName);
        } catch (Exception e) {
            Log.e(TAG, "Unknown exception while trying to invoke rebootOrShutdown");
        }
    }
}