Fix bugs found during cts test.

Test: atest CtsAmbientContextServiceTestCases
Bug: 225108951
Change-Id: I7ca3832cfa6e9dc14563678c93344c3ded4478ee
This commit is contained in:
Kathy Chen
2022-03-29 16:09:33 -07:00
parent 45081ab6a0
commit 616d6100ae
2 changed files with 13 additions and 5 deletions

View File

@@ -217,9 +217,13 @@ final class AmbientContextManagerPerUserService extends
RemoteCallback detectionResultCallback, RemoteCallback statusCallback) {
Slog.d(TAG, "Requested detection of " + request.getEventTypes());
synchronized (mLock) {
ensureRemoteServiceInitiated();
mRemoteService.startDetection(request, callingPackage, detectionResultCallback,
statusCallback);
if (setUpServiceIfNeeded()) {
ensureRemoteServiceInitiated();
mRemoteService.startDetection(request, callingPackage, detectionResultCallback,
statusCallback);
} else {
Slog.w(TAG, "No valid component found for AmbientContextDetectionService");
}
}
}
@@ -371,8 +375,10 @@ final class AmbientContextManagerPerUserService extends
void stopDetection(String packageName) {
Slog.d(TAG, "Stop detection for " + packageName);
synchronized (mLock) {
ensureRemoteServiceInitiated();
mRemoteService.stopDetection(packageName);
if (mComponentName != null) {
ensureRemoteServiceInitiated();
mRemoteService.stopDetection(packageName);
}
}
}

View File

@@ -249,6 +249,8 @@ public class AmbientContextManagerService extends
Objects.requireNonNull(eventTypes);
Objects.requireNonNull(callingPackage);
assertCalledByPackageOwner(callingPackage);
mContext.enforceCallingOrSelfPermission(
Manifest.permission.ACCESS_AMBIENT_CONTEXT_EVENT, TAG);
mService.onStartConsentActivity(eventTypes, callingPackage);
}