private int[] jobConstraints(BackupType backupType) { switch (backupType) { case BROADCAST_INTENT: return new int[0]; default: return preferences.isWifiOnly() ? new int[] { ON_UNMETERED_NETWORK } : new int[] { ON_ANY_NETWORK }; } }
private String summarizeBackupScheduleSettings(boolean isEnabled) { if (!isEnabled) { return null; } final StringBuilder summary = new StringBuilder(); final ListPreference regSchedule = (ListPreference) findPreference(REGULAR_TIMEOUT_SECONDS.key); final ListPreference incomingSchedule = (ListPreference) findPreference(INCOMING_TIMEOUT_SECONDS.key); // values are out-of sync regSchedule.setValue(String.valueOf(preferences.getRegularTimeoutSecs())); incomingSchedule.setValue(String.valueOf(preferences.getIncomingTimeoutSecs())); summary.append(regSchedule.getTitle()) .append(": ") .append(regSchedule.getEntry()) .append(", ") .append(incomingSchedule.getTitle()) .append(": ") .append(incomingSchedule.getEntry()); if (preferences.isWifiOnly()) { summary.append(" (") .append(findPreference(WIFI_ONLY.key).getTitle()) .append(")"); } return summary.toString(); }
@SuppressWarnings("deprecation") private void legacyCheckConnectivity() throws ConnectivityException { NetworkInfo active = getConnectivityManager().getActiveNetworkInfo(); if (active == null || !active.isConnectedOrConnecting()) { throw new NoConnectionException(); } if (getPreferences().isWifiOnly() && isBackgroundTask() && !isConnectedViaWifi()) { throw new RequiresWifiException(); } }
@Test public void shouldCheckForWifiConnectivity() throws Exception { Intent intent = new Intent(); when(preferences.isWifiOnly()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); shadowWifiManager.setWifiEnabled(false); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresWifiException.class); }
@Test public void shouldCheckForWifiConnectivityAndNetworkType() throws Exception { Intent intent = new Intent(); when(preferences.isWifiOnly()).thenReturn(true); shadowConnectivityManager.setBackgroundDataSetting(true); shadowConnectivityManager.setActiveNetworkInfo(connectedViaEdge()); shadowWifiManager.setWifiEnabled(true); service.handleIntent(intent); verifyZeroInteractions(backupTask); assertThat(service.getState().exception).isInstanceOf(RequiresWifiException.class); }