Periodic "unauthorized access to libsqlite.so" on Android FMX App

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
scottlynn
Posts: 4
Joined: Thu 08 Dec 2016 17:46

Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by scottlynn » Wed 26 Apr 2017 12:55

Greetings,

I am developing a Delphi FMX game on Android. I have a TLiteConnection and some TLiteQuery's in a TDataModule accessing a sqlite database file that I create and store in my app's user folder. Which on at least one device is:

/storage/emulated/0/Android/data/com.embarcadero.BibleCourtoom/files/BibleQuestions.db

App is being written in Delphi 10 Seattle. Anyway, everything seems to be working great. I have no LiveBinding controls connected to the queries. Everything is being accessed through code, and rather minimally as well.

Every now and then, when going to the home screen and then switching back to the app, I get the error message listed below, that I have an unauthorized access to "libsqlite.so". But then the database stuff still works great right afterwards. Is there something I should be doing on deactivate to get rid of this message? Thanks.

Exact error message:
Detected problems with the app native libraries (please consult log for detail): libBibleCourtroom.so: unauthorized access to "libsqlite.so"

Image

scottlynn
Posts: 4
Joined: Thu 08 Dec 2016 17:46

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by scottlynn » Mon 01 May 2017 14:23

No answer yet, and I was digging around looking for ways to handle the OnFormSaveState event, so here is what I am trying so far. It is an intermittent error message, so it will take a couple days of testing to determine if I have this fixed. I am trying to close the database connection in OnFormSaveState and then opening it again when my form is reactivated in Android, which requires adding an App event handler and registering it. If anyone else wants to try this, here is the code required to do it.

1) You need to add FMX.Platform to your uses clause.

2) You need something like the following in your OnCreate

var
aFMXApplicationEventService: IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent);

3) Declare the following as a procedure in the public declaration of your form:

function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;

4) In OnFormSaveState close your database connection

5) Make sure your OpenDatabase routine is smart enough to check if it is already open or add a force open flag. Because it will be called once on program restore, but twice during a normal program startup.

6) Here is my HandleAppEvent. I have some extra comments that records the order of events I encountered while testing different restore scenarios. Enjoy. Note I am not doing anything on WillTerminate since I already handle those things in OnFormClose.

function TFormMain.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.aeBecameActive :
begin
// AddLogEvent('TAppEvent.aeBecameActive');
// Reconnect to database if not connected
DM.OpenDatabase(true);
Result := true;
end;
TApplicationEvent.aeWillTerminate :
begin
// AddLogEvent('TAppEvent.aeWillTerminate');
end;

// Have seen these
// TApplicationEvent.aeWillBecomeInactive : AddLogEvent('TAppEvent.aeWillBecomeActive');
// TApplicationEvent.aeEnteredBackground : AddLogEvent('TAppEvent.aeEnteredBackground');
// TApplicationEvent.aeWillBecomeForeground : AddLogEvent('TAppEvent.aeWillBecomeForeground');
// TApplicationEvent.aeFinishedLaunching : AddLogEvent('TAppEvent.aeFinishedLaunching');

// Haven't seen these yet
// TApplicationEvent.aeLowMemory : AddLogEvent('TAppEvent.aeLowMemory');
// TApplicationEvent.aeTimeChange : AddLogEvent('TAppEvent.aeTimeChange');
// TApplicationEvent.aeOpenURL : AddLogEvent('TAppEvent.aeOpenURL');
end;

// Startup sequence --> OnCreate, OnShow, OnActivate, aeFinishingLaunching, aeBecameActive

// Here is the order for a Home screen and then fast switching back to app
// aeEnteredBackground, OnFormSaveState, [fast switch to app], aeWillBecomeForeground, aeBecameActive

// Here is the order for a screen lock (dark) and then wakeup and unlock and app restore
// aeEnteredBackground, OnFormSaveState, [screen off then on], aeWillBecomeActive, aeWillBecomeForeground, aeBecameActive
end;

scottlynn
Posts: 4
Joined: Thu 08 Dec 2016 17:46

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by scottlynn » Mon 01 May 2017 20:39

Well... NOT YET FIXED.

It still fails with the same error message. If I fast switch in Android to another app or click to Home screen then fast switch back into my app, I get "unauthorized access to libsqlite.so". And the only database code that has even run since app startup is:

OpenDatabase call from OnShow:

if (TFile.Exists(FormMain.sPathToDatabase)) then begin
SQLC.Database := FormMain.sPathToDatabase;
SQLC.Connect;
end;

And then the following executes in OnFormSaveState:

if qryGeneral.Active then qryGeneral.Close;
if qryVerseList.Active then qryVerseList.Close;
if qryVerseText.Active then qryVerseText.Close;
if SQLC.Connected then SQLC.Disconnect;

Then I switch out and come back into the app and get the error about unauthorized access. Any help appreciated. Not sure what I could be doing wrong at this point. Trying to figure out how to view the log that is mentioned in the error.

My research so far points to a bug in Android 7 Nougat, and that is the only device that has shown the message in my testing.

Someone else posted the following in a forum for a different development platform:

"In Android 7.0, the low-level Sqlite binary can no longer be used by apps. If you use one of the portable Sqlite libraries for .NET (like sqlite-net or Iridium), you will get the warning. Most libraries will be updated to use the "Android-approved" way of accessing Sqlite on the device." Further down in the same post, someone gives instructions on upgrading package libraries, but I am not sure how that will help my deployment issues. The bug sounds like it is understood and a fix is in the rollout phase.

- Scott

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by MaximG » Mon 15 May 2017 07:46

According to the description this problem occurs only when using Android 7 Nougat and is not directly related to LiteDAC behavior. You can test the work of the developing application using the Direct Mode : https://www.devart.com/litedac/docs/?work_net.htm when working with SQLite DB does not require any external libraries.

wbroyles10
Posts: 6
Joined: Tue 21 Aug 2012 00:56

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by wbroyles10 » Sat 03 Feb 2018 14:15

Direct mode is buggy. I soon as I switched my android app to direct mode I started experiencing random data loss in tables. I would pull back my db from the Android device and tables would no longer have any data in them. I have 6 devices deployed testing an new version of my app and at least 1 a day comes back with missing table data. This never happen using the libsqlite library. Be warned.

Wade

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by MaximG » Mon 05 Feb 2018 15:16

The "unauthorized access to libsqlite.so" error is generated by the SQLite engine, but not by LiteDAC components. We will be able to determine the conditions under which this error occurs. For this, compose and send us a simple sample, execution of which causes the error. It is convenient to do this using the e-support form (https://www.devart.com the "Support"\"Request Support" menu)

HelgeLange
Posts: 17
Joined: Wed 13 Jun 2007 16:40
Location: Caracas

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by HelgeLange » Fri 03 Aug 2018 22:35

Did anything came out on that investigation ? Because it's quite annoying that error.

Thanks :)

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by MaximG » Fri 10 Aug 2018 12:40

Unfortunately, we could not reproduce the issue in our test environment. For further investigation, please compose and send us a small full sample, execution of which causes the described error. It is convenient to do this via the e-support form (https://www.devart.com/company/contactform.html)

friedel
Posts: 6
Joined: Wed 18 Feb 2009 16:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by friedel » Thu 16 Aug 2018 08:13

I have the same problem on a Samsung Galaxy Tab Active2 with Android 7.1.1. It is difficult to narrow the error down to a special situation...

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by MaximG » Wed 29 Aug 2018 12:09

We understand all the complexities and specifics of this behavior. However, without a sample, using which we can detect the described error, we cannot start the necessary investigation

fabiorov
Posts: 1
Joined: Mon 01 Oct 2018 20:12

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by fabiorov » Mon 01 Oct 2018 20:14

I have the same problem
It often happens when app starts and I change to another app, and later I return to the initial app 8the developed one)

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Periodic "unauthorized access to libsqlite.so" on Android FMX App

Post by MaximG » Mon 08 Oct 2018 09:26

To understand the reasons of the described behavior, please compose and send us a small sample, execution of which causes the issue. It is convenient to do via the e-support form (https://www.devart.com/company/contactform.html)

Post Reply