com.google.android.exoplayer2.scheduler.RequirementsWatcher Java Examples

The following examples show how to use com.google.android.exoplayer2.scheduler.RequirementsWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void onRequirementsStateChanged(
    RequirementsWatcher requirementsWatcher,
    @Requirements.RequirementFlags int notMetRequirements) {
  Requirements requirements = requirementsWatcher.getRequirements();
  for (Listener listener : listeners) {
    listener.onRequirementsStateChanged(this, requirements, notMetRequirements);
  }
  if (this.notMetRequirements == notMetRequirements) {
    return;
  }
  this.notMetRequirements = notMetRequirements;
  pendingMessages++;
  internalHandler
      .obtainMessage(MSG_SET_NOT_MET_REQUIREMENTS, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}
 
Example #2
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void onRequirementsStateChanged(
    RequirementsWatcher requirementsWatcher,
    @Requirements.RequirementFlags int notMetRequirements) {
  Requirements requirements = requirementsWatcher.getRequirements();
  for (Listener listener : listeners) {
    listener.onRequirementsStateChanged(this, requirements, notMetRequirements);
  }
  if (this.notMetRequirements == notMetRequirements) {
    return;
  }
  this.notMetRequirements = notMetRequirements;
  pendingMessages++;
  internalHandler
      .obtainMessage(MSG_SET_NOT_MET_REQUIREMENTS, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}
 
Example #3
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void onRequirementsStateChanged(
    RequirementsWatcher requirementsWatcher,
    @Requirements.RequirementFlags int notMetRequirements) {
  Requirements requirements = requirementsWatcher.getRequirements();
  for (Listener listener : listeners) {
    listener.onRequirementsStateChanged(this, requirements, notMetRequirements);
  }
  if (this.notMetRequirements == notMetRequirements) {
    return;
  }
  this.notMetRequirements = notMetRequirements;
  pendingMessages++;
  internalHandler
      .obtainMessage(MSG_SET_NOT_MET_REQUIREMENTS, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}
 
Example #4
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param downloadIndex The download index used to hold the download information.
 * @param downloaderFactory A factory for creating {@link Downloader}s.
 */
public DownloadManager(
    Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory) {
  this.context = context.getApplicationContext();
  this.downloadIndex = downloadIndex;

  maxParallelDownloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
  minRetryCount = DEFAULT_MIN_RETRY_COUNT;
  downloadsPaused = true;
  downloads = Collections.emptyList();
  listeners = new CopyOnWriteArraySet<>();

  @SuppressWarnings("methodref.receiver.bound.invalid")
  Handler mainHandler = Util.createHandler(this::handleMainMessage);
  this.mainHandler = mainHandler;
  HandlerThread internalThread = new HandlerThread("DownloadManager file i/o");
  internalThread.start();
  internalHandler =
      new InternalHandler(
          internalThread,
          downloadIndex,
          downloaderFactory,
          mainHandler,
          maxParallelDownloads,
          minRetryCount,
          downloadsPaused);

  @SuppressWarnings("methodref.receiver.bound.invalid")
  RequirementsWatcher.Listener requirementsListener = this::onRequirementsStateChanged;
  this.requirementsListener = requirementsListener;
  requirementsWatcher =
      new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS);
  notMetRequirements = requirementsWatcher.start();

  pendingMessages = 1;
  internalHandler
      .obtainMessage(MSG_INITIALIZE, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}
 
Example #5
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private RequirementsHelper(
    Context context,
    Requirements requirements,
    @Nullable Scheduler scheduler,
    Class<? extends DownloadService> serviceClass) {
  this.context = context;
  this.requirements = requirements;
  this.scheduler = scheduler;
  this.serviceClass = serviceClass;
  requirementsWatcher = new RequirementsWatcher(context, this, requirements);
}
 
Example #6
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void requirementsMet(RequirementsWatcher requirementsWatcher) {
  try {
    notifyService();
  } catch (Exception e) {
    /* If we can't notify the service, don't stop the scheduler. */
    return;
  }
  if (scheduler != null) {
    scheduler.cancel();
  }
}
 
Example #7
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void requirementsNotMet(RequirementsWatcher requirementsWatcher) {
  try {
    notifyService();
  } catch (Exception e) {
    /* Do nothing. The service isn't running anyway. */
  }
  if (scheduler != null) {
    String servicePackage = context.getPackageName();
    boolean success = scheduler.schedule(requirements, servicePackage, ACTION_RESTART);
    if (!success) {
      Log.e(TAG, "Scheduling downloads failed.");
    }
  }
}
 
Example #8
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private RequirementsHelper(
    Context context,
    Requirements requirements,
    @Nullable Scheduler scheduler,
    Class<? extends DownloadService> serviceClass) {
  this.context = context;
  this.requirements = requirements;
  this.scheduler = scheduler;
  this.serviceClass = serviceClass;
  requirementsWatcher = new RequirementsWatcher(context, this, requirements);
}
 
Example #9
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void requirementsMet(RequirementsWatcher requirementsWatcher) {
  try {
    notifyService();
  } catch (Exception e) {
    /* If we can't notify the service, don't stop the scheduler. */
    return;
  }
  if (scheduler != null) {
    scheduler.cancel();
  }
}
 
Example #10
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void requirementsNotMet(RequirementsWatcher requirementsWatcher) {
  try {
    notifyService();
  } catch (Exception e) {
    /* Do nothing. The service isn't running anyway. */
  }
  if (scheduler != null) {
    String servicePackage = context.getPackageName();
    boolean success = scheduler.schedule(requirements, servicePackage, ACTION_RESTART);
    if (!success) {
      Log.e(TAG, "Scheduling downloads failed.");
    }
  }
}
 
Example #11
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param downloadIndex The download index used to hold the download information.
 * @param downloaderFactory A factory for creating {@link Downloader}s.
 */
public DownloadManager(
    Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory) {
  this.context = context.getApplicationContext();
  this.downloadIndex = downloadIndex;

  maxParallelDownloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
  minRetryCount = DEFAULT_MIN_RETRY_COUNT;
  downloadsPaused = true;
  downloads = Collections.emptyList();
  listeners = new CopyOnWriteArraySet<>();

  @SuppressWarnings("methodref.receiver.bound.invalid")
  Handler mainHandler = Util.createHandler(this::handleMainMessage);
  this.mainHandler = mainHandler;
  HandlerThread internalThread = new HandlerThread("DownloadManager file i/o");
  internalThread.start();
  internalHandler =
      new InternalHandler(
          internalThread,
          downloadIndex,
          downloaderFactory,
          mainHandler,
          maxParallelDownloads,
          minRetryCount,
          downloadsPaused);

  @SuppressWarnings("methodref.receiver.bound.invalid")
  RequirementsWatcher.Listener requirementsListener = this::onRequirementsStateChanged;
  this.requirementsListener = requirementsListener;
  requirementsWatcher =
      new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS);
  notMetRequirements = requirementsWatcher.start();

  pendingMessages = 1;
  internalHandler
      .obtainMessage(MSG_INITIALIZE, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}
 
Example #12
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@link DownloadManager}.
 *
 * @param context Any context.
 * @param downloadIndex The download index used to hold the download information.
 * @param downloaderFactory A factory for creating {@link Downloader}s.
 */
public DownloadManager(
    Context context, WritableDownloadIndex downloadIndex, DownloaderFactory downloaderFactory) {
  this.context = context.getApplicationContext();
  this.downloadIndex = downloadIndex;

  maxParallelDownloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
  minRetryCount = DEFAULT_MIN_RETRY_COUNT;
  downloadsPaused = true;
  downloads = Collections.emptyList();
  listeners = new CopyOnWriteArraySet<>();

  @SuppressWarnings("methodref.receiver.bound.invalid")
  Handler mainHandler = Util.createHandler(this::handleMainMessage);
  this.mainHandler = mainHandler;
  HandlerThread internalThread = new HandlerThread("DownloadManager file i/o");
  internalThread.start();
  internalHandler =
      new InternalHandler(
          internalThread,
          downloadIndex,
          downloaderFactory,
          mainHandler,
          maxParallelDownloads,
          minRetryCount,
          downloadsPaused);

  @SuppressWarnings("methodref.receiver.bound.invalid")
  RequirementsWatcher.Listener requirementsListener = this::onRequirementsStateChanged;
  this.requirementsListener = requirementsListener;
  requirementsWatcher =
      new RequirementsWatcher(context, requirementsListener, DEFAULT_REQUIREMENTS);
  notMetRequirements = requirementsWatcher.start();

  pendingMessages = 1;
  internalHandler
      .obtainMessage(MSG_INITIALIZE, notMetRequirements, /* unused */ 0)
      .sendToTarget();
}