Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d5f512 authored by Jean Chalard's avatar Jean Chalard
Browse files

Ask the client to make itself known when it's not

Upon invoking the settings of the dictionary pack with an unknown
client, we now launch an intent to ask the client to make itself known.
This change also includes the code that receives this intent and
acts upon it.

Bug: 8492879
Change-Id: I2c6496dea845646961ecafcf64e282cb93ee91dc
parent c1dec87a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -95,6 +95,12 @@
            </intent-filter>
        </receiver>

        <receiver android:name=".DictionaryPackInstallBroadcastReceiver">
            <intent-filter>
                <action android:name="com.android.inputmethod.dictionarypack.UNKNOWN_CLIENT" />
            </intent-filter>
        </receiver>

        <provider android:name="com.android.inputmethod.dictionarypack.DictionaryProvider"
                  android:grantUriPermissions="true"
                  android:exported="false"
+21 −3
Original line number Diff line number Diff line
@@ -24,17 +24,35 @@ package com.android.inputmethod.dictionarypack;
 * is needed in particular to cleanly compile regression tests.
 */
public class DictionaryPackConstants {
    /**
     * The root domain for the dictionary pack, upon which authorities and actions will append
     * their own distinctive strings.
     */
    private static final String DICTIONARY_DOMAIN = "com.android.inputmethod.dictionarypack";

    /**
     * Authority for the ContentProvider protocol.
     */
    // TODO: find some way to factorize this string with the one in the resources
    public static final String AUTHORITY = "com.android.inputmethod.dictionarypack.aosp";
    public static final String AUTHORITY = DICTIONARY_DOMAIN + ".aosp";

    /**
     * The action of the intent for publishing that new dictionary data is available.
     */
    // TODO: make this different across different packages. A suggested course of action is
    // to use the package name inside this string.
    public static final String NEW_DICTIONARY_INTENT_ACTION =
            "com.android.inputmethod.dictionarypack.newdict";
    // NOTE: The appended string should be uppercase like all other actions, but it's not for
    // historical reasons.
    public static final String NEW_DICTIONARY_INTENT_ACTION = DICTIONARY_DOMAIN + ".newdict";

    /**
     * The action of the intent sent by the dictionary pack to ask for a client to make
     * itself known. This is used when the settings activity is brought up for a client the
     * dictionary pack does not know about.
     */
    public static final String UNKNOWN_DICTIONARY_PROVIDER_CLIENT = DICTIONARY_DOMAIN
            + ".UNKNOWN_CLIENT";
    // In the above intents, the name of the string extra that contains the name of the client
    // we want information about.
    public static final String DICTIONARY_PROVIDER_CLIENT_EXTRA = "client";
}
+5 −0
Original line number Diff line number Diff line
@@ -509,6 +509,11 @@ public final class DictionaryProvider extends ContentProvider {
                } catch (final BadFormatException e) {
                    Log.w(TAG, "Not enough information to insert this dictionary " + values, e);
                }
                // We just received new information about the list of dictionary for this client.
                // For all intents and purposes, this is new metadata, so we should publish it
                // so that any listeners (like the Settings interface for example) can update
                // themselves.
                UpdateHandler.publishUpdateMetadataCompleted(getContext(), true);
                break;
            case DICTIONARY_V1_WHOLE_LIST:
            case DICTIONARY_V1_DICT_INFO:
+15 −1
Original line number Diff line number Diff line
@@ -110,6 +110,15 @@ public final class DictionarySettingsFragment extends PreferenceFragment
        super.onResume();
        mChangedSettings = false;
        UpdateHandler.registerUpdateEventListener(this);
        final Activity activity = getActivity();
        if (!MetadataDbHelper.isClientKnown(activity, mClientId)) {
            Log.i(TAG, "Unknown dictionary pack client: " + mClientId + ". Requesting info.");
            final Intent unknownClientBroadcast =
                    new Intent(DictionaryPackConstants.UNKNOWN_DICTIONARY_PROVIDER_CLIENT);
            unknownClientBroadcast.putExtra(
                    DictionaryPackConstants.DICTIONARY_PROVIDER_CLIENT_EXTRA, mClientId);
            activity.sendBroadcast(unknownClientBroadcast);
        }
        final IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        getActivity().registerReceiver(mConnectivityChangedReceiver, filter);
@@ -363,8 +372,13 @@ public final class DictionarySettingsFragment extends PreferenceFragment
                            getActivity(), android.R.anim.fade_out));
                    preferenceView.startAnimation(AnimationUtils.loadAnimation(
                            getActivity(), android.R.anim.fade_in));
                    // The menu is created by the framework asynchronously after the activity,
                    // which means it's possible to have the activity running but the menu not
                    // created yet - hence the necessity for a null check here.
                    if (null != mUpdateNowMenu) {
                        mUpdateNowMenu.setTitle(R.string.check_for_updates_now);
                    }
                }
            });
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -16,13 +16,9 @@

package com.android.inputmethod.dictionarypack;

import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public final class EventHandler extends BroadcastReceiver {
    private static final String TAG = EventHandler.class.getName();
Loading