Enabled Notification Access without user interaction - android

I have a rooted phone and i want to assign my application to access notifications without user interaction like open settings and toggle from there but not find any proper way(Not programatically OR visa ADB command).
I have actually seen an old post where someone share a link:
So i have tried like this:
adb shell settings put secure enabled_notification_listeners %nlisteners:mypackageName/com.company.app.service.CallNotificationListener
Command run without any error on shell but when i open Notification Access from phone settings, my application still not mark as a notification receiver. Is there any way to do that?

Since Android 9 Your command is not working anymore. What worked for me was to use :
adb shell cmd notification allow_listener com.mypackage.app/com.mypackage.app.mylistener
It doesn't need root permission even in my case.

Related

How can I provide a command line interface to my Android app?

I would like to be able to type commands on my development machine (macOS/zsh) and have them do things on my Android app. This will require custom code in my Android app. What I'm trying to do is something similar to automating certain settings, so that I don't have to navigate to the settings screen of my Android app manually. This is to help me save time while I'm developing my app.
How can I get started? I'd love to see some examples of this being done but have been having trouble finding them.
Are there any libraries that can help me with this?
Also, for bonus points, I'd love to be able to have some sort of autocomplete on my Mac command line. How might I build that?
There's a few ways to do this:
1)Just write a Linux app, move it to your device, set the executable bit, and run it from adb shell (adb shell opens up a shell on an attached device with debugging enabled).
2)If you really need to access the app while its running, you can send intents to your app via the shell via adb shell am <options> This allows you to send an intent to the system. Then just write a custom Activity, Service, or BroadcastReceiver to receive that Intent and act upon it.

Switch to UID 2000 (shell) in an Android app programmatically? [duplicate]

In my application, I need to start a native binary that opens and read from some /sys/kernel files. If I launch the native binary by connecting using adb shell (launching manually from /data/local/tmp), then everything works fine.
I would like the App to programmatically do two things,
Copy the binary to /data/local/tmp/. Again this wont work as the normal android app doesnt have enough privileges.
Start the binary as a shell user so I can have the necessary privileges. I have tried using android:sharedUserId="android.uid.shell , but that doesnt seem to work.
Please note that I don't need root to open the /sys files.All I need is to be shell user. Any thoughts will be greatly appreciated.
Thanks
The shell UID is reserved for development and testing. Running an app with shell privileges is circumventing Google's security model. So you will not be able do it on a secured commercial device without rooting it.
A possible temporary (non-persistent between reboots) workaround would be:
Use adb shell to start a background service process, running as shell UID
In your application, using IPC to ask the service to perform special task for you

Android things back from settings or other activities

I used Android Things on Raspberry PI 3 with touch screen. And i need configure wifi connection, for example. Call WiFi settings via intent, after configure i need return to my application, but i have only one button, which connect to pin. This button must be work as Back button on android device.
When button press executed this code:
Runtime.getRuntime().exec("adb shell input keyevent 4");
But i get exception:
java.io.IOException: error=13, Permission denied
When i send command via command line from PC - all work good, but on device - Permission denied
What wrong? This is because my android not rooted?
Also tried call OnBackPress in main activity, but this work only in my application and not back from settings.
If you don't have root, you will not be able to execute direct key presses on your device with a shell command. You would need to use an InputDriver to have your button send an event to the system (though I'm unsure if it would support the BACK button).
Additionally, if you are running a shell command on the device, you don't need adb shell. You're already in the shell.
With the latest version of AndroidThings (DP6) you can setup the Wifi Connection through the launcher (before you install your app).
This launcher is visible when no other developer-provided IOT_LAUNCHER Activity is present.
Once you have setup the wifi (using your touchscreen) you can then install your app.
If you wanted a more programmatic approach, you could install your app but disable the activity that has IOT_LAUNCHER intent. This will let the Launcher show. Meanwhile you have registered to monitor for connectivity changes, when the wifi is connected you re-enable your launcher activity. (This is just theoretical I haven't tried this).
With the latest version DP8 , you now need:
<category android:name="android.intent.category.HOME"/>
In your intent, which replaces IOT_LAUNCHER (https://developer.android.com/things/preview/releases.html)

Launch/Create Android Emulator that does not have (without) root access

I need to run a security test on one of our Android mobile applications.
It must not run if the device is rooted.
It should run as expected on non-rooted devices.
I have tested part 1 without issue and found it to work as expected.
However, I cannot seem to create an emulator using the AVD Manager that will not start with root access.
-Is there a command line method to reduce the emulator instance to non-rooted at startup?
-Failing that, is there a method to send an adb shell command (or other command line call) to reduce the permissions to the installed application?
Thanks!
Edit for #Fred.
I have opened the shell and changed it to the user id (uid) of the application under test. Note that in the image you can see the command, "adb shell su u0_a53" and then the next prompt includes the user, "u0_a53#generic_x86_64" as the returned shell and has the "$" indicating non-root access. However, when opening the application under test on the emulator, the application detects the device is rooted. What am I missing?
See attached image - click here
Yes, there is a way using SU to change super user to non root, see answer in this so question for directions:
https://android.stackexchange.com/questions/60599/how-to-get-non-root-access-on-emulators
As it turns out, my question was fundamentally flawed. The environment i'm trying to achieve could not be created with an emulator as part of the security test checks to see if the phone is in 'release' mode, in addition to looking for the presence of 'su'. After conferring with several other teams, I have decided to obtain a physical phone for testing this security restriction.

How to run Android system app without root permission?

Is there any way to run Android system app without root permission? I can execute system app via adb such as:
adb shell /system/bin/screencap -p /sdcard/screen.png
In my own application, I wanna run a shell command like that without "su" command. Is there any way? How does android prevent user apps to execute system app?
You should be able to run this command in java code:
Runtime.getRuntime().exec("screencap -p /sdcard/screen.png");
There are some shell commands you can execute without having root. So you don't need to run "su". I'm not sure if you can execute screencap. Certainly you need permission to write to the SD_CARD in your app.
android.permission.WRITE_EXTERNAL_STORAGE
But why you don't use the Android API to make your screenshot? For more information read this post on stackoverflow: How to programmatically take a screenshot in Android?
Androids security model bases on user ids, like Linux does. Each app gets his own user id. So your app has a userid like 1001. If your user is allowed to run the command you can, otherwise you will receive an error.
EDIT:
You need root to take screenshots or be a system application. There is a permission READ_FRAME_BUFFER but you only can obtain it when you are a system application. Its a security problem when an app could take screenshots of your device.
I've found this API http://code.google.com/p/android-screenshot-library/ which promises to take screenshots without root. I didn't test it. The library starts a native service which then takes the screenshots for you.
But you have to run the service each time your phone boots. So it gets the system privileges. That's not really comfortable...
Conclusion: There is no nice way to take screenshots without root from code...
Is there any way to run android system app without root permission?
It have to be NO, but some times, some functions which are not for public use still can be used. I've seen examples using java reflection.
I can execute system app via adb such as: ...
In my own application, I wanna run a shell command like that without
"su" command. Is there any way? How does android prevent user apps to
execute system app?
I think, no.
The thing is adb shell and user app have different security levels based on User and Group IDs (UID and GID).
More info: http://android-dls.com/wiki/index.php?title=Android_UIDs_and_GIDs
Besides, there are limitations via app permissions and hiden & internal classes, procedures, etc which made for internal use.
P.S.: About screenshots. On android market (google play) there are few apps which provide screenshots without ROOT access. So, it's possible.
Although, since Android 4.0 screenshots are available "from box".

Categories

Resources