Loading apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +14 −6 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.server.LocalServices; import com.android.server.SystemService; Loading @@ -58,8 +59,11 @@ public class AppSearchManagerService extends SystemService { private PackageManagerInternal mPackageManagerInternal; private ImplInstanceManager mImplInstanceManager; // Cache of unlocked user ids so we don't have to query UserManager service each time. private final Set<Integer> mUnlockedUserIds = new ArraySet<>(); // Cache of unlocked user ids so we don't have to query UserManager service each time. The // "locked" suffix refers to the fact that access to the field should be locked; unrelated to // the unlocked status of user ids. @GuardedBy("mUnlockedUserIdsLocked") private final Set<Integer> mUnlockedUserIdsLocked = new ArraySet<>(); public AppSearchManagerService(Context context) { super(context); Loading @@ -74,7 +78,9 @@ public class AppSearchManagerService extends SystemService { @Override public void onUserUnlocked(@NonNull TargetUser user) { mUnlockedUserIds.add(user.getUserIdentifier()); synchronized (mUnlockedUserIdsLocked) { mUnlockedUserIdsLocked.add(user.getUserIdentifier()); } } private class Stub extends IAppSearchManager.Stub { Loading Loading @@ -503,11 +509,13 @@ public class AppSearchManagerService extends SystemService { } private void verifyUserUnlocked(int callingUserId) { if (!mUnlockedUserIds.contains(callingUserId)) { synchronized (mUnlockedUserIdsLocked) { if (!mUnlockedUserIdsLocked.contains(callingUserId)) { throw new IllegalStateException( "User " + callingUserId + " is locked or not running."); } } } private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) { Preconditions.checkNotNull(callingPackage); Loading apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +12 −12 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.storage.StorageManager; import android.util.SparseArray; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.appsearch.external.localstorage.AppSearchImpl; import java.io.File; Loading @@ -43,7 +44,9 @@ public final class ImplInstanceManager { private static ImplInstanceManager sImplInstanceManager; private final SparseArray<AppSearchImpl> mInstances = new SparseArray<>(); @GuardedBy("mInstancesLocked") private final SparseArray<AppSearchImpl> mInstancesLocked = new SparseArray<>(); private final String mGlobalQuerierPackage; private ImplInstanceManager(@NonNull String globalQuerierPackage) { Loading Loading @@ -81,20 +84,17 @@ public final class ImplInstanceManager { * @return An initialized {@link AppSearchImpl} for this user */ @NonNull public AppSearchImpl getAppSearchImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { AppSearchImpl instance = mInstances.get(userId); if (instance == null) { synchronized (ImplInstanceManager.class) { instance = mInstances.get(userId); public AppSearchImpl getAppSearchImpl( @NonNull Context context, @UserIdInt int userId) throws AppSearchException { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); if (instance == null) { instance = createImpl(context, userId); mInstances.put(userId, instance); } } mInstancesLocked.put(userId, instance); } return instance; } } private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { Loading Loading
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +14 −6 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.server.LocalServices; import com.android.server.SystemService; Loading @@ -58,8 +59,11 @@ public class AppSearchManagerService extends SystemService { private PackageManagerInternal mPackageManagerInternal; private ImplInstanceManager mImplInstanceManager; // Cache of unlocked user ids so we don't have to query UserManager service each time. private final Set<Integer> mUnlockedUserIds = new ArraySet<>(); // Cache of unlocked user ids so we don't have to query UserManager service each time. The // "locked" suffix refers to the fact that access to the field should be locked; unrelated to // the unlocked status of user ids. @GuardedBy("mUnlockedUserIdsLocked") private final Set<Integer> mUnlockedUserIdsLocked = new ArraySet<>(); public AppSearchManagerService(Context context) { super(context); Loading @@ -74,7 +78,9 @@ public class AppSearchManagerService extends SystemService { @Override public void onUserUnlocked(@NonNull TargetUser user) { mUnlockedUserIds.add(user.getUserIdentifier()); synchronized (mUnlockedUserIdsLocked) { mUnlockedUserIdsLocked.add(user.getUserIdentifier()); } } private class Stub extends IAppSearchManager.Stub { Loading Loading @@ -503,11 +509,13 @@ public class AppSearchManagerService extends SystemService { } private void verifyUserUnlocked(int callingUserId) { if (!mUnlockedUserIds.contains(callingUserId)) { synchronized (mUnlockedUserIdsLocked) { if (!mUnlockedUserIdsLocked.contains(callingUserId)) { throw new IllegalStateException( "User " + callingUserId + " is locked or not running."); } } } private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) { Preconditions.checkNotNull(callingPackage); Loading
apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +12 −12 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.storage.StorageManager; import android.util.SparseArray; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.server.appsearch.external.localstorage.AppSearchImpl; import java.io.File; Loading @@ -43,7 +44,9 @@ public final class ImplInstanceManager { private static ImplInstanceManager sImplInstanceManager; private final SparseArray<AppSearchImpl> mInstances = new SparseArray<>(); @GuardedBy("mInstancesLocked") private final SparseArray<AppSearchImpl> mInstancesLocked = new SparseArray<>(); private final String mGlobalQuerierPackage; private ImplInstanceManager(@NonNull String globalQuerierPackage) { Loading Loading @@ -81,20 +84,17 @@ public final class ImplInstanceManager { * @return An initialized {@link AppSearchImpl} for this user */ @NonNull public AppSearchImpl getAppSearchImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { AppSearchImpl instance = mInstances.get(userId); if (instance == null) { synchronized (ImplInstanceManager.class) { instance = mInstances.get(userId); public AppSearchImpl getAppSearchImpl( @NonNull Context context, @UserIdInt int userId) throws AppSearchException { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); if (instance == null) { instance = createImpl(context, userId); mInstances.put(userId, instance); } } mInstancesLocked.put(userId, instance); } return instance; } } private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { Loading