Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73673c01 authored by Sahil Sonar's avatar Sahil Sonar 💬 Committed by Nishith Khanna
Browse files

UdfpsController: Ensure node is writeable before proceeding

parent 57e66942
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ import kotlin.Unit;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.ExperimentalCoroutinesApi;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
@@ -251,15 +252,30 @@ public class UdfpsController implements DozeReceiver, Dumpable {

    private void writeToUdfpsNode(String path, String value) {
         mBiometricExecutor.execute(() -> {
             if (isFileWritable(path)) {
                 try (FileWriter writer = new FileWriter(path)) {
                      writer.write(value);
                      Log.d(TAG, "Successfully set " + path + " to " + value);
                 } catch (IOException e) {
                      Log.e(TAG, "Failed to write to " + path, e);
                 }
             }
         });
    }

    private boolean isFileWritable(String path) {
         File file = new File(path);
         if (!file.exists()) {
              Log.e(TAG, "File does not exist: " + path);
              return false;
         }
         if (!file.canWrite()) {
              Log.e(TAG, "File is not writable: " + path);
              return false;
         }
         return true;
    }

    @VisibleForTesting
    public static final VibrationAttributes UDFPS_VIBRATION_ATTRIBUTES =
            new VibrationAttributes.Builder()