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

Commit 32ce3c87 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "[DO NOT MERGE] Don't show account access request UI until app launched." into nyc-mr1-dev

parents 56ecb0a6 d63cde7b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -160,4 +160,12 @@ public abstract class PackageManagerInternal {
     * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
     */
    public abstract boolean isPackageDataProtected(int userId, String packageName);

    /**
     * Gets whether the package was ever launched.
     * @param packageName The package name.
     * @param userId The user for which to check.
     * @return Whether was launched.
     */
    public abstract boolean wasPackageEverLaunched(String packageName, int userId);
}
+4 −1
Original line number Diff line number Diff line
@@ -257,7 +257,9 @@ public final class AccountManagerBackupHelper {
            }

            // Make sure we eventually prune the in-memory pending restores
            synchronized (mLock) {
                mRestoreCancelCommand = new CancelRestoreCommand();
            }
            mAccountManagerService.mMessageHandler.postDelayed(mRestoreCancelCommand,
                    PENDING_RESTORE_TIMEOUT_MILLIS);
        } catch (XmlPullParserException | IOException e) {
@@ -269,6 +271,7 @@ public final class AccountManagerBackupHelper {
        @Override
        public void onPackageAdded(String packageName, int uid) {
            synchronized (mLock) {
                // Can happen if restore is cancelled and there is a notification in flight
                if (mRestorePendingAppPermissions == null) {
                    return;
                }
+1 −1
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ public class AccountManagerService

    private final SparseArray<UserAccounts> mUsers = new SparseArray<>();
    private final SparseBooleanArray mLocalUnlockedUsers = new SparseBooleanArray();
    private CopyOnWriteArrayList<AccountManagerInternal.OnAppPermissionChangeListener>
    private final CopyOnWriteArrayList<AccountManagerInternal.OnAppPermissionChangeListener>
            mAppPermissionChangeListeners = new CopyOnWriteArrayList<>();

    private static AtomicReference<AccountManagerService> sThis = new AtomicReference<>();
+17 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ProviderInfo;
import android.content.pm.RegisteredServicesCache;
import android.content.pm.RegisteredServicesCacheListener;
@@ -324,6 +325,8 @@ public class SyncManager {

    private final AccountManagerInternal mAccountManagerInternal;

    private final PackageManagerInternal mPackageManagerInternal;

    private List<UserInfo> getAllUsers() {
        return mUserManager.getUsers();
    }
@@ -575,6 +578,7 @@ public class SyncManager {
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mAccountManager = (AccountManager) mContext.getSystemService(Context.ACCOUNT_SERVICE);
        mAccountManagerInternal = LocalServices.getService(AccountManagerInternal.class);
        mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);

        mAccountManagerInternal.addOnAppPermissionChangeListener((Account account, int uid) -> {
            // If the UID gained access to the account kick-off syncs lacking account access
@@ -891,9 +895,13 @@ public class SyncManager {
                                + "isSyncable == SYNCABLE_NO_ACCOUNT_ACCESS");
                    }
                    Bundle finalExtras = new Bundle(extras);
                    String packageName = syncAdapterInfo.componentName.getPackageName();
                    // If the app did not run and has no account access, done
                    if (!mPackageManagerInternal.wasPackageEverLaunched(packageName, userId)) {
                        continue;
                    }
                    mAccountManagerInternal.requestAccountAccess(account.account,
                            syncAdapterInfo.componentName.getPackageName(),
                            UserHandle.getUserId(owningUid),
                            packageName, userId,
                            new RemoteCallback((Bundle result) -> {
                                if (result != null
                                        && result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT)) {
@@ -2798,9 +2806,14 @@ public class SyncManager {
            final int syncOpState = computeSyncOpState(op);
            switch (syncOpState) {
                case SYNC_OP_STATE_INVALID_NO_ACCOUNT_ACCESS: {
                    String packageName = op.owningPackage;
                    final int userId = UserHandle.getUserId(op.owningUid);
                    // If the app did not run and has no account access, done
                    if (!mPackageManagerInternal.wasPackageEverLaunched(packageName, userId)) {
                        return;
                    }
                    mAccountManagerInternal.requestAccountAccess(op.target.account,
                            op.owningPackage, UserHandle.getUserId(op.owningUid),
                            new RemoteCallback((Bundle result) -> {
                            packageName, userId, new RemoteCallback((Bundle result) -> {
                                if (result != null
                                        && result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT)) {
                                    updateOrAddPeriodicSync(target, pollFrequency, flex, extras);
+7 −0
Original line number Diff line number Diff line
@@ -21064,6 +21064,13 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        public boolean isPackageDataProtected(int userId, String packageName) {
            return mProtectedPackages.isPackageDataProtected(userId, packageName);
        }
        @Override
        public boolean wasPackageEverLaunched(String packageName, int userId) {
            synchronized (mPackages) {
                return mSettings.wasPackageEverLaunchedLPr(packageName, userId);
            }
        }
    }
    @Override
Loading