1d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy/* 2d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Copyright (C) 2012 Google Inc. 3d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Licensed to The Android Open Source Project. 4d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 5d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Licensed under the Apache License, Version 2.0 (the "License"); 6d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * you may not use this file except in compliance with the License. 7d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * You may obtain a copy of the License at 8d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 9d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 10d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 11d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Unless required by applicable law or agreed to in writing, software 12d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS, 13d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * See the License for the specific language governing permissions and 15d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * limitations under the License. 16d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 17d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedypackage com.android.mail.preferences; 18d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 19d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.content.Context; 20d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 21d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport java.util.concurrent.atomic.AtomicBoolean; 22d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 23d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy/** 24d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Interface to allow migrating preferences from other projects into the UnifiedEmail code, so apps 25d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * can slowly move their preferences into the shared code. 26d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 27d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedypublic abstract class BasePreferenceMigrator { 28d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** If <code>true</code>, we have not attempted a migration since the app started. */ 29d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private static final AtomicBoolean sMigrationNecessary = new AtomicBoolean(true); 30d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 312b1b87f90cb776e95f66aa5514505a0b21dc3d9dAndrew Sapperstein public final boolean performMigration( 32d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Context context, final int oldVersion, final int newVersion) { 33d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy // Ensure we only run this once 34d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (sMigrationNecessary.getAndSet(false)) { 35d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy migrate(context, oldVersion, newVersion); 362b1b87f90cb776e95f66aa5514505a0b21dc3d9dAndrew Sapperstein return true; 37d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 382b1b87f90cb776e95f66aa5514505a0b21dc3d9dAndrew Sapperstein 392b1b87f90cb776e95f66aa5514505a0b21dc3d9dAndrew Sapperstein return false; 40d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 41d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 42d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** 43d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Migrates preferences to UnifiedEmail. 44d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 45d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * @param oldVersion The previous version of UnifiedEmail's preferences 46d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * @param newVersion The new version of UnifiedEmail's preferences 47d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 48d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy protected abstract void migrate(final Context context, int oldVersion, int newVersion); 49d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy} 50