Android - Remove permission programmatically - java

in the last days I try to make a simple Android app that can run adb command , more specific this command pm revoke com.example.app android.permission.ACCESS_NETWORK_STATE.
I try to run this from pc and say me that I can't because this permission isn't changeable.
With root is possible? or there are other method to block the internet connection to one app?

Related

Opening app on macOS 11 Big Sur from JavaFX application randomly fails with kLSNoExecutableErr

We have a desktop JavaFX application (well, TornadoFX) that downloads an archive, extracts another app from it and launches this app with macOS open command.
Simplified kotlin code looks like:
ProcessBuilder(listOf("open", "/path/to/app.app", "arg")).start()
This has worked for years on older versions of macOS (10.15 and earlier) but now with macOS 11 Big Sur launching the app sometimes succeeds and sometimes fails.
In the mac Console.app following error can be seen:
OSStatus _LSCopyApplicationNodeFromOpenState(LSOpenState *): Returning kLSNoExecutableErr because node is a directory but we failed to register with error -10814
We extended the logic to check if all the files are really there before launching the app, and the files existed.
There is an assumption that maybe Launch Services database is not updated fast enough.
Following ways of trying to log what might be happening, didn't reveal any errors:
lsappinfo listen +all forever
log stream --debug --predicate 'subsystem == "com.apple.coreservices.launchservices"'
Does anybody have a clue if there is a way to avoid this behavior and to be always able to launch the app?
After a lot of research and debugging, what seem to have worked for us, was to force Launch Services to register the app in its database by executing command like:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /path/to/app.app
and afterwards we could launch the app.
The idea for such solution was found in this answer.

Different package names to be added in desired capabilities in appium

We have an android app which is composed of two different apps.
Launcher activity is present in 1 project which has a package name
in.foo.android.main.MainActivity
while app package which is shown in uiautomator view is something like
com.abc.android.debug
in desired capabilites I am setting following :
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE ,"com.abc.android.debug");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY,"in.foo.android.main.MainActivity");
So getting below error
com.abc.android.debug/in.foo.android.main.MainActivity is not a launchable activity
Here appium is adding package name by default before the main activity.
can someone provide some help here.
First
Go to CMD as admin type adb devices
Make sure that your device already opened the apps that you want
go to cmd and type adb shell dumpsys window | find "mCurrentFocus"
this the exp
Thats command will showing the current activity
Second
Install the APK Info from playstore (idk if you try on the appstore)
https://play.google.com/store/apps/details?id=com.wt.apkinfo&hl=in&gl=US
Open the APK Info
Search your apps s name and click it
You will see this screen
appdetail
Scroll down and check the activities
activities
You will see all of the activity on the apps
existingactivity

What is the location of SQLite db file on the device/emulator after Android API 25?

I have an android project that demonstrates how to write android test cases which can be executed on an emulator or a device. As a result of those test cases, data is populated in the device and the resultant SQLite *.db file can be downloaded from Android Studio's DDMS screen.
NOTE: I have already tried as a root user in adb shell. Problem I am facing in accessing *.db file is consistent from adb and DDMS in emulator with API 26.
Code is accessible here.
I have created 2 emulators (API 23 and API 26) in AVD Manager.
AVD Manager
When I run the androidTest on both the emulators, all the test cases pass successfully.
Using Android Studio's DDMS ...
On the emulator with API 23, I am able to view the SQLite *.db file under /data/data/<package-name>/databases/weather.db and download it to my desktop and view it through http://inloop.github.io/sqlite-viewer/
DDMS
ADB Shell
On the emulator with API 26, the /data folder is empty?? I do not see the same hierarchy for accessing the SQLite *.db file as on device with API 23.
The android app and androidTest both run successfully on emulator with API 26 which means data is saved somewhere in android emulator but what is the new location?
DDMS
ADB Shell
Is it new behavior after API 25/26 and do I need special permissions to access data in DDMS or adb shell?
If this is new behavior then where is the SQLite *.db file located after API 25/26?
I have googled about it on stack overflow and android documentation but didn't find anything concrete, let me know if I have missed anything.
Make sure:
1) You are running adb as root user.
2) Your emulator should have root access.
Link: How to get root access on Android emulator?
#jrg I have been testing to see how to write to the SD CARD and how to find the path to the INTERNAL location of a sqlite db and how to view it with Api 26 or greater. I am not sure this will help and I am curious about rooting an Emulator once rooted can you remove the rooting by deleting the device from the AVD manager
here is some code that might help
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) && (!state.equals(Environment.MEDIA_MOUNTED_READ_ONLY))) {
File removable = ContextCompat.getExternalFilesDirs(this, null)[1];
THE_PATH = String.valueOf(removable) + "/Documents/";
//System.out.println("ALL TRUE ==> " + THE_PATH);
} else {// if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
THE_PATH = "";
//System.out.println("ALL FALSE ==> "+ THE_PATH);
}
When I eject the SD CARD on the emulator and a real device I use this code to create the path
Context context = this;
String removable = getFilesDir().getAbsolutePath();
THE_PATH = String.valueOf(removable)+"/";
System.out.println("INTERNAL PATH ======> "+THE_PATH);
File file = new File(context.getFilesDir(), "NAME_OF_FILE");
String PA = String.valueOf(file);
System.out.println("Where AM I ======> "+PA);
I do not think Android permits you to navigate to the internal storage without a File Manager application on your device. Have you considered installing a File Manager app on the emulator. Down side to this is I think your need AS 2.4 beta to be permitted to do this

Android Studio, unable to access data folder for database file on emulator

Ok, I have searched and searched without any success for someone with a similar question. I am developing an Android app using Android Studio and have started creating my SQLite database. In order to test my creation and upgrade functions I would like to extract my SQLite database and view it's contents.
Instructions online are fairly clear, open up Android Device Monitor, select the device, go to file explorer, and then browse a few levels deep in the data folder to find your .db file. Here is where the trouble starts. I am unable to expand the root level data folder at all. I have found numerous other questions regarding people having the same problem but they are all due to people trying to do it on un-rooted physical devices. I am simply trying to do it on an emulated device. I am certain it is a permissions problem but I'm not sure how to fix it.
Things I've tried:
Verified that my app is listed as a process on the device selected in the device monitor.
Restarted the AVD, Android Studio, and then my entire machine.
Uninstalled my app and reinstalled.
TLDR; can't access data folder in DDMS for emulated device in order to extract SQLite database file.
Same question to me.
When I want to access /data directory via Android Device Monitor, some error have occurred :
08-21 07:32:36.837: W/ls(3101): type=1400 audit(0.0:50): avc: denied { getattr } for path="/default.prop" dev="rootfs" ino=2941 scontext=u:r:shell:s0 tcontext=u:object_r:rootfs:s0 tclass=file permissive=0
08-21 07:32:37.418: W/PlatformStatsUtil(2507): Could not retrieve Usage & Diagnostics setting. Giving up.
This information tells us we don't have permission to access the directory.
Here are what I have done and works for me.
My OS is Window10
Start your ADV & Open Android Device Monitor
cd to /the/path/to/Android/sdk/platform-tools
Open your cmd or openshell here (shift + right click you will see the option)
execute following commands
.
./adb.exe shell
su
chmod -R 777 /data/data/your/package
Now, enjoy your coding.
Run your app in an emulator with API 23 (or lower).
check detailed information in link below,
Android Device Monitor "data" folder is empty

Trouble reading an XML file in Android

I'm trying to parse an XML file thru a DOM parser. However, I am having difficulty in getting my Main Activity to actually read the file. I've read that I should place the file in Assets and then called with getAssets(). I used something like this:
InputStream is = this.getAssets().open("myXML.xml");
This just results in an error: Unexpected error while launching logcat. Try reselecting the device.] device not found.
I've also tried new File("myXML.xml") using variations on the absolute path. Nothing seems to work. I'm getting a little frustrated. Does anyone have any suggestions?
sounds to me, as if your IDE has no connection to the Emulator or device on which you are trying to test your app.
LogCat is a logging output stream that can be used by any app to print out informations /logs. And LogCat needs to be connected (via ADB) to your device.
If you don't have a real phone connected you can use an emulator:
/path/to/your/androidSDK/tools/android
this SDK manager helps you to create a new AVD (Android Virtual Device). Klick Tools>
Manage ACDs> New...
If you have a real phone or tablet connected to your computer, try restarting ADB
(should be possible from within your IDE) or use the command line.
change to the directory where the Android SDK is installed (in windows something like):
c:\Program Files\Android\android-sdk-windows\platform-tools\
on linux it could be:
/opt/android-sdk-linux/platform-tools/
then type (win and linux)
adb kill-server
adb start-server

Categories