0

What I want: I am trying to create an app protector. When someone opens other apps, I want the user to enter the password/PIN.

SO for this, I am trying to read logs as suggested here: (https://stackoverflow.com/a/7239840/1640009)

Foreground Service:

@Override
    public int onStartCommand(final Intent intent, int flags, int startId) {

        if (intent!=null){
            if (intent.getAction()!=null && intent.getAction().equals(Constants.ACTION.STOP_ACTION)) {
                killPermissionService();
                return START_STICKY;
            }
        }


        if (timer != null) {
            timer.scheduleAtFixedRate(new TimerTask() {
                @Override
                public void run() {

                     try {

                         String logs= LogsUtil.readLogs().toString();

                         if (logs.contains("START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME]")){
                             Log.e(TAG,"app launched");
                          }

                     } catch (Exception ex) {
                        Log.e("here","line 166");
                        ex.printStackTrace();
                    }
                }
            }, 1000, 1000);
        }

        return START_STICKY;
    }

// In LogUtil, I have the function

public static StringBuilder readLogs() {
        StringBuilder logBuilder = new StringBuilder();
        try {
            Process process = Runtime.getRuntime().exec("logcat *:D -d");
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                logBuilder.append(line + "\n");
            }
        } catch (IOException e) {
            Log.e("error while","fetching log");
            e.printStackTrace();
        }
        return logBuilder;
    }

But if conditions never met. I also tried to execute "./adb logcat *:D" directly on the terminal, In the output same line exists when app launch.

Ankur_009
  • 3,823
  • 4
  • 31
  • 47
  • 1
    "I am trying to read logs as suggested here" -- that technique has been blocked for seven years, as is noted [in a comment on that answer](https://stackoverflow.com/questions/3290936/android-detect-when-other-apps-are-launched/7239840#comment15165855_7239840). – CommonsWare Nov 28 '19 at 13:51
  • @CommonsWare but I am getting other logs, and is there any other alternative? – Ankur_009 Nov 28 '19 at 13:54
  • "I am getting other logs" -- only stuff emitted by your app and a few other messages. "is there any other alternative?" -- there might be options using device admin/owner APIs, and there is probably a solution involving root. – CommonsWare Nov 28 '19 at 14:20
  • I don't think there are options via device/owner APIs(as far as my knowledge concern). But there are apps which is using that feature, – Ankur_009 Nov 28 '19 at 14:24
  • 1
    "But there are apps which is using that feature" -- I am genuinely sorry to hear that. It indicates that Google has not yet sufficiently fixed the privacy/security flaws that allow ransomware to block apps from executing. – CommonsWare Nov 28 '19 at 14:26

0 Answers0