Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to detect if user changes system time without running a constant service to check time

In my app I want to allow user to be able to use it for 7 days offline usage for free, but want him to connect online once 7 days are done and buy a subscription after that. So basically, I want to lock him out after 7 days from install. The problem is user can very well change system time and trick the app. Also, I cannot use server as the authority as the app is supposed to also work completely offline, except for the time of purchasing subscription.

I can run a background service to keep track of any system time change but I want to avoid doing that. Is there a straight forward solution which can work even if the device is totally offline for 7 days.

like image 977
Abhishek Sinha Avatar asked Apr 07 '16 11:04

Abhishek Sinha


3 Answers

You can save the current time in shared preference and compare it every time you sample it. If you get an older sample the user changed the time backward.

like image 92
Zach Bublil Avatar answered Oct 15 '22 04:10

Zach Bublil


Use remote clock , for even simple read the time of server from mobile in desired time gap and use those number for your app's clock

like image 35
erluxman Avatar answered Oct 15 '22 02:10

erluxman


So this is how I am planning to solve this, though this is not unbreakable but will work for majority of users.

So while signing for trial I get network time and store it as start_time in preferences. Next on each app start and app resume I read the current_time and write to prefs. Once current_time of pref is greater than time of device, we lock the app. Once preferences are not there we ask user to come online as suggested by @Zach

To make preferences editing a little inconvenient to the rooted device guys I am storing data in encrypted form in prefs.

This is still no way unbreakable as one can decompile the apk and read the obfuscated code to guess the algorithm and the key but I guess the value of content in the app is not that high for someone to go through that much pain.

like image 32
Abhishek Sinha Avatar answered Oct 15 '22 03:10

Abhishek Sinha