Search in sources :

Example 1 with SanitizedFile

use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.

the class LocalRepoManager method symlinkFileElsewhere.

private void symlinkFileElsewhere(String fileName, String symlinkPrefix, File directory) {
    SanitizedFile index = new SanitizedFile(directory, fileName);
    attemptToDelete(index);
    Utils.symlinkOrCopyFileQuietly(new SanitizedFile(new File(directory, symlinkPrefix), fileName), index);
}
Also used : SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) File(java.io.File)

Example 2 with SanitizedFile

use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.

the class LocalRepoManager method symlinkFileElsewhere.

private void symlinkFileElsewhere(String fileName, String symlinkPrefix, File directory) {
    SanitizedFile index = new SanitizedFile(directory, fileName);
    attemptToDelete(index);
    Utils.symlinkOrCopyFileQuietly(new SanitizedFile(new File(directory, symlinkPrefix), fileName), index);
}
Also used : SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) File(java.io.File)

Example 3 with SanitizedFile

use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.

the class LocalRepoManager method writeFdroidApkToWebroot.

private String writeFdroidApkToWebroot() {
    ApplicationInfo appInfo;
    String fdroidClientURL = "https://f-droid.org/F-Droid.apk";
    try {
        appInfo = pm.getApplicationInfo(fdroidPackageName, PackageManager.GET_META_DATA);
        SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
        SanitizedFile fdroidApkLink = new SanitizedFile(fdroidDir, "F-Droid.apk");
        attemptToDelete(fdroidApkLink);
        if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink)) {
            fdroidClientURL = "/" + fdroidDir.getName() + "/" + fdroidApkLink.getName();
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not set up F-Droid apk in the webroot", e);
    }
    return fdroidClientURL;
}
Also used : PackageManager(android.content.pm.PackageManager) SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 4 with SanitizedFile

use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.

the class ApkFileProvider method getSafeUri.

/**
 * Copies the APK into private data directory of F-Droid and returns a
 * {@code file://} or {@code content://} URI to be used for the
 * actual installation process.  Only APKs will ever use a {@code content://}
 * URI, any other file will always use a {@code file://} URI since F-Droid
 * itself handles their whole installation process.
 */
public static Uri getSafeUri(Context context, Uri localApkUri, Apk expectedApk) throws IOException {
    File apkFile = new File(localApkUri.getPath());
    SanitizedFile tempApkFile = ApkCache.copyApkFromCacheToFiles(context, apkFile, expectedApk);
    return getSafeUri(context, tempApkFile, Build.VERSION.SDK_INT >= 24 && expectedApk.isApk());
}
Also used : SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) File(java.io.File)

Example 5 with SanitizedFile

use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.

the class DownloaderService method handleIntent.

/**
 * This method is invoked on the worker thread with a request to process.
 * Only one Intent is processed at a time, but the processing happens on a
 * worker thread that runs independently from other application logic.
 * So, if this code takes a long time, it will hold up other requests to
 * the same DownloaderService, but it will not hold up anything else.
 * When all requests have been handled, the DownloaderService stops itself,
 * so you should not ever call {@link #stopSelf}.
 * <p/>
 * Downloads are put into subdirectories based on hostname/port of each repo
 * to prevent files with the same names from conflicting.  Each repo enforces
 * unique APK file names on the server side.
 *
 * @param intent The {@link Intent} passed via {@link
 *               android.content.Context#startService(Intent)}.
 * @see org.fdroid.fdroid.IndexV1Updater#update()
 */
private void handleIntent(Intent intent) {
    final Uri uri = intent.getData();
    final long repoId = intent.getLongExtra(Downloader.EXTRA_REPO_ID, 0);
    final Uri canonicalUrl = Uri.parse(intent.getStringExtra(Downloader.EXTRA_CANONICAL_URL));
    final SanitizedFile localFile = ApkCache.getApkDownloadPath(this, canonicalUrl);
    sendBroadcast(uri, Downloader.ACTION_STARTED, localFile, repoId, canonicalUrl);
    try {
        activeCanonicalUrl = canonicalUrl.toString();
        downloader = DownloaderFactory.create(this, uri, localFile);
        downloader.setListener(new ProgressListener() {

            @Override
            public void onProgress(long bytesRead, long totalBytes) {
                Intent intent = new Intent(Downloader.ACTION_PROGRESS);
                intent.setData(canonicalUrl);
                intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
                intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
                localBroadcastManager.sendBroadcast(intent);
            }
        });
        downloader.setTimeout(timeout);
        downloader.download();
        if (downloader.isNotFound()) {
            sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, getString(R.string.download_404), repoId, canonicalUrl);
        } else {
            sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile, repoId, canonicalUrl);
        }
    } catch (InterruptedException e) {
        sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, repoId, canonicalUrl);
    } catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e) {
        // if the above list of exceptions changes, also change it in IndexV1Updater.update()
        Log.e(TAG, "CONNECTION_FAILED: " + e.getLocalizedMessage());
        sendBroadcast(uri, Downloader.ACTION_CONNECTION_FAILED, localFile, repoId, canonicalUrl);
    } catch (IOException e) {
        e.printStackTrace();
        sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, e.getLocalizedMessage(), repoId, canonicalUrl);
    } finally {
        if (downloader != null) {
            downloader.close();
        }
    }
    downloader = null;
    activeCanonicalUrl = null;
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) ProtocolException(java.net.ProtocolException) UnknownHostException(java.net.UnknownHostException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Intent(android.content.Intent) IOException(java.io.IOException) SSLKeyException(javax.net.ssl.SSLKeyException) Uri(android.net.Uri) HttpRetryException(java.net.HttpRetryException) NoRouteToHostException(java.net.NoRouteToHostException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLProtocolException(javax.net.ssl.SSLProtocolException) SocketTimeoutException(java.net.SocketTimeoutException) ProgressListener(org.fdroid.fdroid.ProgressListener) SanitizedFile(org.fdroid.fdroid.data.SanitizedFile) ConnectException(java.net.ConnectException)

Aggregations

SanitizedFile (org.fdroid.fdroid.data.SanitizedFile)9 File (java.io.File)6 ApplicationInfo (android.content.pm.ApplicationInfo)3 PackageManager (android.content.pm.PackageManager)2 IOException (java.io.IOException)2 Instrumentation (android.app.Instrumentation)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 ConnectException (java.net.ConnectException)1 HttpRetryException (java.net.HttpRetryException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 ProtocolException (java.net.ProtocolException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 SSLKeyException (javax.net.ssl.SSLKeyException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 SSLProtocolException (javax.net.ssl.SSLProtocolException)1 ProgressListener (org.fdroid.fdroid.ProgressListener)1 Before (org.junit.Before)1