Loading core/java/android/permission/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -499,3 +499,11 @@ flag { description: "Collect sqlite performance metrics for discrete ops." bug: "377584611" } flag { name: "app_ops_service_handler_fix" is_fixed_read_only: true namespace: "permissions" description: "Use IoThread handler for AppOpsService background/IO work." bug: "394380603" } services/core/java/com/android/server/appop/AppOpsService.java +21 −8 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ import static android.content.Intent.EXTRA_REPLACING; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; import static android.content.pm.PermissionInfo.PROTECTION_FLAG_APPOP; import static android.os.Flags.binderFrozenStateChangeCallback; import static android.permission.flags.Flags.appOpsServiceHandlerFix; import static android.permission.flags.Flags.checkOpValidatePackage; import static android.permission.flags.Flags.deviceAwareAppOpNewSchemaEnabled; import static android.permission.flags.Flags.useFrozenAwareRemoteCallbackList; Loading Loading @@ -174,6 +175,7 @@ import com.android.internal.util.XmlUtils; import com.android.internal.util.function.pooled.PooledLambda; import com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import com.android.server.IoThread; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.LockGuard; Loading Loading @@ -277,6 +279,7 @@ public class AppOpsService extends IAppOpsService.Stub { final AtomicFile mStorageFile; final AtomicFile mRecentAccessesFile; private final @Nullable File mNoteOpCallerStacktracesFile; /* AMS handler, this shouldn't be used for IO */ final Handler mHandler; private final AppOpsRecentAccessPersistence mRecentAccessPersistence; Loading Loading @@ -1411,7 +1414,7 @@ public class AppOpsService extends IAppOpsService.Stub { @GuardedBy("this") private void packageRemovedLocked(int uid, String packageName) { mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory, getIoHandler().post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory, mHistoricalRegistry, uid, packageName)); UidState uidState = mUidStates.get(uid); Loading Loading @@ -1693,7 +1696,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (mWriteScheduled) { mWriteScheduled = false; mFastWriteScheduled = false; mHandler.removeCallbacks(mWriteRunner); getIoHandler().removeCallbacks(mWriteRunner); doWrite = true; } } Loading Loading @@ -1979,7 +1982,7 @@ public class AppOpsService extends IAppOpsService.Stub { new String[attributionChainExemptPackages.size()]) : null; // Must not hold the appops lock mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps, getIoHandler().post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps, mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType, filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray, callback).recycleOnUse()); Loading Loading @@ -2010,7 +2013,8 @@ public class AppOpsService extends IAppOpsService.Stub { new String[attributionChainExemptPackages.size()]) : null; // Must not hold the appops lock mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOpsFromDiskRaw, getIoHandler().post(PooledLambda.obtainRunnable( HistoricalRegistry::getHistoricalOpsFromDiskRaw, mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType, filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray, callback).recycleOnUse()); Loading Loading @@ -5074,7 +5078,7 @@ public class AppOpsService extends IAppOpsService.Stub { private void scheduleWriteLocked() { if (!mWriteScheduled) { mWriteScheduled = true; mHandler.postDelayed(mWriteRunner, WRITE_DELAY); getIoHandler().postDelayed(mWriteRunner, WRITE_DELAY); } } Loading @@ -5082,8 +5086,8 @@ public class AppOpsService extends IAppOpsService.Stub { if (!mFastWriteScheduled) { mWriteScheduled = true; mFastWriteScheduled = true; mHandler.removeCallbacks(mWriteRunner); mHandler.postDelayed(mWriteRunner, 10*1000); getIoHandler().removeCallbacks(mWriteRunner); getIoHandler().postDelayed(mWriteRunner, 10 * 1000); } } Loading Loading @@ -5957,7 +5961,8 @@ public class AppOpsService extends IAppOpsService.Stub { final long token = Binder.clearCallingIdentity(); try { synchronized (shell.mInternal) { shell.mInternal.mHandler.removeCallbacks(shell.mInternal.mWriteRunner); shell.mInternal.getIoHandler().removeCallbacks( shell.mInternal.mWriteRunner); } shell.mInternal.writeRecentAccesses(); shell.mInternal.mAppOpsCheckingService.writeState(); Loading Loading @@ -7884,4 +7889,12 @@ public class AppOpsService extends IAppOpsService.Stub { return null; } } private Handler getIoHandler() { if (appOpsServiceHandlerFix()) { return IoThread.getHandler(); } else { return mHandler; } } } Loading
core/java/android/permission/flags.aconfig +8 −0 Original line number Diff line number Diff line Loading @@ -499,3 +499,11 @@ flag { description: "Collect sqlite performance metrics for discrete ops." bug: "377584611" } flag { name: "app_ops_service_handler_fix" is_fixed_read_only: true namespace: "permissions" description: "Use IoThread handler for AppOpsService background/IO work." bug: "394380603" }
services/core/java/com/android/server/appop/AppOpsService.java +21 −8 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ import static android.content.Intent.EXTRA_REPLACING; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; import static android.content.pm.PermissionInfo.PROTECTION_FLAG_APPOP; import static android.os.Flags.binderFrozenStateChangeCallback; import static android.permission.flags.Flags.appOpsServiceHandlerFix; import static android.permission.flags.Flags.checkOpValidatePackage; import static android.permission.flags.Flags.deviceAwareAppOpNewSchemaEnabled; import static android.permission.flags.Flags.useFrozenAwareRemoteCallbackList; Loading Loading @@ -174,6 +175,7 @@ import com.android.internal.util.XmlUtils; import com.android.internal.util.function.pooled.PooledLambda; import com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import com.android.server.IoThread; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.LockGuard; Loading Loading @@ -277,6 +279,7 @@ public class AppOpsService extends IAppOpsService.Stub { final AtomicFile mStorageFile; final AtomicFile mRecentAccessesFile; private final @Nullable File mNoteOpCallerStacktracesFile; /* AMS handler, this shouldn't be used for IO */ final Handler mHandler; private final AppOpsRecentAccessPersistence mRecentAccessPersistence; Loading Loading @@ -1411,7 +1414,7 @@ public class AppOpsService extends IAppOpsService.Stub { @GuardedBy("this") private void packageRemovedLocked(int uid, String packageName) { mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory, getIoHandler().post(PooledLambda.obtainRunnable(HistoricalRegistry::clearHistory, mHistoricalRegistry, uid, packageName)); UidState uidState = mUidStates.get(uid); Loading Loading @@ -1693,7 +1696,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (mWriteScheduled) { mWriteScheduled = false; mFastWriteScheduled = false; mHandler.removeCallbacks(mWriteRunner); getIoHandler().removeCallbacks(mWriteRunner); doWrite = true; } } Loading Loading @@ -1979,7 +1982,7 @@ public class AppOpsService extends IAppOpsService.Stub { new String[attributionChainExemptPackages.size()]) : null; // Must not hold the appops lock mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps, getIoHandler().post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps, mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType, filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray, callback).recycleOnUse()); Loading Loading @@ -2010,7 +2013,8 @@ public class AppOpsService extends IAppOpsService.Stub { new String[attributionChainExemptPackages.size()]) : null; // Must not hold the appops lock mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOpsFromDiskRaw, getIoHandler().post(PooledLambda.obtainRunnable( HistoricalRegistry::getHistoricalOpsFromDiskRaw, mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, dataType, filter, beginTimeMillis, endTimeMillis, flags, chainExemptPkgArray, callback).recycleOnUse()); Loading Loading @@ -5074,7 +5078,7 @@ public class AppOpsService extends IAppOpsService.Stub { private void scheduleWriteLocked() { if (!mWriteScheduled) { mWriteScheduled = true; mHandler.postDelayed(mWriteRunner, WRITE_DELAY); getIoHandler().postDelayed(mWriteRunner, WRITE_DELAY); } } Loading @@ -5082,8 +5086,8 @@ public class AppOpsService extends IAppOpsService.Stub { if (!mFastWriteScheduled) { mWriteScheduled = true; mFastWriteScheduled = true; mHandler.removeCallbacks(mWriteRunner); mHandler.postDelayed(mWriteRunner, 10*1000); getIoHandler().removeCallbacks(mWriteRunner); getIoHandler().postDelayed(mWriteRunner, 10 * 1000); } } Loading Loading @@ -5957,7 +5961,8 @@ public class AppOpsService extends IAppOpsService.Stub { final long token = Binder.clearCallingIdentity(); try { synchronized (shell.mInternal) { shell.mInternal.mHandler.removeCallbacks(shell.mInternal.mWriteRunner); shell.mInternal.getIoHandler().removeCallbacks( shell.mInternal.mWriteRunner); } shell.mInternal.writeRecentAccesses(); shell.mInternal.mAppOpsCheckingService.writeState(); Loading Loading @@ -7884,4 +7889,12 @@ public class AppOpsService extends IAppOpsService.Stub { return null; } } private Handler getIoHandler() { if (appOpsServiceHandlerFix()) { return IoThread.getHandler(); } else { return mHandler; } } }