I wonder whether there is a way to know that my app is preinstalled by vendor (and not installed from Android Market). Application is also available in Android Market and can be updated from there.
One solution is to create a file in the local file system (we can build a special app version for vendor). But there is a case that application can be updated from the market before its first run, and file is not created.
So is there any other way? Probably, installation path?
Also it's interesting whether Android Market app checks this preinstalled app for updates automatically like it's performed for Google Maps.
You have to get the ApplicationInfo of your package (with the PackageManager) and then check its flags.
import android.content.pm.ApplicationInfo;
if ((ApplicationInfo.FLAG_SYSTEM & myApplicationInfo.flags) != 0)
// It is a pre embedded application on the device.
For a more complete example, one could use this:
private String getAllPreInstalledApplications() {
String allPreInstalledApplications = "";
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApplications = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : installedApplications) {
if (isApplicationPreInstalled(applicationInfo)) {
allPreInstalledApplications += applicationInfo.processName + "\n";
}
}
return allPreInstalledApplications;
}
private static boolean isApplicationPreInstalled(ApplicationInfo applicationInfo) {
if (applicationInfo != null) {
int allTheFlagsInHex = Integer.valueOf(
String.valueOf(applicationInfo.flags), 16);
/*
If flags is an uneven number, then it
is a preinstalled application, because in that case
ApplicationInfo.FLAG_SYSTEM ( == 0x00000001 )
is added to flags
*/
if ((allTheFlagsInHex % 2) != 0) {
return true;
}
}
return false;
}
Related
I am attempting to test whether task locking in Android L Preview can be accomplished by rooting the device rather than building a custom ROM.
I've created a 'device_owner.xml' file and placed in \data\system.
<?xml version='1.0' encoding='utf-8'?>
<device-owner>
package="com.ta.instrumentcontroller"
name="TA Instrument Controller"
</device-owner>
Upon reboot, the Nexus 7 2013 tablet just sits at the 'Bouncing Android Balls' logo. If I go into TWRP and delete the file, the boot sequence completes.
Does anyone know what might be going on?
I don't believe what I am attempting is possible, because it was not built in the system image.
At this Google Git page, DevicePolicyManagerService.java, in function isInstalled():
static boolean isInstalled(String packageName, PackageManager pm) {
try {
PackageInfo pi;
if ((pi = pm.getPackageInfo(packageName, 0)) != null) {
if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return true;
}
}
} catch (NameNotFoundException nnfe) {
Slog.w(TAG, "Device Owner package " + packageName + " not installed.");
}
return false;
}
The package info must contain ApplicationInfo.FLAG_SYSTEM, which means is must be part of the system image. ApplicationInfo
I am doing the following to get the list of apps and I am only getting apps that were installed but not ALL apps, including system apps.
I have tried the following:
packageList1 = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
and this:
packageList1 = getPackageManager().getInstalledPackages(0);
For both cases, I am getting the same list of apps that I have installed on the phone.
You are already getting a list of all installed applications including the system apps by calling this:
List<ApplicationInfo> apps = getPackageManager().getInstalledPackages(0);
Those with the flags:
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
ApplicationInfo.FLAG_SYSTEM
are system apps. You can check for the flags like this:
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}
I am creating an android app which has the list of all the apps which user can access from its android phone menu.
Here is my code which is working successfully..
List<App> apps = new ArrayList<App>();
// the package manager contains the information about all installed apps
PackageManager packageManager = getPackageManager();
List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
continue;
}
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
apps.add(app);
}
Now this gives me a big list and i can classify its items in 3 ways :
1st (Apps like): Speed Moto, Subway Surf, Chrome (Which i installed)
2nd (Apps like):Camera, Email, Messaging (Installed by Default)
3rd (.... Like):PageBuddyNotiSvc, Dialer Storage etc (Some Packages)
Now i want to filter the 3rd type of Apps and want to keep only 1st and 2nd type..
How can i achieve this list..
You can get the information about each application using the following code
ApplicationInfo app = context.getPackageManager().getApplicationInfo(packageName, 0);
//And then check the dir
if (app.sourceDir.startsWith("/data/app/")) {
//Non-system app
}
else {
//System app
}
How Can I detect that any system app (Pre Installed) in android is upgraded from its base package?
As well as , I want to know that Does package contain at least one activity that handles the home intent filter ?
I found the solution .
To detect if any system app has been upgraded from its base version-
List<PackageInfo> applications = getPackageManager()
.getInstalledPackages(0);
for (PackageInfo info : applications) {
long firstInstalled = info.firstInstallTime;
long lastUpdate = info.lastUpdateTime;
try {
ApplicationInfo ai = getPackageManager().getApplicationInfo(
info.applicationInfo.packageName, 0);
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0 /*Check system app*/
&& firstInstalled != lastUpdate /*check for updated */) {
Log.i(TAG,
"Upgraded pre installed app is "
+ info.applicationInfo
.loadLabel(getPackageManager()).toString());
}
} catch (NameNotFoundException e) {
Log.e("The exception is"+e.getMessage());
}
}
even There is one more option to check this using ..
if ((appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
{
// APP WAS INSTALL AS AN UPDATE TO A BUILD-IN SYSTEM APP
}
To Detect Home Launcher apps-
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> rinf = getPackageManager().queryIntentActivities(
mainIntent, 0);
if (rinf != null) {
for (ResolveInfo ri : rinf) {
ActivityInfo ai = ri.activityInfo;
if (ai == null) {
continue;
}
Log.i(TAG, "The Home Launcher Activity is " + ai.packageName);
}
}
For the first one you can just go to Settings and check if it gives you the option to Uninstall or just to Uninstall updates (meaning this apk is in the system).
The second one I would connect the device and check the Logcat.
In code:
Get the package and its PackageInfo, there you can access to its lastUpdateTime and its firstInstallTime. About the second one, I dont know but share it if you find how, please :)
I am building an android app in which I need to show the list of currently running apps but It contain all the process including many system or defualt process of android like : launcher,dailer etc.
Now is there any way to check if the currently running process is not a system process (default process) of android.
Thanks a lot.
Here is my code:
First to get a list of running Apps do the following
public void RunningApps() {
final PackageManager pm = getPackageManager();
//Get the Activity Manager Object
ActivityManager aManager =
(ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
//Get the list of running Applications
List<ActivityManager.RunningAppProcessInfo> rapInfoList =
aManager.getRunningAppProcesses();
//Iterate all running apps to get their details
for (ActivityManager.RunningAppProcessInfo rapInfo : rapInfoList) {
//error getting package name for this process so move on
if (rapInfo.pkgList.length == 0)
continue;
try {
PackageInfo pkgInfo = pm.getPackageInfo(rapInfo.pkgList[0],
PackageManager.GET_ACTIVITIES);
if (isSystemPackage(pkgInfo)) {
//do something here
}
else {
//do something here
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.d(TAG, "NameNotFoundException :" + rapInfo.pkgList[0]);
}
}
}
The actual function to check if the running application is system app, and used in the previous method is given below
/**
* Return whether the given PackgeInfo represents a system package or not.
* User-installed packages (Market or otherwise) should not be denoted as
* system packages.
*
* #param pkgInfo The Package info object
* #return Boolean value indicating if the application is system app
*/
private boolean isSystemPackage(PackageInfo pkgInfo) {
return (pkgInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) != 0;
}
I hope it helps.
As per this documentation, it seems you can use FLAG_SYSTEM_PROCESS to identify a process is System process or not. Here is SO discussion on this.
You can use ActivtyManager to get list of all running process in android.See the below link for more information Android process killer .