Jump to content

  1. 0
  2. 0
  3. 0/5

Rate this Topic

- - - - -

[4.2/API 17] WRITE_SECURE_SETTINGS alternative? (RE: stay awake settings)

  • Please log in to reply

OP mordrukk

mordrukk

Member

  • 33 posts

Posted 20 November 2012 - 09:17 AM #1

Mod Type:: Application

Difficulty:: Easy

Mod Status:: Alpha

Apply In:: ADB

Requires Root:: No

Source::
Hi Guys,

I'm wondering if anyone has any information on the Settings.Global API, and in particular, how I might be able to write values to Settings.Global.Stay_On_While_Plugged_In.

Long story short - I built an app on API 16, which was able to write to Settings.System.Stay_On_While_Plugged_In. This was able to successfully override the Exchange security settings which disabled this option from Settings > Developer Options > Stay Awake.

However, in API 17, Google moved this from System to Global, and instead of only requiring WRITE_SETTINGS permissions as I had in API 16, I'll need WRITE_SECURE_SETTINGS. As far as I know, these settings are not possible to write to unless I make my own ROM and embed the app into /system/apps.

Either way, I can't even compile this in Eclipse when trying to ask for the WRITE_SECURE_SETTINGS. Does anyone know how to:
  • A ) Bypass the manifest error in Eclipse so I can at least test my application in the emulator.
  • B ) Configure Eclipse/the app with the proper signing to utilize the WRITE_SECURE_SETTINGS.
  • C ) Know of a generic API that can write to that setting without needing WRITE_SECURE_SETTINGS.
Any help would be appreciated, thanks!
  • 1 Likes

JBirdVegas

JBirdVegas

java code monkey

Posted 21 November 2012 - 07:52 AM #2

The settings provider is backed by a simple SQLite v3 table. As of 4.2 your app won't work through the SDK :( http://developer.and...l#MultipleUsers

a) you may be able to suppress the warning (http://stackoverflow.../3624776/873237) or you could compile against the AOSP source, Settings.Global is not in the sdk but is in the source code.
B) not without system signature... you could submit to one of the big teams but other than that no
c) Reflection?

You still might not be completely screwed but you may have to do a little work to get the same result, gone is your one-liner :(

Does your app have root?

If not have you considered trying Reflection?

Edited by JBirdVegas, 21 November 2012 - 08:13 AM.

  • 1 Likes

Show Your appreciation by clicking Thanks!

I co-maintain the droid2 branch of CyanogenMod, n00bware founder and lead developer and a developer for AOKP
my icon is custom artwork from ThaPHLASH


OP mordrukk

mordrukk

Member

  • 33 posts

Posted 26 November 2012 - 07:18 AM #3

I'm somewhat of a Java noob, so I'll have to research what Reflection does. It sounds like that's the best approach given your solutions. Thanks for pointing out that stackoverflow post, I'll see if I can suppress those warnings to at least get it running on the emulator.

Perhaps there is an alternative, though. I've noticed when using Google Maps navigation the screen never times out. Is there a way to artificially create that same effect?
  • 0 Likes

JBirdVegas

JBirdVegas

java code monkey

Posted 26 November 2012 - 10:52 AM #4

maybe I miss understood your requirements if you need to keep the screen on their are two options holding a WakeLock (huge battery drain; extremely inefficient way to keep the screen on) or a better option is to add the Screen On flag to the window you want to prevent timing out
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

What exactly do you need the app to do? Maybe I can suggest a better method, is the goal to keep the device on if in developer mode and connected via ADB? or are you just trying to keep the screen on while doing a long running task?

Edited by JBirdVegas, 26 November 2012 - 10:53 AM.

  • 1 Likes

Show Your appreciation by clicking Thanks!

I co-maintain the droid2 branch of CyanogenMod, n00bware founder and lead developer and a developer for AOKP
my icon is custom artwork from ThaPHLASH


JBirdVegas

JBirdVegas

java code monkey

Posted 26 November 2012 - 11:04 AM #5

...

  • B ) Configure Eclipse/the app with the proper signing to utilize the WRITE_SECURE_SETTINGS.
...

if you are willing to forgo uploading to the market you might could actually use that flag... but you would need to compile against the android source, NOT the SDK *therefore not Eclipse* (as that is not a valid SDK flag), and use the default signature that ships with aosp source, little known fact but almost all custom ROMs use the default signature... sadly exposing this exact exploit as plausible.

Although to be fair most large ROM teams host their code online so any signature used for production releases would likely also be online, but it wouldn't have to be I guess.

**You can't upload apps to the Play Market with the default signature you must provide a unique signature.

Edited by JBirdVegas, 26 November 2012 - 11:05 AM.

  • 0 Likes

Show Your appreciation by clicking Thanks!

I co-maintain the droid2 branch of CyanogenMod, n00bware founder and lead developer and a developer for AOKP
my icon is custom artwork from ThaPHLASH


OP mordrukk

mordrukk

Member

  • 33 posts

Posted 26 November 2012 - 12:44 PM #6

maybe I miss understood your requirements if you need to keep the screen on their are two options holding a WakeLock (huge battery drain; extremely inefficient way to keep the screen on) or a better option is to add the Screen On flag to the window you want to prevent timing out

getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

What exactly do you need the app to do? Maybe I can suggest a better method, is the goal to keep the device on if in developer mode and connected via ADB? or are you just trying to keep the screen on while doing a long running task?


Thank you for your responses!

This window flag might do the trick - all I want to do is mimic the behavior of the Stay Awake option. When driving, I keep my phone charging and would like the screen to stay on. As of 4.1.X, if you have an exchange account bound, Stay Awake becomes disabled and therefore creates an annoyance while driving (having to unlock the screen every 10 minutes since screen timeouts are thereby enforced).

It sounds like I can use this approach with the onCreate/onPause/onResume intents, where potentially, even if I change apps, that window flag should still be persistent.

The app is mainly for personal use or for anyone else having the same issues; I'm not really looking for a market release, just an exercise to hone my Java skills and learn some Android.
  • 0 Likes

JBirdVegas

JBirdVegas

java code monkey

Posted 26 November 2012 - 01:32 PM #7

good for you!

You may want to write your own receiver for this that holds a wakelock controlled via a persistent notification... lol that make sense?

ok so for the receiver you want to watch for battery changes and check if the device is plugged in if so launch notification.

onClick of notification launch a Dialog/Activity/PreferenceScreen/Whatever that acquires or dismisses the wakelock (maybe a window flag not sure you will have to play with that to see) then dismisses itself.

This way you always have quick access to disable the WakeLock if you should need.

refs:
http://developer.and...monitoring.html
http://developer.and...s.html#Managing
for extra credit place do all your work via a widget (checkbox/switch) in an Expanded Notification ;)
http://developer.and....html#BigNotify

Edited by JBirdVegas, 27 November 2012 - 04:51 PM.

  • 0 Likes

Show Your appreciation by clicking Thanks!

I co-maintain the droid2 branch of CyanogenMod, n00bware founder and lead developer and a developer for AOKP
my icon is custom artwork from ThaPHLASH


OP mordrukk

mordrukk

Member

  • 33 posts

Posted 11 December 2012 - 04:29 AM #8

Thank you for the suggestions. I'll try making a wakelock service at some point, but I've potentially figured out a simpler solution.

I realized by adjusting the sleep timeout (under Display settings), that I effectively achieved the result I wanted. However, the longest sleep time available is 10 minutes.

Using the Settings.System.SCREEN_OFF_TIMEOUT value, I was able to extend this to 60 minutes. This setting is writeable without any system signature.

So far I've tested, and have been able to get more than 10 minutes for screen time, so I believe it works.

I've attached the apk for those interested. Simply run the app, and flip the switch to have a 60 minute time out. Changing apps keeps the 60 minute setting in place. Turning the switch off or when the app is closed will revert back to your previous setting.

EDIT: I tested the app on my drive to work. It appears the maximum sleep time is 30 minutes, even though you can set the value to be higher. Still not bad, it's 3x longer than what I'm able to configure via settings. I'll update the app to reflect that limitation and upload a corrected version tonight.

EDIT2: Uploaded 30min time out version.

Attached Files


Edited by mordrukk, 11 December 2012 - 04:20 PM.

  • 0 Likes