Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two app with shared UserID

Tags:

Can two app with shared UserID access each other resources like drawables or strings?

Can they access each other assets?

Can they enable or disable components of the other?

If any of these is possible please explain how it must be done.

I searched a lot but couldn't find any example about userId sharing.

like image 268
Ali Avatar asked Apr 29 '13 01:04

Ali


People also ask

What is shared user ID in Android?

The Shared User ID mechanism of the Android system allows multiple apps to share the same Linux user ID and Android permissions, access files each other, and even run in the same process. These apps need to have the same signature and Shared User ID cannot be changed after installation.

How can we make 2 different apps interact?

To take the user from one activity to another, your app must use an Intent to define your app's "intent" to do something. When you pass an Intent to the system with a method such as startActivity() , the system uses the Intent to identify and start the appropriate app component.

How can two Android applications share same Linux user ID and share same VM?

It's possible to arrange for two apps to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, apps with the same user ID can also arrange to run in the same Linux process and share the same VM. The apps must also be signed with the same certificate.

Can one app access another app?

Currently, Android 11 apps that request the "Query_All_Packages" permission can see the full list of apps you have stored on your device. Google has now updated its Developer Programme Policy, restricting which apps are allowed to use the permission.


1 Answers

You can use android:sharedUserId in AndroidManifest.xml to let your application share the same user id with another application.

android:sharedUserId

The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process.

Notice that they need to be signed by the same certificate.

Two applications share the same user id may access each other's resource.

For example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.shareusertesta"     android:versionCode="1"     android:versionName="1.0"      android:sharedUserId="com.example"> 

Then we can init a new context of com.example by:

Context friendContext = this.createPackageContext( "com.example",Context.CONTEXT_IGNORE_SECURITY); 

And access some resources of that application:

friendContext.getResources().getString(id); friendContext.getResources().getDrawable(id); friendContext.registerReceiver(...); 
like image 56
StarPinkER Avatar answered Sep 19 '22 15:09

StarPinkER