Skip to content

Commit

Permalink
Remove deprecated MuzeiContract.Sources columns
Browse files Browse the repository at this point in the history
And the parseCommands() used by them.
  • Loading branch information
ianhanniballake committed Sep 4, 2019
1 parent 1618120 commit 5bd9056
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ class MuzeiProvider : ContentProvider() {
"0 AS \"sources._id\"",
MuzeiContract.Sources.COLUMN_NAME_AUTHORITY to
"providerAuthority AS component_name",
MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED to "1 AS selected",
"selected" to "1 AS selected",
MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION to "\"\" AS description",
MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE to "0 AS network",
"network" to "0 AS network",
MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND to
"1 AS supports_next_artwork",
MuzeiContract.Sources.COLUMN_NAME_COMMANDS to "NULL AS commands"
"commands" to "NULL AS commands"
)

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
Expand Down Expand Up @@ -206,14 +206,14 @@ class MuzeiProvider : ContentProvider() {
c.newRow().apply {
add(BaseColumns._ID, 0L)
add(MuzeiContract.Sources.COLUMN_NAME_AUTHORITY, provider.authority)
add(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true)
add("selected", true)
add(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, runBlocking {
ProviderManager.getDescription(context, provider.authority)
})
add(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false)
add("network", false)
add(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND,
provider.supportsNextArtwork)
add(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, null)
add("commands", null)
}
}
return c.apply { setNotificationUri(context.contentResolver, uri) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.content.Context
import android.os.Bundle
import android.os.RemoteException
import android.util.Log
import com.google.android.apps.muzei.api.MuzeiContract
import com.google.android.apps.muzei.api.UserCommand
import com.google.android.apps.muzei.api.internal.ProtocolConstants.DEFAULT_VERSION
import com.google.android.apps.muzei.api.internal.ProtocolConstants.GET_ARTWORK_INFO_MIN_VERSION
Expand All @@ -38,6 +37,8 @@ import com.google.android.apps.muzei.api.internal.ProtocolConstants.METHOD_TRIGG
import com.google.android.apps.muzei.util.ContentProviderClientCompat
import com.google.android.apps.muzei.util.toastFromBackground
import net.nurik.roman.muzei.androidclientcommon.R
import org.json.JSONArray
import org.json.JSONException
import java.util.ArrayList

private const val TAG = "Artwork"
Expand Down Expand Up @@ -82,8 +83,18 @@ suspend fun Artwork.getCommands(context: Context) : List<UserCommand> {
return ContentProviderClientCompat.getClient(context, imageUri)?.use { client ->
return try {
val result = client.call(METHOD_GET_COMMANDS, imageUri.toString())
val commandsString = result?.getString(KEY_COMMANDS, null)
MuzeiContract.Sources.parseCommands(commandsString)
result?.getString(KEY_COMMANDS, null)?.run {
val commands = mutableListOf<UserCommand>()
try {
val commandArray = JSONArray(this)
for (index in 0 until commandArray.length()) {
commands.add(UserCommand.deserialize(commandArray.getString(index)))
}
} catch (e: JSONException) {
Log.e(TAG, "Error parsing commands from $this", e)
}
commands
} ?: ArrayList()
} catch (e: RemoteException) {
Log.i(TAG, "Provider for $imageUri crashed while retrieving commands", e)
ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@
import android.net.Uri;
import android.os.Looper;
import android.provider.BaseColumns;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresPermission;
import androidx.annotation.WorkerThread;

Expand Down Expand Up @@ -249,37 +242,16 @@ public static final class Sources implements BaseColumns {
* <p>Type: TEXT
*/
public static final String COLUMN_NAME_AUTHORITY = "component_name";
/**
* Column name for the flag indicating if the source is currently selected
* <p>Type: INTEGER (boolean): This always returns true (1)
* @deprecated Only selected rows are returned.
*/
@Deprecated
public static final String COLUMN_NAME_IS_SELECTED = "selected";
/**
* Column name for the source's description.
* <p>Type: TEXT
*/
public static final String COLUMN_NAME_DESCRIPTION = "description";
/**
* Column name for the flag indicating if the source wants callbacks for network connectivity changes
* <p>Type: INTEGER (boolean): This always returns false (0)
* @deprecated Only selected rows are returned.
*/
@Deprecated
public static final String COLUMN_NAME_WANTS_NETWORK_AVAILABLE = "network";
/**
* Column name for the flag indicating if the source supports a 'Next Artwork' action
* <p>Type: INTEGER (boolean)
*/
public static final String COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND = "supports_next_artwork";
/**
* Column name for the commands the source supports
* <p>Type: TEXT: This always returns a <code>null</code> String
* @deprecated Commands are no longer exposed outside of Muzei.
*/
@Deprecated
public static final String COLUMN_NAME_COMMANDS = "commands";
/**
* The MIME type of {@link #CONTENT_URI} providing sources.
*/
Expand Down Expand Up @@ -323,29 +295,5 @@ private Sources() {
*/
@Deprecated
public static final String ACTION_SOURCE_CHANGED = "com.google.android.apps.muzei.ACTION_SOURCE_CHANGED";

/**
* Parse the commands found in the {@link #COLUMN_NAME_COMMANDS} field into a List of {@link UserCommand}s.
*
* @param commandsString The serialized commands found in {@link #COLUMN_NAME_COMMANDS}.
*
* @return A deserialized List of {@link UserCommand}s.
*/
@NonNull
public static List<UserCommand> parseCommands(String commandsString) {
ArrayList<UserCommand> commands = new ArrayList<>();
if (commandsString == null) {
return commands;
}
try {
JSONArray commandArray = new JSONArray(commandsString);
for (int h=0; h<commandArray.length(); h++) {
commands.add(UserCommand.deserialize(commandArray.getString(h)));
}
} catch (JSONException e) {
Log.e(MuzeiContract.Sources.class.getSimpleName(), "Error parsing commands from " + commandsString, e);
}
return commands;
}
}
}

0 comments on commit 5bd9056

Please sign in to comment.