Source:
private void writeSettingsLocked ( ) { java.io.FileOutputStream fos = null ; try { java.io.FileOutputStream fstr = new java.io.FileOutputStream ( com.android.server.usb.UsbSettingsManager.sSettingsFile ) ; if ( com.android.server.usb.UsbSettingsManager.DEBUG ) android.util.Slog.d ( com.android.server.usb.UsbSettingsManager.TAG , ( "writing settings to " + fstr ) ) ; java.io.BufferedOutputStream str = new java.io.BufferedOutputStream ( fstr ) ; com.android.internal.util.FastXmlSerializer serializer = new com.android.internal.util.FastXmlSerializer ( ) ; serializer.setOutput ( str , "utf-8" ) ; serializer.startDocument ( null , true ) ; serializer.setFeature ( "http://xmlpull.org/v1/doc/features.html#indent-output" , true ) ; serializer.startTag ( null , "settings" ) ; for ( com.android.server.usb.UsbSettingsManager.DeviceFilter filter : mDevicePreferenceMap.keySet ( ) ) { serializer.startTag ( null , "preference" ) ; serializer.attribute ( null , "package" , mDevicePreferenceMap.get ( filter ) ) ; filter.write ( serializer ) ; serializer.endTag ( null , "preference" ) ; } for ( com.android.server.usb.UsbSettingsManager.AccessoryFilter filter : mAccessoryPreferenceMap.keySet ( ) ) { serializer.startTag ( null , "preference" ) ; serializer.attribute ( null , "package" , mAccessoryPreferenceMap.get ( filter ) ) ; filter.write ( serializer ) ; serializer.endTag ( null , "preference" ) ; } serializer.endTag ( null , "settings" ) ; serializer.endDocument ( ) ; str.flush ( ) ; android.os.FileUtils.sync ( fstr ) ; str.close ( ) ; } catch ( java.lang.Exception e ) { android.util.Slog.e ( com.android.server.usb.UsbSettingsManager.TAG , "error writing settings file, deleting to start fresh" , e ) ; com.android.server.usb.UsbSettingsManager.sSettingsFile.delete ( ) ; } }

Target:
private void writeSettingsLocked ( ) { if ( com.android.server.usb.UsbSettingsManager.DEBUG ) android.util.Slog.v ( com.android.server.usb.UsbSettingsManager.TAG , "writeSettingsLocked()" ) ; java.io.FileOutputStream fos = null ; try { fos = mSettingsFile.startWrite ( ) ; com.android.internal.util.FastXmlSerializer serializer = new com.android.internal.util.FastXmlSerializer ( ) ; serializer.setOutput ( fos , "utf-8" ) ; serializer.startDocument ( null , true ) ; serializer.setFeature ( "http://xmlpull.org/v1/doc/features.html#indent-output" , true ) ; serializer.startTag ( null , "settings" ) ; for ( com.android.server.usb.UsbSettingsManager.DeviceFilter filter : mDevicePreferenceMap.keySet ( ) ) { serializer.startTag ( null , "preference" ) ; serializer.attribute ( null , "package" , mDevicePreferenceMap.get ( filter ) ) ; filter.write ( serializer ) ; serializer.endTag ( null , "preference" ) ; } for ( com.android.server.usb.UsbSettingsManager.AccessoryFilter filter : mAccessoryPreferenceMap.keySet ( ) ) { serializer.startTag ( null , "preference" ) ; serializer.attribute ( null , "package" , mAccessoryPreferenceMap.get ( filter ) ) ; filter.write ( serializer ) ; serializer.endTag ( null , "preference" ) ; } serializer.endTag ( null , "settings" ) ; serializer.endDocument ( ) ; mSettingsFile.finishWrite ( fos ) ; } catch ( java.io.IOException e ) { android.util.Slog.e ( com.android.server.usb.UsbSettingsManager.TAG , "Failed to write settings" , e ) ; if ( fos != null ) { mSettingsFile.failWrite ( fos ) ; } } }