OSDN Git Service

make statsd run in its own uid
authorYao Chen <yaochen@google.com>
Tue, 9 Jan 2018 18:33:15 +0000 (10:33 -0800)
committerYao Chen <yaochen@google.com>
Thu, 11 Jan 2018 19:58:10 +0000 (11:58 -0800)
+ Assign permission android.permission.STATSCOMPANION to statsd
+ Fixes in StatsCompanionService to allow statsd to get uid mapping

Test: manual
Change-Id: I3e6ca79eefed7f93a4588578c156321c4c278fd3

cmds/statsd/statsd.rc
data/etc/platform.xml
services/core/java/com/android/server/stats/StatsCompanionService.java

index 9fb1027..437f9a8 100644 (file)
@@ -14,5 +14,5 @@
 
 service statsd /system/bin/statsd
     class main
-    user system
-    group system
+    user statsd
+    group statsd log
index d2c855b..f169f22 100644 (file)
     <assign-permission name="android.permission.ACCESS_LOWPAN_STATE" uid="lowpan" />
     <assign-permission name="android.permission.MANAGE_LOWPAN_INTERFACES" uid="lowpan" />
 
+    <assign-permission name="android.permission.STATSCOMPANION" uid="statsd" />
+
     <!-- This is a list of all the libraries available for application
          code to link against. -->
 
index b31f4b3..84039f0 100644 (file)
@@ -743,9 +743,13 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                 filter.addAction(Intent.ACTION_SHUTDOWN);
                 mContext.registerReceiverAsUser(
                         mShutdownEventReceiver, UserHandle.ALL, filter, null, null);
-
-                // Pull the latest state of UID->app name, version mapping when statsd starts.
-                informAllUidsLocked(mContext);
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    // Pull the latest state of UID->app name, version mapping when statsd starts.
+                    informAllUidsLocked(mContext);
+                } finally {
+                    restoreCallingIdentity(token);
+                }
             } catch (RemoteException e) {
                 Slog.e(TAG, "Failed to inform statsd that statscompanion is ready", e);
                 forgetEverything();