Merge "Migrate Dreams default settings to DatabaseHelper." into jb-mr1-dev

This commit is contained in:
Daniel Sandler
2012-08-08 08:47:39 -07:00
committed by Android (Google) Code Review
5 changed files with 52 additions and 24 deletions

View File

@@ -5,8 +5,6 @@ import static android.provider.Settings.Secure.SCREENSAVER_COMPONENT;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import com.android.internal.view.IInputMethod;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -16,34 +14,32 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.view.IWindowManager;
import android.view.WindowManager;
/**
*
*
* @hide
*
*/
public class DreamManagerService
extends IDreamManager.Stub
public class DreamManagerService
extends IDreamManager.Stub
implements ServiceConnection
{
private static final boolean DEBUG = true;
private static final String TAG = "DreamManagerService";
final Object mLock = new Object[0];
private Context mContext;
private IWindowManager mIWindowManager;
private ComponentName mCurrentDreamComponent;
private IDreamService mCurrentDream;
private Binder mCurrentDreamToken;
private Binder mCurrentDreamToken;
public DreamManagerService(Context context) {
if (DEBUG) Slog.v(TAG, "DreamManagerService startup");
@@ -60,6 +56,7 @@ public class DreamManagerService
}
// IDreamManager method
@Override
public void dream() {
ComponentName name = getDreamComponent();
if (name != null) {
@@ -75,26 +72,26 @@ public class DreamManagerService
}
// IDreamManager method
@Override
public void setDreamComponent(ComponentName name) {
Settings.Secure.putString(mContext.getContentResolver(), SCREENSAVER_COMPONENT, name.flattenToString());
}
// IDreamManager method
@Override
public ComponentName getDreamComponent() {
// TODO(dsandler) don't load this every time, watch the value
// TODO(dsandler) don't load this every time, watch the value
String component = Settings.Secure.getString(mContext.getContentResolver(), SCREENSAVER_COMPONENT);
if (component == null) {
component = mContext.getResources().getString(
com.android.internal.R.string.config_defaultDreamComponent);
}
if (component != null) {
return ComponentName.unflattenFromString(component);
} else {
// We rely on DatabaseHelper to set a sane default for us when the settings DB is upgraded
return null;
}
}
// IDreamManager method
@Override
public void testDream(ComponentName name) {
if (DEBUG) Slog.v(TAG, "startDream name=" + name
+ " pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
@@ -110,6 +107,7 @@ public class DreamManagerService
}
// IDreamManager method
@Override
public void awaken() {
if (DEBUG) Slog.v(TAG, "awaken()");
synchronized (mLock) {
@@ -123,6 +121,7 @@ public class DreamManagerService
}
// IDreamManager method
@Override
public boolean isDreaming() {
return mCurrentDream != null;
}
@@ -141,14 +140,14 @@ public class DreamManagerService
mCurrentDreamComponent = componentName;
mCurrentDreamToken = new Binder();
try {
if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurrentDreamToken
if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurrentDreamToken
+ " for window type: " + WindowManager.LayoutParams.TYPE_DREAM);
mIWindowManager.addWindowToken(mCurrentDreamToken,
WindowManager.LayoutParams.TYPE_DREAM);
} catch (RemoteException e) {
Slog.w(TAG, "Unable to add window token. Proceed at your own risk.");
}
if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
Slog.w(TAG, "unable to bind service: " + componentName);
}
@@ -172,7 +171,7 @@ public class DreamManagerService
if (DEBUG) Slog.v(TAG, "disconnected: " + name + " service: " + mCurrentDream);
// Only happens in exceptional circumstances
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);

View File

@@ -853,8 +853,6 @@
<!-- enable screen saver feature -->
<bool name="config_enableDreams">true</bool>
<!-- Name of screensaver components to look for if none has been chosen by the user -->
<string name="config_defaultDreamComponent" translatable="false">com.google.android.deskclock/com.android.deskclock.Screensaver</string>
<!-- Base "touch slop" value used by ViewConfiguration as a
movement threshold where scrolling should begin. -->

View File

@@ -1557,7 +1557,6 @@
<java-symbol type="style" name="Theme.Toast" />
<java-symbol type="xml" name="storage_list" />
<java-symbol type="bool" name="config_enableDreams" />
<java-symbol type="string" name="config_defaultDreamComponent" />
<java-symbol type="string" name="enable_explore_by_touch_warning_title" />
<java-symbol type="string" name="enable_explore_by_touch_warning_message" />

View File

@@ -151,4 +151,12 @@
<!-- Number of retries for connecting to DHCP.
Value here is the same as WifiStateMachine.DEFAULT_MAX_DHCP_RETRIES -->
<integer name="def_max_dhcp_retries">9</integer>
<!-- Dreams (screen saver) default settings -->
<!-- Whether the feature is enabled when charging (Settings.Secure.SCREENSAVER_ENABLED) -->
<bool name="def_screensaver_enabled">true</bool>
<!-- Whether the feature activates when docked (SCREENSAVER_ACTIVATE_ON_DOCK) -->
<bool name="def_screensaver_activate_on_dock">true</bool>
<!-- ComponentName of the default screen saver (Settings.Secure.SCREENSAVER_COMPONENT) -->
<string name="def_screensaver_component">com.google.android.deskclock/com.android.deskclock.Screensaver</string>
</resources>

View File

@@ -65,7 +65,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
// is properly propagated through your change. Not doing so will result in a loss of user
// settings.
private static final int DATABASE_VERSION = 79;
private static final int DATABASE_VERSION = 80;
private Context mContext;
@@ -1073,6 +1073,30 @@ public class DatabaseHelper extends SQLiteOpenHelper {
upgradeVersion = 79;
}
// vvv Jelly Bean MR1 changes begin here vvv
if (upgradeVersion == 79) {
// update screensaver settings
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
+ " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED,
R.bool.def_screensaver_enabled);
loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
R.bool.def_screensaver_activate_on_dock);
loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENT,
R.string.def_screensaver_component);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
upgradeVersion = 80;
}
// *** Remember to update DATABASE_VERSION above!
if (upgradeVersion != currentVersion) {