How to Reboot Android phone programmatically? - android

I am trying to reboot Android device through a activity. I'm using following code.
public void reboot(){
PowerManager pm=(PowerManager)getSystemService(Context.Power_Service);
pm.reboot(null)
}
And I have given Manifest permission too.
android:name="android.permission.REBOOT
Error::java.lang.SecurityException: Neither user 10098 nor current
process has android.permission.REBOOT.

Only applications signed with the system firmware signing key are allowed to do these operations.
More information can be found in the links below
How to compile Android Application with system permissions
Programmatically switching off Android phone

Related

Can't broadcast ACTION_AIRPLANE_MODE_CHANGED for a system app

I developed an app and copied it to /system/priv-app in a rooted Android device to make my app a system app and It works But still when I try to run below code I get an exception that only system can broadcast this.
val newIntent = Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
newIntent.putExtra("state", false)
sendBroadcast(newIntent)
My Android version is 7.1.1 is there any workaround for this? I want to broadcast this after changing the airplane mode with this code
Settings.System.putInt(contentResolver, Settings.System.AIRPLANE_MODE_ON, 0)
Your app has to be signed by the platform key and also assigned the system user (specified in the manifest.) Placing the app in /system/priv-app does not grant it any special functionality.

how to turn on / turn off developer mode in Android from app?

I want to create an app to turn on/turn off Android developer mode. This will be on a rooted device. What api's do need to call?
I know i am answering it very late but i will surely help other who are searching on this.
To enable developer options programatically :
Settings.Global.putString(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, "1");
To disable :
Settings.Global.putString(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, "0");
But to access this Settings.Global... , it requires a permission
android.permission.WRITE_SECURE_SETTINGS
But normally , This permission is only granted to system app
You can also grant this permission to user app using ADB
Since you said your app would be running on a rooted deice , so have access to the shell , so you can grant this permission to your app by running the below shell command
pm grant <your.package.name> android.permission.WRITE_SECURE_SETTINGS
I don't think it is possible. Since it is part of the Settings.Secure.
Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.

Airplane mode toggle in Android 4.3

I'm facing a problem in android version 4.3 to control airplane mode by code.For this I converted the user app into system using system/ app mover application available in google play.Once the user enables the airplane mode, the background service have the control to check the airplane mode and reset it to off state and send the broadcast changes to the device.Below the snippet I implemented in my code to keep the airplane mode state in off.But it fails in android version 4.3. It throws an exception called "permission denied". Let me know is these any additional permission need to added in manifest or else let me know your suggestions on these issue to fixed.
try {
Settings.Global.putInt(context.getContentResolver(),
"airplane_mode_on", 0);
isAirplaneModeOn = isAirplaneModeOn(context);
Intent localIntent2 = new Intent(
"android.intent.action.AIRPLANE_MODE");
localIntent2.putExtra("state", isAirplaneModeOn);
context.sendBroadcast(localIntent2);
} catch (Exception e) {
Log.v("TAG",
e.toString() + "\n" + e.getMessage());
}
Moving an App into the /system/app folder does not turn it into a System App - it simply makes the App uninstallable because /system is normally mounted read-only.
What you are trying to do requires full System App privileges. You can only get these by signing your app with the same key used to sign the original firmware Apps - the platform key. In other words, you need access to whoever built the version of Android you are running on and get them to sign your APK.
Actually you cannot do it starting from Android 4.2. Because that settings was relocated here from either Settings.System or Settings.Secure. But on previous vesions it works fine.
http://developer.android.com/about/versions/android-4.2.html
If your app is currently making changes to settings previously defined
in Settings.System (such as AIRPLANE_MODE_ON), then you should expect
that doing so will no longer work on a device running Android 4.2 or
higher if those settings were moved to Settings.Global.
Related question on StackOverflow

What kind of Android application will require android.permission.READ_PHONE_STATE permission?

I have seen some Android apps on my phone require this android.permission.READ_PHONE_STATE permission. I don't know if I could trust them. I know this permission will give the app access to many information. I'm particularly interested in what functionality in an Android app normally require the information like DeviceId , SimSerialNumber, SubscriberId?
Phone state provides access to a lot of information about the phone. Usual usages will be for reading the IMEI of your phone and your phone number. This can be useful to identify you in their systems.
It can also be needed if the application is made compatible for Android 1.5 or lower, because this permission didn't exist back then and is added automatically by the play store to those apps
See also: https://android.stackexchange.com/questions/605/why-do-so-many-applications-require-permission-to-read-the-phone-state-and-ident
Another possible reason is so they can mute audio events if you're in the middle of a call. This is why apps like Pandora, Spotify, etc need the permission - so they can mute themselves when you get a call.
Not long ago I discovered that for some devices you should add android.permission.READ_PHONE_STATE if your application sends SMS. Probably in some cases SmsManager tries to retrieve some information about phone state before sending sms.
For example getting exception for HUAWEI GRA-L09:
java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10174 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1543)
at android.os.Parcel.readException(Parcel.java:1496)
at com.android.internal.telephony.ISms$Stub$Proxy.s! endMultipartTextForSubscriber(ISms.java:1224)
at android.telephony.SmsManager.sendMultipartTextMessage(SmsManager.java:404)

Programmatically change the permission of installing apk from unknown source in android device

For allowing or preventing manually installation of apk file from sdcard we ticks/unticks the checkbox which says "Allow installation of app from unknown source".
Can we do this Programmatically by avoiding any User Interface?
Thanks,
Nirav
No, not unless you're a carrier, or not unless you're on an enterprise phone that your company has admin access over.
This is part of the security model of Android, so that a user can not lose the control of his phone to a malicious application.
Here are the actual permissions you would need to do something like that:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
You can try using those permissions, but by design they won't work unless you have root access to the device.
Within the device settings, users are able to view permissions for
applications they have previously installed. Users can also turn off
some functionality globally when they choose, such as disabling GPS,
radio, or wi-fi.
In the event that an application attempts to use a protected feature
which has not been declared in the application's manifest, the
permission failure will typically result in a security exception being
thrown back to the application. Protected API permission checks are
enforced at the lowest possible level to prevent circumvention.

Categories

Resources