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
Related
I am developing a KIOSK Mode stand alone application for Wear OS(Samsung Watch 4, Wear OS 3.5). For KIOSK mode I am using device owner permission using ADB and used device [DevicePolicyManager][1] class to handle hardware button and status bar etc.
My Issue is, I am not able to open System WIFI settings which navigate to outside of KIOSK mode.
Just for your information I can open system bluetooth settings without disabling KIOSK mode. One more information: case 3 code work perfectly if your KIOSK mode is disable
I tried:
Case1.
context.startActivity(Intent("com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS"))
I can see something gets opened and closed automatically.
Case 2.
val intent = Intent(Settings.ACTION_WIFI_SETTINGS)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.addCategory(Intent.CATEGORY_LAUNCHER)
startActivity(intent)
Case 3.
startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
If any one have any idea or workaround. Much appreciate your inputs!
Finally I achieved it by whitelisted packagename.
devicePolicyManager!!.setLockTaskPackages(deviceAdmin, arrayOf("our.own.package.name","com.google.android.apps.wearable.settings"))
After whitelisted in KIOSK mode. now it will work!
startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
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.
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
My app is working fine, until Android 5.0.2 doesn't allow third party app to connect to HID device over Bluetooth low energy.
myGatt.setCharacteristicNotification(gattChar, true);
06-01 17:39:35.356: W/BluetoothGatt(21599):
java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission:Neither
user 10157 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
BLUETOOTH_PRIVILEGED permission doesn't work on a third party app. It's only for system or manufacturer apps.
The latest changes from Android note:
Enforce BLUETOOTH_PRIVILEGED permission for HID-over-GATT
https://android.googlesource.com/platform/packages/apps/Bluetooth/+/02bebee
Code snippet:
private static final UUID[] HID_UUIDS = {
UUID.fromString("00002A4A-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4B-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4C-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4D-0000-1000-8000-00805F9B34FB") };
if (isHidUuid(charUuid)) enforcePrivilegedPermission();
My question: is there a way to overwrite HID_UUIDS or enforcePrivilegedPermission? Can I use reflection to by pass it?
Every times Android released a new version, it breaks the previous code.
Thanks!
The question is old, but still worth answering.
The HID (and FIDO https://fidoalliance.org/) service is protected and indeed requires system permission source. Only apps signed with the system key may use this service, that is only Bluetooth settings. This is to ensure that 3rd party apps are not able to listen to keys typed on a wireless keyboards, as all notifications and indications are transferred to all BluetoothGatt objects. Without this protection you would be able to connect to a HID device (you still can), enable notifications using gatt.setCharacteristicNotification(.., true) and receive updates whenever a key is typed. With a bit of knowledge about Report characteristics you can then get all the keys and mouse positions, including passwords, etc. So it's not a break, but a bug fix. On KitKat you still may do this.
The only solution is to compile your own AOSP Android version and sign your app with the same key. Otherwise it would be useless protection.
Btw, starting form Android 8 or perhaps earlier you don't get SecurityException. The call just returns true as if any other and you never get any callback.
This might have been changed here: https://android.googlesource.com/platform/packages/apps/Bluetooth/+/32dc7a6b919375aede777f3c821fa316d85449ae%5E%21/#F2
I am trying to determine the storage encryption status of my Android device from within my application. Following the recommendations of the relevant Android Developer page, here is my code:
DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
int encryptionStatus = mDPM.getStorageEncryptionStatus();
if (DEBUG) Log.v(TAG, "checkSecuritySettingsSufficient: encryptionStatus=" + encryptionStatus);
Here's the trouble: when I run this code on a device (I've tried it on a Motorola Droid Maxx running Android 4.4.4 and a Nexus 7 running Android 5.0.2) which I have previously encrypted, DevicePolicyManager.getStorageEncryptionStatus() will always return a value of 1, i.e. ENCRYPTION_STATUS_INACTIVE.
Android is therefore reporting that the device is not encrypted, despite the fact that the file system is definitely encrypted (I checked its status from the Settings > Security page).
Is this function broken? There doesn't seem to be any mention of that on SO or on other web sources. This leads me to believe that I am not doing something correctly with respect to DevicePolicyManager.
UPDATE After running through the encryption steps again with the Motorola device, DevicePolicyManager.getStorageEncryptionStatus() is returning the correct value, but it's still failing on the Nexus 7.
I just ran into this same issue and found out it was happening because the device had disk encryption enabled, but did not require the passcode be entered at startup. Changing the passcode, and forcing the require PIN at startup option to be true made DevicePolicyManager.getStorageEncryptionStatus() correctly return ENCRYPTION_STATUS_ACTIVE.