1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.car.settings.wifi.details; 17 18 import android.car.drivingstate.CarUxRestrictions; 19 import android.content.Context; 20 import android.net.LinkAddress; 21 import android.net.LinkProperties; 22 23 import androidx.core.text.BidiFormatter; 24 import androidx.preference.Preference; 25 26 import com.android.car.settings.common.FragmentController; 27 28 import java.net.Inet6Address; 29 import java.util.StringJoiner; 30 31 /** 32 * Shows info about Wifi IPv6 address. 33 */ 34 public class WifiIpv6AddressPreferenceController extends 35 WifiDetailsBasePreferenceController<Preference> { 36 WifiIpv6AddressPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)37 public WifiIpv6AddressPreferenceController(Context context, String preferenceKey, 38 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 39 super(context, preferenceKey, fragmentController, uxRestrictions); 40 } 41 42 @Override getPreferenceType()43 protected Class<Preference> getPreferenceType() { 44 return Preference.class; 45 } 46 47 @Override updateState(Preference preference)48 protected void updateState(Preference preference) { 49 LinkProperties linkProperties = getWifiInfoProvider().getLinkProperties(); 50 StringJoiner ipv6Addresses = new StringJoiner(System.lineSeparator()); 51 if (linkProperties != null) { 52 for (LinkAddress addr : linkProperties.getLinkAddresses()) { 53 if (addr.getAddress() instanceof Inet6Address) { 54 ipv6Addresses.add(addr.getAddress().getHostAddress()); 55 } 56 } 57 } 58 59 if (ipv6Addresses.length() > 0) { 60 preference.setSummary( 61 BidiFormatter.getInstance().unicodeWrap(ipv6Addresses.toString())); 62 preference.setVisible(true); 63 } else { 64 preference.setVisible(false); 65 } 66 } 67 } 68 69