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

Commit 1f4d0576 authored by Ameya Thakur's avatar Ameya Thakur Committed by Ricardo Cerqueira
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 da1db85d
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ import com.android.server.pm.PackageManagerService;

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

public final class ShutdownThread extends Thread {
    // constants
@@ -519,6 +521,7 @@ public final class ShutdownThread extends Thread {
     * @param reason reason for reboot
     */
    public static void rebootOrShutdown(boolean reboot, String reason) {
        deviceRebootOrShutdown(reboot, reason);
        if (reboot) {
            Log.i(TAG, "Rebooting, reason: " + reason);
            PowerManagerService.lowLevelReboot(reason);
@@ -544,4 +547,28 @@ public final class ShutdownThread extends Thread {
        Log.i(TAG, "Performing low-level shutdown...");
        PowerManagerService.lowLevelShutdown();
    }

    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");
       }
    }
}