From 384b8a69f9897ac7d3407a6da1fb16e2b9f096f8 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Thu, 26 Sep 2019 20:39:03 +0100 Subject: [PATCH] Fix an issue that dumpsys textclassification does not print latest settings Issue: When we run dumpsys textclassification, shell spawns a process to run the dumpsys executable which binds to TCMS and calls TCMS.dump(). In TCMS.dump(), we create a TCM instance, and the TCM instance setups an ContentObserver to observe the settings changes. However, it does not pass the checkContentProviderAccess check because AMS does not keep track of processes spawned from shell. Solution: Create the TCM instance using the system server identity. Fixes: 141690465 Test: Execute the following commands 1. dumpsys textclassification 2. adb shell cmd device_config put textclassifier {key} {value} 3. dumpsys textclassification 4. Verify the output now reflects the latest value. Change-Id: Ia1185bd02688c0e7a3eb83487d3b843250b7f2cf --- .../TextClassificationManagerService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java index 4c935643da55c..5493afd1b1231 100644 --- a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java +++ b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java @@ -365,10 +365,16 @@ public final class TextClassificationManagerService extends ITextClassifierServi protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, fout)) return; IndentingPrintWriter pw = new IndentingPrintWriter(fout, " "); - TextClassificationManager tcm = mContext.getSystemService(TextClassificationManager.class); - tcm.dump(pw); - pw.printPair("context", mContext); pw.println(); + // Create a TCM instance with the system server identity. TCM creates a ContentObserver + // to listen for settings changes. It does not pass the checkContentProviderAccess check + // if we are using the shell identity, because AMS does not track of processes spawn from + // shell. + Binder.withCleanCallingIdentity( + () -> mContext.getSystemService(TextClassificationManager.class).dump(pw)); + + pw.printPair("context", mContext); + pw.println(); synchronized (mLock) { int size = mUserStates.size(); pw.print("Number user states: "); pw.println(size);