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

Commit d8e97493 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Try again to cleanup all blocked apps"

parents e2b1b8e2 5e486f59
Loading
Loading
Loading
Loading
+37 −6
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.app.IStopUserCallback;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.RestrictionEntry;
import android.content.RestrictionEntry;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
@@ -116,7 +117,7 @@ public class UserManagerService extends IUserManager.Stub {


    private static final int MIN_USER_ID = 10;
    private static final int MIN_USER_ID = 10;


    private static final int USER_VERSION = 3;
    private static final int USER_VERSION = 4;


    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms


@@ -162,6 +163,8 @@ public class UserManagerService extends IUserManager.Stub {
    private boolean mGuestEnabled;
    private boolean mGuestEnabled;
    private int mNextSerialNumber;
    private int mNextSerialNumber;
    private int mUserVersion = 0;
    private int mUserVersion = 0;
    // Temporary cleanup variable, this and associated code should be removed later.
    private boolean mUnblockAppsTemp;


    private static UserManagerService sInstance;
    private static UserManagerService sInstance;


@@ -232,12 +235,14 @@ public class UserManagerService extends IUserManager.Stub {
                sInstance = this;
                sInstance = this;
            }
            }
        }
        }

    }
    }


    void systemReady() {
    void systemReady() {
        mUserPackageMonitor.register(ActivityThread.systemMain().getSystemContext(),
        final Context context = ActivityThread.systemMain().getSystemContext();
        mUserPackageMonitor.register(context,
                null, UserHandle.ALL, false);
                null, UserHandle.ALL, false);
        context.registerReceiver(mBootCompletedReceiver,
                new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
        userForeground(UserHandle.USER_OWNER);
        userForeground(UserHandle.USER_OWNER);
    }
    }


@@ -602,12 +607,17 @@ public class UserManagerService extends IUserManager.Stub {
                int userId = mRestrictionsPinStates.keyAt(i);
                int userId = mRestrictionsPinStates.keyAt(i);
                RestrictionsPinState state = mRestrictionsPinStates.valueAt(i);
                RestrictionsPinState state = mRestrictionsPinStates.valueAt(i);
                if (state.salt != 0 && state.pinHash != null) {
                if (state.salt != 0 && state.pinHash != null) {
                    removeRestrictionsForUser(userId);
                    removeRestrictionsForUser(userId, false);
                }
                }
            }
            }
            userVersion = 3;
            userVersion = 3;
        }
        }


        if (userVersion < 4) {
            mUnblockAppsTemp = true;
            userVersion = 4;
        }

        if (userVersion < USER_VERSION) {
        if (userVersion < USER_VERSION) {
            Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
            Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
                    + USER_VERSION);
                    + USER_VERSION);
@@ -1234,10 +1244,10 @@ public class UserManagerService extends IUserManager.Stub {
    public void removeRestrictions() {
    public void removeRestrictions() {
        checkManageUsersPermission("Only system can remove restrictions");
        checkManageUsersPermission("Only system can remove restrictions");
        final int userHandle = UserHandle.getCallingUserId();
        final int userHandle = UserHandle.getCallingUserId();
        removeRestrictionsForUser(userHandle);
        removeRestrictionsForUser(userHandle, true);
    }
    }


    private void removeRestrictionsForUser(final int userHandle) {
    private void removeRestrictionsForUser(final int userHandle, boolean unblockApps) {
        synchronized (mPackagesLock) {
        synchronized (mPackagesLock) {
            // Remove all user restrictions
            // Remove all user restrictions
            setUserRestrictions(new Bundle(), userHandle);
            setUserRestrictions(new Bundle(), userHandle);
@@ -1246,6 +1256,12 @@ public class UserManagerService extends IUserManager.Stub {
            // Remove any app restrictions
            // Remove any app restrictions
            cleanAppRestrictions(userHandle, true);
            cleanAppRestrictions(userHandle, true);
        }
        }
        if (unblockApps) {
            unblockAllAppsForUser(userHandle);
        }
    }

    private void unblockAllAppsForUser(final int userHandle) {
        mHandler.post(new Runnable() {
        mHandler.post(new Runnable() {
            @Override
            @Override
            public void run() {
            public void run() {
@@ -1572,4 +1588,19 @@ public class UserManagerService extends IUserManager.Stub {
            }
            }
        }
        }
    };
    };

    private BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() {
        @Override public void onReceive(Context context, Intent intent) {
            // This code block can be removed after cleanup
            if (mUnblockAppsTemp) {
                synchronized (mPackagesLock) {
                    // Unblock apps due to removal of restrictions feature
                    for (int i = 0; i < mUsers.size(); i++) {
                        int userId = mUsers.keyAt(i);
                        unblockAllAppsForUser(userId);
                    }
                }
            }
        }
    };
}
}