Exemplo n.º 1
0
 private void updateQosRule(int uploadSpeed, int downloadSpeed, String ip) {
   QosObj qosObj = new QosObj(uploadSpeed, downloadSpeed, ip, qosRule.getIndex());
   String ssid = WifiManagerUtil.getWifiName(mContext);
   boolean is5 = (ssid != null && ssid.equals(Settings.getNetName5(mContext)));
   if (Global.getInstance(mContext).isOuterNet()) {
     XMPPClient xmppClient = Global.getInstance(mContext).getXMPPClient();
     if (xmppClient != null && xmppClient.isConnected()) {
       if (is5)
         xmppClient.updateQosRule5(
             Settings.getMacAddress(mContext),
             Settings.getRouteMacAddress(mContext),
             uploadSpeed + "-" + downloadSpeed + "-" + qosObj.getClass() + "-" + ip);
       else
         xmppClient.updateQosRule2(
             Settings.getMacAddress(mContext),
             Settings.getRouteMacAddress(mContext),
             uploadSpeed + "-" + downloadSpeed + "-" + qosObj.getClass() + "-" + ip);
     }
   } else {
     shareCircleClient = Global.getInstance(mContext).getShareCircleClient();
     if (shareCircleClient.isConnected()) {
       UserMessage message = new UserMessage();
       PdmClientMessage clientMsg = new PdmClientMessage(qosObj, null);
       if (is5) {
         message.messageType = PdmClientMessageType.SET_DEVICE_QOSRULE_5.intValue();
       } else {
         message.messageType = PdmClientMessageType.SET_DEVICE_QOSRULE_2.intValue();
       }
       message.messageData = clientMsg;
       shareCircleClient.sendMessage(message);
     } else {
       Toast.makeText(mContext, R.string.network_disconnect, Toast.LENGTH_SHORT).show();
     }
   }
 }
Exemplo n.º 2
0
 private void initLimit(ConnectDevice device) {
   qosRule = device.qosRule;
   if (qosRule == null) { // 没有设置流量限制
     qosRule = new QosRule();
     uploadState = false;
     downloadState = false;
   } else {
     if (qosRule.getUplinkSpeed() == null || qosRule.getUplinkSpeed().contains("-")) {
       uploadState = false;
       uploadText.setText("0");
     } else {
       uploadState = true;
       String uploadSeepText = MyUtils.formatNetRate(qosRule.getUplinkSpeed());
       if (uploadSeepText.endsWith("K")) {
         uploadUnit = UnitType.KB;
         uploadText.setText(uploadSeepText.substring(0, uploadSeepText.indexOf("K")).trim());
       } else {
         uploadUnit = UnitType.MB;
         uploadText.setText(uploadSeepText.substring(0, uploadSeepText.indexOf("M")).trim());
       }
       tv_uploadUnit.setText(uploadUnit.getText());
     }
     if (StringUtil.isNullOrEmpty(qosRule.getDownlinkSpeed())
         || qosRule.getDownlinkSpeed().contains("-")) {
       downloadText.setText("0");
       downloadState = false;
     } else {
       downloadState = true;
       String downloadSeepText = MyUtils.formatNetRate(qosRule.getDownlinkSpeed());
       if (downloadSeepText.endsWith("K")) {
         downloadUnit = UnitType.KB;
         downloadText.setText(downloadSeepText.substring(0, downloadSeepText.indexOf("K")).trim());
       } else {
         downloadUnit = UnitType.MB;
         downloadText.setText(downloadSeepText.substring(0, downloadSeepText.indexOf("M")).trim());
       }
       tv_downloadUnit.setText(downloadUnit.getText());
     }
   }
 }