Loading packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java +2 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import com.android.systemui.dreams.DreamOverlayNotificationCountProvider; import com.android.systemui.dreams.DreamOverlayService; import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule; import com.android.systemui.dreams.touch.scrim.dagger.ScrimModule; import com.android.systemui.process.condition.UserProcessCondition; import com.android.systemui.process.condition.SystemProcessCondition; import com.android.systemui.shared.condition.Condition; import com.android.systemui.shared.condition.Monitor; Loading Loading @@ -126,7 +126,7 @@ public interface DreamModule { @Binds @IntoSet @Named(DREAM_PRETEXT_CONDITIONS) Condition bindsUserProcessCondition(UserProcessCondition condition); Condition bindSystemProcessCondition(SystemProcessCondition condition); /** */ @Provides Loading packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java +5 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,10 @@ public class ProcessWrapper { @Inject public ProcessWrapper() {} public int getUserHandleIdentifier() { return android.os.Process.myUserHandle().getIdentifier(); /** * Returns {@code true} if System User is running the current process. */ public boolean isSystemUser() { return android.os.Process.myUserHandle().isSystem(); } } packages/SystemUI/src/com/android/systemui/process/condition/UserProcessCondition.java→packages/SystemUI/src/com/android/systemui/process/condition/SystemProcessCondition.java +6 −9 Original line number Diff line number Diff line Loading @@ -17,29 +17,26 @@ package com.android.systemui.process.condition; import com.android.systemui.process.ProcessWrapper; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.condition.Condition; import javax.inject.Inject; /** * {@link UserProcessCondition} provides a signal when the process handle belongs to the current * user. * {@link SystemProcessCondition} checks to make sure the current process is being ran by the * System User. */ public class UserProcessCondition extends Condition { public class SystemProcessCondition extends Condition { private final ProcessWrapper mProcessWrapper; private final UserTracker mUserTracker; @Inject public UserProcessCondition(ProcessWrapper processWrapper, UserTracker userTracker) { public SystemProcessCondition(ProcessWrapper processWrapper) { super(); mProcessWrapper = processWrapper; mUserTracker = userTracker; } @Override protected void start() { updateCondition(mUserTracker.getUserId() == mProcessWrapper.getUserHandleIdentifier()); updateCondition(mProcessWrapper.isSystemUser()); } @Override Loading packages/SystemUI/tests/src/com/android/systemui/process/condition/UserProcessConditionTest.java→packages/SystemUI/tests/src/com/android/systemui/process/condition/SystemProcessConditionTest.java +11 −18 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.process.ProcessWrapper; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.condition.Condition; import com.android.systemui.shared.condition.Monitor; import com.android.systemui.util.concurrency.FakeExecutor; Loading @@ -41,10 +40,7 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper @SmallTest public class UserProcessConditionTest extends SysuiTestCase { @Mock UserTracker mUserTracker; public class SystemProcessConditionTest extends SysuiTestCase { @Mock ProcessWrapper mProcessWrapper; Loading @@ -59,15 +55,14 @@ public class UserProcessConditionTest extends SysuiTestCase { } /** * Verifies condition reports false when tracker reports a different user id than the * identifier from the process handle. * Verifies condition reports false when tracker reports the process is being ran by the * system user. */ @Test public void testConditionFailsWithDifferentIds() { public void testConditionFailsWithNonSystemProcess() { final Condition condition = new UserProcessCondition(mProcessWrapper, mUserTracker); when(mProcessWrapper.getUserHandleIdentifier()).thenReturn(0); when(mUserTracker.getUserId()).thenReturn(1); final Condition condition = new SystemProcessCondition(mProcessWrapper); when(mProcessWrapper.isSystemUser()).thenReturn(false); final Monitor monitor = new Monitor(mExecutor); Loading @@ -81,15 +76,14 @@ public class UserProcessConditionTest extends SysuiTestCase { } /** * Verifies condition reports false when tracker reports a different user id than the * identifier from the process handle. * Verifies condition reports true when tracker reports the process is being ran by the * system user. */ @Test public void testConditionSucceedsWithSameIds() { public void testConditionSucceedsWithSystemProcess() { final Condition condition = new UserProcessCondition(mProcessWrapper, mUserTracker); when(mProcessWrapper.getUserHandleIdentifier()).thenReturn(0); when(mUserTracker.getUserId()).thenReturn(0); final Condition condition = new SystemProcessCondition(mProcessWrapper); when(mProcessWrapper.isSystemUser()).thenReturn(true); final Monitor monitor = new Monitor(mExecutor); Loading @@ -101,5 +95,4 @@ public class UserProcessConditionTest extends SysuiTestCase { verify(mCallback).onConditionsChanged(true); } } Loading
packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamModule.java +2 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import com.android.systemui.dreams.DreamOverlayNotificationCountProvider; import com.android.systemui.dreams.DreamOverlayService; import com.android.systemui.dreams.complication.dagger.RegisteredComplicationsModule; import com.android.systemui.dreams.touch.scrim.dagger.ScrimModule; import com.android.systemui.process.condition.UserProcessCondition; import com.android.systemui.process.condition.SystemProcessCondition; import com.android.systemui.shared.condition.Condition; import com.android.systemui.shared.condition.Monitor; Loading Loading @@ -126,7 +126,7 @@ public interface DreamModule { @Binds @IntoSet @Named(DREAM_PRETEXT_CONDITIONS) Condition bindsUserProcessCondition(UserProcessCondition condition); Condition bindSystemProcessCondition(SystemProcessCondition condition); /** */ @Provides Loading
packages/SystemUI/src/com/android/systemui/process/ProcessWrapper.java +5 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,10 @@ public class ProcessWrapper { @Inject public ProcessWrapper() {} public int getUserHandleIdentifier() { return android.os.Process.myUserHandle().getIdentifier(); /** * Returns {@code true} if System User is running the current process. */ public boolean isSystemUser() { return android.os.Process.myUserHandle().isSystem(); } }
packages/SystemUI/src/com/android/systemui/process/condition/UserProcessCondition.java→packages/SystemUI/src/com/android/systemui/process/condition/SystemProcessCondition.java +6 −9 Original line number Diff line number Diff line Loading @@ -17,29 +17,26 @@ package com.android.systemui.process.condition; import com.android.systemui.process.ProcessWrapper; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.condition.Condition; import javax.inject.Inject; /** * {@link UserProcessCondition} provides a signal when the process handle belongs to the current * user. * {@link SystemProcessCondition} checks to make sure the current process is being ran by the * System User. */ public class UserProcessCondition extends Condition { public class SystemProcessCondition extends Condition { private final ProcessWrapper mProcessWrapper; private final UserTracker mUserTracker; @Inject public UserProcessCondition(ProcessWrapper processWrapper, UserTracker userTracker) { public SystemProcessCondition(ProcessWrapper processWrapper) { super(); mProcessWrapper = processWrapper; mUserTracker = userTracker; } @Override protected void start() { updateCondition(mUserTracker.getUserId() == mProcessWrapper.getUserHandleIdentifier()); updateCondition(mProcessWrapper.isSystemUser()); } @Override Loading
packages/SystemUI/tests/src/com/android/systemui/process/condition/UserProcessConditionTest.java→packages/SystemUI/tests/src/com/android/systemui/process/condition/SystemProcessConditionTest.java +11 −18 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.process.ProcessWrapper; import com.android.systemui.settings.UserTracker; import com.android.systemui.shared.condition.Condition; import com.android.systemui.shared.condition.Monitor; import com.android.systemui.util.concurrency.FakeExecutor; Loading @@ -41,10 +40,7 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper @SmallTest public class UserProcessConditionTest extends SysuiTestCase { @Mock UserTracker mUserTracker; public class SystemProcessConditionTest extends SysuiTestCase { @Mock ProcessWrapper mProcessWrapper; Loading @@ -59,15 +55,14 @@ public class UserProcessConditionTest extends SysuiTestCase { } /** * Verifies condition reports false when tracker reports a different user id than the * identifier from the process handle. * Verifies condition reports false when tracker reports the process is being ran by the * system user. */ @Test public void testConditionFailsWithDifferentIds() { public void testConditionFailsWithNonSystemProcess() { final Condition condition = new UserProcessCondition(mProcessWrapper, mUserTracker); when(mProcessWrapper.getUserHandleIdentifier()).thenReturn(0); when(mUserTracker.getUserId()).thenReturn(1); final Condition condition = new SystemProcessCondition(mProcessWrapper); when(mProcessWrapper.isSystemUser()).thenReturn(false); final Monitor monitor = new Monitor(mExecutor); Loading @@ -81,15 +76,14 @@ public class UserProcessConditionTest extends SysuiTestCase { } /** * Verifies condition reports false when tracker reports a different user id than the * identifier from the process handle. * Verifies condition reports true when tracker reports the process is being ran by the * system user. */ @Test public void testConditionSucceedsWithSameIds() { public void testConditionSucceedsWithSystemProcess() { final Condition condition = new UserProcessCondition(mProcessWrapper, mUserTracker); when(mProcessWrapper.getUserHandleIdentifier()).thenReturn(0); when(mUserTracker.getUserId()).thenReturn(0); final Condition condition = new SystemProcessCondition(mProcessWrapper); when(mProcessWrapper.isSystemUser()).thenReturn(true); final Monitor monitor = new Monitor(mExecutor); Loading @@ -101,5 +95,4 @@ public class UserProcessConditionTest extends SysuiTestCase { verify(mCallback).onConditionsChanged(true); } }