全志文件管理器移植到RK3288(三)----修改文件浏览器
需要修改的地方:
1,修改文件浏览器源码
2,根据文件浏览器报错修改framework
首先把全志文件浏览器工程导入到eclipse,把编译好的系统jar引入工程。发现好多报错。一步步来。
上一篇文章,我们修改了swextend里java的包名,所有我们也要修改import,如:import com.softwinner.SystemMix;修改为:import android.com.softwinner.SystemMix;其它一样的该法。改好后报错会少很多。
接着改,以下是参考http://blog.csdn.net/bolin675149/article/details/38435099
修改framework/base/core/java/android/net/EthernetDataTracker ,在方法sendEthStateChangedBroadcast()修改,这个从函数名就知道是网络改变发送广播的意思了。我们把需要的netmask通过这个函数发送出去。修改如下:
private void sendEthStateChangedBroadcast(int curState) {
ethCurrentState=curState;
final Intent intent = new Intent(ETHERNET_STATE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); //
intent.putExtra(EXTRA_ETHERNET_STATE, curState);
intent.putExtra(EthernetManager.EXTRA_LINK_PROPERTIES,
new LinkProperties (mLinkProperties));
intent.putExtra(EthernetManager.EXTRA_NET_MASK,mNetmask); //这里就关键,具体mNetmask是哪里赋值,自己看源码就知道
mContext.sendStickyBroadcast(intent);
}
还有EthernetManager.EXTRA_LINK_PROPERTIES、EthernetManager.EXTRA_NET_MASK,这个需要在frameworks/base/ethernet/java/android/net/ethernet/EthernetManager.java下定义:
public static final String EXTRA_LINK_PROPERTIES = "linkProperties";
public static final String EXTRA_NET_MASK ="netmask";
因为无线网络模块都是用android源生的,所以不用改。
应用层也要对应修改:修改SambaManager
private BroadcastReceiver mNetStatusReveicer;
private void initSambaProp(){
Log.e(TAG, "#initSambaProp...");
jcifs.Config.setProperty("jcifs.encoding", "GBK");
jcifs.Config.setProperty("jcifs.util.loglevel", "0");
LocalNetwork.setCurIpv4("172.16.10.66",null);
mNetStatusReveicer = new BroadcastReceiver() {
private String intToIp(int paramInt) {
return (paramInt & 0xFF) + "." + (0xFF & paramInt >> 8) + "." + (0xFF & paramInt >> 16) + "."
+ (0xFF & paramInt >> 24);
}
@Override
public void onReceive(Context context, Intent intent) {
EthernetManager mEthernetManager;
String action = intent.getAction();
NetworkInfo info;
LinkProperties link;
Log.d("Samba", "Networks action:" + action);
if(action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
info = (NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
link = (LinkProperties)intent.getParcelableExtra(WifiManager.EXTRA_LINK_PROPERTIES);
if(info.getDetailedState() == DetailedState.CONNECTED){
WifiManager wifiMng = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcpInfo = wifiMng.getDhcpInfo();
String netMask = null;
if(dhcpInfo != null)
netMask = intToIp(dhcpInfo.netmask);
for(LinkAddress l:link.getLinkAddresses()){
LocalNetwork.setCurIpv4(l.getAddress().getHostAddress(),netMask);
return;
}
}
}else if(action.equals(EthernetDataTracker.ETHERNET_STATE_CHANGED_ACTION)){
EthernetDataTracker mEthernetDataTracker = EthernetDataTracker.getInstance();
mEthernetDataTracker.getDefaultGatewayAddr();
ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean ethConnected = cm.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnected();
link = (LinkProperties)intent.getParcelableExtra(EthernetManager.EXTRA_LINK_PROPERTIES);
String netMask = intent.getStringExtra(EthernetManager.EXTRA_NET_MASK);
if(netMask==null||netMask.equals("")){
netMask =mNetMask;
}
if(link!=null)
for(LinkAddress l:link.getLinkAddresses()){
LocalNetwork.setCurIpv4(l.getAddress().getHostAddress(), netMask);
return;
}
}
}
}
};
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
//filter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION);
filter.addAction(EthernetDataTracker.ETHERNET_STATE_CHANGED_ACTION);
mContext.registerReceiver(mNetStatusReveicer, filter);
}
好了,基本上要改的都改了,可能还有一些细节漏了,毕竟做了一个多月后才写的。