Android developing: restrict user to only run and use my application - android

I'm developing android application for CAR usage and I need that in phone or tablet the driver can only run and use this application: No calling or running other app. Is that possible? If it is not, is there any way to restrict the user for example uninstallaing other apps and disabling the installation system and disabling the calling system?
Thanks in Advance,

I have done a similar app like this, which is in fact an in-cab entertainment system. I have also written a blog post about it, you can check it out here: http://arnab.ch/blog/2012/01/android-auto-updating-homescreen-application/.
This is a complex application and let me list out the relevant items for you:
Your app should be a HomeScreen application (search google for how to create HomeScreen app for Android)
It seems clear that you would have some control over the device, so you can ensure that no additional applications are installed.
The homescreen can be dynamically enabled/disabled, check out KytePhone app to see what I meant. In short you would need some password to exit your HomeScreen app.
If you want to silently uninstall/install any application, then you'd need root access, or you'd have to have a custom Android build where your app will have System privilege (might not be what you're looking for).
I hope I am able to give you some direction, if anything is not clear then let me know.

You can use Accessibility service to solve this issue and you need to check granted application packages inside onAccessibilityEvent method.
import android.accessibilityservice.AccessibilityService;
public class MyAccessibilityService extends AccessibilityService {
...
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
}
#Override
public void onInterrupt() {
}
...
}
please follow the link: https://developer.android.com/training/accessibility/service.html

Related

Receive broadcasts in stopped application

By default, an application which in stopped state (not yet run even once) could not receive broadcasts. There is a way to receive it if we add the flag FLAG_INCLUDE_STOPPED_PACKAGES to the broadcast intent.
My problem is that I need to receive system intent android.intent.action.MEDIA_MOUNTED (and I don't want to add that flag to it).
How can I receive it even in stopped application?
It seems to me that for sure it's possible because for example com.android.shell application is able to receive such intents even if it's force stopped. How it does it?
EDIT:
Just to clarify, because it appeared that this is not obvious:
Everything here is from the point of view of Android Open Source Project developer. I'm modifying the operating system source code and the application which I want to receive the broadcast could be preinstalled, signed with platform certificate, it can use hidden API, etc. Everything is permitted, even modifications of the system.
Declaring your application as a system app should allow you to receive regular broadcasts even if your app is in "stopped state".
Add the following to your manifest and make sure your application is signed by the platform key:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
android:sharedUserId="android.uid.system">
If you are not referring to Force Stopped applications, but rather to closed applications that are in the stopped state, then look at these two links to find out how to implement a BroadcastReceiver that can be activated after the app is closed. Otherwise a custom ROM and or sys app is the way to go probably.
BroadcastReceiver 1
BroadcastReceiver 2
If you are on a rooted device you can use Xposed to modify android.content.Intent#isExcludingStopped, as such:
public class DontExcludeStoppedPackagesFromIntents implements IXposedHookLoadPackage {
#Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName.equals("android")) {
XposedBridge.log("In package: " + lpparam.packageName);
findAndHookMethod("android.content.Intent", lpparam.classLoader, "isExcludingStopped", new XC_MethodReplacement() {
#Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
return false;
}
});
}
}
}
Don't forget to put the class name in xposed_init.
Of course this has some security implications, effectively taking you back to Android 3.0-, though this shouldn't be much of an issue because noone expects to exploit a vulnerability that is not present on nearly all existing Android devices that do no have this patch applied.
I tried the above and it works!

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..

android Detect when an application is installing, pause installation and prompt an alert box

is it possible to run a broadcast receiver to detect, pause installing and alert when an application is installing.
onRecive
public class Receiver extends BroadcastReciver{
public void onReceive(Context context, Intent intent ){
if(intent.getAction().equals("android.intent.action.PACKAGE_INSTALL")){
//i want to pause the installing activity and prompt an alert box
}
}
}
Purpose would be, when an application is going to install, it ask are you really want to install this application.
After doing a lot of R & D I'm really stuck with a solution for this, if u please can help me out with this, thank you a lot.
This is possible according to this research paper. Look page 2 Figure 1.
You cannot pause it. There is no API for this. This is a system level function not meant to be handled by 3rd party applications.
This is a security measure. Image if every app could control the installation of all other apps! It would be a big security misstep! Hence it's not available.
You can, however detect the installation of a package. See this thread:
Receiving package install and uninstall events

Change permissions of another application on Android (rooted)

I see a couple threads on this, but none really speak to what I would like to do. I am trying to write an application that will deny another application the ability to connect to the internet (IE Firewall). Based on algorithms I am creating it will determine that application as being malicious. The app would be on a rooted phone. I would then like to either
Strip all permissions from the Application
Deny it specific permissions (Internet Access)
Force Uninstall that application.
I know there are several programs already out there, but I would like to code this myself :]]
With that being said could anyone point me in the right direction?
Thank you!
EDIT: So I have found this:
public static void killRunningPackage(final Context context, String packageName)
{
ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(packageName);
}
What argument do I pass in for a context? I looked at contexts online but I didnt really understand them
Build Perspective
Even with a rooted phone, because this is handled by the frameworks, I highly doubt that you can achieve something like this.
Specifically unless you have the source and can compile the source of a new phone, you cannot do this.
SDK Perspective
Also another thing about this is you can't "strip" an application of its permissions BECAUSE its in the Manifest.xml which gets embedded into the .apk of an application, which is a binary and is registered with the PackageManager.
This is far beyond the scope of the SDK.
What you CAN do is kill an application if it isn't to your liking. The PackageManager would be your best option, however; that is as far as you can go.
Update
Check this out:
http://android.amberfog.com/?p=98

How do I tell the system to do setup() when my android app is installed?

I would like to make an album and add some music files when my android app is first installed on a device. Is there a way is can do something like below?
public void onInstall(){
setup();
}
You can't do anything after the app is installed, only after it is run.
Just store a flag in your SharedPreferences to see whether or not it has done its first-time install process already and then perform it, or, if you're installing music files, check for their existence and install them if they're not there yet.
There's no way to know when your app is installed... however, you can detect when it's first launched. It has been discussed a lot of times here. You just need to persist it using a shared preference.
here comes the answer ;-)
Get referrer after installing app from Android Market

Categories

Resources