コード例 #1
0
ファイル: FakeRouter.java プロジェクト: brentn/TomatoHub
 private void setupFakeDevices() {
   mDevices = new Devices(mContext);
   mDevices.removeFakeDevices(getRouterId());
   mTimestamp = System.currentTimeMillis();
   getNetworkIds();
   int total_devices = rnd.nextInt(40) + 3;
   Log.d(TAG, "Generating " + total_devices + " fake devices");
   for (int i = 0; i < total_devices; i++) {
     Device device = new Device(getRouterId(), randomMACAddress(), randomDeviceName());
     device.setCurrentIP("192.168.1." + (rnd.nextInt(253) + 1));
     device.setCurrentNetwork(mNetworkIds[rnd.nextInt(mNetworkIds.length)]);
     device.setActive(rnd.nextInt(100) < 25);
     device.setTrafficStats(0, 0, mTimestamp - 60000); // 1 min ago
     mDevices.insertOrUpdate(device);
   }
 }
コード例 #2
0
ファイル: FakeRouter.java プロジェクト: brentn/TomatoHub
 @Override
 public void updateTrafficStats() {
   long now = System.currentTimeMillis();
   for (String networkId : mNetworkIds) {
     for (Device d : mDevices.getDevicesOnNetwork(getRouterId(), networkId)) {
       if (d.isActive()) {
         long elapsed_time = (now - mTimestamp) / 1000;
         long bytes = Math.round(Math.pow((rnd.nextInt(5000) / 10000F), -1.7) * 10240);
         long traffic = Math.round((float) bytes / elapsed_time);
         d.setTrafficStats(traffic, traffic, now);
         mDevices.insertOrUpdate(d);
       }
     }
   }
   mTimestamp = now;
   handler.postDelayed(
       new Runnable() {
         @Override
         public void run() {
           mListener.onRouterActivityComplete(ACTIVITY_TRAFFIC_UPDATED, ACTIVITY_STATUS_SUCCESS);
         }
       },
       300);
 }