I am trying to write to eeprom (at24) from user space in android.
I got the exception
com.ipil.ipilMdm.service.lib I/System.out: java.io.FileNotFoundException: /sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom (No such file or directory)
The path mentioned works perfect from echo and cat in command line. It is also tested in linux based application where it is opened as a read-write file.
I have added the permissions in manifest file. What else might be the issue?
Below is my code:
@Override
public void prod_eeprom_write(String data, int id) {
String someText = "Writesomething";
//String fileName = Environment.getRootDirectory().getAbsolutePath();
final File permFile = new File("/sys/devices/soc.0/78ba000.i2c/i2c-6/6-0050/eeprom");
try {
/* if (file == null) {
System.out.print("error open\n");
return;
}*/
//=================== Condition for action==========================
switch (id) {
case IMEI_NUMBER:
offset = IMEI_NUMBER_OFFSET;
length = IMEI_NUMBER_LENGTH;
break;
case HARDWARE_REVISION:
offset = HW_REV_OFFSET;
length = HW_REV_LENGTH;
break;
case WIFI_MAC_ADDRESS:
offset = WIFI_MAC_OFFSET;
length = WIFI_MAC_LENGTH;
break;
case BT_MAC_ADDRESS:
offset = BT_MAC_OFFSET;
length = BT_MAC_LENGTH;
break;
default : return;
}
/* now got offset and length, so update max buffer */
//strncpy(data,max_data.length + offset, length);
if (data.length() < length)
length = data.length();
if(data.length() > length){
System.out.print("LENGTH OF DATA IS TOO BIG : CAN NOT WRITE\nMAX LENGTH IS %d BYTES\n"+ length);
return;
}
//strncpy(data, max_data.length + offset, data.length());
max_data[INFO_MAX_LENGTH] = '\0';
System.out.println("DATA TO BE WRITTEN TO EEPROM: "+ data);
//if(file.canWrite()){
fileOutputStream = new FileOutputStream(permFile);
byte[] b = data.getBytes(); //new byte[max_data.length];
//for (int i = 0; i < b.length; i++)
// b[i] = (byte) max_data[i];
fileOutputStream.write(b, max_data.length + offset, data.length());
Log.i(TAG, " prod_eeprom_written-----------ok : hogya ");
Thread.sleep(10);
fileOutputStream.close();
System.out.println("success...");
}catch (Exception io){
io.printStackTrace();
}
}