diff options
-rw-r--r-- | android/ultimate/src/org/jetbrains/android/database/AndroidDbUtil.java | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/android/ultimate/src/org/jetbrains/android/database/AndroidDbUtil.java b/android/ultimate/src/org/jetbrains/android/database/AndroidDbUtil.java index 2cdd25ed7e6..4b7fdbcc614 100644 --- a/android/ultimate/src/org/jetbrains/android/database/AndroidDbUtil.java +++ b/android/ultimate/src/org/jetbrains/android/database/AndroidDbUtil.java @@ -1,9 +1,6 @@ package org.jetbrains.android.database; -import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.IDevice; -import com.android.ddmlib.MultiLineReceiver; -import com.android.ddmlib.SyncService; +import com.android.ddmlib.*; import com.android.tools.idea.ddms.DevicePropertyUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -62,6 +59,10 @@ class AndroidDbUtil { errorReporter.reportError(output); return false; } + // recreating is needed for Genymotion emulator (IDEA-114732) + if (!recreateRemoteFile(device, packageName, remoteDbPath, errorReporter, progressIndicator)) { + return false; + } outputReceiver = new MyShellOutputReceiver(progressIndicator); device.executeShellCommand("run-as " + packageName + " cat " + TEMP_REMOTE_DB_PATH + " >" + remoteDbPath, outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS); @@ -80,6 +81,32 @@ class AndroidDbUtil { return true; } + private static boolean recreateRemoteFile(IDevice device, + String packageName, + String remotePath, + AndroidDbErrorReporter errorReporter, + ProgressIndicator progressIndicator) throws Exception { + MyShellOutputReceiver outputReceiver = new MyShellOutputReceiver(progressIndicator); + device.executeShellCommand("run-as " + packageName + " rm " + remotePath, + outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS); + String output = outputReceiver.getOutput(); + + if (!output.isEmpty() && !output.startsWith("rm failed")) { + errorReporter.reportError(output); + return false; + } + outputReceiver = new MyShellOutputReceiver(progressIndicator); + device.executeShellCommand("run-as " + packageName + " touch " + remotePath, + outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS); + output = outputReceiver.getOutput(); + + if (!output.isEmpty()) { + errorReporter.reportError(output); + return false; + } + return true; + } + public static boolean downloadDatabase(@NotNull IDevice device, @NotNull String packageName, @NotNull String dbName, |