Merge "Require unlocked user for AppSearchImpl." into sc-dev
This commit is contained in:
@@ -38,6 +38,7 @@ import android.os.ParcelableException;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
@@ -49,6 +50,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/** TODO(b/142567528): add comments when implement this class */
|
/** TODO(b/142567528): add comments when implement this class */
|
||||||
public class AppSearchManagerService extends SystemService {
|
public class AppSearchManagerService extends SystemService {
|
||||||
@@ -56,6 +58,9 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
private PackageManagerInternal mPackageManagerInternal;
|
private PackageManagerInternal mPackageManagerInternal;
|
||||||
private ImplInstanceManager mImplInstanceManager;
|
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<>();
|
||||||
|
|
||||||
public AppSearchManagerService(Context context) {
|
public AppSearchManagerService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@@ -67,6 +72,11 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
mImplInstanceManager = ImplInstanceManager.getInstance(getContext());
|
mImplInstanceManager = ImplInstanceManager.getInstance(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUserUnlocked(@NonNull TargetUser user) {
|
||||||
|
mUnlockedUserIds.add(user.getUserIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
private class Stub extends IAppSearchManager.Stub {
|
private class Stub extends IAppSearchManager.Stub {
|
||||||
@Override
|
@Override
|
||||||
public void setSchema(
|
public void setSchema(
|
||||||
@@ -86,6 +96,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
List<AppSearchSchema> schemas = new ArrayList<>(schemaBundles.size());
|
List<AppSearchSchema> schemas = new ArrayList<>(schemaBundles.size());
|
||||||
for (int i = 0; i < schemaBundles.size(); i++) {
|
for (int i = 0; i < schemaBundles.size(); i++) {
|
||||||
@@ -133,6 +144,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
@@ -165,6 +177,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchBatchResult.Builder<String, Void> resultBuilder =
|
AppSearchBatchResult.Builder<String, Void> resultBuilder =
|
||||||
new AppSearchBatchResult.Builder<>();
|
new AppSearchBatchResult.Builder<>();
|
||||||
@@ -207,6 +220,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchBatchResult.Builder<String, Bundle> resultBuilder =
|
AppSearchBatchResult.Builder<String, Bundle> resultBuilder =
|
||||||
new AppSearchBatchResult.Builder<>();
|
new AppSearchBatchResult.Builder<>();
|
||||||
@@ -253,6 +267,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
@@ -287,6 +302,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
@@ -318,6 +334,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
// TODO(b/162450968) check nextPageToken is being advanced by the same uid as originally
|
// TODO(b/162450968) check nextPageToken is being advanced by the same uid as originally
|
||||||
// opened it
|
// opened it
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
SearchResultPage searchResultPage = impl.getNextPage(nextPageToken);
|
SearchResultPage searchResultPage = impl.getNextPage(nextPageToken);
|
||||||
@@ -337,6 +354,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
impl.invalidateNextPageToken(nextPageToken);
|
impl.invalidateNextPageToken(nextPageToken);
|
||||||
@@ -364,6 +382,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
impl.reportUsage(packageName, databaseName, namespace, uri, usageTimeMillis);
|
impl.reportUsage(packageName, databaseName, namespace, uri, usageTimeMillis);
|
||||||
@@ -392,6 +411,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchBatchResult.Builder<String, Void> resultBuilder =
|
AppSearchBatchResult.Builder<String, Void> resultBuilder =
|
||||||
new AppSearchBatchResult.Builder<>();
|
new AppSearchBatchResult.Builder<>();
|
||||||
@@ -431,6 +451,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
verifyCallingPackage(callingUid, packageName);
|
verifyCallingPackage(callingUid, packageName);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
@@ -453,6 +474,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
AppSearchImpl impl =
|
AppSearchImpl impl =
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
impl.persistToDisk();
|
impl.persistToDisk();
|
||||||
@@ -470,6 +492,7 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
int callingUserId = handleIncomingUser(userId, callingUid);
|
int callingUserId = handleIncomingUser(userId, callingUid);
|
||||||
final long callingIdentity = Binder.clearCallingIdentity();
|
final long callingIdentity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
verifyUserUnlocked(callingUserId);
|
||||||
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId);
|
||||||
invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null));
|
invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -479,6 +502,13 @@ public class AppSearchManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyUserUnlocked(int callingUserId) {
|
||||||
|
if (!mUnlockedUserIds.contains(callingUserId)) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"User " + callingUserId + " is locked or not running.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) {
|
private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) {
|
||||||
Preconditions.checkNotNull(callingPackage);
|
Preconditions.checkNotNull(callingPackage);
|
||||||
if (mPackageManagerInternal.getPackageUid(
|
if (mPackageManagerInternal.getPackageUid(
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ public final class ImplInstanceManager {
|
|||||||
/**
|
/**
|
||||||
* Gets an instance of AppSearchImpl for the given user.
|
* Gets an instance of AppSearchImpl for the given user.
|
||||||
*
|
*
|
||||||
* <p>If no AppSearchImpl instance exists for this user, Icing will be initialized and one will
|
* <p>If no AppSearchImpl instance exists for the unlocked user, Icing will be initialized and
|
||||||
* be created.
|
* one will be created.
|
||||||
*
|
*
|
||||||
* @param context The context
|
* @param context The context
|
||||||
* @param userId The multi-user userId of the device user calling AppSearch
|
* @param userId The multi-user userId of the device user calling AppSearch
|
||||||
|
|||||||
Reference in New Issue
Block a user