Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chmod failed: EPERM (Operation not permitted) in android?

i want to create database in sdcard or external sdcard for this i have try this code and using this i have successfully created database in sdcard but in logcat it give me warning like below

Logcat

07-18 14:18:22.140: W/FileUtils(8595): Failed to chmod(/mnt/sdcard/peakmedia/DB_PMD): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)

DB_Helper.java

public class DB_Helper extends SQLiteOpenHelper
{

    public DB_Helper(Context context) 
    {   
        super(context, Environment.getExternalStorageDirectory().getAbsolutePath() 
                       + File.separator + DB_Constant.DB.FILE_DIR 
                       + File.separator + DB_Constant.DB.DATABASENAME, null, DB_Constant.DB.DB_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) 
    {
        String  query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYFILES_TABLE);
        db.execSQL(query);


        query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYUSERS_TABLE);
        db.execSQL(query);

        query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYPLAYLIST_TABLE);
        db.execSQL(query);

        query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYDEVICE_TABLE);
        db.execSQL(query);

    }

     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
     {
            if(newVersion > oldVersion)
            {   

                db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYFILES);
                onCreate(db);

                db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYUSERS);
                onCreate(db);

                db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYPLAYLIST);
                onCreate(db);

                db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYDEVICE);
                onCreate(db);

            }
     }
}
like image 682
Mahesh Avatar asked Jul 18 '14 11:07

Mahesh


1 Answers

Just solved this problem.

You have to let your app join linux build to grant it SYSTEM permission.

  1. add this line into Android.mk

    LOCAL_CERTIFICATE := platform

  2. add this into manifest node of AndroidManifest.xml

    android:sharedUserId="android.uid.system"

  3. Generate apk and push it into /system/app/

  4. Now you can try to run

    final String command = "chmod 777 /data/ena";
    Process p = Runtime.getRuntime().exec(command);
    

    or

    File file = new File("/data/ena");
    if (file.exists()) {
        boolean result = file.setExecutable(true);
        Log.e(TAG, "trpb67, RESULT IS " + result);
    }
    

    value of result should be true

like image 101
Chandler Avatar answered Nov 09 '22 11:11

Chandler