1

I am developing a COSU/KIOSK application and I need to manually update the time on the device.

I am using AlertManager.setTime(Calendar) to do so, but I can't grant my application the SET_TIME permission that it is required.

The application is the device owner, and this allowed me to use many other system permissions, for example

android:name="android.permission.REBOOT"
android:name="android.permission.SHUTDOWN"
android:name="android.permission.WRITE_SETTINGS"
android:name="android.permission.INSTALL_PACKAGES"
android:name="android.permission.DELETE_PACKAGES"

All of these permissions were granted to my application, just by listing them in the manifest.xml

But SET_TIME does not work.

I also tried using the device policy manager

mDevicePolicyManager.setPermissionGrantState(mAdminComponentName, getPreferredPackageName(),
                Manifest.permission.SET_TIME, DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);

This function returned false meaning it couldn't grant permission.

How can I solve this problem without prompting the user to grant this permission to my application.

Bako
  • 313
  • 1
  • 15

1 Answers1

0

If you are targeting devices api 28+ (android 9 and higher) you can set it with setTime(ComponentName admin, long millis) function.

For lower android versions I had to rely on a device manufacturer api to set device time.

Manifest.permission.SET_TIME is proteced/system permission, sadly deviceOwner cannot grant any protected permissions with setPermissionGrantState() function. There is very important word in its documentation:

Sets the grant state of a !runtime! permission for a specific application.

Pavel Luzhetskiy
  • 789
  • 1
  • 8
  • 26
  • Sadly I am targeting a lower target API. My confusion comes from, that I could do other stuff that also requires system permission, for example, I was able to re-install silently an application while running, without any user interaction. Setting a new time is way less dangerous than the stuff I was able to do. – Bako Nov 17 '20 at 14:46
  • well, installing an app doesnt require system permission if you are DeviceOwner – Pavel Luzhetskiy Nov 17 '20 at 15:42