Android Open Source - Amphitheatre Network Search Task






From Project

Back to project page Amphitheatre.

License

The source code is released under:

Apache License

If you think the Android project Amphitheatre listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jerrellmardis.amphitheatre.task;
//w  w  w. ja va  2  s . c o m
import android.os.AsyncTask;
import android.util.Log;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

/**
 * Searches the network looking for valid Samba shares.
 */
public class NetworkSearchTask extends AsyncTask<Void, Void, List<String>> {

    private static final String TAG = NetworkSearchTask.class.getSimpleName();

    private OnSharesFoundListener mListener;

    public interface OnSharesFoundListener {
        void onSharesFound(List<String> shares);
    }

    public NetworkSearchTask(OnSharesFoundListener listener) {
        mListener = listener;
    }

    @Override
    protected List<String> doInBackground(Void... voids) {
        List<String> publicShares = new ArrayList<String>();

        SmbFile[] domains = new SmbFile[0];
        try {
            domains = new SmbFile("smb://").listFiles();
        } catch (MalformedURLException e) {
            Log.e(TAG, "Invalid URL.", e);
        } catch (SmbException e) {
            Log.e(TAG, "Failed to search network for shares.", e);
        }

        // No domains found on network.
        if (domains.length == 0) {
            return null;
        }

        for (SmbFile d : domains) {
            if (isCancelled()) {
                return null;
            }

            SmbFile[] servers = new SmbFile[0];
            try {
                servers = new SmbFile(d.getPath()).listFiles();
            } catch (SmbException e) {
                Log.e(TAG, "Invalid URL.", e);
            } catch (MalformedURLException e) {
                Log.e(TAG, "Failed to search domain " + d + " for servers.", e);
            }

            if (servers == null || servers.length <= 0) {
                continue;
            }

            for (SmbFile server : servers) {
                if (isCancelled()) {
                    return null;
                }

                SmbFile[] shares = new SmbFile[0];
                try {
                    shares = new SmbFile(server.getPath()).listFiles();
                } catch (SmbException e) {
                    Log.e(TAG, "Invalid URL.", e);
                } catch (MalformedURLException e) {
                    Log.e(TAG, "Failed to search server " + server + " for shares.", e);
                }

                if (shares == null || shares.length <= 0) {
                    continue;
                }

                for (SmbFile share : shares) {
                    // Skip hidden shares
                    if (share.getPath().endsWith("$/")) {
                        continue;
                    }
                    publicShares.add(share.getPath());
                }
            }
        }

        return publicShares;
    }

    @Override
    protected void onPostExecute(List<String> strings) {
        if (!isCancelled() && mListener != null) {
            mListener.onSharesFound(strings);
        }
    }
}




Java Source Code List

com.jerrellmardis.amphitheatre.activity.BootupActivity.java
com.jerrellmardis.amphitheatre.activity.BrowseActivity.java
com.jerrellmardis.amphitheatre.activity.DetailsActivity.java
com.jerrellmardis.amphitheatre.activity.GridViewActivity.java
com.jerrellmardis.amphitheatre.activity.SearchActivity.java
com.jerrellmardis.amphitheatre.api.ApiClient.java
com.jerrellmardis.amphitheatre.api.GuessItClient.java
com.jerrellmardis.amphitheatre.api.MediaClientFactory.java
com.jerrellmardis.amphitheatre.api.MediaClient.java
com.jerrellmardis.amphitheatre.api.TMDbClient.java
com.jerrellmardis.amphitheatre.api.TVDBClientTest.java
com.jerrellmardis.amphitheatre.api.TVDBClient.java
com.jerrellmardis.amphitheatre.api.TVDBService.java
com.jerrellmardis.amphitheatre.fragment.AddSourceDialogFragment.java
com.jerrellmardis.amphitheatre.fragment.BrowseFragment.java
com.jerrellmardis.amphitheatre.fragment.CustomizeDialogFragment.java
com.jerrellmardis.amphitheatre.fragment.SearchFragment.java
com.jerrellmardis.amphitheatre.fragment.VerticalGridFragment.java
com.jerrellmardis.amphitheatre.fragment.VideoDetailsFragment.java
com.jerrellmardis.amphitheatre.listeners.RowBuilderTaskListener.java
com.jerrellmardis.amphitheatre.listeners.TaskListener.java
com.jerrellmardis.amphitheatre.model.GridGenre.java
com.jerrellmardis.amphitheatre.model.Source.java
com.jerrellmardis.amphitheatre.model.VideoGroup.java
com.jerrellmardis.amphitheatre.model.Video.java
com.jerrellmardis.amphitheatre.model.guessit.Guess.java
com.jerrellmardis.amphitheatre.model.tmdb.Config.java
com.jerrellmardis.amphitheatre.model.tmdb.Episode.java
com.jerrellmardis.amphitheatre.model.tmdb.Genre.java
com.jerrellmardis.amphitheatre.model.tmdb.Movie.java
com.jerrellmardis.amphitheatre.model.tmdb.ProductionCompany.java
com.jerrellmardis.amphitheatre.model.tmdb.SearchResult.java
com.jerrellmardis.amphitheatre.model.tmdb.TvShow.java
com.jerrellmardis.amphitheatre.model.tmdb.Videos.java
com.jerrellmardis.amphitheatre.model.tvdb.BaseResponse.java
com.jerrellmardis.amphitheatre.model.tvdb.EpisodeResponse.java
com.jerrellmardis.amphitheatre.model.tvdb.Episode.java
com.jerrellmardis.amphitheatre.model.tvdb.Language.java
com.jerrellmardis.amphitheatre.model.tvdb.SeriesResult.java
com.jerrellmardis.amphitheatre.model.tvdb.Series.java
com.jerrellmardis.amphitheatre.server.StreamServer.java
com.jerrellmardis.amphitheatre.server.StreamSource.java
com.jerrellmardis.amphitheatre.server.Streamer.java
com.jerrellmardis.amphitheatre.service.LibraryUpdateService.java
com.jerrellmardis.amphitheatre.service.RecommendationsService.java
com.jerrellmardis.amphitheatre.task.DetailRowBuilderTask.java
com.jerrellmardis.amphitheatre.task.DownloadMovieTask.java
com.jerrellmardis.amphitheatre.task.DownloadTaskHelper.java
com.jerrellmardis.amphitheatre.task.DownloadTvShowTask.java
com.jerrellmardis.amphitheatre.task.DownloadVideoTask.java
com.jerrellmardis.amphitheatre.task.GetFilesTask.java
com.jerrellmardis.amphitheatre.task.NetworkSearchTask.java
com.jerrellmardis.amphitheatre.util.ApiConstants.java
com.jerrellmardis.amphitheatre.util.Base64.java
com.jerrellmardis.amphitheatre.util.BlurTransform.java
com.jerrellmardis.amphitheatre.util.Constants.java
com.jerrellmardis.amphitheatre.util.Enums.java
com.jerrellmardis.amphitheatre.util.PicassoBackgroundManagerTarget.java
com.jerrellmardis.amphitheatre.util.RecommendationBuilder.java
com.jerrellmardis.amphitheatre.util.SecurePreferences.java
com.jerrellmardis.amphitheatre.util.Utils.java
com.jerrellmardis.amphitheatre.util.VideoUtils.java
com.jerrellmardis.amphitheatre.widget.CardPresenter.java
com.jerrellmardis.amphitheatre.widget.DetailsDescriptionPresenter.java
com.jerrellmardis.amphitheatre.widget.GridItemPresenter.java
com.jerrellmardis.amphitheatre.widget.SeasonCardPresenter.java
com.jerrellmardis.amphitheatre.widget.SortedObjectAdapter.java
com.jerrellmardis.amphitheatre.widget.TvShowsCardPresenter.java