/*
 * Copyright (C) 2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cyanogenmod.hardware;

import org.cyanogenmod.hardware.util.FileUtils;

import java.io.File;

public class VibratorHW {

    private static String LEVEL_PATH = "/sys/class/timed_output/vibrator/intensity";

    public static boolean isSupported() {
        File f = new File(LEVEL_PATH);
        return f.exists();
    }

    public static int getMaxIntensity()  {
        return 10000;
    }

    public static int getMinIntensity()  {
        return 0;
    }

    public static int getWarningThreshold()  {
        return 9000;
    }

    public static int getCurIntensity()  {
        File f = new File(LEVEL_PATH);
        String actualIntensity = FileUtils.readOneLine(LEVEL_PATH).replace("intensity: ", "");

        return f.exists() ? Integer.parseInt(actualIntensity) : 0;
    }

    public static int getDefaultIntensity()  {
        return 7500;
    }

    public static boolean setIntensity(int intensity)  {
        File f = new File(LEVEL_PATH);

        return f.exists() && FileUtils.writeLine(LEVEL_PATH, String.valueOf(intensity));
    }
}

@@ -664,24 +664,24 @@
 ogenmod.
-hardware
+internal
 .util.Fi
@@ -694,30 +694,8 @@
 s;%0A%0A
-import java.io.File;%0A%0A
 publ
@@ -857,63 +857,90 @@
     
-File f = new File(LEVEL_PATH);%0A        return f.exists(
+return FileUtils.isFileReadable(LEVEL_PATH) && FileUtils.isFileWritable(LEVEL_PATH
 );%0A 
@@ -1207,39 +1207,50 @@
   %7B%0A        
-File f = new Fi
+if (FileUtils.isFileReadab
 le(LEVEL_PAT
@@ -1247,26 +1247,32 @@
 (LEVEL_PATH)
-;%0A
+) %7B%0A    
         Stri
@@ -1354,17 +1354,20 @@
 %22, %22%22);%0A
-%0A
+    
         
@@ -1376,21 +1376,8 @@
 turn
- f.exists() ?
  Int
@@ -1410,10 +1410,34 @@
 ity)
- :
+;%0A        %7D%0A        return
  0;%0A
@@ -1587,23 +1587,34 @@
     
-File f = new Fi
+if (FileUtils.isFileWritab
 le(L
@@ -1623,19 +1623,24 @@
 EL_PATH)
-;%0A%0A
+) %7B%0A    
         
@@ -1649,22 +1649,8 @@
 turn
- f.exists() &&
  Fil
@@ -1706,16 +1706,48 @@
 sity));%0A
+        %7D%0A        return false;%0A
     %7D%0A%7D%0A

Update for CMSDK FileUtils