Is there any way to check which app is doing what in android, from my application.
I mean
if any app is reading call logs
if any app is reading msg
if any app is reading data from server
if any app is accessing gps,
if any app is playing music
Please suggest any idea, any help will be appreciated.
The best you can do is check if an app has the permissions required to do each task. The following snippet retrieves the permissions for all installed Applications:
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
try {
PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;
if(requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
Log.d("test", requestedPermissions[i]);
}
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
Beyond that, just because an app has permission to do something doesn't mean it is doing that. Some permissions cover more than one use, and the app could be using one part of what it has access to.
Related
In my app , I am showing the memory usage of each app. I tried the solutions provided in SOF as,
Getting from MemInfo shell command
Process process = Runtime.getRuntime().exec("dumpsys meminfo " + info.packageName);
Permission denied to run this command.
Tried with TOP command
Process process = Runtime.getRuntime().exec("top -n 1 -d 1");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
for(int i=0;i<5;i++)
in.readLine();
do {
try {
String trial[] = in.readLine().split(" ");
int j=0;
String array[]=new String[trial.length];
for(String a:trial)
{
if(!a.isEmpty()) {
array[j] = a;
j++;
}
}
String package_name=array[9];
if(package_name!=null)
{
if(package_name.contains(":"))
package_name=package_name.substring(0,package_name.indexOf(":"));
}
publishProgress(package_name);
Debug.MemoryInfo[] procsMemInfo = manager.getProcessMemoryInfo(new int[] {Integer.parseInt(array[0])});
long memory=0;
for (Debug.MemoryInfo info:procsMemInfo)
{
memory+=info.getTotalPss();
}
processDescriptions.add(new ProcessDescription(array[0], Integer.parseInt(array[1]),
array[2], MemorySizeConverter.MBorKB_Converter((double) memory, 1), array[8], package_name));
}
catch (Exception e)
{
Log.d("skipped",e.toString());
}
} while (in.readLine() != null );
It worked and I can get running processes memory info. Not for all installed apps.
As this statement, My app should be signed with the platform key, or installed in the system partition to access it. But how third party apps available in playstore are accessing it . Can anyone help me.
Developers or clients who want to use my skd should go to my website to apply for a APP_KEY.To apply for a APP_KEY,they should offer the app's package name,something like this "com.edward.myapp".Also the SHA-1 of the developers's certificate(generated from keytool).
Now I can only send the APP_KEY to my server to verify the APP_KEY,the only thing I know is that the APP_KEY is valid or invalid.But I don't know if it is my clients' app,it can be anyone else's app,and it can be any package name.I don't want to something like this happen.
So how can I verify it to ensure it is the right app to use the sdk?
Your SDK at runtime can obtain the SHA1 of the certificate used to sign the APK.
String getSignatureSha1(Context context) {
PackageManager pm = context.getPackageManager();
PackageInfo info = null;
try {
info = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not find info for " + context.getPackageName());
return null;
}
byte[] signatureBytes = info.signatures[0].toByteArray();
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signatureBytes);
byte[] digestBytes = md.digest();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < digestBytes.length; i++) {
// you can omit this if block if you don't care about the colon separators
if (i > 0) {
builder.append(':');
}
builder.append(String.format("%02X", digestBytes[i] & 0xFF));
}
return builder.toString();
}
You should do this once when the app starts and cache the result if you need it more than once.
I would like to be able to get the Linux UID (user ID) of an installed Android application.
Excerpt from Security and Permissions: "At install time, Android gives each package a distinct Linux user ID. The identity remains constant for the duration of the package's life on that device."
Is there a way to retrieve this UID?
adb shell dumpsys package com.example.myapp | grep userId=
Use PackageManager and getApplicationInfo().
The ā€¨packages.xml file present in /data/system
The packages.list file present in /data/system
Contain the list of applications installed and their corresponding UID's.
Use android.os.Process.myUid() to get the calling apps UID directly.
Using the PackageManager is not necessary to find the own UID.
PackageManager packageManager = getPackageManager();
try {
applicationId = String.valueOf(packageManager.getApplicationInfo("com.example.app", PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
As CommonsWare already wrote, you can use PackageManager to get the UID.
Here's an example:
int uid;
try {
ApplicationInfo info = context.getPackageManager().getApplicationInfo(
context.getPackageName(), 0);
uid = info.uid;
} catch (PackageManager.NameNotFoundException e) {
uid = -1;
}
Log.i(LOG_TAG, "UID = " + uid);
i have build my android apps using phone gap in this i wanted to add one more feature when my apps gets install it also check for flash player if flash player is not there ask to install through showing link how can i do this ??
i am new for phone gap
Please help me if possible share code with me
User following code
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null)
flashInstalled = true;
} catch (NameNotFoundException e) {
flashInstalled = false;
}
Detect if Flash is installed on Android and embed a Flash video in an Activity
from above: It will throw an exception of such a package doesn't exist.
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null)
flashInstalled = true;
} catch (NameNotFoundException e) {
flashInstalled = false;
}
as for installing it you could just provide a link to flash on the marketplace.
Am I late here? I have used a simple library FlashDetect.
And the usage is pretty simple :
<script type="text/javascript" src="flash_detect_min.js"></script>
...
<script type="text/javascript">
var isFlashInstalled = FlashDetect.installed;
</script>
I want to get the name and package name of a third party application installed in Android.
I have tried but I got the name of all applications (third party and pre installed).
How can I identify whether an application is a system application or an other application?
This will do the trick...cheers :)
PackageManager pm = getPackageManager();
List<PackageInfo> list = pm.getInstalledPackages(0);
for (PackageInfo pi : list) {
ApplicationInfo ai;
try {
ai = pm.getApplicationInfo(pi.packageName, 0);
System.out.println(">>>>>>packages is<<<<<<<<" + ai.publicSourceDir);
// this condition if satisfied means the application currently refered by ai
// variable is
// a system application
if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.d(getClass().getSimpleName(), ">>>>>>packages is system package" + pi.packageName);
}
} catch (NameNotFoundException e) {
Log.d(getClass().getSimpleName(), "Name not found", e);
}
}
Goto DDMS Perspective ---> Click on the Emulator or Device ---> Check File Explorer ---> data --> data folder ---> there will be app names installed, note their package name :)
Hope it helps