summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-09-19 07:34:36 -0700
committerRoshan Pius <rpius@google.com>2019-09-20 14:00:04 +0000
commit4d27cab6de2984871ab38d22e13f7677f95a3341 (patch)
tree2440d2beffa38fd59d3671e5d771fb36ffa970f5
parentc9d68061749a93378f575199798f676a2b5c37a8 (diff)
Fix a bunch of multi-user API calls
To handle multi-user scenarios, pass in the corresponding app's user id to fetch app info. Bug: 140895783 Test: atest com.android.server.wifi Test: Ran presubmit ACTS tests Change-Id: I400bad75510b064ad405fae07f56671d2c211178 Merged-In: I400bad75510b064ad405fae07f56671d2c211178 (cherry-picked from a1bbebf25cb7b4e33a7b5abaa6ee6402de95ebc9)
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java8
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java7
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java5
6 files changed, 23 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index 1f060cf73..c375e9f59 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -1141,10 +1141,11 @@ public class WifiNetworkFactory extends NetworkFactory {
mConnectionTimeoutSet = true;
}
- private @NonNull CharSequence getAppName(@NonNull String packageName) {
+ private @NonNull CharSequence getAppName(@NonNull String packageName, int uid) {
ApplicationInfo applicationInfo = null;
try {
- applicationInfo = mContext.getPackageManager().getApplicationInfo(packageName, 0);
+ applicationInfo = mContext.getPackageManager().getApplicationInfoAsUser(
+ packageName, 0, UserHandle.getUserId(uid));
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to find app name for " + packageName);
return "";
@@ -1159,7 +1160,8 @@ public class WifiNetworkFactory extends NetworkFactory {
intent.addCategory(UI_START_INTENT_CATEGORY);
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(UI_START_INTENT_EXTRA_APP_NAME,
- getAppName(mActiveSpecificNetworkRequestSpecifier.requestorPackageName));
+ getAppName(mActiveSpecificNetworkRequestSpecifier.requestorPackageName,
+ mActiveSpecificNetworkRequestSpecifier.requestorUid));
intent.putExtra(UI_START_INTENT_EXTRA_REQUEST_IS_FOR_SINGLE_NETWORK,
isActiveRequestForSingleNetwork());
mContext.startActivityAsUser(intent, UserHandle.getUserHandleForUid(
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index 972d1c93f..644eb6523 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -761,10 +761,11 @@ public class WifiNetworkSuggestionsManager {
PendingIntent.FLAG_UPDATE_CURRENT);
}
- private @NonNull CharSequence getAppName(@NonNull String packageName) {
+ private @NonNull CharSequence getAppName(@NonNull String packageName, int uid) {
ApplicationInfo applicationInfo = null;
try {
- applicationInfo = mPackageManager.getApplicationInfo(packageName, 0);
+ applicationInfo = mContext.getPackageManager().getApplicationInfoAsUser(
+ packageName, 0, UserHandle.getUserId(uid));
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to find app name for " + packageName);
return "";
@@ -787,7 +788,7 @@ public class WifiNetworkSuggestionsManager {
packageName, uid))
.build();
- CharSequence appName = getAppName(packageName);
+ CharSequence appName = getAppName(packageName, uid);
Notification notification = new Notification.Builder(
mContext, SystemNotificationChannels.NETWORK_STATUS)
.setSmallIcon(R.drawable.stat_notify_wifi_in_range)
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 354c0a555..2d15af53c 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -755,10 +755,11 @@ public class WifiServiceImpl extends BaseWifiService {
}
// Helper method to check if the entity initiating the binder call is a system app.
- private boolean isSystem(String packageName) {
+ private boolean isSystem(String packageName, int uid) {
long ident = Binder.clearCallingIdentity();
try {
- ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(packageName, 0);
+ ApplicationInfo info = mContext.getPackageManager().getApplicationInfoAsUser(
+ packageName, 0, UserHandle.getUserId(uid));
return info.isSystemApp() || info.isUpdatedSystemApp();
} catch (PackageManager.NameNotFoundException e) {
// In case of exception, assume unknown app (more strict checking)
@@ -858,7 +859,7 @@ public class WifiServiceImpl extends BaseWifiService {
// DO/PO apps should be able to add/modify saved networks.
|| isDeviceOrProfileOwner(uid)
// TODO: Remove this system app bypass once Q is released.
- || isSystem(packageName)
+ || isSystem(packageName, uid)
|| mWifiPermissionsUtil.checkSystemAlertWindowPermission(uid, packageName);
}
@@ -877,7 +878,7 @@ public class WifiServiceImpl extends BaseWifiService {
if (!isPrivileged && !isDeviceOrProfileOwner(Binder.getCallingUid())
&& !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q,
Binder.getCallingUid())
- && !isSystem(packageName)) {
+ && !isSystem(packageName, Binder.getCallingUid())) {
mLog.info("setWifiEnabled not allowed for uid=%")
.c(Binder.getCallingUid()).flush();
return false;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index 968527a8d..63cc8bf60 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -173,7 +173,8 @@ public class WifiNetworkFactoryTest {
.thenReturn(mConnectivityManager);
when(mPackageManager.getNameForUid(TEST_UID_1)).thenReturn(TEST_PACKAGE_NAME_1);
when(mPackageManager.getNameForUid(TEST_UID_2)).thenReturn(TEST_PACKAGE_NAME_2);
- when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(new ApplicationInfo());
+ when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt()))
+ .thenReturn(new ApplicationInfo());
when(mPackageManager.getApplicationLabel(any())).thenReturn(TEST_APP_NAME);
when(mActivityManager.getPackageImportance(TEST_PACKAGE_NAME_1))
.thenReturn(IMPORTANCE_FOREGROUND_SERVICE);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index ae4da66d6..612fdf575 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -150,10 +150,12 @@ public class WifiNetworkSuggestionsManagerTest {
when(mContext.getApplicationInfo()).thenReturn(ourAppInfo);
// test app info
ApplicationInfo appInfO1 = new ApplicationInfo();
- when(mPackageManager.getApplicationInfo(TEST_PACKAGE_1, 0)).thenReturn(appInfO1);
+ when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_1), eq(0), anyInt()))
+ .thenReturn(appInfO1);
when(mPackageManager.getApplicationLabel(appInfO1)).thenReturn(TEST_APP_NAME_1);
ApplicationInfo appInfO2 = new ApplicationInfo();
- when(mPackageManager.getApplicationInfo(TEST_PACKAGE_2, 0)).thenReturn(appInfO2);
+ when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_2), eq(0), anyInt()))
+ .thenReturn(appInfO2);
when(mPackageManager.getApplicationLabel(appInfO2)).thenReturn(TEST_APP_NAME_2);
mWifiNetworkSuggestionsManager =
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 9702d2ba6..9a3bd75be 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -349,7 +349,8 @@ public class WifiServiceImplTest {
when(mContext.getResources()).thenReturn(mResources);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo);
+ when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), anyInt()))
+ .thenReturn(mApplicationInfo);
when(mWifiInjector.getWifiApConfigStore()).thenReturn(mWifiApConfigStore);
doNothing().when(mFrameworkFacade).registerContentObserver(eq(mContext), any(),
anyBoolean(), any());
@@ -2658,7 +2659,7 @@ public class WifiServiceImplTest {
PackageManager pm = mock(PackageManager.class);
when(pm.hasSystemFeature(PackageManager.FEATURE_WIFI_PASSPOINT)).thenReturn(true);
when(mContext.getPackageManager()).thenReturn(pm);
- when(pm.getApplicationInfo(any(), anyInt())).thenReturn(mApplicationInfo);
+ when(pm.getApplicationInfoAsUser(any(), anyInt(), anyInt())).thenReturn(mApplicationInfo);
when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(),
eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true);