Skip to content

Commit

Permalink
Add CMSettingsProvider and CMDatabaseHelper
Browse files Browse the repository at this point in the history
issue-id: CYNGNOS-828

Change-Id: I01c08c0e432d6a941950a565e5ab6664664e2a7f
  • Loading branch information
Yvonne Wong committed Aug 31, 2015
1 parent e949433 commit 0eb2999
Show file tree
Hide file tree
Showing 17 changed files with 2,217 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Android.mk
Expand Up @@ -163,7 +163,7 @@ LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR:= build/tools/droiddoc/templates-sdk

LOCAL_DROIDDOC_OPTIONS:= \
-stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/cmsdk_stubs_current_intermediates/src \
-stubpackages cyanogenmod.alarmclock:cyanogenmod.app:cyanogenmod.hardware:cyanogenmod.os:cyanogenmod.profiles:cyanogenmod.platform:org.cyanogenmod.platform \
-stubpackages cyanogenmod.alarmclock:cyanogenmod.app:cyanogenmod.hardware:cyanogenmod.os:cyanogenmod.profiles:cyanogenmod.providers:cyanogenmod.platform:org.cyanogenmod.platform \
-api $(INTERNAL_CM_PLATFORM_API_FILE) \
-removedApi $(INTERNAL_CM_PLATFORM_REMOVED_API_FILE) \
-nodocs \
Expand Down Expand Up @@ -192,7 +192,7 @@ LOCAL_MODULE := cm-system-api-stubs

LOCAL_DROIDDOC_OPTIONS:=\
-stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/cmsdk_system_stubs_current_intermediates/src \
-stubpackages cyanogenmod.alarmclock:cyanogenmod.app:cyanogenmod.hardware:cyanogenmod.os:cyanogenmod.profiles:cyanogenmod.platform:org.cyanogenmod.platform \
-stubpackages cyanogenmod.alarmclock:cyanogenmod.app:cyanogenmod.hardware:cyanogenmod.os:cyanogenmod.profiles:cyanogenmod.providers:cyanogenmod.platform:org.cyanogenmod.platform \
-showAnnotation android.annotation.SystemApi \
-api $(INTERNAL_CM_PLATFORM_SYSTEM_API_FILE) \
-removedApi $(INTERNAL_CM_PLATFORM_SYSTEM_REMOVED_API_FILE) \
Expand Down
67 changes: 67 additions & 0 deletions api/cm_current.txt
Expand Up @@ -442,6 +442,8 @@ package cyanogenmod.platform {
field public static final java.lang.String MODIFY_SOUND_SETTINGS = "cyanogenmod.permission.MODIFY_SOUND_SETTINGS";
field public static final java.lang.String PUBLISH_CUSTOM_TILE = "cyanogenmod.permission.PUBLISH_CUSTOM_TILE";
field public static final java.lang.String READ_MSIM_PHONE_STATE = "cyanogenmod.permission.READ_MSIM_PHONE_STATE";
field public static final java.lang.String WRITE_SECURE_SETTINGS = "cyanogenmod.permission.WRITE_SECURE_SETTINGS";
field public static final java.lang.String WRITE_SETTINGS = "cyanogenmod.permission.WRITE_SETTINGS";
}

public final class R {
Expand Down Expand Up @@ -566,3 +568,68 @@ package cyanogenmod.profiles {

}

package cyanogenmod.providers {

public final class CMSettings {
ctor public CMSettings();
field public static final java.lang.String AUTHORITY = "cmsettings";
}

public static class CMSettings.CMSettingNotFoundException extends android.util.AndroidException {
ctor public CMSettings.CMSettingNotFoundException(java.lang.String);
}

public static final class CMSettings.Global extends android.provider.Settings.NameValueTable {
ctor public CMSettings.Global();
method public static float getFloat(android.content.ContentResolver, java.lang.String, float);
method public static float getFloat(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static int getInt(android.content.ContentResolver, java.lang.String, int);
method public static int getInt(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static long getLong(android.content.ContentResolver, java.lang.String, long);
method public static long getLong(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static java.lang.String getString(android.content.ContentResolver, java.lang.String);
method public static boolean putFloat(android.content.ContentResolver, java.lang.String, float);
method public static boolean putInt(android.content.ContentResolver, java.lang.String, int);
method public static boolean putLong(android.content.ContentResolver, java.lang.String, long);
method public static boolean putString(android.content.ContentResolver, java.lang.String, java.lang.String);
field public static final android.net.Uri CONTENT_URI;
field public static final java.lang.String SYS_PROP_CM_SETTING_VERSION = "sys.cm_settings_global_version";
}

public static final class CMSettings.Secure extends android.provider.Settings.NameValueTable {
ctor public CMSettings.Secure();
method public static float getFloat(android.content.ContentResolver, java.lang.String, float);
method public static float getFloat(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static int getInt(android.content.ContentResolver, java.lang.String, int);
method public static int getInt(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static long getLong(android.content.ContentResolver, java.lang.String, long);
method public static long getLong(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static java.lang.String getString(android.content.ContentResolver, java.lang.String);
method public static boolean putFloat(android.content.ContentResolver, java.lang.String, float);
method public static boolean putInt(android.content.ContentResolver, java.lang.String, int);
method public static boolean putLong(android.content.ContentResolver, java.lang.String, long);
method public static boolean putString(android.content.ContentResolver, java.lang.String, java.lang.String);
field public static final android.net.Uri CONTENT_URI;
field public static final java.lang.String NAME_THEME_CONFIG = "name_theme_config";
field public static final java.lang.String SYS_PROP_CM_SETTING_VERSION = "sys.cm_settings_secure_version";
}

public static final class CMSettings.System extends android.provider.Settings.NameValueTable {
ctor public CMSettings.System();
method public static float getFloat(android.content.ContentResolver, java.lang.String, float);
method public static float getFloat(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static int getInt(android.content.ContentResolver, java.lang.String, int);
method public static int getInt(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static long getLong(android.content.ContentResolver, java.lang.String, long);
method public static long getLong(android.content.ContentResolver, java.lang.String) throws cyanogenmod.providers.CMSettings.CMSettingNotFoundException;
method public static java.lang.String getString(android.content.ContentResolver, java.lang.String);
method public static boolean putFloat(android.content.ContentResolver, java.lang.String, float);
method public static boolean putInt(android.content.ContentResolver, java.lang.String, int);
method public static boolean putLong(android.content.ContentResolver, java.lang.String, long);
method public static boolean putString(android.content.ContentResolver, java.lang.String, java.lang.String);
field public static final android.net.Uri CONTENT_URI;
field public static final java.lang.String SYS_PROP_CM_SETTING_VERSION = "sys.cm_settings_system_version";
}

}

13 changes: 13 additions & 0 deletions cm/res/AndroidManifest.xml
Expand Up @@ -69,6 +69,19 @@
android:description="@string/permdesc_useHardwareFramework"
android:protectionLevel="system|signature" />

<!-- Allows an application to write to CM system settings -->
<permission android:name="cyanogenmod.permission.WRITE_SETTINGS"
android:label="@string/permlab_writeSettings"
android:description="@string/permdesc_writeSettings"
android:protectionLevel="normal" />

<!-- Allows an application to write to secure CM system settings.
<p>Not for use by third-party applications. -->
<permission android:name="cyanogenmod.permission.WRITE_SECURE_SETTINGS"
android:label="@string/permlab_writeSecureSettings"
android:description="@string/permdesc_writeSecureSettings"
android:protectionLevel="signature|system|development" />

<application android:process="system"
android:persistent="true"
android:hasCode="false"
Expand Down
7 changes: 7 additions & 0 deletions cm/res/res/values/strings.xml
Expand Up @@ -42,6 +42,13 @@
<string name="permlab_useHardwareFramework">use hardware framework</string>
<string name="permdesc_useHardwareFramework">Allows an app access to the CM hardware framework.</string>

<!-- Labels for the WRITE_SETTINGS permission -->
<string name="permlab_writeSettings">modify CM system settings</string>
<string name="permdesc_writeSettings">Allows an app to modify CM system settings.</string>

<!-- Labels for the WRITE_SECURE_SETTINGS permission -->
<string name="permlab_writeSecureSettings">modify CM secure system settings</string>
<string name="permdesc_writeSecureSettings">Allows an app to modify CM secure system settings. Not for use by normal apps.</string>

<!-- Label to show for a service that is running because it is observing the user's custom tiles. -->
<string name="custom_tile_listener_binding_label">Custom tile listener</string>
Expand Down
36 changes: 36 additions & 0 deletions packages/CMSettingsProvider/Android.mk
@@ -0,0 +1,36 @@
#
# Copyright (C) 2015 The CyanogenMod Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

src_dir := src
res_dir := res

LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dir))
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))

LOCAL_PACKAGE_NAME := CMSettingsProvider
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

LOCAL_JAVA_LIBRARIES := \
org.cyanogenmod.platform.sdk

include $(BUILD_PACKAGE)

########################
include $(call all-makefiles-under,$(LOCAL_PATH))
42 changes: 42 additions & 0 deletions packages/CMSettingsProvider/AndroidManifest.xml
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The CyanogenMod Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cyanogenmod.cmsettings"
coreApp="true"
android:sharedUserId="android.uid.system">
<!-- It is necessary to be a system app in order to update table versions in SystemProperties for
CMSettings to know whether or not the client side cache is up to date. It is also necessary
to run in the system process in order to start the content provider prior to running migration
for CM settings on user starting -->

<uses-permission android:name="android.permission.MANAGE_USERS" />

<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:process="system"
android:killAfterRestore="false"
android:allowClearUserData="false"
android:enabled="true">

<provider android:name="CMSettingsProvider" android:authorities="cmsettings"
android:multiprocess="false"
android:exported="true"
android:writePermission="cyanogenmod.permission.WRITE_SETTINGS"
android:singleUser="true"
android:initOrder="100" />

</application>
</manifest>
Binary file added packages/CMSettingsProvider/res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/CMSettingsProvider/res/values/strings.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014-2015 The CyanogenMod Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<string name="app_name">CMSettingsProvider</string>
</resources>
@@ -0,0 +1,126 @@
/**
* Copyright (c) 2015, The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cyanogenmod.cmsettings;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.os.UserHandle;
import android.util.Log;

import java.io.File;

/**
* The CMDatabaseHelper allows creation of a database to store CM specific settings for a user
* in System, Secure, and Global tables.
*/
public class CMDatabaseHelper extends SQLiteOpenHelper{
private static final String TAG = "CMDatabaseHelper";
private static final boolean LOCAL_LOGV = false;

private static final String DATABASE_NAME = "cmsettings.db";
private static final int DATABASE_VERSION = 1;

static class CMTableNames {
static final String TABLE_SYSTEM = "system";
static final String TABLE_SECURE = "secure";
static final String TABLE_GLOBAL = "global";
}

private static final String CREATE_TABLE_SQL_FORMAT = "CREATE TABLE %s (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT UNIQUE ON CONFLICT REPLACE," +
"value TEXT" +
");)";

private static final String CREATE_INDEX_SQL_FORMAT = "CREATE INDEX %sIndex%d ON %s (name);";

private int mUserHandle;

/**
* Gets the appropriate database path for a specific user
* @param userId The database path for this user
* @return The database path string
*/
static String dbNameForUser(final int userId) {
// The owner gets the unadorned db name;
if (userId == UserHandle.USER_OWNER) {
return DATABASE_NAME;
} else {
// Place the database in the user-specific data tree so that it's
// cleaned up automatically when the user is deleted.
File databaseFile = new File(
Environment.getUserSystemDirectory(userId), DATABASE_NAME);
return databaseFile.getPath();
}
}

/**
* Creates an instance of {@link CMDatabaseHelper}
* @param context
* @param userId
*/
public CMDatabaseHelper(Context context, int userId) {
super(context, dbNameForUser(userId), null, DATABASE_VERSION);
mUserHandle = userId;
}

/**
* Creates System, Secure, and Global tables in the specified {@link SQLiteDatabase}
* @param db The database.
*/
@Override
public void onCreate(SQLiteDatabase db) {
db.beginTransaction();

try {
createDbTable(db, CMTableNames.TABLE_SYSTEM);
createDbTable(db, CMTableNames.TABLE_SECURE);

if (mUserHandle == UserHandle.USER_OWNER) {
createDbTable(db, CMTableNames.TABLE_GLOBAL);
}

db.setTransactionSuccessful();

if (LOCAL_LOGV) Log.v(TAG, "Successfully created tables for cm settings db");
} finally {
db.endTransaction();
}
}

/**
* Creates a table and index for the specified database and table name
* @param db
* @param tableName
*/
private void createDbTable(SQLiteDatabase db, String tableName) {
if (LOCAL_LOGV) Log.v(TAG, "Creating table and index for: " + tableName);

String createTableSql = String.format(CREATE_TABLE_SQL_FORMAT, tableName);
db.execSQL(createTableSql);

String createIndexSql = String.format(CREATE_INDEX_SQL_FORMAT, tableName, 1, tableName);
db.execSQL(createIndexSql);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

0 comments on commit 0eb2999

Please sign in to comment.