wifisetting.java_SavedAccessPointsWifiSettings.java

/*

* Copyright (C) 2014 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

package com.android.settings.wifi;

import android.app.Dialog;

import android.content.Context;

import android.content.DialogInterface;

import android.content.res.Resources;

import android.net.wifi.WifiManager;

import android.os.Bundle;

import android.preference.Preference;

import android.preference.PreferenceScreen;

import android.util.Log;

import com.android.internal.logging.MetricsLogger;

import com.android.settings.R;

import com.android.settings.SettingsPreferenceFragment;

import com.android.settings.search.BaseSearchIndexProvider;

import com.android.settings.search.Indexable;

import com.android.settings.search.SearchIndexableRaw;

import com.android.settings.wifi.AccessPointPreference.UserBadgeCache;

import com.android.settingslib.wifi.AccessPoint;

import com.android.settingslib.wifi.WifiTracker;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Comparator;

import java.util.List;

import android.net.wifi.WifiConfiguration;

import android.net.wifi.WifiEnterpriseConfig.Eap;

import android.net.wifi.WifiConfiguration.KeyMgmt;

import android.os.SystemProperties;

/**

* UI to manage saved networks/access points.

*/

public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment

implements DialogInterface.OnClickListener, Indexable {

private static final String TAG = "SavedAccessPointsWifiSettings";

private WifiDialog mDialog;

private WifiManager mWifiManager;

private AccessPoint mDlgAccessPoint;

private Bundle mAccessPointSavedState;

private AccessPoint mSelectedAccessPoint;

private UserBadgeCache mUserBadgeCache;

// Instance state key

private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";

@Override

protected int getMetricsCategory() {

return MetricsLogger.WIFI_SAVED_ACCESS_POINTS;

}

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.wifi_display_saved_access_points);

mUserBadgeCache = new UserBadgeCache(getPackageManager());

}

@Override

public void onResume() {

super.onResume();

initPreferences();

}

@Override

public void onActivityCreated(Bundle savedInstanceState) {

super.onActivityCreated(savedInstanceState);

mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

if (savedInstanceState != null) {

if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {

mAccessPointSavedState =

savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);

}

}

}

private void initPreferences() {

PreferenceScreen preferenceScreen = getPreferenceScreen();

final Context context = getActivity();

final List accessPoints = WifiTracker.getCurrentAccessPoints(context, true,

false, true);

//lubo

boolean addssid=true;

String firstCradmnc = SystemProperties.get("persist.sys.ecid.first-mnc","");

String firstCradmcc = SystemProperties.get("persist.sys.ecid.first-mcc","");

for(AccessPoint accessPoint : accessPoints){

WifiConfiguration config=accessPoint.getConfig();

Log.e("lubo","=======>>>ssid:"+config.SSID);

if(config.SSID.equals("\"Singtel WIFI\"") || config.SSID.equals("Singtel WIFI") ){

Log.e("lubo","=======>>>contain:"+config.SSID);

addssid=false;

}

}

if(addssid){

if((firstCradmnc.equals("01") && firstCradmcc.equals("525")) || (firstCradmnc.equals("02") && firstCradmcc.equals("525"))){

Log.e("lubo","=======>>>add singtel wifi");

WifiConfiguration config = new WifiConfiguration();

Bundle b=new Bundle();

AccessPoint ap=new AccessPoint(getActivity(),b);

config.SSID="Singtel WIFI";

config.enterpriseConfig.setEapMethod(Eap.SIM);

config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);

config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);

ap.loadConfig(config);

accessPoints.add(ap);

}

}

Collections.sort(accessPoints, new Comparator() {

public int compare(AccessPoint ap1, AccessPoint ap2) {

if (ap1.getConfigName() != null) {

return ap1.getConfigName().compareTo(ap2.getConfigName());

} else {

return -1;

}

}

});

preferenceScreen.removeAll();

final int accessPointsSize = accessPoints.size();

for (int i = 0; i < accessPointsSize; ++i){

AccessPointPreference preference = new AccessPointPreference(accessPoints.get(i),

context, mUserBadgeCache, true);

preference.setIcon(null);

preferenceScreen.addPreference(preference);

}

if(getPreferenceScreen().getPreferenceCount() < 1) {

Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");

}

}

private void showDialog(AccessPointPreference accessPoint, boolean edit) {

if (mDialog != null) {

removeDialog(WifiSettings.WIFI_DIALOG_ID);

mDialog = null;

}

// Save the access point and edit mode

mDlgAccessPoint = accessPoint.getAccessPoint();

showDialog(WifiSettings.WIFI_DIALOG_ID);

}

@Override

public Dialog onCreateDialog(int dialogId) {

switch (dialogId) {

case WifiSettings.WIFI_DIALOG_ID:

if (mDlgAccessPoint == null) { // For re-launch from saved state

mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);

// Reset the saved access point data

mAccessPointSavedState = null;

}

mSelectedAccessPoint = mDlgAccessPoint;

String firstCradmnc = SystemProperties.get("persist.sys.ecid.first-mnc","");

String firstCradmcc = SystemProperties.get("persist.sys.ecid.first-mcc","");

// Hide forget button if config editing is locked down

boolean hideForgetButton = WifiSettings.isEditabilityLockedDown(getActivity(),

mDlgAccessPoint.getConfig());

///M:[HQ_SINGTEL_SSID] modify{@

android.util.Log.d("BingWu.Lee","ssid1 = "+mDlgAccessPoint.getSsid());

if (mDlgAccessPoint != null && mDlgAccessPoint.getSsid() != null &&

"Singtel WIFI".equals(mDlgAccessPoint.getSsid().toString())){

android.util.Log.d("BingWu.Lee","hide forget button");

hideForgetButton = true;

}

// movistart & VIVO start

if(firstCradmnc.equals("00") && firstCradmcc.equals("740")){

if (mDlgAccessPoint != null && mDlgAccessPoint.getSsid() != null &&

("MOVISTAR WIFI".equals(mDlgAccessPoint.getSsid().toString()) || "VIVO-WIFI".equals(mDlgAccessPoint.getSsid().toString()))){

android.util.Log.d("BingWu.Lee","hide forget button");

hideForgetButton = true;

}

}

// movistart & VIVO end

///@}

mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,

false /* not editting */, false, true /* hide the submit button */,

hideForgetButton);

return mDialog;

}

return super.onCreateDialog(dialogId);

}

@Override

public void onSaveInstanceState(Bundle outState) {

super.onSaveInstanceState(outState);

// If the dialog is showing, save its state.

if (mDialog != null && mDialog.isShowing()) {

if (mDlgAccessPoint != null) {

mAccessPointSavedState = new Bundle();

mDlgAccessPoint.saveWifiState(mAccessPointSavedState);

outState.putBundle(SAVE_DIALOG_ACCESS_POINT_STATE, mAccessPointSavedState);

}

}

}

@Override

public void onClick(DialogInterface dialogInterface, int button) {

if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {

mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, null);

/// M: get and remove ap that matches the unique networkId for CR ALPS02279153 @{

if (findSelectedAccessPointPreference() != null) {

getPreferenceScreen().removePreference(findSelectedAccessPointPreference());

}

/// @}

//getPreferenceScreen().removePreference((Preference) mSelectedAccessPoint.getTag());

mSelectedAccessPoint = null;

}

}

/// M: extract the ap selection process @{

private AccessPointPreference findSelectedAccessPointPreference() {

PreferenceScreen prefScreen = getPreferenceScreen();

int size = prefScreen.getPreferenceCount();

for (int i = 0; i < size; i++) {

AccessPointPreference ap = (AccessPointPreference) prefScreen.getPreference(i);

if (ap.getAccessPoint() != null && mSelectedAccessPoint != null

&& (ap.getAccessPoint().getConfig().networkId

== mSelectedAccessPoint.getConfig().networkId)) {

return ap;

}

}

return null;

}

/// @}

@Override

public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {

if (preference instanceof AccessPointPreference) {

showDialog((AccessPointPreference) preference, false);

return true;

} else{

return super.onPreferenceTreeClick(screen, preference);

}

}

/**

* For search.

*/

public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =

new BaseSearchIndexProvider() {

@Override

public List getRawDataToIndex(Context context, boolean enabled) {

final List result = new ArrayList();

final Resources res = context.getResources();

final String title = res.getString(R.string.wifi_saved_access_points_titlebar);

// Add fragment title

SearchIndexableRaw data = new SearchIndexableRaw(context);

data.title = title;

data.screenTitle = title;

data.enabled = enabled;

result.add(data);

// Add available Wi-Fi access points

final List accessPoints = WifiTracker.getCurrentAccessPoints(context,

true, false, true);

final int accessPointsSize = accessPoints.size();

for (int i = 0; i < accessPointsSize; ++i){

data = new SearchIndexableRaw(context);

data.title = accessPoints.get(i).getSsidStr();

data.screenTitle = title;

data.enabled = enabled;

result.add(data);

}

return result;

}

};

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值