Buggy code:
@ Override public void resetAllModes ( int reqUserId , String reqPackageName ) { } @ Override public void startWatchingMode ( int op , String packageName , IAppOpsCallback callback ) { } @ Override public void stopWatchingMode ( IAppOpsCallback callback ) { } @ Override public IBinder getToken ( IBinder clientToken ) { } @ Override public int checkOperation ( int code , int uid , String packageName ) { } @ Override public int checkAudioOperation ( int code , int usage , int uid , String packageName ) { } private int checkRestrictionLocked ( int code , int usage , int uid , String packageName ) { } @ Override public void setAudioRestriction ( int code , int usage , int uid , int mode , String [ ] exceptionPackages ) { } @ Override public int checkPackage ( int uid , String packageName ) { } @ Override public int noteOperation ( int code , int uid , String packageName ) { } @ Override public int startOperation ( IBinder token , int code , int uid , String packageName ) { } @ Override public void finishOperation ( IBinder token , int code , int uid , String packageName ) { } void finishOperationLocked ( AppOpsService . Op op ) { } private void verifyIncomingUid ( int uid ) { } private void verifyIncomingOp ( int op ) { } private AppOpsService . Ops getOpsLocked ( int uid , String packageName , boolean edit ) { } private AppOpsService . Ops getOpsRawLocked ( int uid , String packageName , boolean edit ) { } private void scheduleWriteLocked ( ) { } private void scheduleFastWriteLocked ( ) { } private AppOpsService . Op getOpLocked ( int code , int uid , String packageName , boolean edit ) { } private AppOpsService . Op getOpLocked ( AppOpsService . Ops ops , int code , boolean edit ) { } private boolean isOpRestricted ( int uid , int code , String packageName ) { } void readState ( ) { } void readPackage ( XmlPullParser parser ) throws IOException , NumberFormatException , XmlPullParserException { } void readUid ( XmlPullParser parser , String pkgName ) throws IOException , NumberFormatException , XmlPullParserException { } void writeState ( ) { } @ Override protected void dump ( FileDescriptor fd , PrintWriter pw , String [ ] args ) { } private static final class Restriction { private static final ArraySet < String > NO_EXCEPTIONS = new ArraySet < String > ( ) ; int mode ; ArraySet < String > exceptionPackages = AppOpsService . Restriction . NO_EXCEPTIONS ; } @ Override public void setUserRestrictions ( Bundle restrictions , int userHandle ) throws RemoteException { } @ Override public void removeUser ( int userHandle ) throws RemoteException { } private void checkSystemUid ( String function ) { } final class AskRunnable implements Runnable { final int code ; final int uid ; final String packageName ; final AppOpsService . Op op ; final PermissionDialogReq request ; public AskRunnable ( int code , int uid , String packageName , AppOpsService . Op op , PermissionDialogReq request ) { } @ Override public void run ( ) { } } private PermissionDialogReq askOperationLocked ( int code , int uid , String packageName , AppOpsService . Op op ) { } private int getDefaultMode ( int code , int uid , String packageName ) { } private boolean isStrict ( int code , int uid , String packageName ) { } private void printOperationLocked ( AppOpsService . Op op , int mode , String operation ) { } private void recordOperationLocked ( int code , int uid , String packageName , int mode ) { } public void notifyOperation ( int code , int uid , String packageName , int mode , boolean remember ) { verifyIncomingUid ( uid ) ; verifyIncomingOp ( code ) ; ArrayList < AppOpsService . Callback > repCbs = null ; int switchCode = AppOpsManager . opToSwitch ( code ) ; synchronized ( this ) { recordOperationLocked ( code , uid , packageName , mode ) ; AppOpsService . Op op = getOpLocked ( switchCode , uid , packageName , true ) ; if ( op != null ) { if ( ( op . dialogReqQueue . getDialog ( ) ) != null ) { op . dialogReqQueue . notifyAll ( mode ) ; op . dialogReqQueue . setDialog ( null ) ; } if ( remember && ( ( op . mode ) != mode ) ) { op . mode = mode ; ArrayList < AppOpsService . Callback > cbs = mOpModeWatchers . get ( switchCode ) ; if ( cbs != null ) { if ( repCbs == null ) { repCbs = new ArrayList < AppOpsService . Callback > ( ) ; } repCbs . addAll ( cbs ) ; } cbs = mPackageModeWatchers . get ( packageName ) ; if ( cbs != null ) { if ( repCbs == null ) { repCbs = new ArrayList < AppOpsService . Callback > ( ) ; } repCbs . addAll ( cbs ) ; } if ( mode == ( getDefaultMode ( op . op , op . uid , op . packageName ) ) ) { pruneOp ( op , uid , packageName ) ; } <START_BUG> scheduleWriteNowLocked ( ) ; <END_BUG> } } } if ( repCbs != null ) { for ( int i = 0 ; i < ( repCbs . size ( ) ) ; i ++ ) { try { repCbs . get ( i ) . mCallback . opChanged ( switchCode , packageName ) ; } catch ( RemoteException e ) { } } } } private void readPolicy ( ) { } public boolean isControlAllowed ( int code , String packageName ) { } }

Fix:
scheduleFastWriteLocked ( ) ;