当前位置:首页 » 计算机系统

mtk android 4.4.2系统, 添加ethernet

2015-04-03 14:01 本站整理 浏览(646)



From:http://blog.csdn.net/u010916467/article/details/44831821Mtk的mt6582平台 8312/8382, android 4.4.2添加ethernet

一、 移植全志A33/A23平台的ethernet代码,方法如下:

二、 Framework service and core层

1、 新增文件

frameworks/base/Ethernet

frameworks/base/services/java/com/android/server/EthernetService.java

frameworks/base/core/java/android/net/EthernetDataTracker.java

2、 frameworks/base/Android.mk

+ ethernet/java/android/net/ethernet/IEthernetManager.aidl \

+LOCAL_AIDL_INCLUDES := frameworks/base/ethernet/java

# FRAMEWORKS_BASE_JAVA_SRC_DIRS comes from build/core/pathmap.mk

LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)

3、build/core/pathmap.mk

FRAMEWORKS_BASE_SUBDIRS := \

$(addsuffix /java, \

core \

graphics \

location \

media \

media/mca/effect \

media/mca/filterfw \

media/mca/filterpacks \

drm \

opengl \

sax \

telephony \

wifi \

keystore \

+ethernet \

)

4、 修改frameworks/base /services/java/com/android/server/SystemServer.java

public void initAndLoop() {

+EthernetService ethernet = null;

try {

Slog.i(TAG, "Wi-Fi Service");

wifi = new WifiService(context);

ServiceManager.addService(Context.WIFI_SERVICE, wifi);

} catch (Throwable e) {

reportWtf("starting Wi-Fi Service", e);

}

+ try {

+ Slog.i(TAG, "Ethernet Service");

+ ethernet = new EthernetService(context);

+ServiceManager.addService(Context.ETHERNET_SERVICE, ethernet);

+ } catch (Throwable e) {

+ reportWtf("starting Ethernet Service", e);

}

5、 修改frameworks/base /services/java/com/android/server/ConnectivityService.java

+import android.net.ethernet.EthernetDataTracker;

if (mRadioAttributes[n.radio] == null) {

+if ((n.type != ConnectivityManager.TYPE_ETHERNET) && (mRadioAttributes[n.radio] == null)) { //Michael_LeePP for ethernet

+loge("Error in networkAttributes - ignoring attempt to use undefined " +

"radio " + n.radio + " in network type " + n.type);

+continue;

+}

+}

mNetConfigs[n.type] = n;

mNetworksDefined++;

6、 frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON,

R.bool.def_bluetooth_on);

+loadBooleanSetting(stmt, Settings.Global.ETHERNET_ON,

R.bool.def_ethernet_on);

+loadBooleanSetting(stmt, Settings.Global.ETHERNET_MODE,

R.bool.def_ethernet_mode);

7、frameworks/base/packages/SettingsProvider/res/values/defaults.xml

+<bool name="def_ethernet_on">false</bool>

+<bool name="def_ethernet_mode">true</bool>

8、frameworks\base\core\res\res\values\config.xml

<item><xliff:g id="id">wifi</xliff:g></item>

+<item><xliff:g id="id">ethernet</xliff:g></item>

<item><xliff:g id="id">cdma_eri</xliff:g></item>

<item>"mobile_hipri,5,0,3,300000,true"</item>

+<item>"ethernet,9,9,1,300000,true"</item>//不可缺少这个,否则NetworkInfo networkinfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);空指针

<item>"mobile_fota,10,0,2,300000,true"</item>

9、frameworks\base\core\java\android\provider\Settings.java

+ public static final String ACTION_ETHERNET_SETTINGS =

"android.settings.ETHERNET_SETTINGS";

MOVED_TO_GLOBAL.add(Settings.Global.WIFI_WATCHDOG_ON);

MOVED_TO_GLOBAL.add(Settings.Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED);

+MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_ON);

+ MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_MODE);

+MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_IP);

+MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_MASK);

+MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_DNS);

+MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_ROUTE);

+ MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_CONF);

+ MOVED_TO_GLOBAL.add(Settings.Global.ETHERNET_IFNAME);

MOVED_TO_GLOBAL.add(Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON);

MOVED_TO_GLOBAL.add(Settings.Global.PACKAGE_VERIFIER_ENABLE);

public static final String WIFI_P2P_DEVICE_NAME = "wifi_p2p_device_name";

/**

* Ethernet configuration

*/

+public static final String ETHERNET_ON = "eth_on";

+public static final String ETHERNET_MODE = "eth_mode";

+public static final String ETHERNET_IP = "eth_ip";

+public static final String ETHERNET_MASK = "eth_netmask";

+public static final String ETHERNET_DNS = "eth_dns";

+public static final String ETHERNET_ROUTE = "eth_route";

+public static final String ETHERNET_CONF = "eth_conf";

+public static final String ETHERNET_IFNAME = "eth_ifname";

/**

* The min time between wifi disable and wifi enable

* @hide

*/

public static final String WIFI_REENABLE_DELAY_MS = "wifi_reenable_delay";

10、frameworks\base\core\java\android\content\Context.java

+ public static final String

ETHERNET_SERVICE

= "ethernet";

public static final String NSD_SERVICE = "servicediscovery";

11、frameworks\base\api\current.txt

field public static final java.lang.String DROPBOX_SERVICE = "dropbox";

+field public static final java.lang.String ETHERNET_SERVICE = "ethernet";

field public static final java.lang.String INPUT_METHOD_SERVICE = "input_method";

+package android.net.ethernet {

+public class EthernetDevInfo implements android.os.Parcelable {

ctor public EthernetDevInfo();

method public int describeContents();

method public int getConnectMode();

method public java.lang.String getDnsAddr();

method public java.lang.String getGateWay();

method public java.lang.String getHwaddr();

method public java.lang.String getIfName();

method public java.lang.String getIpAddress();

method public java.lang.String getNetMask();

method public void setConnectMode(int);

method public void setDnsAddr(java.lang.String);

method public void setGateWay(java.lang.String);

method public void setHwaddr(java.lang.String);

method public void setIfName(java.lang.String);

method public void setIpAddress(java.lang.String);

method public void setNetMask(java.lang.String);

method public void writeToParcel(android.os.Parcel, int);

field public static final int ETHERNET_CONN_MODE_DHCP = 1; // 0x1

field public static final int ETHERNET_CONN_MODE_MANUAL = 0; // 0x0

}

+public class EthernetManager {

method public boolean addInterfaceToService(java.lang.String);

method public int checkLink(java.lang.String);

method public java.util.List<android.net.ethernet.EthernetDevInfo> getDeviceNameList();

method public static android.net.ethernet.EthernetManager getInstance();

method public android.net.ethernet.EthernetDevInfo getSavedConfig();

method public int getState();

method public int getTotalInterface();

method public boolean isConfigured();

method public boolean isDhcp();

method public boolean isOn();

method public void removeInterfaceFormService(java.lang.String);

method public void updateDevInfo(android.net.ethernet.EthernetDevInfo);

field public static final int ETHERNET_DEVICE_SCAN_RESULT_READY = 2; // 0x2

field public static final java.lang.String ETHERNET_STATE_CHANGED_ACTION = "android.net.ethernet.ETHERNET_STATE_CHANGED";

field public static final int ETHERNET_STATE_DISABLED = 0; // 0x0

field public static final int ETHERNET_STATE_ENABLED = 1; // 0x1

field public static final int EVENT_CONFIGURATION_FAILED = 6; // 0x6

field public static final int EVENT_CONFIGURATION_SUCCEEDED = 5; // 0x5

field public static final int EVENT_DEVREM = 3; // 0x3

field public static final int EVENT_DISCONNECTED = 7; // 0x7

field public static final int EVENT_NEWDEV = 4; // 0x4

field public static final java.lang.String EXTRA_ETHERNET_INFO = "ethernetInfo";

field public static final java.lang.String EXTRA_ETHERNET_STATE = "ethernet_state";

field public static final java.lang.String EXTRA_LINK_PROPERTIES = "linkProperties";

field public static final java.lang.String EXTRA_NETWORK_INFO = "networkInfo";

field public static final java.lang.String NETWORK_STATE_CHANGED_ACTION = "android.net.ethernet.STATE_CHANGE";

}

}

package android.net.http {

field public static final java.lang.String ACTION_DREAM_SETTINGS = "android.settings.DREAM_SETTINGS";

+field public static final java.lang.String ACTION_ETHERNET_SETTINGS = "android.settings.ETHERNET_SETTINGS";

field public static final java.lang.String ACTION_INPUT_METHOD_SETTINGS = "android.settings.INPUT_METHOD_SETTINGS";

field public static final java.lang.String DEVICE_PROVISIONED = "device_provisioned";

+ field public static final java.lang.String ETHERNET_CONF = "eth_conf";

+field public static final java.lang.String ETHERNET_DNS = "eth_dns";

+field public static final java.lang.String ETHERNET_IFNAME = "eth_ifname";

+ field public static final java.lang.String ETHERNET_IP = "eth_ip";

+field public static final java.lang.String ETHERNET_MASK = "eth_netmask";

+ field public static final java.lang.String ETHERNET_MODE = "eth_mode";

+field public static final java.lang.String ETHERNET_ON = "eth_on";

+field public static final java.lang.String ETHERNET_ROUTE = "eth_route";

field public static final java.lang.String HTTP_PROXY = "http_proxy";

三、Framework SystemUI层,主要功能是图标的显示

1、添加的文件如下

frameworks/base/packages/SystemUI/res/drawable-hdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-hdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-mdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-mdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-mdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-mdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-hdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-hdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-xhdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-xhdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-xhdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-sw600dp-xhdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-xhdpi/stat_sys_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_qs_ethernet_established.png

frameworks/base/packages/SystemUI/res/drawable-xhdpi/stat_sys_ethernet_error.png

frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_qs_ethernet_error.png

frameworks/base/packages/SystemUI/res/layout/quick_settings_tile_ethernet.xml

2、frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java

private IconIdWrapper mWifiActivityId = new IconIdWrapper();

private String mWifiDescription;

+private boolean mEthernetVisible = false;

+private int mEthernetStateId = 0, mEthernetActivityId = 0;

+private String mEthernetDescription;

+ViewGroup mEthernetGroup;

+ImageView mEthernet;

private boolean[] mMobileVisible;

private IconIdWrapper[][] mMobileStrengthId;

mSpacer = findViewById(R.id.spacer);

mAirplane = (ImageView) findViewById(R.id.airplane);

+mEthernetGroup = (ViewGroup) findViewById(R.id.ethernet_combo);

+mEthernet = (ImageView) findViewById(R.id.ethernet_state);

mWifiActivity = null;

mDataConnectionGroup = null;

+ mEthernetGroup = null;

+ mEthernet = null;

+ public void setEthernetIndicators(boolean

visible, int strengthIcon, int activityIcon,

String contentDescription) {

+ mEthernetVisible = visible;

+mEthernetStateId = strengthIcon;

+ mEthernetActivityId = activityIcon;

+mEthernetDescription = contentDescription;

+if(mEthernetDescription == null || mEthernetDescription.isEmpty()) {

+ mEthernetDescription = "Ethernet";

+if(DEBUG)

+ Xlog.d(TAG, "mEthernetDescription is empty.");

+}

+apply();

+}

public void setMobileDataIndicators(int slotId, boolean visible, IconIdWrapper[] strengthIcon,

if (DEBUG) {

Xlog.d(TAG, String.format("wifi: %s sig=%d act=%d", (mWifiVisible ? "VISIBLE" : "GONE"), mWifiStrengthId,

mWifiActivityId.getIconId()));

}

+if(mEthernetVisible){

+ mEthernetGroup.setVisibility(View.VISIBLE);

+mEthernet.setImageResource(mEthernetStateId);

+mEthernetGroup.setContentDescription(mEthernetDescription);

+ } else {

+mEthernetGroup.setVisibility(View.GONE);

+ }

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

3、frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\policy\NetworkController.java

import android.net.wifi.WifiManager;

+import android.net.ethernet.EthernetManager;

import android.net.wimax.WimaxManagerConstants;

String mContentDescriptionWimax;

String[] mContentDescriptionDataType;

+ String mContentDescriptionEthernet;

NetworkType[] mNetworkType;

boolean[] mSimIndicatorFlag;

private IconIdWrapper mWifiActivityIconId = new IconIdWrapper();

private int mWifiActivity = WifiManager.DATA_ACTIVITY_NONE;

+// ethernet

+ boolean mEthernetConnected;

+ // record the last connected state

+boolean mLastEthernetConnected = false;

+ int mEthernetIconId = R.drawable.stat_sys_ethernet_error;

+int mEthernetActivityIconId = 0; // overlay arrows for ethernet direction

// bluetooth

private boolean mBluetoothTethered = false;

private int mBluetoothTetherIconId =

void setShowSimIndicator(int slotId, boolean showSimIndicator,int resId);

void apply();

+void setEthernetIndicators(boolean visible, int strengthIcon,

int activityIcon, String contentDescription);

filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);

+filter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION);

filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);

// only show ethernet int the cluster if connected or connecting

+++cluster.setEthernetIndicators(

+mEthernetConnected,

+mEthernetIconId,

+ mEthernetActivityIconId,

+mContentDescriptionEthernet);

if (mIsWimaxEnabled && mWimaxConnected) {

// wimax is special

cluster.setMobileDataIndicators(

} else if (action.equals(WimaxManagerConstants.NET_4G_STATE_CHANGED_ACTION) ||

action.equals(WimaxManagerConstants.SIGNAL_LEVEL_CHANGED_ACTION) ||

action.equals(WimaxManagerConstants.WIMAX_NETWORK_STATE_CHANGED_ACTION)) {

updateWimaxState(intent);

refreshViews();

} +else if (action.equals(EthernetManager.NETWORK_STATE_CHANGED_ACTION)) {

+if(DEBUG) {

+ Xlog.d(TAG, "EthernetManger network state change.");

+ }

+ updateEthernetState(intent);

+refreshViews();

}else if (action.equals(Intent.SIM_SETTINGS_INFO_CHANGED)) {=

// ===== Ethernet State =========================================================

+private void updateEthernetState(Intent intent) {

final String action = intent.getAction();

if(DEBUG) {

Log.d(TAG, "updateEthernetState(), action = " + action);

}

if (action.equals(EthernetManager.NETWORK_STATE_CHANGED_ACTION)) {

final NetworkInfo networkInfo =

(NetworkInfo) intent.getParcelableExtra(EthernetManager.EXTRA_NETWORK_INFO);

mEthernetConnected = networkInfo != null && networkInfo.isConnected();

if(DEBUG) {

Log.d(TAG, "updateEthernetState: mEthernetConnected = " + mEthernetConnected + ".");

}

}

updateEthernetIcons();

}

+private void updateEthernetIcons(){

if (mEthernetConnected) {

mEthernetIconId = R.drawable.stat_sys_ethernet_established;

mContentDescriptionEthernet = mContext.getString(R.string.ethernet_description);

} else {

mEthernetIconId = R.drawable.stat_sys_ethernet_error;

//mContentDescriptionEthernet = "DISCONNECTED";

}

}

// ===== Wimax ===================================================================

private final void updateWimaxState(Intent intent) {

updateTelephonySignalStrength(slotId);

updateWifiIcons();

+ updateEthernetIcons();

if (mBluetoothTethered) {

combinedLabel = mContext.getString(R.string.bluetooth_tethered);

combinedSignalIconId.setResources(null);

combinedSignalIconId.setIconId(mBluetoothTetherIconId);

tempContentDescriptionCombinedSignal = mContext.getString(

R.string.accessibility_bluetooth_tether);

}

+ if (mEthernetConnected) {

+ if(DEBUG) {

+Xlog.d(TAG, "show ethernet icon in statusbar.");

+ }

+combinedLabel = mContext.getString(R.string.ethernet_link);//change below to "Ethernet"

+ //combinedSignalIconId = mEthernetIconId;

+combinedSignalIconId.setResources(null);

+combinedSignalIconId.setIconId(mEthernetIconId);

+ tempContentDescriptionCombinedSignal = mContentDescriptionEthernet;

+ }

+ final boolean ethernetConnected = (mConnectedNetworkType == ConnectivityManager.TYPE_ETHERNET);

+if (ethernetConnected) {//Michael_LeePP for ethernet

+ // TODO: icons and strings for Ethernet connectivity

+ //combinedLabel = mConnectedNetworkTypeName;

+ combinedLabel = context.getString(R.string.ethernet_label);

+ }

if (mAirplaneMode &&

tempContentDescriptionCombinedSignal = tempContentDescriptionPhoneSignal;

combinedSignalIconId = tempDataSignalIconId.clone();

}

} +else if (!tempDataConnected && !mWifiConnected && !mBluetoothTethered && !mWimaxConnected && !mEthernetConnected) {

// pretty much totally disconnected

combinedLabel = context.getString(R.string.status_bar_settings_signal_meter_disconnected);

// update QS

for (NetworkSignalChangedCallback cb : mSignalsChangedCallbacks) {

notifySignalsChangedCallbacks(cb);

}

+boolean isEthernetStateChanged = (mLastEthernetConnected != mEthernetConnected);

+if(DEBUG) {

+Xlog.d(TAG, "mLastEthernetConnected= " + mLastEthernetConnected+ ", mEthernetConnected= " + mEthernetConnected);

+}

+mLastEthernetConnected = mEthernetConnected;

if (tempLastPhoneSignalIconId[0] != tempPhoneSignalIconId[0].getIconId()

|| tempLastPhoneSignalIconId[1] != tempPhoneSignalIconId[1].getIconId()

|| mLastDataDirectionOverlayIconId != combinedActivityIconId.getIconId()

|| mLastWifiIconId != mWifiIconId.getIconId()

|| mLastWimaxIconId != mWimaxIconId

|| tempLastDataTypeIconId != tempDataTypeIconId.getIconId()

+|| isEthernetStateChanged

|| tempLastMobileActivityIconId != tempMobileActivityIconId.getIconId()

|| mLastAirplaneMode != mAirplaneMode

|| mLastLocale != mLocale) {

4、frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\QuickSettingsModel.java

private QuickSettingsTileView mRemoteDisplayTile;

private RefreshCallback mRemoteDisplayCallback;

private State mRemoteDisplayState = new State();

+private QuickSettingsTileView mEthernetTile;

+private RefreshCallback mEthernetCallback;

+ private State mEthernetState = new State();

// Ethernet

+ void addEthernetTile(QuickSettingsTileView view, RefreshCallback cb) {

mEthernetTile = view;

mEthernetCallback = cb;

}

+public void onEthernetStateChanged(boolean on) {

mEthernetState.enabled = on;

if (on) {

mEthernetState.label = mContext.getString(R.string.quick_settings_ethernet_label);

mEthernetState.iconId = R.drawable.ic_qs_ethernet_established;

} else {

mEthernetState.label = mContext.getString(

R.string.quick_settings_ethernet_no_connection_label);

mEthernetState.iconId = R.drawable.ic_qs_ethernet_error;

}

mEthernetCallback.refreshView(mEthernetTile, mEthernetState);

}

// Time

void addTimeTile(QuickSettingsTileView view, RefreshCallback cb) {

mTimeTile = view;

mTimeCallback = cb;

mTimeCallback.refreshView(view, mTimeState);

}

5、frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\QuickSettings.java

import android.media.MediaRouter;

import android.net.wifi.WifiManager;

+import android.net.ethernet.EthernetManager;

+import android.net.ConnectivityManager;

+import android.net.NetworkInfo;

import android.net.Uri;

import android.os.AsyncTask;

private WifiManager mWifiManager;

+ private ConnectivityManager mCm;

+private boolean mEthernetConnected;

private BluetoothController mBluetoothController;

private RotationLockController mRotationLockController;

mHandler = new Handler();

+mCm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

+ if(mCm != null) {

+ NetworkInfo networkinfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);

+ if(networkinfo.isConnected()) {

+ mEthernetConnected = true;

+} else {

+mEthernetConnected = false;

+ }

+ } else

+ mEthernetConnected = false;

IntentFilter filter = new IntentFilter();

filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);

filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);

filter.addAction(KeyChain.ACTION_STORAGE_CHANGED);

+filter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION);

mContext.registerReceiver(mReceiver, filter);

setupQuickSettings();

updateResources();

applyLocationEnabledStatus();

+updateEthernetStatus();

mModel.addRemoteDisplayTile(remoteDisplayTile,

new QuickSettingsModel.BasicRefreshCallback(remoteDisplayTile)

.setShowWhenEnabled(true));

parent.addView(remoteDisplayTile);

// Ethernet

+QuickSettingsTileView ethernetTile = (QuickSettingsTileView)

inflater.inflate(R.layout.quick_settings_tile, parent, false);

ethernetTile.setContent(R.layout.quick_settings_tile_ethernet, inflater);

ethernetTile.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

startSettingsActivity(android.provider.Settings.ACTION_ETHERNET_SETTINGS);

}

});

+ mModel.addEthernetTile(ethernetTile, new QuickSettingsModel.RefreshCallback() {

@Override

public void refreshView(QuickSettingsTileView view, State state) {

TextView tv = (TextView) view.findViewById(R.id.ethernet_textview);

tv.setText(state.label);

tv.setCompoundDrawablesWithIntrinsicBounds(0, state.iconId, 0, 0);

view.setVisibility(state.enabled ? View.VISIBLE : View.GONE);

}

});

+ parent.addView(ethernetTile);

if (SHOW_IME_TILE || DEBUG_GONE_TILES) {

+private void updateEthernetStatus() {

mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

if(mCm != null) {

NetworkInfo networkinfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);

if(networkinfo.isConnected()) {

mEthernetConnected = true;

} else {

mEthernetConnected = false;

}

} else

mEthernetConnected = false;

applyEthernetStatus();

}

+ private void applyEthernetStatus() {

mModel.onEthernetStateChanged(mEthernetConnected);

}

private void applyBluetoothStatus() {

mModel.onBluetoothStateChange(mBluetoothState);

}

}+ else if(EthernetManager.NETWORK_STATE_CHANGED_ACTION.equals(action)){

+ final NetworkInfo networkInfo =

+ (NetworkInfo) intent.getParcelableExtra(EthernetManager.EXTRA_NETWORK_INFO);

+ mEthernetConnected = networkInfo != null && networkInfo.isConnected();

+ applyEthernetStatus();

} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {

reloadUserInfo();

6、frameworks\base\packages\SystemUI\res\layout\gemini_signal_cluster_view.xml && signal_cluster_view.xml

+<FrameLayout

android:id="@+id/ethernet_combo"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:layout_marginStart="6dp"

android:layout_marginEnd="-6dp">

+<ImageView

android:id="@+id/ethernet_state"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:layout_alignParentEnd="true"

android:layout_centerVertical="true"

android:scaleType="center"/>

+ </FrameLayout>

<View

android:layout_height="8dp"

android:layout_width="8dp"

android:visibility="gone"

android:id="@+id/spacer"

/>

7、frameworks\base\packages\SystemUI\res\values\strings.xml

<!-- Content description of the clear button in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->

<string name="accessibility_clear_all">Clear all notifications.</string>

+ <!-- ethernet string -->

+<string name="ethernet_link">Ethernet connect to network</string>

+<string name="ethernet_description">Ethernet</string>

<!-- Title shown in notification popup for inspecting the responsible

application -->

<string name="status_bar_notification_inspect_item_title">App info</string>

<string name="quick_settings_brightness_dialog_auto_brightness_label">AUTO</string>

+ <!-- QuickSettings: Ethernet [CHAR LIMIT=NONE] -->

+<string name="quick_settings_ethernet_label">Connected</string>

+<!-- QuickSettings: Ethernet [CHAR LIMIT=NONE] -->

+<string name="quick_settings_ethernet_no_connection_label">No Connection</string>

<!-- Glyph to be overlaid atop the battery when the level is extremely low. Do not translate. -->

<string name="battery_meter_very_low_overlay_symbol">!</string>

四、package/apps/Settings

1、添加文件

packages\apps\Settings\src\com\android\settings\ethernet

packages\apps\Settings\res\layout\ethernet_dialog.xml

packages\apps\Settings\res\xml\ethernet_settings.xml

2、packages\apps\Settings\AndroidManifest.xml

+<activity android:name="Settings$EthernetSettingsActivity"

android:label="@string/eth_settings_title"

android:taskAffinity=""

android:excludeFromRecents="true">

+ <intent-filter>

<action android:name="android.intent.action.MAIN" />

<action android:name="android.settings.ETHERNET_SETTINGS" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.VOICE_LAUNCH" />

<category android:name="com.android.settings.SHORTCUT" />

+ </intent-filter>

+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"

android:value="com.android.settings.ethernet.EthernetSettings" />

<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"

android:resource="@id/wireless_settings" />

<meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"

android:resource="@string/wireless_networks_settings_title" />

<meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"

android:value="com.android.settings.Settings$WirelessSettingsActivity" />

+ </activity>

<activity android:name="Settings$VpnSettingsActivity"

android:label="@string/vpn_settings_title"

android:taskAffinity=""

android:excludeFromRecents="true"

3、\packages\apps\Settings\res\values\strings.xml

<!-- Text to display in regulatory info screen (from device overlay). -->

<string name="regulatory_info_text"></string>

+ <!-- Ethernet Settings settings title [CHAR LIMIT=20] -->

+<string name="eth_settings_title">Ethernet</string>

+<string name="eth_toggle_title">Use Ethernet</string>

+<string name="eth_settings">Ethernet Settings</string>

+ <string name="eth_devices">Ethernet Devices</string>

+ <string name="eth_conf">Ethernet Configure</string>

+ <string name="eth_ip_address">IP Address</string>

+<string name="eth_ip_string">0.0.0.0</string>

+<string name="eth_mac_address">MAC Address</string>

+<string name="eth_mac_string">00:00:00:00:00:00</string>

+<string name="eth_advanced_configure">Advanced Configure</string>

+<string name="eth_mask_address">Mask Address</string>

+ <string name="eth_dns_address">DNS Server</string>

+<string name="eth_gw_address">GateWay</string>

+<string name="eth_dhcp_choice">DHCP</string>

+<string name="eth_dev_more">None Device</string>

+ <string name="eth_dev_summaryoff">DISCONNECTED</string>

+ <string name="eth_dev_summaryon">CONNECTED -- USED DEVICE: </string>

+ <string name="eth_link_status">Link Status</string>

+ <string name="eth_link_mode">Link Mode</string>

+ <string name="eth_ip_mode">IP Mode: </string>

+ <string name="eth_dhcp_mode">DHCP</string>

+ <string name="eth_manual_mode">MANUAL</string>

+ <string name="eth_ok">Ok</string>

+<string name="eth_cancel">Cancel</string>

+<string name="eth_advand">Advand</string>

+<string name="eth_message">Are you apply this device?</string>

4、apps\Settings\res\xml\wireless_settings.xml

<PreferenceScreen

android:fragment="com.android.settings.TetherSettings"

android:key="tether_settings"

android:title="@string/tether_settings_title_all" />

+<PreferenceScreen

+android:fragment="com.android.settings.ethernet.EthernetSettings"

+ android:key="ethernet_settings"

+android:title="@string/eth_settings_title" />

<PreferenceScreen

android:fragment="com.android.settings.vpn2.VpnSettings"

android:key="vpn_settings"

android:title="@string/vpn_settings_title" />