5

I'm just playing around with some code. I create an Activity and simply do something like this:

long lo = currentTimeMillis();
System.out.println(lo);

lo *= 3;
System.out.println(lo);

SystemClock.setCurrentTimeMillis(lo);
System.out.println( currentTimeMillis() );

Yes, in my AndroidManifest.xml, I've added:

<uses-permission android:name="android.permission.SET_TIME"></uses-permission>
<uses-permission android:name="android.permission.SET_TIME_ZONE"></uses-permission>

Nothing changes. The SystemClock is never reset...it just keeps on ticking. The error that I'm getting just says that the permission "SET_TIME" was not granted to the program. Protection level 3.

The permissions are there...and in the API for 2.2 it says that this feature is supported now. I have no idea what I'm doing wrong.

If android.content.Intent; comes into play, please explain. I don't really understand what the idea behind intents!

Thanks for any help!

K-RAN
  • 896
  • 1
  • 13
  • 26

3 Answers3

12

There is a SET_TIME_ZONE permission but there's no SET_TIME permission. Applications cannot programmatically change the system clock.

Update

SET_TIME is available since 2.2, but can only be granted to the system process or apps signed with the system signature.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • According to http://developer.android.com/reference/android/Manifest.permission.html#SET_TIME, it's available since API 8. What's the deal? – JRL May 27 '10 at 06:18
  • Indeed it is in the 2.2 docs, I just realized I was checking the 2.0 source code instead of 2.2. Sorry about the confusion. I checked the 2.2 source code and the SET_TIME permission can only be granted to applications signed with the system signature. This mean you cannot use this permission. – Romain Guy May 27 '10 at 06:48
  • thanks for the clarification. Is the protection level for a given permission documented anywhere or is it required to look at AndroidManifest.xml in the source? – JRL May 27 '10 at 07:06
  • Is it possible to write a user level application with the system signature?? If not then I'm kind of annoyed as to why the Android developers would release this :( – K-RAN May 27 '10 at 18:38
  • No you cannot use the system signature. Unless you can get it from the manufacturer. – Romain Guy May 28 '10 at 17:31
2

using AlarmManager with SET_TIME permission to set system time seems to work :)

user718146
  • 400
  • 1
  • 4
  • 16
  • You just saved me a huge headache. Thanks! – Jason Nichols Sep 15 '11 at 14:46
  • 2
    On which API-Level have you tested this? I Always get an Exception saying: "java.lang.SecurityException: setTime: Neither user 10041 nor current process has android.permission.SET_TIME." I set the permission: "android.permission.SET_TIME" in my Manifest. Can anybody confirm that? – Hemeroc Dec 13 '11 at 13:16
  • @Hemeroc Same here. Tested on API level 8. Looks like the application must be signed with system certificate. – Dheeraj Vepakomma Dec 15 '11 at 11:28
-3

insetad of System.out.println() use Log.v() or similar.

I think I found your error, please try it out: Remove </uses-permission> on both lines, that should work

poeschlorn
  • 12,230
  • 17
  • 54
  • 65