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
diff --git a/services/core/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
index eafbf16..ab09be7 100644
--- a/services/core/java/com/android/server/power/ShutdownThread.java
+++ b/services/core/java/com/android/server/power/ShutdownThread.java
@@ -49,6 +49,8 @@
 
 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 @@
      * @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 @@
         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");
+       }
+    }
 }
+