Android N lets you link an activity of yours into your app's page in
Settings. Just add an <intent-filter>
for android.intent.action.APPLICATION_PREFERENCES
. Android N's Settings app will look for the activity in your app that
has that <intent-filter>
. If Settings finds one, it will add a gear
icon to your app's page in Settings, and if the user taps the gear, they
will be taken to your designated activity.
I was worried about security, and so I filed an issue, looking for a permission we could use with android:permission
to allow Settings to start our activity, but not allow other apps to start our activity (e.g., WRITE_SECURE_SETTINGS
).
cketti then pointed out that you could just mark the activity as not exported, via android:exported="false"
. Much to my surprise, this works.
How can the Settings app start an activity that is marked as not exported?
I can certainly see there being a permission that controls this. However, a quick read of the Settings app's manifest (master branch, n-developer-preview-5 branch) didn't turn up anything obvious.
So:
Is there a permission that allows an app to start a non-exported component of another app? If so, which is it?
If not, how is Settings pulling this off?
If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);
The exported attribute is used to define if an activity, service, or receiver in your app is accessible and can be launched from an external application. As a practical example, if you try to share a file you'll see a set of applications available.
Swipe up from the bottom of your screen to the top. If you get All Apps , tap it. Tap the app that you want to open.
The intent-filter inside the activity tells Android which Activity to launch.
I would guess there is nothing in the manifest that gives an app the permission to call exported activities. I believe the way it's accomplishing this is by setting LOCAL_PRIVILEGED_MODULE := true
in the Android.mk file for the Settings application. This flag will give an application system level permissions and place it in the system/priv-app/
directory during OS compile time.
If you look at frameworks/base/core/java/android/app/ActivityManager.java
for the method checkComponentPermission
you can see that if the UID is that of the SYSTEM, component permission is granted regardless of the exported setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With