Esempio n. 1
0
 private boolean addRoot(String pathname, String filename, boolean listIt) {
   FileInfo dir = new FileInfo();
   dir.isDirectory = true;
   dir.pathname = pathname;
   dir.filename = filename;
   if (findRoot(pathname) != null) {
     log.w("skipping duplicate root " + pathname);
     return false; // exclude duplicates
   }
   if (listIt) {
     log.i("Checking FS root " + pathname);
     if (!dir.isReadableDirectory()) { // isWritableDirectory
       log.w("Skipping " + pathname + " - it's not a readable directory");
       return false;
     }
     if (!listDirectory(dir)) {
       log.w("Skipping " + pathname + " - listing failed");
       return false;
     }
     log.i("Adding FS root: " + pathname + "  " + filename);
   }
   mRoot.addDir(dir);
   dir.parent = mRoot;
   if (!listIt) {
     dir.isListed = true;
     dir.isScanned = true;
   }
   return true;
 }
 /**
  * Send a WARN message and log the exception.
  *
  * @param tag Used to identify the source of a log message. It usually identifies the class or
  *     activity where the log call occurs.
  * @param formatString The string you would like logged plus format specifiers.
  * @param tr An exception to log
  * @param args Variable number of Object args to be used as params to formatString.
  */
 public static void w(String tag, String formatString, Throwable tr, Object... args) {
   if (logger != null && isLoggingEnabled(tag, WARN)) {
     try {
       logger.w(tag, String.format(formatString, args));
     } catch (Exception e) {
       logger.w(tag, String.format("Unable to format log: %s", formatString), e);
     }
   }
 }
  @Test
  public void warningLoggedCorrectly() {
    String expectedMessage = "Hello World";

    logger.w(tag, "Hello %s", "World");

    assertLogged(WARN, tag, expectedMessage, null);
  }
  @Test
  public void warningWithThrowableLoggedCorrectly() {
    String expectedMessage = "Hello World";
    Throwable t = new Throwable("Test Throwable");

    logger.w(t, tag, "Hello %s", "World");

    assertLogged(WARN, tag, expectedMessage, t);
  }
Esempio n. 5
0
  private void flushLogToDB(Context context) {
    try {
      int logSize = SettingsStorage.getInstance().getProfileSwitchLogSize();
      if (logSize > -1) {
        Builder opp = ContentProviderOperation.newDelete(DB.SwitchLogDB.CONTENT_URI);
        String time = Long.toString(System.currentTimeMillis() - (logSize * HOURS_IN_MILLIES));
        opp.withSelection(DB.SwitchLogDB.SELECTION_BY_TIME, new String[] {time});
        operations.add(opp.build());
      }

      context.getContentResolver().applyBatch(CpuTunerProvider.AUTHORITY, operations);
      operations.clear();
    } catch (Exception e) {
      Logger.w("Cannot flush to switch log");
    }
  }
 @TargetApi(11)
 public static <T> AsyncTask<T, ?, ?> executeTaskOnExecutor(AsyncTask<T, ?, ?> task, T... arg) {
   for (int i = 0; i < 2; i++) {
     try {
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
         task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arg);
       } else {
         task.execute(arg);
       }
       break;
     } catch (RejectedExecutionException ignore) {
       Logger.w("unable to start thread", ignore);
       sleep(1000);
     }
   }
   return task;
 }
  /** App needs to give permission to AccountManager to use broker. */
  private boolean verifyManifestPermissions() {
    PackageManager pm = mContext.getPackageManager();
    boolean permission =
        PackageManager.PERMISSION_GRANTED
                == pm.checkPermission("android.permission.GET_ACCOUNTS", mContext.getPackageName())
            && PackageManager.PERMISSION_GRANTED
                == pm.checkPermission(
                    "android.permission.MANAGE_ACCOUNTS", mContext.getPackageName())
            && PackageManager.PERMISSION_GRANTED
                == pm.checkPermission(
                    "android.permission.USE_CREDENTIALS", mContext.getPackageName());
    if (!permission) {
      Logger.w(
          TAG,
          "Broker related permissions are missing for GET_ACCOUNTS, MANAGE_ACCOUNTS, USE_CREDENTIALS",
          "",
          ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING);
    }

    return permission;
  }
 /**
  * Send a WARN message and log the exception.
  *
  * @param tag Used to identify the source of a log message. It usually identifies the class or
  *     activity where the log call occurs.
  * @param msg The message you would like logged.
  * @param tr An exception to log
  */
 public static void w(String tag, String msg, Throwable tr) {
   if (logger != null && isLoggingEnabled(tag, WARN)) {
     logger.w(tag, msg, tr);
   }
 }
Esempio n. 9
0
 /**
  * Adds dir and file children to directory FileInfo item.
  *
  * @param baseDir is directory to list files and dirs for
  * @return true if successful.
  */
 public boolean listDirectory(FileInfo baseDir) {
   Set<String> knownItems = null;
   if (baseDir.isListed) {
     knownItems = new HashSet<String>();
     for (int i = baseDir.itemCount() - 1; i >= 0; i--) {
       FileInfo item = baseDir.getItem(i);
       if (!item.exists()) {
         // remove item from list
         baseDir.removeChild(item);
       } else {
         knownItems.add(item.getBasePath());
       }
     }
   }
   try {
     File dir = new File(baseDir.pathname);
     File[] items = dir.listFiles();
     // process normal files
     if (items != null) {
       for (File f : items) {
         // check whether file is a link
         if (Engine.isLink(f.getAbsolutePath()) != null) {
           log.w("skipping " + f + " because it's a link");
           continue;
         }
         if (!f.isDirectory()) {
           // regular file
           if (f.getName().startsWith(".")) continue; // treat files beginning with '.' as hidden
           if (f.getName().equalsIgnoreCase("LOST.DIR")) continue; // system directory
           String pathName = f.getAbsolutePath();
           if (knownItems != null && knownItems.contains(pathName)) continue;
           if (engine.isRootsMountPoint(pathName)) {
             // skip mount root
             continue;
           }
           boolean isZip = pathName.toLowerCase().endsWith(".zip");
           FileInfo item = mFileList.get(pathName);
           boolean isNew = false;
           if (item == null) {
             item = new FileInfo(f);
             if (isZip) {
               item = scanZip(item);
               if (item == null) continue;
               if (item.isDirectory) {
                 // many supported files in ZIP
                 item.parent = baseDir;
                 baseDir.addDir(item);
                 for (int i = 0; i < item.fileCount(); i++) {
                   FileInfo file = item.getFile(i);
                   mFileList.put(file.getPathName(), file);
                 }
               } else {
                 item.parent = baseDir;
                 baseDir.addFile(item);
                 mFileList.put(pathName, item);
               }
               continue;
             }
             isNew = true;
           }
           if (item.format != null) {
             item.parent = baseDir;
             baseDir.addFile(item);
             if (isNew) mFileList.put(pathName, item);
           }
         }
       }
       // process directories
       for (File f : items) {
         if (f.isDirectory()) {
           if (f.getName().startsWith(".")) continue; // treat dirs beginning with '.' as hidden
           FileInfo item = new FileInfo(f);
           if (knownItems != null && knownItems.contains(item.getPathName())) continue;
           item.parent = baseDir;
           baseDir.addDir(item);
         }
       }
     }
     baseDir.isListed = true;
     return !baseDir.isEmpty();
   } catch (Exception e) {
     L.e("Exception while listing directory " + baseDir.pathname, e);
     baseDir.isListed = true;
     return false;
   }
 }