Reputation: 1016
I have built my AOSP custom ROM using Android 4.4.4 sources. I want to do a kiosk mode app (always full screen - impossible for the user to leave it or to switch to another app).
In order to have a full immersive mode, I followed this SO post Enabling KioskMode in Android 4.4.2 with Root
I dit exactly as they say but it's not working. System UI is not disabled and I have no error.
So I decided to create a .sh file that I run from Android SDK code:
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "/etc/stop-ui.sh" });
It works perfectly. But when I want to start the System UI again :
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "/etc/start-ui.sh" });
it returns error 1.
When I run /etc/start-ui.sh from adb shell it works.
Here is my stop.sh (with permission 555) file :
#!/system/bin/sh
service call activity 42 s16 com.android.systemui
Here is my start.sh (with permission 555) file :
#!/system/bin/sh
am startservice -n com.android.systemui/.SystemUIService
My app is a system app (I signed it with the platform signature)
Conclusion: I can restart system UI from shell but not from app programmatically
Upvotes: 3
Views: 3493
Reputation: 4301
I had this 2 methods (on rooted phone) and they worked perfectly:
public static void hideSystemUi(){
try {
Build.VERSION_CODES vc = new Build.VERSION_CODES();
Build.VERSION vr = new Build.VERSION();
String ProcID = "79"; //HONEYCOMB AND OLDER
//v.RELEASE //4.0.3
if(vr.SDK_INT >= vc.ICE_CREAM_SANDWICH){
ProcID = "42"; //ICS AND NEWER
}
Process proc = Runtime.getRuntime().exec(new String[]{
"su","-c","service call activity " + ProcID + " s16 com.android.systemui"});
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void showSystemUi(){
try {
Process proc = Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
Try to pass user id in am startservice -n com.android.systemui/.SystemUIService
command. In my case it's 0
(root user id).
Upvotes: 5