The link Get the REBOOT permission in Android app do provide a little info.i am able to sign an app with debug.keystore,but i hav to sign with same key used by the system so that it allows permission to reboot.where to find the platform/certificate key pairs?
-
If it is your device, hold down the power key. If it's someone else's please explain the justification for why your application should be allowed to reboot it. – Chris Stratton May 31 '11 at 15:42
-
@chris for security purpose,a reboot may allow a chance of closing malicious processes before starting a particular app.i wanna do that from code. – yashika Jun 06 '11 at 01:06
-
@yahsika No, it won't really. – Chris Stratton Jun 06 '11 at 14:00
-
2@chris: the point here is not really to question the good intentions of yashika, but rather to suggest a solution to a technical problem. – njzk2 Nov 16 '11 at 08:58
-
2@njzk2 - the problem is not technical but rather one of policy and mistaken beliefs about security. Android was engineered to prohibit application developers from doing system-level things, regardless if they would do it out of malice or out of a mistaken belief that rebooting would be a security measure (the problem app can just restart itself on startup) – Chris Stratton Nov 17 '11 at 04:58
3 Answers
You will not be able to sign using a system signature. It is a very basic security measure.
As CommonsWare said in the answer you linked, you will need a custom firmware for that. A simpler option is to provide the functionality only in rooted phones (See here for a simple way to do it: Can a Device Administration Application on a rooted Android phone programmatically force a shutdown or reboot?).
-
i hav tried that code earlier but still i get permission denial masgges.i am rooting the emulator using superapp.apk to get root permission.is there any other way of rooting it? – yashika Jun 06 '11 at 01:04
-
@yashika take a look at this post: http://russelldavis.blogspot.com/2011/01/rooting-android-emulator.html – Aleadam Jun 06 '11 at 05:34
Check here if you are working on emulator: essentials for creating system apk
If you are working on a real device:
- What you need is the vendor signature that's used to sign all the modified Android system inside the device.
- You won't have any system signature of any producer unless they publish it.
- So, you will not get the signature or the platform files unless you have the vendor/security folder of the rom inside the device.
You should go for rooting method after your application is ready to be installed.
- Root your phone
- Open a terminal on your pc, go to platform-tools folder and start adb executable
adb push /path/to/your/apk/your_apk.apk /sdcard/Download
- Go into adb shell
su
mount -o remount,rw /system
cp /sdcard/Download/your_apk.apk /system/app
chmod 666 /system/app/your_apk.apk
- Reboot your phone
You will have an application which is working with system permissions after rebooting.
EDIT: Not sure if it works for 5.0 +, used to work for 5.0 and lower.

- 907
- 14
- 28
-
This line failed for me `mount -o remount,rw /system` I had to do `mount -o rw,remount /system` instead – Elliptica Aug 24 '17 at 21:26
-
I followed the directions but I can't Inject Touches still, it says `java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission` which I have in my manifest. The only thing I can think is I need to ask users directly, but it won't let me because it's a system-level permission. But shouldn't my app be treated as system now? How do I do this? – Elliptica Aug 24 '17 at 21:35
-
Have you solved your problem? I have some time to look at it now. Btw if you are getting that error, probably your application isn't running with system permissions. – Burak Day Aug 29 '17 at 08:46
-
That is the puzzling part, because it's in the `/system/app folder` and has been given `chmod 777` (all) permissions. So how is it not running with system permissions? The problem remains unsolved. – Elliptica Aug 29 '17 at 19:52
-
You also gave permissions to your apk right? Since you are moving apk from outside, you will have to manually give permissions to your apk as well. One more to ask; which android version is it? I believe for 5.0 - 6.0 you have to use /system/priv-app/ instead of 'app'. And for 6.0+, I haven't really tried it, they might have fixed it. – Burak Day Aug 31 '17 at 07:17
-
Hi Burak, yes I gave permissions to my apk with `chmod 777` (gives an extra permission that `666` doesn't). I'm using version 6.0.1 I believe. – Elliptica Sep 06 '17 at 15:16
-
Like i said, you can try using /system/priv-app but that's the only shot i have. They have probably fixed it on 6.0. Sorry i couldn't help. – Burak Day Sep 22 '17 at 15:16
Building a APK that should be signed with the platform key
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := platform
# Tell it to build an APK
include $(BUILD_PACKAGE)

- 42
- 3