android - 从应用程序内部更改已root设备的系统设置

发布于 2024-12-04 05:31:19 字数 420 浏览 1 评论 0原文

我正在尝试从内部更改此处描述的短信限制该应用程序。假定该应用程序在已取得 root 权限的设备上运行。我正在使用 RootTools 检查设备是否已root。我正在尝试弄清楚如何将实际设置写入 settings.db。任何可以帮助我的建议都将受到高度赞赏。

提前致谢。

I am trying to change the sms limit described here from inside the app. The app is assumed to be running on a rooted device. I'm using the RootTools to check if the device is rooted or not. I'm trying to figure out how to write the actual setting on to the settings.db. Any suggestion which could help me in this is highly appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对岸观火 2024-12-11 05:31:19

我通过这样做解决了这个问题:

  • /data/data/com.android.providers.settings/databases/settings.db 复制到我的应用程序文件夹 /data/data/my_app_directory/< /代码>。
  • 使用 SQLiteDatabase 类更新数据库中的表。
  • 将数据库从 /data/data/my_app_directory/settings.db 复制回 /data/data/com.android.providers.settings/databases/

复制操作已完成通过使用RootTools.sendShell

I got this solved by doing this:

  • copy the /data/data/com.android.providers.settings/databases/settings.db to my application folder /data/data/my_app_directory/.
  • update the table in the database using the SQLiteDatabase class.
  • copy back the database from /data/data/my_app_directory/settings.db to /data/data/com.android.providers.settings/databases/

The copy operations were done by using RootTools.sendShell

缱绻入梦 2024-12-11 05:31:19

迟到的答案,但你不需要复制settings.db,你可以用RootTools更新它,比如

CommandCapture commandLogcat = new CommandCapture(0, "sqlite3 /data/data/com.android.providers.settings/databases/settings.db \"UPDATE secure SET value = '192.168.2.140' WHERE name = 'eth_ip';\"");
RootTools.getShell(true).add(commandLogcat).getExitCode();

Late answer, but you don't need to copy settings.db, you can update it with RootTools like

CommandCapture commandLogcat = new CommandCapture(0, "sqlite3 /data/data/com.android.providers.settings/databases/settings.db \"UPDATE secure SET value = '192.168.2.140' WHERE name = 'eth_ip';\"");
RootTools.getShell(true).add(commandLogcat).getExitCode();
面犯桃花 2024-12-11 05:31:19

是的,如果您具有 root 访问权限,则可以执行此操作。这是一个漫长的过程,但您可以这样做:

第 1 步:/data/data/com.android.providers.settings/databases/ 复制 settings.db 使用设备中的 RootBrowser 并使用 sqliteBrowser 更改要更新的值,然后更新 settings.db 并放入 assets > 您的项目包

第 2 步:使用 asset manager 将此文件复制到您的应用程序文件夹(您可以访问的任何位置),因为您需要

此函数将从资产中复制文件

public static void copyAssets(Context context, String assetPath, String outFilename) {
        AssetManager assetManager = context.getAssets();
        InputStream in = null;
        OutputStream out = null;
        try {
            in = assetManager.open(assetPath);
            File outFile = new File(context.getExternalFilesDir(null), outFilename);
              
            out = new FileOutputStream(outFile);
            copyFile(in, out);
        } catch (IOException e) {
            Log.e(TAG, "Failed to copy asset: " + outFilename, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }

public static void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
    }

第3步:覆盖系统settings.db< /code> 文件系统路径 (destPath) 为 /data/data/com.android.providers.settings/databases/

public static void copyToSystem(final String sourceFilePath, final String destPath) {
        Thread background = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Process process = Runtime.getRuntime().exec("su");
                    DataOutputStream os = new DataOutputStream(process.getOutputStream());
//                    
                    os.writeBytes("cp -f " + sourceFilePath + " " + destPath + "\n");
                    os.flush();
                    os.writeBytes("exit\n");
                    os.flush();
                    process.waitFor();
                    process.waitFor();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                }
            }
        });
        background.start();
    }

第 4 步: 重新启动

设备全部完成。

Yes, You can do this if you have root access. Its a lengthy process but you can do this :

Step 1: copy settings.db from /data/data/com.android.providers.settings/databases/ using RootBrowser from the device and than change the value using sqliteBrowser which you want to update than update settings.db and put in assets package of your project

Step 2: Copy this file into your application folder (anywhere where you can access) using asset manager for that you need

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

this function will copy file from assets

public static void copyAssets(Context context, String assetPath, String outFilename) {
        AssetManager assetManager = context.getAssets();
        InputStream in = null;
        OutputStream out = null;
        try {
            in = assetManager.open(assetPath);
            File outFile = new File(context.getExternalFilesDir(null), outFilename);
              
            out = new FileOutputStream(outFile);
            copyFile(in, out);
        } catch (IOException e) {
            Log.e(TAG, "Failed to copy asset: " + outFilename, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }

public static void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
    }

Step 3: overwrite the system settings.db file system path (destPath) is /data/data/com.android.providers.settings/databases/

public static void copyToSystem(final String sourceFilePath, final String destPath) {
        Thread background = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Process process = Runtime.getRuntime().exec("su");
                    DataOutputStream os = new DataOutputStream(process.getOutputStream());
//                    
                    os.writeBytes("cp -f " + sourceFilePath + " " + destPath + "\n");
                    os.flush();
                    os.writeBytes("exit\n");
                    os.flush();
                    process.waitFor();
                    process.waitFor();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e(TAG, e.toString());
                }
            }
        });
        background.start();
    }

Step 4: Reboot device

That's all done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文