Demo app limited to trial period

William Hunter

Active Member
Licensed User
Longtime User
Is there a way to create a demo app that could be limited to a specific number of days, at which time the app would be exited with an end of trial message? Some record would have to be left on the device after uninstall, so that any reinstall would not run, giving the same end of trial message.

This can be done in Windows using a registry key named in such a fashion that it appears to be associated with Windows, rather than the demo app. This makes it virtually impossible to find, unless you know what to look for.

I haven’t been able to think of a way to accomplish this with Android. Has anyone else found a way of doing this? Any help would be greatly appreciated. :sign0163:
 

William Hunter

Active Member
Licensed User
Longtime User
I’ve come up with a possible solution, depending on how secure a hidden file is in DirRootExternal. On first run a hidden file is created in this directory. On subsequent runs the current date is compared to the creation date of the data file, to determine the number of days of use. When the allowable test period has been exceeded, the app exits with a toast message. On uninstall that data file will remain in DirRootExternal, and should prevent a reinstall from running.

It works fine with the emulator, but I haven’t yet tested it on a devise. Can anyone give me a little insight as to how secure, from user access, a hidden file actually is.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   If FirstTime Then
      If File.Exists(File.DirRootExternal, ".Data.txt") = False Then ' use dot "." before the file name to create hidden file
         File.OpenOutput(File.DirRootExternal, ".Data.txt", False)
      Else
         TrialPeriodCheck
      End If
   End If
   ExitApplication ' used for testing
End Sub

Sub TrialPeriodCheck
   Dim CurrentDate As String
   Dim OtherDate As String
   Dim d, CurrDate, OthDate, NumOfDays As Long
   d = File.LastModified(File.DirRootExternal, ".Data.txt")
   CurrentDate = DateTime.Date(DateTime.Now)
   OtherDate = DateTime.Date(d)
   CurrDate = DateTime.DateParse(CurrentDate)
   OthDate = DateTime.DateParse(OtherDate)
   NumOfDays = ((CurrDate-OthDate)/(DateTime.TicksPerDay))
   Log("TrialDays = " & NumOfDays)
   'If NumOfDays < 10 Then ' used for testing
   If NumOfDays > 10 Then
      ToastMessageShow("End of Trial Period" & CRLF & "Closing Application ...", True)
      Wait(2)
      ExitApplication
   End If
End Sub

Sub Wait(Seconds As Int)
   'Sleep for defined seconds
   Dim Ti As Long
   Ti = DateTime.Now + (Seconds * 1000)
   Do While DateTime.Now < Ti
      DoEvents
   Loop
End Sub
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Can you post apk so we can test?

This is the APK for testing the code I posted.

JonPM - The APK may not be of much use to you. It's exactly the same code as posted. In testing with the emulator I simply alternated between If NumOfDays > 10 and NumOf Days < 10 to validate the code, along with loging info.
 

Attachments

  • TrialPeriod.apk
    116.5 KB · Views: 222
Last edited:
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
It's not secure. A hidden file is just not display by default in Android and the user can always see the file with a PC.

Thank you MLDev. I guess I'll have rethink this. I have no doubt that there is a secure method of introducing a trial limit period. It's just going to take a better coder than me to show the way. :sign0080:
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
I don't think there is a "secure" when the app is creating the check file. What you may want to hard code is a check to make sure the file's date isn't in the future of the checked date. Meaning, if I was a cracker, I would bypass your check by setting the file's creation date to say 2015, that way I'm always "within" the trial period.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
What you may want to hard code is a check to make sure the file's date isn't in the future of the checked date.

If I were to change "If NumOfDays > 10 Then" to "If NumOfDays > 10 OR OthDate > CurrDate Then" - do you think this would be an appropriate means of countering a hackers change of the Data.text file date to a time beyond the current date? Thank you for the feedback.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
I persisted with this, mainly because there were a few things I needed to know. Things have changed a little. Now on first run a hidden file is created, and the long date is written to this file. On subsequent runs the current date is compared to the creation date of the data file, to determine the number of days of use. Also, a comparison is made of the data file creation date, and the long date written to the file. When the allowable test period has been exceeded, or if the data file creation date and the long date contained in that file are not identical, then the app exits with a toast message. The latter should defend against anyone changing the data file creation date, or the file’s content.

There are a few deficiencies that make this routine impractical for serious use:

1. If the data file is installed to DirInternal, while inaccessible to the user, it would be removed on uninstall. The app would then run again normally on reinstall.

2. If the data file is installed to DirRootExternal, while it would be hidden to the user on the device and remain on the device after uninstall, it is not hidden to a PC. It could be deleted using a PC, and the app would run normally on reinstall.

3. Not every device is equipped with an SD card. So, condition 1 would likely be the most prevalent.

It could be used to simply annoy the cheapskates with a very short trial period. But, if you were a serious developer, this would not be a good strategy.

I just thought I would post the code for those that might care to know the outcome. If anyone has developed an iron-clad means of limiting a trial period and would care to share, I and other members of this forum would be greatly appreciative. :wav:

Regards

PS: If only I had access to DirRootInternal.

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim defDir As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   If FirstTime Then
      Dim CurrentDate As String
      Dim LogLongDate As Long
      CurrentDate = DateTime.Date(DateTime.Now)
      LogLongDate = DateTime.DateParse(CurrentDate)
      If File.ExternalReadable AND File.ExternalWritable Then
          defDir = File.DirRootExternal
       Else
          defDir = File.DirInternal
       End If
      ' ### used for testing --------------------------------------
      'If File.Exists(defDir, ".Data.txt") = True Then
         'File.Delete(defDir, ".Data.txt")
      'End If
      ' ### -------------------------------------------------------
      If File.Exists(defDir, ".Data.txt") = False Then ' use dot "." before the file name to create hidden file
         File.OpenOutput(defDir, ".Data.txt", False)
         File.WriteString(defDir, ".Data.txt", LogLongDate)
         'File.WriteString(defDir, ".Data.txt", "12345678900000") ' used for testing
      Else
         TrialPeriodCheck
      End If
   End If
   ExitApplication ' used for testing
End Sub

Sub TrialPeriodCheck
   Dim CurrentDate As String
   Dim StartingDate As String
   Dim LoggedDate As String
   Dim d, CurrDate, StartDate, NumOfDays As Long
   d = File.LastModified(defDir, ".Data.txt")
   CurrentDate = DateTime.Date(DateTime.Now)
   StartingDate = DateTime.Date(d)
   CurrDate = DateTime.DateParse(CurrentDate)
   StartDate = DateTime.DateParse(StartingDate)
   NumOfDays = ((CurrDate-StartDate)/(DateTime.TicksPerDay))
   LoggedDate = File.ReadString(defDir, ".Data.txt")
   Log("CurrentDate = " & CurrentDate)
   Log("StartingDate = " & StartingDate)
   Log("CurrDate = " & CurrDate)
   Log("StartDate = " & StartDate)
   Log("TrialDays = " & NumOfDays)
   Log("LoggedDate = " & LoggedDate)
   'If NumOfDays < 10 Then ' used for testing
   If NumOfDays > 10 Then
      ToastMessageShow("End of Trial Period" & CRLF & "Closing Application ...", True)
      Wait(2)
      ExitApplication
   Else If StartDate <> LoggedDate Then
      ToastMessageShow("End of Trial Period" & CRLF & "Closing Application ...", True)
      Wait(2)
      ExitApplication
   End If
End Sub

Sub Wait(Seconds As Int)
   'Sleep for defined seconds
   Dim Ti As Long
   Ti = DateTime.Now + (Seconds * 1000)
   Do While DateTime.Now < Ti
      DoEvents
   Loop
End Sub
 
Last edited:
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
You could write it to both internal and external memory, perhaps with differen names, which would lengthen the time for the 'cheapskates' to work it out.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
@DouglasNYoung & wheretheidevides – Thanks for your interest. For better or for worse there is nothing in Android that approximates the Windows registry, which makes it relatively easy to enforce a trial period, with a reasonable expectation of being successful. I’ve thought of limiting to a trial period that would be removed after the purchase and installation of a key. Unfortunately, that also would require the installation of a reference file to the device. I can’t think of a way to enforce a trial period without a reference file. But, that’s just me. There may be a way, but so far it eludes me.

If the reference file is installed to external storage, then this might work to enforce a trial period with most users. If the reference file is installed to internal storage only, then the reference file is removed on uninstall. This permits a reinstall to run again for the trial period. Things just become a merry-go-round.

I guess the good news is that Android is well secured, unless of course the device is rooted.

If anyone would care to share a code sample showing an unassailable way of enforcing a trial period, that would be very helpful to a number of fellow forum members. :sign0163:

Regards
 
Upvote 0

MLDev

Active Member
Licensed User
Longtime User
If anyone would care to share a code sample showing an unassailable way of enforcing a trial period, that would be very helpful to a number of fellow forum members.

The first programmer to code that could be very very rich. Like Bill Gates rich.

The estimated value of pirated software worldwide rose 14 percent to $58.8 billion in 2010 from 2009.
 
Last edited:
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
The first programmer to code that could be very very rich. Like Bill Gates rich.

Do you mean if I figure this out I’ll be Bill Gates rich? Oh great, now I won’t sleep nights. JUST KIDDING!!! :D
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
If anyone would care to share a code sample showing an unassailable way of enforcing a trial period, that would be very helpful to a number of fellow forum members. :sign0163:

Ya that'll never happen. So long as programs/apps have to be written and compiled, they can be decompiled and re-written (i.e. cracked). Only thing you can do is try to implement many different features to make it more difficult. Remember, companies like EA, Activision, etc can't stop crackers with their billions of dollars. Neither will you.
 
Upvote 0

MLDev

Active Member
Licensed User
Longtime User
Do you mean if I figure this out I’ll be Bill Gates rich? Oh great, now I won’t sleep nights. JUST KIDDING!!! :D

LOL If you could figure out a guaranteed way to protect software from piracy I'd bet Microsoft would try to be first in line to buy a license to use it.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
LOL If you could figure out a guaranteed way to protect software from piracy I'd bet Microsoft would try to be first in line to buy a license to use it.

Really, it needs to come from goggle. They should have a expiration date when you upload to the play store. or a yearly license amount. That way they take care of it. They can check every time the program is run.
 
Upvote 0

Vader

Well-Known Member
Licensed User
Longtime User
Ok, so if you did everything you have already brought up, but you also did the whole "run home to mama" web server / registration thing, wouldn't the combination work well enough that you would be say 98% covered?

Think of it this way - if the device does not have internet access to "phone home", and they hop on the install/uninstall/install merry-go-round, so what.

That's a license you never would have had, so you don't lose anything. The user would have just used the trial and uninstalled it.

However if someone gets the app in a controlled manner (ie, the Play store), and decides to give it to his mate, if his mate ALSO doesn't have internet access, then he will be ok. Until the trial runs out, then he also has to jump on the merry-go-round.

Finally, if it gets back to someone that DOES have internet access, they will be blocked because they haven't got a key. BUT if they wanted to buy one, they could.

So, what is the count?
3 installs, 1, maybe 2 license payments, and 1 or 2 people playing the install/uninstall game that you would never have got any revenue from anyway.

Sounds ok to me, but that's just my view.

Dave
 
Upvote 0

sergiones

Member
Licensed User
Longtime User
Hey guys, nice discussion here. idivides is correct but also be aware that using server to check licenses is not so safety as it seens. Network analysis can be made easily today, someone can use a notebook with adhoc network to give access to android and analyze it's traffic. So, two apps looks the better solution so far. Basic4Android rocks!!!!!!!!
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Before getting too concerned, bear in mind that anyone knowledgeable enough to get the app to bypass licensing checks of whatever kind have been coded in the app, or who downloads a pirated copy from one of many sites, or any one of a dozen ways used to bypass licensing, is very unlikely to have purchased the app anyway - they would never be a paying customer - so you are not really out any revenue. These people will either not purchase any app or like to get hold of pirated software that they seldom, if ever, actually use just so they can brag about how many the programs and apps they have. To get a feel for the problem, go to http://thepiratebay.se/ and do a search for 'Android apps' - brings up quite a long list.
 
Upvote 0
Top