コード例 #1
0
ECode FileBackupHelper::RestoreEntity(
    /* [in] */ IBackupDataInputStream* data)
{
    //if (DEBUG) Log.d(TAG, "got entity '" + data.getKey() + "' size=" + data.size());
    assert(data != NULL);
    String key;
    data->GetKey(&key);
    if (IsKeyInList(key, mFiles)) {
        AutoPtr<IFile> f;
        CFile::New(mFilesDir, key, (IFile**) &f);
        WriteFile(f, data);
    }

    return NOERROR;
}
コード例 #2
0
/**
 * Restore one absolute file entity from the restore stream.  If we're restoring the
 * magic wallpaper file, take specific action to determine whether it is suitable for
 * the current device.
 */
ECode CWallpaperBackupHelper::RestoreEntity(
    /* [in] */ IBackupDataInputStream *data)
{
    String key;
    data->GetKey(&key);
    if (IsKeyInList(key, mKeys)) {
        if (key.Equals(WALLPAPER_IMAGE_KEY)) {
            // restore the file to the stage for inspection
            AutoPtr<IFile> f;
            CFile::New(GetSTAGE_FILE(), (IFile**)&f);
            if (WriteFile(f, data)) {
                // Preflight the restored image's dimensions without loading it
                AutoPtr<IBitmapFactoryOptions> options;
                ASSERT_SUCCEEDED(CBitmapFactoryOptions::New((IBitmapFactoryOptions**)&options));
                options->SetInJustDecodeBounds(TRUE);
                AutoPtr<IBitmapFactory> factory;
                ASSERT_SUCCEEDED(CBitmapFactory::AcquireSingleton((IBitmapFactory**)&factory));
                AutoPtr<IBitmap> bm;
                ASSERT_SUCCEEDED(factory->DecodeFile(GetSTAGE_FILE(), options, (IBitmap**)&bm));
                Int32 w, h;
                options->GetOutWidth(&w);
                options->GetOutHeight(&h);
                if (DEBUG) {
                    Slogger::D(TAG, "Restoring wallpaper image w=%d, h=%d",w, h);
                }

                // How much does the image differ from our preference?  The threshold
                // here is set to accept any image larger than our target, because
                // scaling down is acceptable; but to reject images that are deemed
                // "too small" to scale up attractively.  The value 1.33 is just barely
                // too low to pass Nexus 1 or Droid wallpapers for use on a Xoom, but
                // will pass anything relatively larger.
                Double widthRatio = mDesiredMinWidth / w;
                Double heightRatio = mDesiredMinHeight / h;
                if (widthRatio > 0 && widthRatio < 1.33
                    && heightRatio > 0 && heightRatio < 1.33) {
                    // sufficiently close to our resolution; go ahead and use it
                    if (DEBUG) Slogger::D(TAG, "wallpaper dimension match; using");
                    AutoPtr<IFile> file;
                    CFile::New(GetWALLPAPER_IMAGE(), (IFile**)&file);
                    Boolean b;
                    f->RenameTo(file, &b);
                    // TODO: spin a service to copy the restored image to sd/usb storage,
                    // since it does not exist anywhere other than the private wallpaper
                    // file.
                } else {
                    if (DEBUG) {
                        Slogger::D(TAG, "dimensions too far off: wr=%lu, hr=%lu", widthRatio, heightRatio);
                        Boolean b;
                        f->Delete(&b);
                    }
                }

            }

        } else if (key.Equals(WALLPAPER_INFO_KEY)) {
            // XML file containing wallpaper info
            AutoPtr<IFile> file;
            CFile::New(GetWALLPAPER_INFO(), (IFile**)&file);
            WriteFile(file, data);
        }
    }
    return NOERROR;
}