Following is working on many thousands of devices but recently I got following errors, twice, both from android 6.0, so it may be related to the new android version:
RootUtils.copyDatabase(path, pathApp);
if (new File(pathApp).exists())
{
L.d(this, "Database copied!"); // <= this is called, so copying file succeeds!!!
SQLiteDatabase db = SQLiteDatabase.openDatabase(pathApp, null, SQLiteDatabase.OPEN_READONLY);
final Cursor cursor = db.rawQuery("select * from contacts", new String[0]); // <= this line throws the exception
cursor.moveToFirst();
....
}
Log/Exception
c.m.s.utils.RootUtils [RootUtils-91] copyDatabase: true
c.m.s.networks.utils.Util [FUtil-105] Database copied!
c.m.s.networks.utils.Util [FUtil-185] unknown error (code 14): Could not open database
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
...
My copy function is following:
public final static boolean copyDatabase(String pathSource, String pathTarget) throws IOException, InterruptedException, TimeoutException, RootDeniedException
{
Shell shell = RootTools.getShell(true);
Command command = new Command(0,
"su\n",
"rm " + pathTarget + "\n",
"cat " + pathSource + " > " + pathTarget + "\n",
"chown root.root " + pathTarget + "\n",
"chmod 777 " + pathTarget + "\n");
command = shell.add(command);
int exitCode = command.getExitCode();
while (!command.isFinished()) {
Thread.sleep(50);
}
shell.close();
boolean success = exitCode == -1 && command.isFinished();
L.d(RootUtils.class, "copyDatabase: " + success);
return success;
}
Aucun commentaire:
Enregistrer un commentaire