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

The following examples show how to use com.google.android.exoplayer2.scheduler.Requirements. 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 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 #2
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onRequirementsStateChanged(
    DownloadManager downloadManager,
    Requirements requirements,
    @Requirements.RequirementFlags int notMetRequirements) {
  boolean requirementsMet = notMetRequirements == 0;
  if (downloadService == null && requirementsMet) {
    try {
      Intent intent = getIntent(context, serviceClass, DownloadService.ACTION_INIT);
      context.startService(intent);
    } catch (IllegalStateException e) {
      /* startService fails if the app is in the background then don't stop the scheduler. */
      return;
    }
  }
  if (scheduler != null) {
    setSchedulerEnabled(/* enabled= */ !requirementsMet, requirements);
  }
}
 
Example #3
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 #4
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 #5
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onRequirementsStateChanged(
    DownloadManager downloadManager,
    Requirements requirements,
    @Requirements.RequirementFlags int notMetRequirements) {
  boolean requirementsMet = notMetRequirements == 0;
  if (downloadService == null && requirementsMet) {
    try {
      Intent intent = getIntent(context, serviceClass, DownloadService.ACTION_INIT);
      context.startService(intent);
    } catch (IllegalStateException e) {
      /* startService fails if the app is in the background then don't stop the scheduler. */
      return;
    }
  }
  if (scheduler != null) {
    setSchedulerEnabled(/* enabled= */ !requirementsMet, requirements);
  }
}
 
Example #6
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequirementsStateChanged(
    DownloadManager downloadManager,
    Requirements requirements,
    @Requirements.RequirementFlags int notMetRequirements) {
  boolean requirementsMet = notMetRequirements == 0;
  if (downloadService == null && requirementsMet) {
    try {
      Intent intent = getIntent(context, serviceClass, DownloadService.ACTION_INIT);
      context.startService(intent);
    } catch (IllegalStateException e) {
      /* startService fails if the app is in the background then don't stop the scheduler. */
      return;
    }
  }
  if (scheduler != null) {
    setSchedulerEnabled(scheduler, /* enabled= */ !requirementsMet, requirements);
  }
}
 
Example #7
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private DownloadManagerHelper(
    Context context,
    DownloadManager downloadManager,
    @Nullable Scheduler scheduler,
    Class<? extends DownloadService> serviceClass) {
  this.context = context;
  this.downloadManager = downloadManager;
  this.scheduler = scheduler;
  this.serviceClass = serviceClass;
  downloadManager.addListener(this);
  if (scheduler != null) {
    Requirements requirements = downloadManager.getRequirements();
    setSchedulerEnabled(
        scheduler, /* enabled= */ !requirements.checkRequirements(context), requirements);
  }
}
 
Example #8
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void setSchedulerEnabled(boolean enabled, Requirements requirements) {
  if (!enabled) {
    scheduler.cancel();
  } else {
    String servicePackage = context.getPackageName();
    boolean success = scheduler.schedule(requirements, servicePackage, ACTION_RESTART);
    if (!success) {
      Log.e(TAG, "Scheduling downloads failed.");
    }
  }
}
 
Example #9
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void setSchedulerEnabled(
    Scheduler scheduler, boolean enabled, Requirements requirements) {
  if (!enabled) {
    scheduler.cancel();
  } else {
    String servicePackage = context.getPackageName();
    boolean success = scheduler.schedule(requirements, servicePackage, ACTION_RESTART);
    if (!success) {
      Log.e(TAG, "Scheduling downloads failed.");
    }
  }
}
 
Example #10
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private DownloadManagerHelper(
    Context context,
    DownloadManager downloadManager,
    @Nullable Scheduler scheduler,
    Class<? extends DownloadService> serviceClass) {
  this.context = context;
  this.downloadManager = downloadManager;
  this.scheduler = scheduler;
  this.serviceClass = serviceClass;
  downloadManager.addListener(this);
  if (scheduler != null) {
    Requirements requirements = downloadManager.getRequirements();
    setSchedulerEnabled(/* enabled= */ !requirements.checkRequirements(context), requirements);
  }
}
 
Example #11
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void maybeStartWatchingRequirements(Requirements requirements) {
  if (downloadManager.getDownloadCount() == 0) {
    return;
  }
  Class<? extends DownloadService> clazz = getClass();
  RequirementsHelper requirementsHelper = requirementsHelpers.get(clazz);
  if (requirementsHelper == null) {
    requirementsHelper = new RequirementsHelper(this, requirements, getScheduler(), clazz);
    requirementsHelpers.put(clazz, requirementsHelper);
    requirementsHelper.start();
    logd("started watching requirements");
  }
}
 
Example #12
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 #13
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void maybeStartWatchingRequirements(Requirements requirements) {
  if (downloadManager.getDownloadCount() == 0) {
    return;
  }
  Class<? extends DownloadService> clazz = getClass();
  RequirementsHelper requirementsHelper = requirementsHelpers.get(clazz);
  if (requirementsHelper == null) {
    requirementsHelper = new RequirementsHelper(this, requirements, getScheduler(), clazz);
    requirementsHelpers.put(clazz, requirementsHelper);
    requirementsHelper.start();
    logd("started watching requirements");
  }
}
 
Example #14
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 #15
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void setSchedulerEnabled(boolean enabled, Requirements requirements) {
  if (!enabled) {
    scheduler.cancel();
  } else {
    String servicePackage = context.getPackageName();
    boolean success = scheduler.schedule(requirements, servicePackage, ACTION_RESTART);
    if (!success) {
      Log.e(TAG, "Scheduling downloads failed.");
    }
  }
}
 
Example #16
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private DownloadManagerHelper(
    Context context,
    DownloadManager downloadManager,
    @Nullable Scheduler scheduler,
    Class<? extends DownloadService> serviceClass) {
  this.context = context;
  this.downloadManager = downloadManager;
  this.scheduler = scheduler;
  this.serviceClass = serviceClass;
  downloadManager.addListener(this);
  if (scheduler != null) {
    Requirements requirements = downloadManager.getRequirements();
    setSchedulerEnabled(/* enabled= */ !requirements.checkRequirements(context), requirements);
  }
}
 
Example #17
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the requirements needed to be met to progress. */
public Requirements getRequirements() {
  return requirementsWatcher.getRequirements();
}
 
Example #18
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void setNotMetRequirements(@Requirements.RequirementFlags int notMetRequirements) {
  this.notMetRequirements = notMetRequirements;
  syncTasks();
}
 
Example #19
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/** Returns the requirements needed to be met to progress. */
public Requirements getRequirements() {
  return requirementsWatcher.getRequirements();
}
 
Example #20
Source File: DownloadManager.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void setNotMetRequirements(@Requirements.RequirementFlags int notMetRequirements) {
  this.notMetRequirements = notMetRequirements;
  syncTasks();
}
 
Example #21
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void setNotMetRequirements(@Requirements.RequirementFlags int notMetRequirements) {
  this.notMetRequirements = notMetRequirements;
  syncTasks();
}
 
Example #22
Source File: DownloadManager.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/** Returns the requirements needed to be met to progress. */
public Requirements getRequirements() {
  return requirementsWatcher.getRequirements();
}
 
Example #23
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Starts the service if not started already and sets the requirements that need to be met for
 * downloads to progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether the service is started in the foreground.
 */
public static void sendSetRequirements(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  Intent intent = buildSetRequirementsIntent(context, clazz, requirements, foreground);
  startService(context, intent, foreground);
}
 
Example #24
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Builds an {@link Intent} for setting the requirements that need to be met for downloads to
 * progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service being targeted by the intent.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether this intent will be used to start the service in the foreground.
 * @return The created intent.
 */
public static Intent buildSetRequirementsIntent(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  return getIntent(context, clazz, ACTION_SET_REQUIREMENTS, foreground)
      .putExtra(KEY_REQUIREMENTS, requirements);
}
 
Example #25
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Builds an {@link Intent} for setting the requirements that need to be met for downloads to
 * progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service being targeted by the intent.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether this intent will be used to start the service in the foreground.
 * @return The created intent.
 */
public static Intent buildSetRequirementsIntent(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  return getIntent(context, clazz, ACTION_SET_REQUIREMENTS, foreground)
      .putExtra(KEY_REQUIREMENTS, requirements);
}
 
Example #26
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Starts the service if not started already and sets the requirements that need to be met for
 * downloads to progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether the service is started in the foreground.
 */
public static void sendSetRequirements(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  Intent intent = buildSetRequirementsIntent(context, clazz, requirements, foreground);
  startService(context, intent, foreground);
}
 
Example #27
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Starts the service if not started already and sets the requirements that need to be met for
 * downloads to progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether the service is started in the foreground.
 */
public static void sendSetRequirements(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  Intent intent = buildSetRequirementsIntent(context, clazz, requirements, foreground);
  startService(context, intent, foreground);
}
 
Example #28
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Builds an {@link Intent} for setting the requirements that need to be met for downloads to
 * progress.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service being targeted by the intent.
 * @param requirements A {@link Requirements}.
 * @param foreground Whether this intent will be used to start the service in the foreground.
 * @return The created intent.
 */
public static Intent buildSetRequirementsIntent(
    Context context,
    Class<? extends DownloadService> clazz,
    Requirements requirements,
    boolean foreground) {
  return getIntent(context, clazz, ACTION_SET_REQUIREMENTS, foreground)
      .putExtra(KEY_REQUIREMENTS, requirements);
}
 
Example #29
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Called when the download requirements state changed.
 *
 * @param downloadManager The reporting instance.
 * @param requirements Requirements needed to be met to start downloads.
 * @param notMetRequirements {@link Requirements.RequirementFlags RequirementFlags} that are not
 *     met, or 0.
 */
default void onRequirementsStateChanged(
    DownloadManager downloadManager,
    Requirements requirements,
    @Requirements.RequirementFlags int notMetRequirements) {}
 
Example #30
Source File: DownloadManager.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the requirements needed for downloads to progress that are not currently met.
 *
 * @return The not met {@link Requirements.RequirementFlags}, or 0 if all requirements are met.
 */
@Requirements.RequirementFlags
public int getNotMetRequirements() {
  return getRequirements().getNotMetRequirements(context);
}