Skip to content

Commit

Permalink
Merge pull request chenxiaolong#1146 from chenxiaolong/reboot-shutdown
Browse files Browse the repository at this point in the history
Revamp reboot/shutdown mechanism
  • Loading branch information
chenxiaolong authored May 26, 2018
2 parents 477d1d7 + 5ac525d commit f64dfc4
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ interface MbtoolInterface {
@Throws(IOException::class, MbtoolException::class, MbtoolCommandException::class)
fun rebootViaMbtool(arg: String?)

/**
* Shuts down the device via the framework.
*
* mbtool will launch an intent to start Android's ShutdownActivity
*
* @param confirm Whether Android's shutdown dialog should be shown
* @throws IOException When any socket communication error occurs
* @throws MbtoolException
* @throws MbtoolCommandException
*/
@Throws(IOException::class, MbtoolException::class, MbtoolCommandException::class)
fun shutdownViaFramework(confirm: Boolean)

/**
* Shuts down the device via init.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,27 @@ class MbtoolInterfaceV3(
}
}

@Synchronized
@Throws(IOException::class, MbtoolException::class, MbtoolCommandException::class)
override fun shutdownViaFramework(confirm: Boolean) {
// Create request
val builder = FlatBufferBuilder(FBB_SIZE)
ShutdownRequest.startShutdownRequest(builder);
ShutdownRequest.addType(builder, ShutdownType.FRAMEWORK);
ShutdownRequest.addConfirm(builder, confirm);
val fbRequest = ShutdownRequest.endShutdownRequest(builder);

// Send request
val response = sendRequest(builder, fbRequest, RequestType.ShutdownRequest,
ResponseType.ShutdownResponse) as ShutdownResponse

val error = response.error()
if (error != null) {
throw MbtoolCommandException("Failed to shut down via framework")
}
}


@Synchronized
@Throws(IOException::class, MbtoolException::class, MbtoolCommandException::class)
override fun shutdownViaInit() {
Expand Down
14 changes: 9 additions & 5 deletions Android_GUI/src/mbtool/daemon/v3/ShutdownRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ public final class ShutdownRequest extends Table {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public ShutdownRequest __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }

public short type() { int o = __offset(4); return o != 0 ? bb.getShort(o + bb_pos) : 0; }
public short type() { int o = __offset(4); return o != 0 ? bb.getShort(o + bb_pos) : 2; }
public boolean confirm() { int o = __offset(6); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }

public static int createShutdownRequest(FlatBufferBuilder builder,
short type) {
builder.startObject(1);
short type,
boolean confirm) {
builder.startObject(2);
ShutdownRequest.addType(builder, type);
ShutdownRequest.addConfirm(builder, confirm);
return ShutdownRequest.endShutdownRequest(builder);
}

public static void startShutdownRequest(FlatBufferBuilder builder) { builder.startObject(1); }
public static void addType(FlatBufferBuilder builder, short type) { builder.addShort(0, type, 0); }
public static void startShutdownRequest(FlatBufferBuilder builder) { builder.startObject(2); }
public static void addType(FlatBufferBuilder builder, short type) { builder.addShort(0, type, 2); }
public static void addConfirm(FlatBufferBuilder builder, boolean confirm) { builder.addBoolean(1, confirm, false); }
public static int endShutdownRequest(FlatBufferBuilder builder) {
int o = builder.endObject();
return o;
Expand Down
3 changes: 2 additions & 1 deletion Android_GUI/src/mbtool/daemon/v3/ShutdownType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public final class ShutdownType {
private ShutdownType() { }
public static final short INIT = 0;
public static final short DIRECT = 1;
public static final short FRAMEWORK = 2;

public static final String[] names = { "INIT", "DIRECT", };
public static final String[] names = { "INIT", "DIRECT", "FRAMEWORK", };

public static String name(int e) { return names[e]; }
}
Expand Down
1 change: 0 additions & 1 deletion libmbutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ foreach(variant ${variants})
src/external/system_properties.cpp
src/external/system_properties_compat.c
src/result/file_op_result.cpp
external/android_reboot.c
)

# Includes
Expand Down
142 changes: 0 additions & 142 deletions libmbutil/external/android_reboot.c

This file was deleted.

34 changes: 0 additions & 34 deletions libmbutil/external/android_reboot.h

This file was deleted.

1 change: 1 addition & 0 deletions libmbutil/include/mbutil/reboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace mb::util
bool reboot_via_framework(bool show_confirm_dialog);
bool reboot_via_init(const std::string &reboot_arg);
bool reboot_via_syscall(const std::string &reboot_arg);
bool shutdown_via_framework(bool show_confirm_dialog);
bool shutdown_via_init();
bool shutdown_via_syscall();

Expand Down
Loading

0 comments on commit f64dfc4

Please sign in to comment.