Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can the Settings App Start an App's Non-Exported Activity?

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?

like image 763
CommonsWare Avatar asked Aug 18 '16 11:08

CommonsWare


People also ask

How do I start an app from another activity?

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);

What is exported activity in Android?

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.

How do I open another app on Android?

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.

Where would we specify which activity should launch first in app?

The intent-filter inside the activity tells Android which Activity to launch.


Video Answer


1 Answers

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.

like image 84
Bobbake4 Avatar answered Oct 24 '22 18:10

Bobbake4