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

Commit 20680339 authored by Shashank Mittal's avatar Shashank Mittal Committed by Steve Kondik
Browse files

services: Add hook to run device specific shutdown code.

Add hook to call OEM specific shutdown synchronously. OEMs need to add
ShutdownOem class and define deviceRebootOrShutdown function in that.

ShutdownThread class would call this OEM defined function just before shutting
down the device.

Change-Id: I620495bfc99c6b0855a98ac54c6ede96e20ff1b8
parent e17f5f5b
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.android.internal.telephony.msim.ITelephonyMSim;
import android.util.Log;
import android.view.WindowManager;
import android.view.KeyEvent;
import java.lang.reflect.Method;

public final class ShutdownThread extends Thread {
    // constants
@@ -626,8 +627,35 @@ public final class ShutdownThread extends Thread {
            }
        }

        // Oem specific shutdown
        deviceRebootOrShutdown(reboot, reason);

        // Shutdown power
        Log.i(TAG, "Performing low-level shutdown...");
        PowerManagerService.lowLevelShutdown();
    }

    private static void deviceRebootOrShutdown(boolean reboot, String reason) {

        Class<?> cl;
        String deviceShutdownClassName = "com.android.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) {
                //Method not found.
            } catch (Exception ex) {
                //Unknown exception
            }
        }catch(ClassNotFoundException e){
        //Classnotfound!
        }catch(Exception e){
        //Unknown exception
        }
     }
}