content: package androidx.work.impl.utils;
  
  import android.content.Context;
  import android.content.SharedPreferences;
  import androidx.arch.core.util.Function;
  import androidx.lifecycle.LiveData;
  import androidx.lifecycle.Transformations;
  import androidx.sqlite.db.SupportSQLiteDatabase;
  import androidx.work.impl.WorkDatabase;
  import androidx.work.impl.WorkDatabaseMigrations;
  import androidx.work.impl.model.Preference;
  
  public class PreferenceUtils {
      public static final String KEY_LAST_CANCEL_ALL_TIME_MS = "last_cancel_all_time_ms";
      public static final String KEY_RESCHEDULE_NEEDED = "reschedule_needed";
      public static final String PREFERENCES_FILE_NAME = "androidx.work.util.preferences";
      private final WorkDatabase mWorkDatabase;
  
      public PreferenceUtils(WorkDatabase workDatabase) {
          this.mWorkDatabase = workDatabase;
      }
  
      public static void migrateLegacyPreferences(Context context, SupportSQLiteDatabase sqLiteDatabase) {
          SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_FILE_NAME, 0);
          if (sharedPreferences.contains(KEY_RESCHEDULE_NEEDED) || sharedPreferences.contains(KEY_LAST_CANCEL_ALL_TIME_MS)) {
              long j = 0;
              long j2 = sharedPreferences.getLong(KEY_LAST_CANCEL_ALL_TIME_MS, 0);
              if (sharedPreferences.getBoolean(KEY_RESCHEDULE_NEEDED, false)) {
                  j = 1;
              }
              sqLiteDatabase.beginTransaction();
              try {
                  sqLiteDatabase.execSQL(WorkDatabaseMigrations.INSERT_PREFERENCE, new Object[]{KEY_LAST_CANCEL_ALL_TIME_MS, Long.valueOf(j2)});
                  sqLiteDatabase.execSQL(WorkDatabaseMigrations.INSERT_PREFERENCE, new Object[]{KEY_RESCHEDULE_NEEDED, Long.valueOf(j)});
                  sharedPreferences.edit().clear().apply();
                  sqLiteDatabase.setTransactionSuccessful();
              } finally {
                  sqLiteDatabase.endTransaction();
              }
          }
      }
  
      public long getLastCancelAllTimeMillis() {
          Long longValue = this.mWorkDatabase.preferenceDao().getLongValue(KEY_LAST_CANCEL_ALL_TIME_MS);
          if (longValue != null) {
              return longValue.longValue();
          }
          return 0;
      }
  
      public LiveData<Long> getLastCancelAllTimeMillisLiveData() {
          return Transformations.map(this.mWorkDatabase.preferenceDao().getObservableLongValue(KEY_LAST_CANCEL_ALL_TIME_MS), new Function<Long, Long>() {
              public Long apply(Long value) {
                  return Long.valueOf(value != null ? value.longValue() : 0);
              }
          });
      }
  
      public boolean getNeedsReschedule() {
          Long longValue = this.mWorkDatabase.preferenceDao().getLongValue(KEY_RESCHEDULE_NEEDED);
          return longValue != null && longValue.longValue() == 1;
      }
  
      public void setLastCancelAllTimeMillis(long timeMillis) {
          this.mWorkDatabase.preferenceDao().insertPreference(new Preference(KEY_LAST_CANCEL_ALL_TIME_MS, timeMillis));
      }
  
      public void setNeedsReschedule(boolean needsReschedule) {
          this.mWorkDatabase.preferenceDao().insertPreference(new Preference(KEY_RESCHEDULE_NEEDED, needsReschedule));
      }
  }
  