Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d277a7b authored by Chad Brubaker's avatar Chad Brubaker
Browse files

Change ANDROID_ID for Instant Apps

ANDROID_ID for Instant Apps now has the following properties:
1) per-app scoped
2) reset if the user clears the Instant App
3) remains the same if the Instant App gets upgraded to an installed
app.

Note that if the user goes instant -> installed_1 -> uninstall ->
installed_2 the ANDROID_ID at installed_1 will not be the same as
installed_2. This was deemed better than the id changing on the upgrade
step.

Test: manual
Change-Id: I532975c50049c94ff80902a897e001dd35a69f9f
parent 4132f860
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2630,4 +2630,13 @@ public class ApplicationPackageManager extends PackageManager {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public String getInstantAppAndroidId(String packageName, UserHandle user) {
        try {
            return mPM.getInstantAppAndroidId(packageName, user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -634,4 +634,6 @@ interface IPackageManager {
    ComponentName getInstantAppResolverSettingsComponent();

    ComponentName getInstantAppInstallerComponent();

    String getInstantAppAndroidId(String packageName, int userId);
}
+8 −0
Original line number Diff line number Diff line
@@ -6293,4 +6293,12 @@ public abstract class PackageManager {
     */
    @SystemApi
    public abstract ComponentName getInstantAppInstallerComponent();

    /**
     * Return the Android Id for a given Instant App.
     *
     * @see {@link android.provider.Settings.Secure#ANDROID_ID}
     * @hide
     */
    public abstract String getInstantAppAndroidId(String packageName, @NonNull UserHandle user);
}
+4 −0
Original line number Diff line number Diff line
@@ -5082,6 +5082,10 @@ public final class Settings {
         * (available on certain devices running Android 4.2 or higher), each user appears as a
         * completely separate device, so the {@code ANDROID_ID} value is unique to each
         * user.</p>
         *
         * <p class="note"><strong>Note:</strong> If the caller is an Instant App the id is scoped
         * to the Instant App, it is generated when the Instant App is first installed and reset if
         * the user clears the Instant App.
         */
        public static final String ANDROID_ID = "android_id";

+27 −0
Original line number Diff line number Diff line
@@ -1109,6 +1109,33 @@ public class SettingsProvider extends ContentProvider {
        // Retrieve the ssaid from the table if present.
        final Setting ssaid = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SSAID, owningUserId,
                name);
        // If the app is an Instant App use its stored SSAID instead of our own.
        final String instantSsaid;
        final long token = Binder.clearCallingIdentity();
        try {
            instantSsaid = mPackageManager.getInstantAppAndroidId(callingPkg.packageName,
                    owningUserId);
        } catch (RemoteException e) {
            Slog.e(LOG_TAG, "Failed to get Instant App Android ID", e);
            return null;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        if (instantSsaid != null) {
            // Use the stored value if it is still valid.
            if (ssaid != null && instantSsaid.equals(ssaid.getValue())) {
                return ssaid;
            }
            // The value has changed, update the stored value.
            final SettingsState ssaidSettings = mSettingsRegistry.getSettingsLocked(
                    SETTINGS_TYPE_SSAID, owningUserId);
            final boolean success = ssaidSettings.insertSettingLocked(name, instantSsaid, null,
                    true, callingPkg.packageName);
            if (!success) {
                throw new IllegalStateException("Failed to update instant app android id");
            }
            return mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SSAID, owningUserId, name);
        }

        // Lazy initialize ssaid if not yet present in ssaid table.
        if (ssaid == null || ssaid.isNull() || ssaid.getValue() == null) {
Loading