From 4d27cab6de2984871ab38d22e13f7677f95a3341 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 19 Sep 2019 07:34:36 -0700 Subject: 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) --- service/java/com/android/server/wifi/WifiNetworkFactory.java | 8 +++++--- .../com/android/server/wifi/WifiNetworkSuggestionsManager.java | 7 ++++--- service/java/com/android/server/wifi/WifiServiceImpl.java | 9 +++++---- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'service') 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; -- cgit v1.2.3