Can an app give its permission to another application in android? - android

I have an application say A that have all the permissions enabled at installation. Another app Say B don't have a permission and want to get that permission. Can B communicate with A, So that A can transfer its permission to B.
PLS reply, I'm stuck here. I want to get some permissions dynamically. Is this the best idea or any other idea?

As far as I know, apps can't necessarily give permissions to other apps, BUT AppB could inherit permissions from AppA IF you are the developer of both apps. If both AppA and AppB declare the same sharedUserId value in their manifest (android:sharedUserId="xyz") AND both AppA and AppB are signed with the same signature, then Android will consider them to be the same app as far as permissions go. So, AppB could exist on the device without permission "perm1" for example. Then, AppA could be installed with "perm1". IF AppA and AppB have the same sharedUserId and signature then, when AppA is installed, AppB will be "granted" "perm1".
I haven't tested this just now, but I know it used to work (as of a year ago or so).

That would be quite in-secure, don't your think, if an application could give any permissions to another application...
Some evil-doer would just have to convince you to install his A application ; and, then, no matter what other B application you'd install, that B application wouldn't have to request any specific permission at installation (those would later be granted by A) -- and B would still be able to do anything on your device ?
I sure hope what you're asking is not possible ;-)

Your application A can provide some Content Providers to access information. Application B could use the content provider of A to gain the information. http://developer.android.com/guide/topics/providers/content-providers.html
But somehow this sounds like you want to do something evil. If you like to have more information please provide more about your need to do that!

Yes this is possible in a roundabout way using PendingIntents. This is not an exact code snippet but should give you the idea:
You cannot transfer the permissions, but you can transfer capabilities to perform certain actions from A to B. Let's say you want to transfer the capability of executing a certain ACTION.
A needs to create a pending intent:
Intent intent = new Intent(ACTION);
PendingIntent pIntent = PendingIntent.getActivity(context, requestCode, intent, flags);
A sends this to B by marshalling the pending intent
Intent intent = new Intent(context, B.class);
intent.putExtra("pendingIntent", pIntent);
startActivity(intent);
At B we deserialize the pending intent and we can use it to perform the restricted ACTION
PendingIntent pIntent = intent.getExtra("pendingIntent");
pIntent.send();

Related

Which permissions does an Android launcher need to run shortcuts

I am writing an Android launcher that does not support widgets, but it does support shortcuts. One of the shortcuts provided by AOSP is Direct dial, and my launcher needs the android.permission.CALL_PHONE permission for that. My question is, are there any other permissions that I need to add, to allow all possible shortcuts, even those provided by third party apps?
FOR NOUGAT SHORTCUTS ( API LEVEL 25+ )
There is not standard permission to add/launch shortcuts. If target api level of your app is 25+, you can use ShortcutManager or static shortcut via .xml meta-data.
https://developer.android.com/guide/topics/ui/shortcuts.html
FOR LEGACY SHORTCUTS ( BELOW API LEVEL 25 )
If you want to install&use Legacy shortcuts without user interaction, you need to declare INSTALL SHORTCUT permission.
Legacy shortcuts use Intent Action:
Create shortcut for Launcher: "android.intent.action.CREATE_SHORTCUT"
Install shortcut on Launcher: "com.android.launcher.action.INSTALL_SHORTCUT"
Required permission on AndroidManifest.xml:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
You can find more resources when you search for intent actions above.
There is no way to know this in advance. Some apps just assume that the caller of their shortcuts have some permissions (e.g. some system launcher shortcuts often only work in the system launcher itself, as they sometimes require some self defined permission).
In general, any app that offers shortcuts, should run the code in itself instead of the calling app to be sure the required permissions are present, but apparently this is not the case in some apps (especially in launchers e.g.).
I face this problem in an app of mine every now and then as well and catch the exception and tell the user, that the selected shortcut does not support other apps and is implemented in a wrong way.
Example - shortcut to call someone that works and that does not work
E.g. think about a third party app that offers a direct call shortcut. It can handle this in 2 way:
wrong way
It can return an intent like following:
Intent intent = new Intent();
Intent launchIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
...
This intent can ONLY be run by an app that has the action call permission
correct way
The app knows, that the caller may not have the call phone permission, so it does not return the direct phone call intent directly, but a custom one that it handles itself like e.g.
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.icon);
Intent intent = new Intent();
Intent launchIntent = new Intent(this, MyPhoneCallActivity.class);
launchIntent.putExtra("number", number);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(pause != null ? (pause ? R.string.shortcut_pause : R.string.shortcut_resume) : R.string.shortcut_toggle_pause_resume));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
If the caller executes the shortcut, the MyPhoneCallActivity will be started - this runs inside the app itself and has all permissions of the shortcut provider. This activity then can simply execute the Intent.ACTION_CALL intent itself and finishes itself afterwards. This way, the calling app does not need any special permissions. The workaround via an activity is one solution for this problem that works.
This is not a definitive answer, as I couldn't find this explicitly stated anywhere, but it seems that only phone call shortcuts require a permission, so the CALL_PHONE permission is the only one you need, to launch shortcuts.
AOSP launcher only checks for the CALL_PHONE permission. Source: https://android.googlesource.com/platform/packages/apps/Launcher3/+/master/src/com/android/launcher3/Launcher.java#1630
I haven't been able to find any other types of shortcuts that require permissions.

how to grant permission for device id through Pending intent in android

I have two apps A & B. I have included device id permission in A and the whole code in B which gets deviceId. How can I grant permission for B from A using pending intent. IS there any possibility to do so??
Not possible permission are application specific it cannot be transferred from one app to another, you can transfer the information or data between application.
You can easily pass data from one activity to other thorough intent.
In Activity A:-
Intent intent=new Intent(A.this,B.class);
intent.putExtra(""DEVICEID",device_id);
startActivity(intent);
In Activity B:-
String device_id = getIntent().getExtras().getString("DEVICEID");
You can't do this. The user approves granting the permission to a specific app. That app cannot then (in secret without the user's knowledge or approval) grant this permission to other apps. That would be a huge security hole and would undermine the entire permissions concept.

Im looking to start a specific application using intent in android studio

I am looking to start a specific application(Dictionary app) from my app. Using intents, how would I go about launching that specific app and use it to look up the word.
There are implicit intents and explicit intents, you want an explicit intent to get your desirable.
Here is how you can do it.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
in the setComponent method your Dictionary app information should go in.
CommonsWare addition to this answer,
Using an explicit Intent to talk to a third-party app is rarely the right thing to do. This code will break if the activity is not exported, or requires permissions, or the developer refactors the code and changes the class name or package, etc.
If the author of the app is documenting that your recipe is the correct way to work with that activity on that app, then that is fine, as the developer presumably intends to support this use case.

Pasing data through app after install without launching

Refering to this post I need to ask something else.
I have an application "A" which download and install another app "B".
I want B to "transfer" data to A and then A will use this data to do work.
I know that we can transfer data with intent.
After installing B app with A, Android provide a choice with "Ok" or "Launch" ; my question is :
Is that possible to pass data from B to A when we click on "Ok"? (So we stay in A app without launching B)
If yes, how? Is that possible to "invisible" launch B? How should I code B to get this comportement?
I know that might be hard to understand, you can try to check my previous draw (here again).
EDIT:
I use this code to launch B installation from A.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString() + "/downloadedfile.apk"));
Intent.setDataAndType(uri, "application/vnd.android.package-archive");
getApplicationContext().startActivity(intent);
There are many ways to handle this, here is one that (I believe) is quite simple to implement. Since your A app [presumably] knows what it is installing:
App A: Add a BroadcastReceiver to react to the installation, though by default it is off.
Android: BroadcastReceiver on application install / uninstall
App B: Add a Service for background communication.
Note: A Service must be exported to be accessible to other apps via explicit intent, but this creates a security concern, as it is open to all other apps.
When a user of App A clicks to install App B:
Start the BroadcastReceiver with a filter set to detect the install:
stackoverflow...android-broadcastreceiver-on-application-install-uninstall
App A starts the install.
When the BroadcastReceiver detects the package has been added (the package name will be in the received intent,) it can stop the BroadcastReceiver, and can send an explicit Intent naming the Service in AppB. You can pass whatever data you need in the intent.
When the AppB service receives the intent, it can act in any way you'd like.
Service is always created using a non-null Intent, though the 'action' of explicit Intents is null.
Service.onStartCommand() might receive a null Intent if the service was re-created.
I'd fill in more of the code, but I have a day job ;)
Note:
Intent.ACTION_PACKAGE_ADDED called when a package is installed.
Intent.ACTION_PACKAGE_INSTALL was never used, and was deprecated in API 14.
http://developer.android.com/reference/android/content/BroadcastReceiver.html
http://developer.android.com/reference/android/content/Intent.html

is it possible to call more packages in single project,without installing the other packages in emulator/phone.want single apk

is it possible to call more packages in single project,without installing the other packages in emulator/phone,want single apk file..I Kept this code...but is possible when the package is available in emulator/phone..Please suggest me...if that package is not available in emulator/phone
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.abc.def.packname",
"com.abc.def.packname.MyActivity"));
startActivity(intent);
To be able to use an Intent to launch any Activity, there must be an Activity available to Handle it. This applies for both direct intents that target one particular Activity, and more general intents which would result in a Chooser dialog, like the share intent.
So in short, yes, the package you are referencing must be installed as well, or else your app will crash. If you have access to the source code of the other project, you could combine them into one. If this isn't possible, you could request that the user installs the other app when your app starts.

Categories

Resources