Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
🐧🐛 Issue #167: Clearing cache on Android device is ineffective
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Feb 7, 2017
1 parent d88a36a commit 883247b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<param name="android-package" value="com.adobe.phonegap.contentsync.Sync"/>
</feature>
</config-file>
<framework src="com.android.support:support-v4:23+"/>
<source-file src="src/android/Sync.java" target-dir="src/com/adobe/phonegap/contentsync"/>
</platform>
<platform name="browser">
Expand Down Expand Up @@ -90,4 +91,4 @@
</config-file>
<framework src="libz.dylib"/>
</platform>
</plugin>
</plugin>
13 changes: 10 additions & 3 deletions src/android/Sync.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import android.net.Uri;
import android.os.Environment;
import android.os.StatFs;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.Patterns;
import android.webkit.CookieManager;
Expand Down Expand Up @@ -431,6 +432,7 @@ private void sync(final JSONArray args, final CallbackContext callbackContext) t
copyCordovaAssets = args.getBoolean(4);
}
final String manifestFile = args.getString(8);
final boolean backup = args.getBoolean(10);
Log.d(LOG_TAG, "sync called with id = " + id + " and src = " + src + "!");

final ProgressEvent progress = createProgressEvent(id);
Expand All @@ -453,7 +455,7 @@ public void run() {
}
}

String outputDirectory = getOutputDirectory(id);
String outputDirectory = getOutputDirectory(id, backup);

// Check to see if we should just return the cached version
String type = args.optString(2, TYPE_REPLACE);
Expand Down Expand Up @@ -607,9 +609,14 @@ private boolean isZipFile(File targetFile) {
return success;
}

private String getOutputDirectory(final String id) {
private String getOutputDirectory(final String id, boolean backup) {
// Production
String outputDirectory = cordova.getActivity().getFilesDir().getAbsolutePath();
String outputDirectory = null;
if (backup) {
outputDirectory = cordova.getActivity().getFilesDir().getAbsolutePath();
} else {
outputDirectory = ContextCompat.getNoBackupFilesDir(cordova.getActivity()).getAbsolutePath();
}
// Testing
//String outputDirectory = cordova.getActivity().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
outputDirectory += outputDirectory.endsWith(File.separator) ? "" : File.separator;
Expand Down
12 changes: 8 additions & 4 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ var ContentSync = function(options) {
}

if (typeof options.manifest === 'undefined') {
options.manifest = "";
options.manifest = '';
}

if (typeof options.validateSrc === 'undefined') {
options.validateSrc = true;
}

if (typeof options.backup === 'undefined') {
options.backup = false;
}

// store the options to this object instance
this.options = options;

Expand All @@ -106,7 +110,7 @@ var ContentSync = function(options) {

// wait at least one process tick to allow event subscriptions
setTimeout(function() {
exec(success, fail, 'Sync', 'sync', [options.src, options.id, options.type, options.headers, options.copyCordovaAssets, options.copyRootApp, options.timeout, options.trustHost, options.manifest, options.validateSrc]);
exec(success, fail, 'Sync', 'sync', [options.src, options.id, options.type, options.headers, options.copyCordovaAssets, options.copyRootApp, options.timeout, options.trustHost, options.manifest, options.validateSrc, options.backup]);
}, 10);
};

Expand Down Expand Up @@ -228,11 +232,11 @@ module.exports = {
var callback = (typeof headers == "function" ? headers : cb);
exec(callback, callback, 'Sync', 'download', [url, null, headers]);
},

/**
* loadUrl
*
* This method allows loading file:// urls when using WKWebViews on iOS.
* This method allows loading file:// urls when using WKWebViews on iOS.
*
*/

Expand Down

0 comments on commit 883247b

Please sign in to comment.