Skip to content

Commit 1295696

Browse files
Julia Reynoldsaoleary
Julia Reynolds
authored andcommitted
Always show all approved apps
Regardless of what the current criteria is in order to be approved, show everything that's currently approved, since the criteria might have been more lax when it was approved Test: manual Test: ServiceListingTest Flag: EXEMPT bug fix Bug: 365738306 (cherry picked from commit 234c5e843ca427b1dd47e91e3969f3309dd787bf) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:0cafbe4e9bf9875709e9296e5d2fd5a7666364a2) Merged-In: I6c19d3dbff6ecabc74729a7f021f293e26601944 Change-Id: I6c19d3dbff6ecabc74729a7f021f293e26601944
1 parent d5a636f commit 1295696

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

packages/SettingsLib/src/com/android/settingslib/applications/ServiceListing.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,37 @@ public void reload() {
138138
}
139139

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

146-
if (!mPermission.equals(info.permission)) {
147-
Slog.w(mTag, "Skipping " + mNoun + " service "
148-
+ info.packageName + "/" + info.name
149-
+ ": it does not require the permission "
150-
+ mPermission);
151-
continue;
147+
if (!mEnabledServices.contains(info.getComponentName())) {
148+
if (!mPermission.equals(info.permission)) {
149+
Slog.w(mTag, "Skipping " + mNoun + " service "
150+
+ info.packageName + "/" + info.name
151+
+ ": it does not require the permission "
152+
+ mPermission);
153+
continue;
154+
}
155+
if (mValidator != null && !mValidator.test(info)) {
156+
continue;
157+
}
158+
mServices.add(info);
152159
}
153-
if (mValidator != null && !mValidator.test(info)) {
154-
continue;
160+
}
161+
162+
// Add all apps with access, in case prior approval was granted without full validation
163+
for (ComponentName cn : mEnabledServices) {
164+
List<ResolveInfo> enabledServices = pmWrapper.queryIntentServicesAsUser(
165+
new Intent().setComponent(cn), flags, user);
166+
for (ResolveInfo resolveInfo : enabledServices) {
167+
ServiceInfo info = resolveInfo.serviceInfo;
168+
mServices.add(info);
155169
}
156-
mServices.add(info);
157170
}
171+
158172
for (Callback callback : mCallbacks) {
159173
callback.onServicesReloaded(mServices);
160174
}

packages/SettingsLib/tests/robotests/src/com/android/settingslib/applications/ServiceListingTest.java

+65-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.mockito.ArgumentMatchers.any;
2222
import static org.mockito.ArgumentMatchers.anyInt;
2323
import static org.mockito.ArgumentMatchers.anyList;
24+
import static org.mockito.ArgumentMatchers.argThat;
2425
import static org.mockito.Mockito.mock;
2526
import static org.mockito.Mockito.spy;
2627
import static org.mockito.Mockito.times;
@@ -29,6 +30,7 @@
2930

3031
import android.content.ComponentName;
3132
import android.content.Context;
33+
import android.content.Intent;
3234
import android.content.pm.PackageManager;
3335
import android.content.pm.ResolveInfo;
3436
import android.content.pm.ServiceInfo;
@@ -42,6 +44,7 @@
4244
import org.junit.Test;
4345
import org.junit.runner.RunWith;
4446
import org.mockito.ArgumentCaptor;
47+
import org.mockito.ArgumentMatcher;
4548
import org.robolectric.RobolectricTestRunner;
4649
import org.robolectric.RuntimeEnvironment;
4750

@@ -72,19 +75,26 @@ public void setUp() {
7275
.build();
7376
}
7477

78+
private ArgumentMatcher<Intent> filterEquals(Intent intent) {
79+
return (test) -> {
80+
return intent.filterEquals(test);
81+
};
82+
}
83+
7584
@Test
7685
public void testValidator() {
7786
ServiceInfo s1 = new ServiceInfo();
7887
s1.permission = "testPermission";
7988
s1.packageName = "pkg";
89+
s1.name = "Service1";
8090
ServiceInfo s2 = new ServiceInfo();
8191
s2.permission = "testPermission";
8292
s2.packageName = "pkg2";
93+
s2.name = "service2";
8394
ResolveInfo r1 = new ResolveInfo();
8495
r1.serviceInfo = s1;
8596
ResolveInfo r2 = new ResolveInfo();
8697
r2.serviceInfo = s2;
87-
8898
when(mPm.queryIntentServicesAsUser(any(), anyInt(), anyInt())).thenReturn(
8999
ImmutableList.of(r1, r2));
90100

@@ -118,9 +128,11 @@ public void testNoValidator() {
118128
ServiceInfo s1 = new ServiceInfo();
119129
s1.permission = "testPermission";
120130
s1.packageName = "pkg";
131+
s1.name = "Service1";
121132
ServiceInfo s2 = new ServiceInfo();
122133
s2.permission = "testPermission";
123134
s2.packageName = "pkg2";
135+
s2.name = "service2";
124136
ResolveInfo r1 = new ResolveInfo();
125137
r1.serviceInfo = s1;
126138
ResolveInfo r2 = new ResolveInfo();
@@ -193,4 +205,56 @@ public void testSaveLoad() {
193205
assertThat(Settings.Secure.getString(RuntimeEnvironment.application.getContentResolver(),
194206
TEST_SETTING)).contains(testComponent2.flattenToString());
195207
}
208+
209+
@Test
210+
public void testHasPermissionWithoutMeetingCurrentRegs() {
211+
ServiceInfo s1 = new ServiceInfo();
212+
s1.permission = "testPermission";
213+
s1.packageName = "pkg";
214+
s1.name = "Service1";
215+
ServiceInfo s2 = new ServiceInfo();
216+
s2.permission = "testPermission";
217+
s2.packageName = "pkg2";
218+
s2.name = "service2";
219+
ResolveInfo r1 = new ResolveInfo();
220+
r1.serviceInfo = s1;
221+
ResolveInfo r2 = new ResolveInfo();
222+
r2.serviceInfo = s2;
223+
224+
ComponentName approvedComponent = new ComponentName(s2.packageName, s2.name);
225+
226+
Settings.Secure.putString(
227+
mContext.getContentResolver(), TEST_SETTING, approvedComponent.flattenToString());
228+
229+
when(mPm.queryIntentServicesAsUser(argThat(
230+
filterEquals(new Intent(TEST_INTENT))), anyInt(), anyInt()))
231+
.thenReturn(ImmutableList.of(r1));
232+
when(mPm.queryIntentServicesAsUser(argThat(
233+
filterEquals(new Intent().setComponent(approvedComponent))),
234+
anyInt(), anyInt()))
235+
.thenReturn(ImmutableList.of(r2));
236+
237+
mServiceListing = new ServiceListing.Builder(mContext)
238+
.setTag("testTag")
239+
.setSetting(TEST_SETTING)
240+
.setNoun("testNoun")
241+
.setIntentAction(TEST_INTENT)
242+
.setValidator(info -> {
243+
if (info.packageName.equals("pkg")) {
244+
return true;
245+
}
246+
return false;
247+
})
248+
.setPermission("testPermission")
249+
.build();
250+
ServiceListing.Callback callback = mock(ServiceListing.Callback.class);
251+
mServiceListing.addCallback(callback);
252+
mServiceListing.reload();
253+
254+
verify(mPm, times(2)).queryIntentServicesAsUser(any(), anyInt(), anyInt());
255+
ArgumentCaptor<List<ServiceInfo>> captor = ArgumentCaptor.forClass(List.class);
256+
verify(callback, times(1)).onServicesReloaded(captor.capture());
257+
258+
assertThat(captor.getValue()).containsExactlyElementsIn(ImmutableList.of(s2, s1));
259+
}
196260
}

0 commit comments

Comments
 (0)