2

I have run into an error around the use of SqlCipher with MvvmCross on an Android application.

The issue I am currently facing seems to be permissions regarding the creation of a database locally on the simulated device I am running. After having spent a large amount of time searching the topic I don't seem to be able to find the solution. I will list below the things that I have tried, and then give further details to the error:

  • Adding of various permissions on the Manifest.xml file to allow SqlCipher to write to the device. (After a certain amount of research, you should only have to do this if writing to an SDCard on the device)
  • Looked through any possibility of needed permission to access the company's SqlCipher account - that also isn't the issue as we added the necessary dll into the project.
  • All references to necessary files + packages seem to be there and up to date with the current context.

I have narrowed down where the problem starts in the project. Essentially, I am writing an android application and slowly bringing in the business logic that we already have set-up, to get it up and going. Our iOS application uses the same libraries and database structure I am trying to use for Android, yet I don't get this error on the iOS side.

This is the error that I get:

data/user/0/"company file location"/files/Xamarin.Social.Accounts (Permission denied)

This errors pops up when MvvmCross tries to resolve the following code to create the database locally:

namespace HiddenForSecurity.Mobile.Data.Droid { public class DatabaseContextService : IDatabaseContextService { private SQLiteConnection _connection = null; private object _connectionLock = new object();

    public object Connection
    {
        get
        {
            lock (_connectionLock)
            {
                return _connection;
            }
        }
    }

    public DatabaseContextService()
    {
        _connection = new SQLiteConnection(DatabasePath, DatabasePassword);
    }

    public void InitialiseDatabase()
    {
        _connection.CreateTable<MobileUser>();
        _connection.CreateTable<UserRole>();
        _connection.CreateTable<OfflineReport>();
        _connection.CreateTable<OfflineDiary>();
    }

    public void Close()
    {
        _connection.Close();
        _connection.Dispose();
    }

    public string DatabasePath
    {
        get
        {
            return Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "patientportal.db");
        }
    }

    private string DatabasePassword
    {
        get
        {
            var context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity.ApplicationContext;
            Account accounts = AccountStore.Create(context)
                .FindAccountsForService("PatientPortal")
                .FirstOrDefault(x => x.Username == "systemUser");

            if (accounts == null)
            {
                accounts = new Account("systemUser");
                accounts.Properties["db"] = System.Guid.NewGuid().ToString();
                AccountStore.Create(context).Save(accounts, "PatientPortal");
            }

            return accounts.Properties["db"];
        }
    }
}

}

Does anyone have any ideas as to why I'm getting an error regarding Xamarin.Social.Account at all ?

Many thanks in advance - Please ask for any necessary information.

Liam

Liam Lamb
  • 21
  • 1

0 Answers0