Loading services/core/java/com/android/server/timedetector/TimeDetectorService.java +13 −16 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.timedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.time.ExternalTimeSuggestion; import android.app.time.ITimeDetectorListener; import android.app.time.TimeCapabilitiesAndConfig; Loading @@ -30,7 +29,6 @@ import android.app.timedetector.ITimeDetectorService; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.TelephonyTimeSuggestion; import android.content.Context; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.ParcelableException; Loading Loading @@ -166,8 +164,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub */ boolean updateConfiguration(@UserIdInt int userId, @NonNull TimeConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "updateConfiguration", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "updateConfiguration"); enforceManageTimeDetectorPermission(); Loading Loading @@ -280,11 +277,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub public TimeState getTimeState() { enforceManageTimeDetectorPermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { return mTimeDetectorStrategy.getTimeState(); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -295,11 +292,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void setTimeState(@NonNull TimeState timeState) { enforceManageTimeDetectorPermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { mTimeDetectorStrategy.setTimeState(timeState); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -308,11 +305,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub enforceManageTimeDetectorPermission(); Objects.requireNonNull(time); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { return mTimeDetectorStrategy.confirmTime(time); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -324,13 +321,13 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub // This calls suggestManualTime() as the logic is identical, it only differs in the // permission required, which is handled on the line above. int userId = mCallerIdentityInjector.getCallingUserId(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { final boolean bypassUserPolicyChecks = false; return mTimeDetectorStrategy.suggestManualTime( userId, suggestion, bypassUserPolicyChecks); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading Loading @@ -377,11 +374,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void clearLatestNetworkTime() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { mTimeDetectorStrategy.clearLatestNetworkSuggestion(); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading Loading @@ -473,7 +470,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void clearNetworkTimeForSystemClockForTests() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { // TODO(b/222295093): Remove this condition once we can be sure that all uses of // NtpTrustedTime result in a suggestion being made to the time detector. Loading @@ -485,7 +482,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub mNtpTrustedTime.clearCachedTimeResult(); } } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading services/core/java/com/android/server/timezonedetector/CallerIdentityInjector.java +13 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.timezonedetector; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.os.Binder; import android.os.UserHandle; Loading @@ -29,6 +30,12 @@ public interface CallerIdentityInjector { /** A singleton for the real implementation of {@link CallerIdentityInjector}. */ CallerIdentityInjector REAL = new Real(); /** * A {@link ActivityManager#handleIncomingUser} call. This can be used to map the abstract * user ID value USER_CURRENT to the actual user ID. */ @UserIdInt int resolveUserId(@UserIdInt int userId, String debugInfo); /** A {@link UserHandle#getCallingUserId()} call. */ @UserIdInt int getCallingUserId(); Loading @@ -44,6 +51,12 @@ public interface CallerIdentityInjector { protected Real() { } @Override public int resolveUserId(@UserIdInt int userId, String debugName) { return ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, debugName, null); } @Override public int getCallingUserId() { return UserHandle.getCallingUserId(); Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java +3 −6 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.timezonedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.time.ITimeZoneDetectorListener; import android.app.time.TimeZoneCapabilitiesAndConfig; import android.app.time.TimeZoneConfiguration; Loading @@ -28,7 +27,6 @@ import android.app.timezonedetector.ITimeZoneDetectorService; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import android.content.Context; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; Loading Loading @@ -168,8 +166,8 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub enforceManageTimeZoneDetectorPermission(); // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "getCapabilitiesAndConfig", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "getCapabilitiesAndConfig"); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { Loading @@ -190,8 +188,7 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub boolean updateConfiguration( @UserIdInt int userId, @NonNull TimeZoneConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "updateConfiguration", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "updateConfiguration"); enforceManageTimeZoneDetectorPermission(); Loading services/tests/timetests/AndroidManifest.xml +0 −3 Original line number Diff line number Diff line Loading @@ -17,9 +17,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.framework.services.tests.time"> <!-- Required for user checks --> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <application> <uses-library android:name="android.test.runner" /> </application> Loading services/tests/timetests/src/com/android/server/timezonedetector/TestCallerIdentityInjector.java +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ public class TestCallerIdentityInjector implements CallerIdentityInjector { mCurrentCallingUserId = userId; } @Override public int resolveUserId(int userId, String debugInfo) { return userId; } @Override public int getCallingUserId() { assertNotNull("callingUserId has been cleared", mCurrentCallingUserId); Loading Loading
services/core/java/com/android/server/timedetector/TimeDetectorService.java +13 −16 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.timedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.time.ExternalTimeSuggestion; import android.app.time.ITimeDetectorListener; import android.app.time.TimeCapabilitiesAndConfig; Loading @@ -30,7 +29,6 @@ import android.app.timedetector.ITimeDetectorService; import android.app.timedetector.ManualTimeSuggestion; import android.app.timedetector.TelephonyTimeSuggestion; import android.content.Context; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.ParcelableException; Loading Loading @@ -166,8 +164,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub */ boolean updateConfiguration(@UserIdInt int userId, @NonNull TimeConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "updateConfiguration", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "updateConfiguration"); enforceManageTimeDetectorPermission(); Loading Loading @@ -280,11 +277,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub public TimeState getTimeState() { enforceManageTimeDetectorPermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { return mTimeDetectorStrategy.getTimeState(); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -295,11 +292,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void setTimeState(@NonNull TimeState timeState) { enforceManageTimeDetectorPermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { mTimeDetectorStrategy.setTimeState(timeState); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -308,11 +305,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub enforceManageTimeDetectorPermission(); Objects.requireNonNull(time); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { return mTimeDetectorStrategy.confirmTime(time); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading @@ -324,13 +321,13 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub // This calls suggestManualTime() as the logic is identical, it only differs in the // permission required, which is handled on the line above. int userId = mCallerIdentityInjector.getCallingUserId(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { final boolean bypassUserPolicyChecks = false; return mTimeDetectorStrategy.suggestManualTime( userId, suggestion, bypassUserPolicyChecks); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading Loading @@ -377,11 +374,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void clearLatestNetworkTime() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { mTimeDetectorStrategy.clearLatestNetworkSuggestion(); } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading Loading @@ -473,7 +470,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub void clearNetworkTimeForSystemClockForTests() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { // TODO(b/222295093): Remove this condition once we can be sure that all uses of // NtpTrustedTime result in a suggestion being made to the time detector. Loading @@ -485,7 +482,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub mNtpTrustedTime.clearCachedTimeResult(); } } finally { Binder.restoreCallingIdentity(token); mCallerIdentityInjector.restoreCallingIdentity(token); } } Loading
services/core/java/com/android/server/timezonedetector/CallerIdentityInjector.java +13 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.timezonedetector; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.os.Binder; import android.os.UserHandle; Loading @@ -29,6 +30,12 @@ public interface CallerIdentityInjector { /** A singleton for the real implementation of {@link CallerIdentityInjector}. */ CallerIdentityInjector REAL = new Real(); /** * A {@link ActivityManager#handleIncomingUser} call. This can be used to map the abstract * user ID value USER_CURRENT to the actual user ID. */ @UserIdInt int resolveUserId(@UserIdInt int userId, String debugInfo); /** A {@link UserHandle#getCallingUserId()} call. */ @UserIdInt int getCallingUserId(); Loading @@ -44,6 +51,12 @@ public interface CallerIdentityInjector { protected Real() { } @Override public int resolveUserId(@UserIdInt int userId, String debugName) { return ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, debugName, null); } @Override public int getCallingUserId() { return UserHandle.getCallingUserId(); Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java +3 −6 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.server.timezonedetector; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.time.ITimeZoneDetectorListener; import android.app.time.TimeZoneCapabilitiesAndConfig; import android.app.time.TimeZoneConfiguration; Loading @@ -28,7 +27,6 @@ import android.app.timezonedetector.ITimeZoneDetectorService; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import android.content.Context; import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; Loading Loading @@ -168,8 +166,8 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub enforceManageTimeZoneDetectorPermission(); // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "getCapabilitiesAndConfig", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "getCapabilitiesAndConfig"); final long token = mCallerIdentityInjector.clearCallingIdentity(); try { Loading @@ -190,8 +188,7 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub boolean updateConfiguration( @UserIdInt int userId, @NonNull TimeZoneConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, false, false, "updateConfiguration", null); int resolvedUserId = mCallerIdentityInjector.resolveUserId(userId, "updateConfiguration"); enforceManageTimeZoneDetectorPermission(); Loading
services/tests/timetests/AndroidManifest.xml +0 −3 Original line number Diff line number Diff line Loading @@ -17,9 +17,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.framework.services.tests.time"> <!-- Required for user checks --> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <application> <uses-library android:name="android.test.runner" /> </application> Loading
services/tests/timetests/src/com/android/server/timezonedetector/TestCallerIdentityInjector.java +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ public class TestCallerIdentityInjector implements CallerIdentityInjector { mCurrentCallingUserId = userId; } @Override public int resolveUserId(int userId, String debugInfo) { return userId; } @Override public int getCallingUserId() { assertNotNull("callingUserId has been cleared", mCurrentCallingUserId); Loading