Drop_caches by app doesn't work
Asked Answered
B

3

0

I've made this script but doesn't work:

package com.mkyong.android;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import com.example.toast.R;

public class MainActivity extends Activity {


private Button button;

public void onCreate(Bundle savedInstanceState) {
    final Runtime runtime = Runtime.getRuntime();
    try {
        runtime.exec("su");
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab1);


    button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {
        @SuppressLint("SdCardPath")
        @Override
        public void onClick(View arg0) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("echo 3 > /proc/sys/vm/drop_caches");
                Toast.makeText(MainActivity.this, "Script lanciato con `successo, memoria svuotata.", Toast.LENGTH_LONG).show();`
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
}

Doesn't free the RAM memory :( but via terminal emulator goes..If i try to change command and for example, make a dir with mkdir goes, goes even the writing of a file txt.. what's wrong?

Bogey answered 9/4, 2013 at 18:19 Comment(0)
M
0

Your runtime.exec("su"); just started a shell process. And your next "runtime.exec("echo 3 > xxx")"; is not executed in the first shell.

My suggestion is to stick with java.lang.process, start a process which executes "su" and use the redirected stdin to write your command to it.

Macmacabre answered 10/4, 2013 at 9:18 Comment(6)
Do you mean the problem is basically that my shell is after the firt (su)? So my process doesn't go? My gosh i can't find a way out :( . But why the other commands (mkdir etc..) goes and this one not? It's incredible!!!Bogey
I've tryied to change again and write : runtime.exec("su -c /free.sh"); but nothing..i've also tryied runtime.exec("su -c '/free.sh'"); and nothing... i've also tryied runtime.exec("su -c echo 3 > XXX"); but nothing change!!!!!! wtf is so difficult! I tryied everything!Bogey
When you say NOTHING you mean the kernel did not drop all the file cache? Did you tried to make sure it really works on your devices by do this on your adb shell?Macmacabre
i explain you what i do.i write the "free" command to see the free memory, then start the app,click the button,again "free" command and nothing change...else if i launch the shell directly from the terminal i see the difference in free memory.something is wrong?Bogey
As you wrote yesterday i think the problem is the successions of the shell.. first must be the "su" command and then the "echo XXXXXXXX". The "su" go, no problem for that..the other nope. Maybe is only a syntax error i don't know..Bogey
Could be a way? : Process p = Runtime.getRuntime().exec(“su”); DataOutputStream outs=new DataOutputStream(p.getOutputStream()); String cmd="echo 3 > /proc/sys/vm/drop_caches"; os.writeBytes(cmd);Bogey
U
0

You could try this.

try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "echo 3 > /proc/sys/vm/drop_caches" });
proc.waitFor();
} catch (Exception e) {
Log.d("Exceptions", "Exception dropping caches: "+e);
}

OR

            Process p=null;
            try {
                p = new ProcessBuilder()
                .command("PathToYourScript")
                .start();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(p!=null) p.destroy();
            }
Unthread answered 19/11, 2013 at 13:36 Comment(3)
Hi, welcome to SO. Glad to see a answer, but notice next time when the question was asked. This is a very old question, and doesnt need any effort.Enquire
Hi, and thank you for the welcome. I didnt notice it was an old question. I have found useful answers for myself from very old questions though. Maybe this helps someone. And writing answers helps me understand more about android aswell.Unthread
I was helped just now :)Scute
F
0

import requests

def login(devil_bilal_45, devilkaif): # Same as before...

def report_user(session, devil_bilal_45): # Same as before...

  • List item

if name == "main": # Replace 'your_username' and 'your_devilkaif' with your actual Instagram credentials devil_bilal_45' = 'devil_bilal_45' Devilkaif'= 'devilkaif'

user_id_to_report = 'devil_bilal_45'   'devil_bilal_45' with the user ID of the profile you want to report
num_reports = 100

session = login(devil_bilal_45, devilkaif)

for i in range(num_reports):
    report_user(session, user_id_to_report)
    print(f"Report {i + 1} completed.")

print("All reports completed
Fimbria answered 10/9, 2023 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.