Question

If I uninstall an app from my Android device and reinstall it, does the user id change? For example, if the user was app-60 before, will it be app-60 (uid 60) again after reinstallation?

Was it helpful?

Solution

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. On a different device, the same package may have a different UID; what matters is that each package has a distinct UID on a given device."

When installing an app, Android by default(1) creates a UID specifically for that package, so that it can have its private resources / storage space. When no packages are using anymore that UID, the UID is deleted.

So I believe it changes. You can use Pratik's code to checkout and determine the difference after successive installs.

Here is the code for the Package Manager service. Could be a starting point to dig in deep.

OTHER TIPS

You can obtain UID within your application

String your app_selected = "your package name";
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(
        PackageManager.GET_META_DATA);
int UID;
//loop through the list of installed packages and see if the selected
//app is in the list
for (ApplicationInfo packageInfo : packages) {
    if(packageInfo.packageName.equals(app_selected)){
        //get the UID for the selected app
        UID = packageInfo.uid;

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top