2017-10-04 157 views
1

我遇到以下問題。如何在有根系統上寫入* .kl文件並複製到系統上

我需要鎖定我的平板電腦的特定應用程序。我在KioskMode中使用我的應用程序,但是我需要阻止一些按鈕,「Switch_app」,「Volume_UP」,「Volume_DOWN」等。

我能夠通過訪問ES文件資源管理器來阻止這些按鈕,手動文件保存並重新啓動平板電腦。

但是,我想以編程方式更改此文件。

我已經試過如下:

 { 
      using (StreamReader sr = new StreamReader("/system/usr/keylayout/Generic.kl")) 
      { 
       string line; 
       // Read and display lines from the file until the end of 
       // the file is reached. 
       while ((line = sr.ReadLine()) != null) 
       { 
        if (line.Contains("VOLUME")) 
        { 
         line = $"# {line}"; 

        } 
        text += line + "\n"; 
        System.Console.WriteLine(text); 
       } 
      } 
      CreateFile(); 

      TransferFile(); 
     }; 


    void CreateFile() 
    { 


     string sdCard = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; 
     string path = Path.Combine(sdCard, "MyFolder/Generic.kl"); 
     // This text is added only once to the file. 
     if (!System.IO.File.Exists(path)) 
     { 
      // Create a file to write to. 
      System.IO.File.WriteAllText(path, text); 
     } 
    } 

而且所創建的文件傳輸到/系統的/ usr/Keylayout我用這個:

Java.Lang.Runtime.GetRuntime().Exec("su -c mount -o rw,remount,rw /system"); 
Java.Lang.Runtime.GetRuntime().Exec("su -c rm system/usr/keylayout/Generic.kl"); 
Java.Lang.Runtime.GetRuntime().Exec("su -c mv /storage/emulated/0/MyFolder/Generic.kl system/usr/keylayout/Generic.kl"); 

當我使用這些命令,文件被複制,但是當我重新啓動平板電腦時,不再有物理按鈕可以工作。所以我相信這是與刪除舊文件並添加新文件有關的一些問題。

任何幫助將是非常歡迎以及想法。

謝謝大家。

回答

2

沒有必要擔心所有權,權限等,如果你將就地編輯使用sed的:

GetRuntime().Exec("su 0 mount -o remount,rw /system"); 
GetRuntime().Exec("su 0 sed -i 's/^[^#]*VOLUME_DOWN/# &/' /system/usr/keylayout/Generic.kl"); 
GetRuntime().Exec("su 0 sed -i 's/^[^#]*VOLUME_UP/# &/' /system/usr/keylayout/Generic.kl"); 
GetRuntime().Exec("su 0 sed -i 's/^[^#]*APP_SWITCH/# &/' /system/usr/keylayout/Generic.kl"); 

你仍然需要儘管重新啓動。

+0

謝謝亞歷克斯P. 你幫了我很多,因爲我面臨的權限問題,現在我沒有他們了。 你能給我一個問題嗎?如果我需要禁用,我怎麼寫反向? –

+0

刪除VOLUME_DOWN - VOLUME_UP處的註釋 –

0

這就是解決方案根植設備

 Java.Lang.Runtime.GetRuntime().Exec("su -c mount -o rw,remount,rw /system"); 
     Java.Lang.Runtime.GetRuntime().Exec("su -c rm system/usr/keylayout/Generic.kl"); 
     Java.Lang.Runtime.GetRuntime().Exec("su -c mv /storage/emulated/0/MyFolder/Generic.kl system/usr/keylayout/"); 
     **Java.Lang.Runtime.GetRuntime().Exec("su -c chmod 644 /system/usr/keylayout/Generic.kl"); 
     Java.Lang.Runtime.GetRuntime().Exec("su -c chown system.system /system/usr/keylayout/Generic.kl");**