Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 154cdf1b authored by Junyu Lai's avatar Junyu Lai
Browse files

[MS69.1] Fix TrafficStats.init crashs for supplemental process

Supplemental apps has limited capabilities and service discovery
is restricted. Hence, calling TrafficStats.init would result in
crash.

This change includes:
1. Print log instead of crashing process when running into
   any unexpected cases.

Test: atest SupplementalProcessManagerTests
Bug: 216062904
Change-Id: I7f827ccc485c997745779053b5936a6cb30e8219
parent 96bc724b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.MediaPlayer;
import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.util.Log;

import com.android.server.NetworkManagementSocketTagger;

@@ -212,6 +213,13 @@ public class TrafficStats {
        }
        final NetworkStatsManager statsManager =
                context.getSystemService(NetworkStatsManager.class);
        if (statsManager == null) {
            // TODO: Currently Process.isSupplemental is not working yet, because it depends on
            //  process to run in a certain UID range, which is not true for now. Change this
            //  to Log.wtf once Process.isSupplemental is ready.
            Log.e(TAG, "TrafficStats not initialized, uid=" + Binder.getCallingUid());
            return;
        }
        sStatsService = statsManager.getBinder();
    }