Search in sources :

Example 1 with WifiEntry

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);
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference) Test(org.junit.Test)

Example 2 with WifiEntry

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();
}
Also used : Context(android.content.Context) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 3 with WifiEntry

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();
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) Preference(androidx.preference.Preference) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 4 with WifiEntry

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;
}
Also used : WifiAutoConnectPreferenceController2(com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2) WifiMeteredPreferenceController2(com.android.settings.wifi.details2.WifiMeteredPreferenceController2) WifiSubscriptionDetailPreferenceController2(com.android.settings.wifi.details2.WifiSubscriptionDetailPreferenceController2) WifiSecondSummaryController2(com.android.settings.wifi.details2.WifiSecondSummaryController2) ConnectivityManager(android.net.ConnectivityManager) WifiEntry(com.android.wifitrackerlib.WifiEntry) Handler(android.os.Handler) AddDevicePreferenceController2(com.android.settings.wifi.details2.AddDevicePreferenceController2) WifiPrivacyPreferenceController2(com.android.settings.wifi.details2.WifiPrivacyPreferenceController2)

Example 5 with WifiEntry

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();
        }
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) RESULT_OK(android.app.Activity.RESULT_OK) NonNull(androidx.annotation.NonNull) ImageView(android.widget.ImageView) Intent(android.content.Intent) SystemClock(android.os.SystemClock) Drawable(android.graphics.drawable.Drawable) Process(android.os.Process) FragmentActivity(androidx.fragment.app.FragmentActivity) ArrayList(java.util.ArrayList) InstrumentedFragment(com.android.settings.core.InstrumentedFragment) WifiNetworkSuggestion(android.net.wifi.WifiNetworkSuggestion) Handler(android.os.Handler) Looper(android.os.Looper) PasspointConfiguration(android.net.wifi.hotspot2.PasspointConfiguration) View(android.view.View) Button(android.widget.Button) Settings(android.provider.Settings) ZoneOffset(java.time.ZoneOffset) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) R(com.android.settings.R) RESULT_CANCELED(android.app.Activity.RESULT_CANCELED) KeyMgmt(android.net.wifi.WifiConfiguration.KeyMgmt) WifiEntry(com.android.wifitrackerlib.WifiEntry) LayoutInflater(android.view.LayoutInflater) WifiPickerTracker(com.android.wifitrackerlib.WifiPickerTracker) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) FeatureFactory(com.android.settings.overlay.FeatureFactory) ViewGroup(android.view.ViewGroup) WifiManager(android.net.wifi.WifiManager) ArrayAdapter(android.widget.ArrayAdapter) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Message(android.os.Message) HandlerThread(android.os.HandlerThread) Utils(com.android.settings.Utils) Clock(java.time.Clock) Optional(java.util.Optional) ListView(android.widget.ListView) SimpleClock(android.os.SimpleClock) PreferenceImageView(androidx.preference.internal.PreferenceImageView) WifiEntry(com.android.wifitrackerlib.WifiEntry) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

WifiEntry (com.android.wifitrackerlib.WifiEntry)54 Test (org.junit.Test)28 WifiConfiguration (android.net.wifi.WifiConfiguration)10 WifiEntryPreference (com.android.settingslib.wifi.WifiEntryPreference)10 LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)8 Intent (android.content.Intent)7 Preference (androidx.preference.Preference)5 Context (android.content.Context)4 Bundle (android.os.Bundle)4 DataUsagePreference (com.android.settings.datausage.DataUsagePreference)4 WifiManager (android.net.wifi.WifiManager)3 Handler (android.os.Handler)3 View (android.view.View)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)3 AddWifiNetworkPreference (com.android.settings.wifi.AddWifiNetworkPreference)3 ConnectedWifiEntryPreference (com.android.settings.wifi.ConnectedWifiEntryPreference)3 FooterPreference (com.android.settingslib.widget.FooterPreference)3 LayoutPreference (com.android.settingslib.widget.LayoutPreference)3 ArrayList (java.util.ArrayList)3