Check MAINLINE_NETWORK_STACK as well to make GTS can access proper stats

Follow up from aosp/1933093. The test failed because certain
devices use a flattened apex that lacks the NETWORK_STACK
permission for sharing with the GTS apk.
Additionally, the NetworkStatsAccess does not recognize the
GTS apk, which holds the MAINLINE_NETWORK_STACK permission.

Test: TH
Bug: 275532605
Change-Id: Icce80a3d3dbea4a84fbd369d9b5fbe0029ab463e
This commit is contained in:
Junyu Lai
2023-04-11 10:49:49 +08:00
parent 4c6fe239fe
commit e68c42b888
2 changed files with 17 additions and 4 deletions

View File

@@ -17,7 +17,6 @@
package android.net;
import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.NetworkStats.UID_ALL;
import static android.net.TrafficStats.UID_REMOVED;
import static android.net.TrafficStats.UID_TETHERING;
@@ -33,6 +32,8 @@ import android.os.Process;
import android.os.UserHandle;
import android.telephony.TelephonyManager;
import com.android.net.module.util.PermissionUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -100,6 +101,7 @@ public final class NetworkStatsAccess {
* <li>Device owners.
* <li>Carrier-privileged applications.
* <li>The system UID.
* <li>NetworkStack application.
* </ul>
*/
int DEVICE = 3;
@@ -125,9 +127,9 @@ public final class NetworkStatsAccess {
final int appId = UserHandle.getAppId(callingUid);
final boolean isNetworkStack = context.checkPermission(
android.Manifest.permission.NETWORK_STACK, callingPid, callingUid)
== PERMISSION_GRANTED;
final boolean isNetworkStack = PermissionUtils.checkAnyPermissionOf(
context, callingPid, callingUid, android.Manifest.permission.NETWORK_STACK,
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK);
if (hasCarrierPrivileges || isDeviceOwner
|| appId == Process.SYSTEM_UID || isNetworkStack) {