Permission check event (or log) for Android - android

I understand that when you install an android app you need to accept the permissions requested by the app. When you run the app, when it comes to the point that app really about to use that permission and perform a task, the android system has to check again "whether this app is allowed to perform this task?". I need to perform some task (log the event) at this moment. How can I do this?
There is a catch. I want to identify these instances (moments) for other running apps (not for my app)
(Ex: I want to know when DropBox app is about to access the internet.)

I need to perform some task (log the event) at this moment. How can I do this?
You can download the Android source code, modify it to incorporate your desired security flaw, compile the results into a ROM mod, and install that ROM mod on your own device.
This is not possible via the Android SDK.
There is a catch. I want to identify these instances (moments) for other running apps (not for my app) (Ex: I want to know when DropBox app is about to access the internet.)
You are welcome to install and use a firewall package on your rooted Android device and perhaps hook something up that way, for this specific scenario. In general, what you seek is not possible, for blindingly obvious privacy and security reasons.

Related

update application from USB flash drive

I need to update multiple applications installed on many Android devices.
Is there anyway to put theirs updated apks on USB flash drive, write some script that updates them and run this script manually after I plug it to the device?
I guess the most basic question would be why? Is this something you are purposely keeping off the app store? If it is not TOS breaking just pay the 25$ for a dev account and you can even just keep it in a beta/alpha status so only people you allow to can download it.
Beyond that Android phones can install APK's from third party sources, host the APK somewhere or get it to the user in some fashion and they can download from the phone and install.
Really the app store is your best bet.
It really depends on your use case and control of the devices that you are updating. Using an OTA update tool is always the fastest option for getting upgrades out. You can use BETA distribution, or TestFairy, or even hockey app, however, if you are not choosing to use these items then you will need to do a little extra leg work. Don't worry I won't patronize you with "why are you doing this", you asked a question so I'll do my best to answer it.
1) Register a service or app who's whole goal is to update others. Maybe you call it updateService.
2) Register a Broadcast Receiver for the updateService that listens for USB connected
3) Read the contents of the USB stick to know what needs to be updated. Possibly a folder system where you check "if folder exists, then update" or you can keep a local sql db of update service ownership that keeps track of last updates or current versions.
4) Once you see what needs installed have your service run ADB Install commands. However, if you have new permissions added then user interaction would be required unless you have root access or system level privelages on your update service.
Here is a package installer thread that will give you some ideas of how to silently update. Install apps silently, with granted INSTALL_PACKAGES permission
So the short answer is, yes you can do it, but the longer answer is revolving around the type of control you have, and if you have root or system level access and how much leg work is it worth to you. If you are ok with User Interactions on install then you won't have to worry as much, but I'm guessing you want silent installations.
Hope that helps.

Delete system cache on android 6.0

I'm using method freeStorageAndNotify() with permission android.permission.CLEAR_APP_CACHE to delete system cache of all installed applications. But the method started throwing InvocationTargetException from the android marshmallow 6.0 version.
After googling the issues I found the same issue as reported here:
Android M reflection method freeStorageAndNotify exception
So here the conclusion was, freeStorageAndNotify() stopped working since google has raised the method's signature level now to signature|system.
But now the question is how other third-party apps like 'Clean master' are still able to delete system cache of all installed applications by taking accessibility permission from the user for 6.0 devices?
I don't think that 'Clean master' actually uses Accessibility Permissions to clean installed apps cache.
But, if you're interested, this goal can be achieved by using AccessibilityService in your application.
Within your class that extends AccessibilityService you have this callback:
#Override
public void onAccessibilityEvent(AccessibilityEvent aEvent) {
AccessibilityNodeInfo rootNode = aEvent.getSource();
//...
}
Here you can invoke
rootNode.findAccessibilityNodeInfosByViewId()
or
rootNode.findAccessibilityNodeInfosByText(),
it will return all matching AccessibilityNodeInfo objects (sub-nodes) in tree. Then, you just need to detect which of them is Button (node.getClassName()) and call subNode.performAction(AccessibilityNodeInfo.ACTION_CLICK).
On Android M, you first need to to open system's App Info screen (you can find instructions here How can I start android application info screen programmatically?) for the concrete app and, by the scheme described above, perform sequential clicks on the buttons "Storage" —> "Clear cache".
In order to clear cache for all installed apps you probably have to iterate through the all installed apps (List<ApplicationInfo> installedApplications = context.getPackageManager.getInstalledApplications(0);)
and repeat the procedure mentioned above.
The system cleaner I'm using has access to the STORAGE permissions. This permission gives the app authority to clear any data in the shared external storage directory.
http://developer.android.com/reference/android/Manifest.permission_group.html#STORAGE
I don't think any 3rd party app can actually clear system cache anymore unless the device is rooted and the app is designed for rooted devices.
those apps only do the same thing all the time. use it on an old device and a new device the results are the same. the only help i have seen is that they can kill or restart some background processes, not to clean the cache. therefore no API can restrict their trick..

Security Exception: Permission denial for DEVICE_POWER

I am trying to write a simple android app that switches off my phone screen. When I am runnning this app I get Security Exception: Permission denial app requires android.permission.DEVICE_POWER. I know that this is a protected permission but my phone is rooted. What do I specify that I can use this permission? I have already tried declaring DEVICE_ADMIN permssion along with the DEVICE_POWER permission but it still doesn't work.
Rooting potentially lets you circumvent or modify the android security model, but it doesn't necessarily mean you get special privileges for an android API which enforces it. You cannot ordinarily run an application itself as root, while code in a helper executable which you could start as root will have substantial difficulty interacting with the Android APIs.
What you are trying to do may really not be a very good idea. But if you really want to do it, you would need to either install your own build of Android so that you have a (self generated) key matching that which you used to sign the platform, which you can then use to sign your application, or else try to install your application on the system partition.
If all you want to do is turn the screen off, then why don't you use the PowerManager? According to the documentation, the goToSleep() function will force the device to go to sleep.

Scan the Application during the installation process in android

i just want an application that would scan the installing application and decide whether to deny the installation process or not basing upon the package name ?
Fortunately, this is not possible, for obvious security reasons. Malware authors would really like it if they could block other applications from being installed.
Do you want an application which self-checks for integrity?
Or an application which check ANY other new application?
On the former, I would suggest to put some piece of code on the main activity which checks this. But if you are trying to have some sort of 'anti-hacking' feature it would be quite pointless, as it would simply be needed to remove those lines.
On the latter, that would be more complicated and, also, how would you know the 'correct' package name?
Third party security applications such as Lookout, McAfee, Avast, etc. run with the same limited permissions and capabilities as any other Android application. That said, it's not possible for any Android application to "man-in-the-middle" an application installation process for security checks or any other purpose. As mentioned by others, this would have negative security implications, as it would allow any application to modify or deny the installation of other apps.
As a third party app, the best you can do is to monitor installed packages using a broadcast receiver that listens for android.intent.action.PACKAGE_ADDED intents, or use FileObserver to trigger a security review once the app is written to the file system. At this point if you detected an application you wanted to uninstall, you would still have to ask the user for their approval to uninstall the application.
FWIW, device manufacturers have the capability to make low-level modification to provide this capability, but I assume this is out of scope for your case.

How to show an Activity BEFORE my app is uninstalled (Android) [duplicate]

This question already has answers here:
Is it possible to detect Android app uninstall?
(8 answers)
Perform a task on uninstall in android [duplicate]
(4 answers)
Closed 7 years ago.
I though it was not possible but I noticed that NQ Mobile Security is able to show a message after I click on Uninstall and before the PackageUninstaller is called.
I would like to replicate this behavior in my App.
I tried with an Activity listening to "android.intent.action.DELETE" Intent, as suggested here:
How to know my app is uninstalled from the device...?
But as I'm about to uninstall my app, the chooser pops up asking to pick my application or the package uninstaller. How can I avoid this?
Is there a different way to intercept your application UNINSTALL event? (before answering that it is not possible, please try to uninstall NQ Mobile Security and see what happens. On my Android 2.3.4 it shows a nice screen saying that is not safe to go without a security app).
I noticed that NQ Mobile Security is able to show a message after I click on Uninstall and before the PackageUninstaller is called
They must be exploiting some security flaw in Android. I will research it and see if I can get it fixed. Apps are not supposed to get control at uninstall time.
Thanks for pointing this out!
Is there a different way to intercept your application UNINSTALL event?
I sure hope not.
Opera Max is an app that does something similar - after being uninstalled opens a webpage.
How do they do this?
By using libevent, from native code, they watch /data/data/com.opera.max directory to be removed and then post good old action.VIEW broadcast when it happens.
Install their app, run it, and on rooted device from adb shell remove /data/data/com.opera.max directory
UPDATE: I created a sample app that shows how it works. BTW it doesn't work with recent (KitKat+ I think) Android versions: https://github.com/pelotasplus/ActionAfterUninstall
I'm pretty sure that they are monitoring the LogCat to intercept when the Activity Manager calls the PackageUninstaller. I think they kill the task and start their own Activity.
It's pretty clever but it's definitely exploiting a security hole in Android.
They are likely asking for a very critical permission that the user is granting them unknowingly. Look at the "Permissions" tab for this app (as of 6/15/2012): https://play.google.com/store/apps/details?id=com.nqmobile.antivirus20&hl=en.
The list of permissions this app gets is downright chilling. Among other things:
SYSTEM TOOLS RETRIEVE RUNNING APPS Allows the app to retrieve
information about currently and recently running tasks. Malicious apps
may discover private information about other apps.
CHANGE/INTERCEPT NETWORK SETTINGS AND TRAFFIC Allows the app to change network settings
and to intercept and inspect all network traffic, for example to
change the proxy and port of any APN. Malicious apps may monitor,
redirect, or modify network packets without your knowledge.
PREVENT TABLET FROM SLEEPING PREVENT PHONE FROM SLEEPING Allows the app to
prevent the tablet from going to sleep. Allows the app to prevent the
phone from going to sleep.
CHANGE YOUR UI SETTINGS Allows the app to
change the current configuration, such as the locale or overall font
size.
MODIFY GLOBAL SYSTEM SETTINGS Allows the app to modify the
system's settings data. Malicious apps may corrupt your system's
configuration.
DISPLAY SYSTEM-LEVEL ALERTS Allows the app to show
system alert windows. Malicious apps may take over the entire screen.
MOUNT AND UNMOUNT FILESYSTEMS Allows the app to mount and unmount
filesystems for removable storage.
CHANGE NETWORK CONNECTIVITY Allows
the app to change the state of network connectivity.
CHANGE WI-FI STATE Allows the app to connect to and disconnect from Wi-Fi access
points, and to make changes to configured Wi-Fi networks.
-- Update --
I also found that the Android Package Manager pretty much just deletes a package if it is asked to do so. The only check it performs prior to doing so is whether the package being deleted is currently registered as having an active device admin:
try {
if (dpm != null && dpm.packageHasActiveAdmins(packageName)) {
Slog.w(TAG, "Not removing package " + packageName + ": has active device admin");
return PackageManager.DELETE_FAILED_DEVICE_POLICY_MANAGER;
}
} catch (RemoteException e) {
}
See line 6900 in PackageManagerService in the AOSP source here.
For this, the application must be explicitly registered as a device admin by the user. See notes on device administration here: http://developer.android.com/training/enterprise/device-management-policy.html.
As per https://stackoverflow.com/a/26829978/1317564, here is some example code that does it: https://github.com/zzljob/android-uninstall-feedback/blob/master/library/jni/feedback-uninstall.c. This won't actually stop the uninstall from taking place, but does provide a way to catch it and take some action. I'm honestly surprised that this works in Android and the team may have plugged the gap in recent releases.

Categories

Resources