Skip to content

Commit

Permalink
Merge branch 'lineage-22.1' of https://github.com/LineageOS/android_f…
Browse files Browse the repository at this point in the history
…rameworks_base into fifteen-los
  • Loading branch information
Jayant-Deshmukh committed Jan 12, 2025
2 parents d50d5f1 + 1e9e157 commit 2433d1a
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,37 @@ public void reload() {
}

final PackageManager pmWrapper = mContext.getPackageManager();
// Add requesting apps, with full validation
List<ResolveInfo> installedServices = pmWrapper.queryIntentServicesAsUser(
new Intent(mIntentAction), flags, user);
for (ResolveInfo resolveInfo : installedServices) {
ServiceInfo info = resolveInfo.serviceInfo;

if (!mPermission.equals(info.permission)) {
Slog.w(mTag, "Skipping " + mNoun + " service "
+ info.packageName + "/" + info.name
+ ": it does not require the permission "
+ mPermission);
continue;
if (!mEnabledServices.contains(info.getComponentName())) {
if (!mPermission.equals(info.permission)) {
Slog.w(mTag, "Skipping " + mNoun + " service "
+ info.packageName + "/" + info.name
+ ": it does not require the permission "
+ mPermission);
continue;
}
if (mValidator != null && !mValidator.test(info)) {
continue;
}
mServices.add(info);
}
if (mValidator != null && !mValidator.test(info)) {
continue;
}

// Add all apps with access, in case prior approval was granted without full validation
for (ComponentName cn : mEnabledServices) {
List<ResolveInfo> enabledServices = pmWrapper.queryIntentServicesAsUser(
new Intent().setComponent(cn), flags, user);
for (ResolveInfo resolveInfo : enabledServices) {
ServiceInfo info = resolveInfo.serviceInfo;
mServices.add(info);
}
mServices.add(info);
}

for (Callback callback : mCallbacks) {
callback.onServicesReloaded(mServices);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
Expand All @@ -29,6 +30,7 @@

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
Expand All @@ -42,6 +44,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

Expand Down Expand Up @@ -72,19 +75,26 @@ public void setUp() {
.build();
}

private ArgumentMatcher<Intent> filterEquals(Intent intent) {
return (test) -> {
return intent.filterEquals(test);
};
}

@Test
public void testValidator() {
ServiceInfo s1 = new ServiceInfo();
s1.permission = "testPermission";
s1.packageName = "pkg";
s1.name = "Service1";
ServiceInfo s2 = new ServiceInfo();
s2.permission = "testPermission";
s2.packageName = "pkg2";
s2.name = "service2";
ResolveInfo r1 = new ResolveInfo();
r1.serviceInfo = s1;
ResolveInfo r2 = new ResolveInfo();
r2.serviceInfo = s2;

when(mPm.queryIntentServicesAsUser(any(), anyInt(), anyInt())).thenReturn(
ImmutableList.of(r1, r2));

Expand Down Expand Up @@ -118,9 +128,11 @@ public void testNoValidator() {
ServiceInfo s1 = new ServiceInfo();
s1.permission = "testPermission";
s1.packageName = "pkg";
s1.name = "Service1";
ServiceInfo s2 = new ServiceInfo();
s2.permission = "testPermission";
s2.packageName = "pkg2";
s2.name = "service2";
ResolveInfo r1 = new ResolveInfo();
r1.serviceInfo = s1;
ResolveInfo r2 = new ResolveInfo();
Expand Down Expand Up @@ -193,4 +205,56 @@ public void testSaveLoad() {
assertThat(Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(),
TEST_SETTING)).contains(testComponent2.flattenToString());
}

@Test
public void testHasPermissionWithoutMeetingCurrentRegs() {
ServiceInfo s1 = new ServiceInfo();
s1.permission = "testPermission";
s1.packageName = "pkg";
s1.name = "Service1";
ServiceInfo s2 = new ServiceInfo();
s2.permission = "testPermission";
s2.packageName = "pkg2";
s2.name = "service2";
ResolveInfo r1 = new ResolveInfo();
r1.serviceInfo = s1;
ResolveInfo r2 = new ResolveInfo();
r2.serviceInfo = s2;

ComponentName approvedComponent = new ComponentName(s2.packageName, s2.name);

Settings.Secure.putString(
mContext.getContentResolver(), TEST_SETTING, approvedComponent.flattenToString());

when(mPm.queryIntentServicesAsUser(argThat(
filterEquals(new Intent(TEST_INTENT))), anyInt(), anyInt()))
.thenReturn(ImmutableList.of(r1));
when(mPm.queryIntentServicesAsUser(argThat(
filterEquals(new Intent().setComponent(approvedComponent))),
anyInt(), anyInt()))
.thenReturn(ImmutableList.of(r2));

mServiceListing = new ServiceListing.Builder(mContext)
.setTag("testTag")
.setSetting(TEST_SETTING)
.setNoun("testNoun")
.setIntentAction(TEST_INTENT)
.setValidator(info -> {
if (info.packageName.equals("pkg")) {
return true;
}
return false;
})
.setPermission("testPermission")
.build();
ServiceListing.Callback callback = mock(ServiceListing.Callback.class);
mServiceListing.addCallback(callback);
mServiceListing.reload();

verify(mPm, times(2)).queryIntentServicesAsUser(any(), anyInt(), anyInt());
ArgumentCaptor<List<ServiceInfo>> captor = ArgumentCaptor.forClass(List.class);
verify(callback, times(1)).onServicesReloaded(captor.capture());

assertThat(captor.getValue()).containsExactlyElementsIn(ImmutableList.of(s2, s1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.android.systemui.deviceentry.domain.interactor

import android.content.Intent
import android.content.mockedContext
import android.content.res.Resources
import android.hardware.fingerprint.FingerprintManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
Expand All @@ -41,20 +42,24 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.ActivityStarter.OnDismissAction
import com.android.systemui.plugins.activityStarter
import com.android.systemui.power.data.repository.fakePowerRepository
import com.android.systemui.res.R
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.eq
import org.mockito.ArgumentMatchers.isNull
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.kotlin.mock

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
Expand All @@ -63,8 +68,8 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {

private val kosmos = testKosmos()
private val testScope = kosmos.testScope
private val underTest = kosmos.occludingAppDeviceEntryInteractor

private lateinit var underTest: OccludingAppDeviceEntryInteractor
private lateinit var mockedResources: Resources
private val fingerprintAuthRepository = kosmos.deviceEntryFingerprintAuthRepository
private val keyguardRepository = kosmos.fakeKeyguardRepository
private val bouncerRepository = kosmos.keyguardBouncerRepository
Expand All @@ -74,9 +79,18 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
private val mockedContext = kosmos.mockedContext
private val mockedActivityStarter = kosmos.activityStarter

@Before
fun setup() {
mockedResources = mock<Resources>()
whenever(mockedContext.resources).thenReturn(mockedResources)
whenever(mockedResources.getBoolean(R.bool.config_goToHomeFromOccludedApps))
.thenReturn(true)
}

@Test
fun fingerprintSuccess_goToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(true)
fingerprintAuthRepository.setAuthenticationStatus(
SuccessFingerprintAuthenticationStatus(0, true)
Expand All @@ -85,9 +99,24 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
verifyGoToHomeScreen()
}

@Test
fun fingerprintSuccess_configOff_doesNotGoToHomeScreen() =
testScope.runTest {
whenever(mockedResources.getBoolean(R.bool.config_goToHomeFromOccludedApps))
.thenReturn(false)
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(true)
fingerprintAuthRepository.setAuthenticationStatus(
SuccessFingerprintAuthenticationStatus(0, true)
)
runCurrent()
verifyNeverGoToHomeScreen()
}

@Test
fun fingerprintSuccess_notInteractive_doesNotGoToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(true)
powerRepository.setInteractive(false)
fingerprintAuthRepository.setAuthenticationStatus(
Expand All @@ -100,6 +129,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun fingerprintSuccess_dreaming_doesNotGoToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(true)
keyguardRepository.setDreaming(true)
fingerprintAuthRepository.setAuthenticationStatus(
Expand All @@ -112,6 +142,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun fingerprintSuccess_notOnOccludingApp_doesNotGoToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(false)
fingerprintAuthRepository.setAuthenticationStatus(
SuccessFingerprintAuthenticationStatus(0, true)
Expand All @@ -123,11 +154,12 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun lockout_goToHomeScreenOnDismissAction() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(true)
fingerprintAuthRepository.setAuthenticationStatus(
ErrorFingerprintAuthenticationStatus(
FingerprintManager.FINGERPRINT_ERROR_LOCKOUT,
"lockoutTest"
"lockoutTest",
)
)
runCurrent()
Expand All @@ -137,11 +169,12 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun lockout_notOnOccludingApp_neverGoToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(false)
fingerprintAuthRepository.setAuthenticationStatus(
ErrorFingerprintAuthenticationStatus(
FingerprintManager.FINGERPRINT_ERROR_LOCKOUT,
"lockoutTest"
"lockoutTest",
)
)
runCurrent()
Expand All @@ -151,11 +184,12 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun lockout_onOccludingApp_onCommunal_neverGoToHomeScreen() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
givenOnOccludingApp(isOnOccludingApp = true, isOnCommunal = true)
fingerprintAuthRepository.setAuthenticationStatus(
ErrorFingerprintAuthenticationStatus(
FingerprintManager.FINGERPRINT_ERROR_LOCKOUT,
"lockoutTest"
"lockoutTest",
)
)
runCurrent()
Expand All @@ -165,6 +199,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun message_fpFailOnOccludingApp_thenNotOnOccludingApp() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
val message by collectLastValue(underTest.message)

givenOnOccludingApp(true)
Expand All @@ -186,6 +221,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun message_fpErrorHelpFailOnOccludingApp() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
val message by collectLastValue(underTest.message)

givenOnOccludingApp(true)
Expand Down Expand Up @@ -218,6 +254,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun message_fpError_lockoutFilteredOut() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
val message by collectLastValue(underTest.message)

givenOnOccludingApp(true)
Expand Down Expand Up @@ -246,6 +283,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
@Test
fun noMessage_fpErrorsWhileDozing() =
testScope.runTest {
underTest = kosmos.occludingAppDeviceEntryInteractor
val message by collectLastValue(underTest.message)

givenOnOccludingApp(true)
Expand All @@ -254,7 +292,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
from = KeyguardState.OCCLUDED,
to = KeyguardState.DOZING,
testScope
testScope,
)
runCurrent()

Expand Down Expand Up @@ -283,7 +321,7 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {

private suspend fun givenOnOccludingApp(
isOnOccludingApp: Boolean,
isOnCommunal: Boolean = false
isOnCommunal: Boolean = false,
) {
powerRepository.setInteractive(true)
keyguardRepository.setIsDozing(false)
Expand All @@ -305,13 +343,13 @@ class OccludingAppDeviceEntryInteractorTest : SysuiTestCase() {
kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
from = KeyguardState.LOCKSCREEN,
to = KeyguardState.OCCLUDED,
testScope
testScope,
)
} else {
kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
from = KeyguardState.OCCLUDED,
to = KeyguardState.LOCKSCREEN,
testScope
testScope,
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/SystemUI/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@
<!-- Whether to show the full screen user switcher. -->
<bool name="config_enableFullscreenUserSwitcher">false</bool>

<!-- Whether to go to the launcher when unlocking via an occluding app -->
<bool name="config_goToHomeFromOccludedApps">false</bool>

<!-- Determines whether the shell features all run on another thread. -->
<bool name="config_enableShellMainThread">true</bool>

Expand Down
Loading

0 comments on commit 2433d1a

Please sign in to comment.