diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2012-11-20 21:17:17 +0000 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2012-11-24 14:09:39 +0000 |
commit | ad3c9416092f09213d32eee8b59287766eae5d19 (patch) | |
tree | 0bc1e318ca15560299c662e37c6c4fedf0bcf1e6 /media | |
parent | 7d114fb838017d86ece76e18a7e1b0d8534595fa (diff) | |
download | frameworks_base-ad3c9416092f09213d32eee8b59287766eae5d19.zip frameworks_base-ad3c9416092f09213d32eee8b59287766eae5d19.tar.gz frameworks_base-ad3c9416092f09213d32eee8b59287766eae5d19.tar.bz2 |
Squashed commit of the theme engine support.
Updated 4.2 support for the old T-Mobile theme engine, as usual
needs the provider and switcher apps installed as well.
I'm finally dropping the 400+ commit history on this, since everybody
else keeps picking it up from CM as a single patch anyway... But
for the record, nothing of this would be possible without Josh, Ed,
and the rest of the TMo guys who wrote and maintained it until 2.2:
amit chabra <amit.chabra@t-mobile.com>
Amit Kohli <amit.kohli@t-mobile.com>
Chris Cogar <chriscogar@t-mobile.com>
Dirk Sigurdson <dirk.sigurdson@t-mobile.com>
Ed Carrigan <edward.carrigan@t-mobile.com>
Gaurav Sharma <gaurav.sharma3@t-mobile.com>
Hui Feng <hui.feng@t-mobile.com>
John Ritz <john.ritz1@t-mobile.com>
Josh Guilfoyle <josh.guilfoyle@t-mobile.com>
Mark Roberts <mark.roberts48@t-mobile.com>
Pankaj Kumar <Pankaj.kumar6@t-mobile.com>
Samuel Cheung <samuel.cheung@t-mobile.com>
Sergey Ten <sergey.ten6@t-mobile.com>
Change-Id: I7148d51be48f28a2dc4bdf9ec9018f04b268ffc4
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioService.java | 33 | ||||
-rw-r--r-- | media/java/android/media/Ringtone.java | 22 | ||||
-rw-r--r-- | media/java/android/media/RingtoneManager.java | 77 |
3 files changed, 110 insertions, 22 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index fe98458..9dba53a 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -70,6 +70,7 @@ import android.util.Log; import android.view.KeyEvent; import android.view.VolumePanel; +import com.android.internal.app.ThemeUtils; import com.android.internal.telephony.ITelephony; import java.io.FileDescriptor; @@ -115,6 +116,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished { /** The UI */ private VolumePanel mVolumePanel; + private Context mUiContext; + private Handler mHandler; // sendMsg() flags /** If the msg is already queued, replace it with this one. */ @@ -446,6 +449,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished { public AudioService(Context context) { mContext = context; mContentResolver = context.getContentResolver(); + mHandler = new Handler(); mVoiceCapable = mContext.getResources().getBoolean( com.android.internal.R.bool.config_voice_capable); @@ -463,7 +467,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { sSoundEffectVolumeDb = context.getResources().getInteger( com.android.internal.R.integer.config_soundEffectVolumeDb); - mVolumePanel = new VolumePanel(context, this); mMode = AudioSystem.MODE_NORMAL; mForcedUseForComm = AudioSystem.FORCE_NONE; @@ -527,6 +530,13 @@ public class AudioService extends IAudioService.Stub implements OnFinished { pkgFilter.addDataScheme("package"); context.registerReceiver(mReceiver, pkgFilter); + ThemeUtils.registerThemeChangeReceiver(context, new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + mUiContext = null; + } + }); + // Register for phone state monitoring TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); @@ -1081,7 +1091,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished { streamType = AudioSystem.STREAM_NOTIFICATION; } - mVolumePanel.postVolumeChanged(streamType, flags); + showVolumeChangeUi(streamType, flags); if ((flags & AudioManager.FLAG_FIXED_VOLUME) == 0) { oldIndex = (oldIndex + 5) / 10; @@ -3960,6 +3970,25 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } } + private void showVolumeChangeUi(final int streamType, final int flags) { + if (mUiContext != null && mVolumePanel != null) { + mVolumePanel.postVolumeChanged(streamType, flags); + } else { + mHandler.post(new Runnable() { + @Override + public void run() { + if (mUiContext == null) { + mUiContext = ThemeUtils.createUiContext(mContext); + } + + final Context context = mUiContext != null ? mUiContext : mContext; + mVolumePanel = new VolumePanel(context, AudioService.this); + mVolumePanel.postVolumeChanged(streamType, flags); + } + }); + } + } + //========================================================================================== // AudioFocus //========================================================================================== diff --git a/media/java/android/media/Ringtone.java b/media/java/android/media/Ringtone.java index f190eb9..4cad61c 100644 --- a/media/java/android/media/Ringtone.java +++ b/media/java/android/media/Ringtone.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2006 The Android Open Source Project + * This code has been modified. Portions copyright (C) 2010, T-Mobile USA, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,6 +110,19 @@ public class Ringtone { return mTitle = getTitle(context, mUri, true); } + private static String stringForQuery(Cursor cursor) { + if (cursor != null) { + try { + if (cursor.moveToFirst()) { + return cursor.getString(0); + } + } finally { + cursor.close(); + } + } + return null; + } + private static String getTitle(Context context, Uri uri, boolean followSettingsUri) { Cursor cursor = null; ContentResolver res = context.getContentResolver(); @@ -127,6 +141,14 @@ public class Ringtone { .getString(com.android.internal.R.string.ringtone_default_with_actual, actualTitle); } + } else if (RingtoneManager.THEME_AUTHORITY.equals(authority)) { + Uri themes = Uri.parse("content://com.tmobile.thememanager.themes/themes"); + title = stringForQuery(res.query(themes, new String[] { "ringtone_name" }, + "ringtone_uri = ?", new String[] { uri.toString() }, null)); + if (title == null) { + title = stringForQuery(res.query(themes, new String[] { "notif_ringtone_name" }, + "notif_ringtone_uri = ?", new String[] { uri.toString() }, null)); + } } else { try { if (DrmStore.AUTHORITY.equals(authority)) { diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index b5a672a..a0ea993 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 The Android Open Source Project + * This code has been modified. Portions copyright (C) 2010, T-Mobile USA, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +26,6 @@ import android.content.ContentUris; import android.app.ProfileGroup; import android.app.ProfileManager; import android.content.Context; -import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; import android.os.Environment; @@ -177,23 +177,28 @@ public class RingtoneManager { public static final String EXTRA_RINGTONE_PICKED_URI = "android.intent.extra.ringtone.PICKED_URI"; + /** + * @hide + */ + public static final String THEME_AUTHORITY = "com.tmobile.thememanager.packageresources"; + // Make sure the column ordering and then ..._COLUMN_INDEX are in sync private static final String[] INTERNAL_COLUMNS = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, - "\"" + MediaStore.Audio.Media.INTERNAL_CONTENT_URI + "\"", + "\"" + MediaStore.Audio.Media.INTERNAL_CONTENT_URI + "/\" || " + MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE_KEY }; private static final String[] DRM_COLUMNS = new String[] { DrmStore.Audio._ID, DrmStore.Audio.TITLE, - "\"" + DrmStore.Audio.CONTENT_URI + "\"", + "\"" + DrmStore.Audio.CONTENT_URI + "/\" || " + DrmStore.Audio._ID, DrmStore.Audio.TITLE + " AS " + MediaStore.Audio.Media.TITLE_KEY }; private static final String[] MEDIA_COLUMNS = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, - "\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "\"", + "\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/\" || " + MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE_KEY }; @@ -368,7 +373,11 @@ public class RingtoneManager { final Cursor drmCursor = mIncludeDrm ? getDrmRingtones() : null; final Cursor mediaCursor = getMediaRingtones(); - return mCursor = new SortCursor(new Cursor[] { internalCursor, drmCursor, mediaCursor }, + final Cursor themeRegularCursor = getThemeRegularRingtones(); + final Cursor themeNotifCursor = getThemeNotificationRingtones(); + + return mCursor = new SortCursor(new Cursor[] { internalCursor, drmCursor, mediaCursor, + themeRegularCursor, themeNotifCursor }, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); } @@ -405,8 +414,7 @@ public class RingtoneManager { } private static Uri getUriFromCursor(Cursor cursor) { - return ContentUris.withAppendedId(Uri.parse(cursor.getString(URI_COLUMN_INDEX)), cursor - .getLong(ID_COLUMN_INDEX)); + return Uri.parse(cursor.getString(URI_COLUMN_INDEX)); } /** @@ -426,23 +434,12 @@ public class RingtoneManager { return -1; } - // Only create Uri objects when the actual URI changes - Uri currentUri = null; - String previousUriString = null; for (int i = 0; i < cursorCount; i++) { - String uriString = cursor.getString(URI_COLUMN_INDEX); - if (currentUri == null || !uriString.equals(previousUriString)) { - currentUri = Uri.parse(uriString); - } - - if (ringtoneUri.equals(ContentUris.withAppendedId(currentUri, cursor - .getLong(ID_COLUMN_INDEX)))) { + if (ringtoneUri.equals(getUriFromCursor(cursor))) { return i; } cursor.move(1); - - previousUriString = uriString; } return -1; @@ -468,6 +465,14 @@ public class RingtoneManager { uri = getValidRingtoneUriFromCursorAndClose(context, rm.getDrmRingtones()); } + if (uri == null) { + uri = getValidRingtoneUriFromCursorAndClose(context, rm.getThemeRegularRingtones()); + } + + if (uri == null) { + uri = getValidRingtoneUriFromCursorAndClose(context, rm.getThemeNotificationRingtones()); + } + return uri; } @@ -512,7 +517,39 @@ public class RingtoneManager { MediaStore.Audio.Media.DEFAULT_SORT_ORDER) : null; } - + + private String getThemeWhereClause(String uriColumn) { + /* Filter out themes with no ringtone and the default theme (which has no package). */ + String clause = uriColumn + " IS NOT NULL AND LENGTH(theme_package) > 0"; + if (mIncludeDrm) { + return clause; + } else { + return clause + " AND " + uriColumn + " NOT LIKE '%/assets/%locked%'"; + } + } + + private Cursor getThemeRegularRingtones() { + if ((mType & TYPE_RINGTONE) != 0) { + return query(Uri.parse("content://com.tmobile.thememanager.themes/themes"), + new String[] { "_id", "ringtone_name AS " + MEDIA_COLUMNS[1], "ringtone_uri", + "ringtone_name_key AS " + MEDIA_COLUMNS[3] }, + getThemeWhereClause("ringtone_uri"), null, MEDIA_COLUMNS[3]); + } else { + return null; + } + } + + private Cursor getThemeNotificationRingtones() { + if ((mType & TYPE_NOTIFICATION) != 0) { + return query(Uri.parse("content://com.tmobile.thememanager.themes/themes"), + new String[] { "_id", "notif_ringtone_name AS " + MEDIA_COLUMNS[1], "notif_ringtone_uri", + "notif_ringtone_name_key AS " + MEDIA_COLUMNS[3] }, + getThemeWhereClause("notif_ringtone_uri"), null, MEDIA_COLUMNS[3]); + } else { + return null; + } + } + private void setFilterColumnsList(int type) { List<String> columns = mFilterColumns; columns.clear(); |