use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.
the class WifiConnectionPreferenceControllerTest method onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced.
@Test
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
final WifiEntry wifiEntry1 = mock(WifiEntry.class);
when(wifiEntry1.getKey()).thenReturn("KEY_1");
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry1);
mController.displayPreference(mScreen);
final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(WifiEntryPreference.class);
final WifiEntry wifiEntry2 = mock(WifiEntry.class);
when(wifiEntry1.getKey()).thenReturn("KEY_2");
when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry2);
final int onUpdatedCountBefore = mOnChildUpdatedCount;
mController.onWifiEntriesChanged();
verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
final WifiEntryPreference pref1 = captor.getAllValues().get(0);
final WifiEntryPreference pref2 = captor.getAllValues().get(1);
assertThat(pref1.getWifiEntry()).isEqualTo(wifiEntry1);
assertThat(pref2.getWifiEntry()).isEqualTo(wifiEntry2);
verify(mPreferenceCategory).removePreference(eq(pref1));
assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
}
use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.
the class WifiSettings method launchNetworkDetailsFragment.
private void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
final WifiEntry wifiEntry = pref.getWifiEntry();
final Context context = getContext();
final CharSequence title = FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_DATAUSAGE_HEADER) ? wifiEntry.getTitle() : context.getText(R.string.pref_title_network_details);
final Bundle bundle = new Bundle();
bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY, wifiEntry.getKey());
new SubSettingLauncher(context).setTitleText(title).setDestination(WifiNetworkDetailsFragment.class.getName()).setArguments(bundle).setSourceMetricsCategory(getMetricsCategory()).launch();
}
use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.
the class WifiSettings method updateWifiEntryPreferences.
private void updateWifiEntryPreferences() {
// in case state has changed
if (mWifiPickerTracker.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
return;
}
boolean hasAvailableWifiEntries = false;
mStatusMessagePreference.setVisible(false);
mWifiEntryPreferenceCategory.setVisible(true);
final WifiEntry connectedEntry = mWifiPickerTracker.getConnectedWifiEntry();
mConnectedWifiEntryPreferenceCategory.setVisible(connectedEntry != null);
if (connectedEntry != null) {
final LongPressWifiEntryPreference connectedPref = mConnectedWifiEntryPreferenceCategory.findPreference(connectedEntry.getKey());
if (connectedPref == null || connectedPref.getWifiEntry() != connectedEntry) {
mConnectedWifiEntryPreferenceCategory.removeAll();
final ConnectedWifiEntryPreference pref = new ConnectedWifiEntryPreference(getPrefContext(), connectedEntry, this);
pref.setKey(connectedEntry.getKey());
pref.refresh();
mConnectedWifiEntryPreferenceCategory.addPreference(pref);
pref.setOnPreferenceClickListener(preference -> {
if (connectedEntry.canSignIn()) {
connectedEntry.signIn(null);
} else {
launchNetworkDetailsFragment(pref);
}
return true;
});
pref.setOnGearClickListener(preference -> {
launchNetworkDetailsFragment(pref);
});
if (mClickedConnect) {
mClickedConnect = false;
scrollToPreference(mConnectedWifiEntryPreferenceCategory);
}
}
} else {
mConnectedWifiEntryPreferenceCategory.removeAll();
}
int index = 0;
cacheRemoveAllPrefs(mWifiEntryPreferenceCategory);
List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
for (WifiEntry wifiEntry : wifiEntries) {
hasAvailableWifiEntries = true;
String key = wifiEntry.getKey();
LongPressWifiEntryPreference pref = (LongPressWifiEntryPreference) getCachedPreference(key);
if (pref != null) {
if (pref.getWifiEntry() == wifiEntry) {
pref.setOrder(index++);
continue;
} else {
// Create a new preference if the underlying WifiEntry object has changed
removePreference(key);
}
}
pref = createLongPressWifiEntryPreference(wifiEntry);
pref.setKey(wifiEntry.getKey());
pref.setOrder(index++);
pref.refresh();
if (wifiEntry.getHelpUriString() != null) {
pref.setOnButtonClickListener(preference -> {
openSubscriptionHelpPage(wifiEntry);
});
}
mWifiEntryPreferenceCategory.addPreference(pref);
}
removeCachedPrefs(mWifiEntryPreferenceCategory);
if (!hasAvailableWifiEntries) {
setProgressBarVisible(true);
Preference pref = new Preference(getPrefContext());
pref.setSelectable(false);
pref.setSummary(R.string.wifi_empty_list_wifi_on);
pref.setOrder(index++);
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
mWifiEntryPreferenceCategory.addPreference(pref);
} else {
// Continuing showing progress bar for an additional delay to overlap with animation
getView().postDelayed(mHideProgressBarRunnable, 1700);
}
mAddWifiNetworkPreference.setOrder(index++);
mWifiEntryPreferenceCategory.addPreference(mAddWifiNetworkPreference);
setAdditionalSettingsSummaries();
}
use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.
the class WifiNetworkDetailsFragment method createPreferenceControllers.
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
final ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
setupNetworksDetailTracker();
final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
final WifiSecondSummaryController2 wifiSecondSummaryController2 = new WifiSecondSummaryController2(context);
wifiSecondSummaryController2.setWifiEntry(wifiEntry);
mControllers.add(wifiSecondSummaryController2);
mWifiDetailPreferenceController2 = WifiDetailPreferenceController2.newInstance(wifiEntry, cm, context, this, // UI thread.
new Handler(Looper.getMainLooper()), getSettingsLifecycle(), context.getSystemService(WifiManager.class), mMetricsFeatureProvider);
mControllers.add(mWifiDetailPreferenceController2);
final WifiAutoConnectPreferenceController2 wifiAutoConnectPreferenceController2 = new WifiAutoConnectPreferenceController2(context);
wifiAutoConnectPreferenceController2.setWifiEntry(wifiEntry);
mControllers.add(wifiAutoConnectPreferenceController2);
final AddDevicePreferenceController2 addDevicePreferenceController2 = new AddDevicePreferenceController2(context);
addDevicePreferenceController2.setWifiEntry(wifiEntry);
mControllers.add(addDevicePreferenceController2);
final WifiMeteredPreferenceController2 meteredPreferenceController2 = new WifiMeteredPreferenceController2(context, wifiEntry);
mControllers.add(meteredPreferenceController2);
final WifiPrivacyPreferenceController2 privacyController2 = new WifiPrivacyPreferenceController2(context);
privacyController2.setWifiEntry(wifiEntry);
mControllers.add(privacyController2);
final WifiSubscriptionDetailPreferenceController2 wifiSubscriptionDetailPreferenceController2 = new WifiSubscriptionDetailPreferenceController2(context);
wifiSubscriptionDetailPreferenceController2.setWifiEntry(wifiEntry);
mControllers.add(wifiSubscriptionDetailPreferenceController2);
// Sets callback listener for wifi dialog.
mWifiDialogListeners.add(mWifiDetailPreferenceController2);
mWifiDialogListeners.add(privacyController2);
mWifiDialogListeners.add(meteredPreferenceController2);
return mControllers;
}
use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.
the class AddAppNetworksFragment method updateScanResultsToUi.
@VisibleForTesting
void updateScanResultsToUi() {
if (mUiToRequestedList == null) {
// Nothing need to be updated.
return;
}
List<WifiEntry> reachableWifiEntries = null;
if (mWifiPickerTracker.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
reachableWifiEntries = mWifiPickerTracker.getWifiEntries();
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
if (connectedWifiEntry != null) {
reachableWifiEntries.add(connectedWifiEntry);
}
}
// Update the signal level of the UI networks.
for (UiConfigurationItem uiConfigurationItem : mUiToRequestedList) {
uiConfigurationItem.mLevel = 0;
if (reachableWifiEntries != null) {
final Optional<WifiEntry> matchedWifiEntry = reachableWifiEntries.stream().filter(wifiEntry -> TextUtils.equals(uiConfigurationItem.mWifiNetworkSuggestion.getSsid(), wifiEntry.getSsid())).findFirst();
uiConfigurationItem.mLevel = matchedWifiEntry.isPresent() ? matchedWifiEntry.get().getLevel() : 0;
}
}
if (mIsSingleNetwork) {
updateSingleNetworkSignalIcon(mUiToRequestedList.get(0).mLevel);
} else {
if (mUiConfigurationItemAdapter != null) {
mUiConfigurationItemAdapter.notifyDataSetChanged();
}
}
}
Aggregations