Esempio n. 1
0
 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);
   }
 }
Esempio n. 2
0
 @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);
 }