views:

216

answers:

2

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!

A: 

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
Log.*() is better, but System.out.println() works. <uses-permission></uses-permission> is the same as <uses-permission/>. The latter is just a short version of the former.
Romain Guy
As @Romain said, <tag /> is really a short hand of <tag></tag> which is empty.
Dave G
+6  A: 

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
According to http://developer.android.com/reference/android/Manifest.permission.html#SET_TIME, it's available since API 8. What's the deal?
JRL
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
@Romain: 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
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
No you cannot use the system signature. Unless you can get it from the manufacturer.
Romain Guy