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

Commit ee2a1219 authored by Jeff Davidson's avatar Jeff Davidson
Browse files

API tweaks for network score settings.

Expose "isAppValidScorer" so Settings can call it.

Also rename ACTION_CHANGE_DEFAULT to ACTION_CHANGE_ACTIVE for
consistency with other naming.

Change-Id: I6c2d0099622958f06c2916ca76090e14d5273c86
parent 83474f5b
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -40,33 +40,33 @@ import android.os.ServiceManager;
 *     and (eventually) calls {@link #updateScores} with the results.
 * </ul>
 *
 * <p>The system keeps track of a default scorer application; at any time, only this application
 * <p>The system keeps track of an active scorer application; at any time, only this application
 * will receive {@link #ACTION_SCORE_NETWORKS} broadcasts and will be permitted to call
 * {@link #updateScores}. Applications may determine the current default scorer with
 * {@link #getActiveScorerPackage()} and request to change the default scorer by sending an
 * {@link #ACTION_CHANGE_DEFAULT} broadcast with another scorer.
 * {@link #updateScores}. Applications may determine the current active scorer with
 * {@link #getActiveScorerPackage()} and request to change the active scorer by sending an
 * {@link #ACTION_CHANGE_ACTIVE} broadcast with another scorer.
 *
 * @hide
 */
public class NetworkScoreManager {
    /**
     * Activity action: ask the user to change the default network scorer. This will show a dialog
     * that asks the user whether they want to replace the current default scorer with the one
     * Activity action: ask the user to change the active network scorer. This will show a dialog
     * that asks the user whether they want to replace the current active scorer with the one
     * specified in {@link #EXTRA_PACKAGE_NAME}. The activity will finish with RESULT_OK if the
     * default was changed or RESULT_CANCELED if it failed for any reason.
     * active scorer was changed or RESULT_CANCELED if it failed for any reason.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_CHANGE_DEFAULT = "android.net.scoring.CHANGE_DEFAULT";
    public static final String ACTION_CHANGE_ACTIVE = "android.net.scoring.CHANGE_ACTIVE";

    /**
     * Extra used with {@link #ACTION_CHANGE_DEFAULT} to specify the new scorer package. Set with
     * Extra used with {@link #ACTION_CHANGE_ACTIVE} to specify the new scorer package. Set with
     * {@link android.content.Intent#putExtra(String, String)}.
     */
    public static final String EXTRA_PACKAGE_NAME = "packageName";

    /**
     * Broadcast action: new network scores are being requested. This intent will only be delivered
     * to the current default scorer app. That app is responsible for scoring the networks and
     * to the current active scorer app. That app is responsible for scoring the networks and
     * calling {@link #updateScores} when complete. The networks to score are specified in
     * {@link #EXTRA_NETWORKS_TO_SCORE}, and will generally consist of all networks which have been
     * configured by the user as well as any open networks.
@@ -99,7 +99,7 @@ public class NetworkScoreManager {
     * <p>At any time, only one scorer application will receive {@link #ACTION_SCORE_NETWORKS}
     * broadcasts and be allowed to call {@link #updateScores}. Applications may use this method to
     * determine the current scorer and offer the user the ability to select a different scorer via
     * the {@link #ACTION_CHANGE_DEFAULT} intent.
     * the {@link #ACTION_CHANGE_ACTIVE} intent.
     * @return the full package name of the current active scorer, or null if there is no active
     *     scorer.
     */
+5 −7
Original line number Diff line number Diff line
@@ -97,8 +97,7 @@ public final class NetworkScorerAppManager {
    public static String getActiveScorer(Context context) {
        String scorerPackage = Settings.Global.getString(context.getContentResolver(),
                Global.NETWORK_SCORER_APP);
        Collection<String> applications = getAllValidScorers(context);
        if (isPackageValidScorer(applications, scorerPackage)) {
        if (isPackageValidScorer(context, scorerPackage)) {
            return scorerPackage;
        } else {
            return null;
@@ -131,8 +130,7 @@ public final class NetworkScorerAppManager {
            return true;
        } else {
            // We only make the change if the new package is valid.
            Collection<String> applications = getAllValidScorers(context);
            if (isPackageValidScorer(applications, packageName)) {
            if (isPackageValidScorer(context, packageName)) {
                Settings.Global.putString(context.getContentResolver(),
                        Settings.Global.NETWORK_SCORER_APP, packageName);
                return true;
@@ -159,8 +157,8 @@ public final class NetworkScorerAppManager {
    }

    /** Returns true if the given package is a valid scorer. */
    private static boolean isPackageValidScorer(Collection<String> scorerPackageNames,
            String packageName) {
        return packageName != null && scorerPackageNames.contains(packageName);
    public static boolean isPackageValidScorer(Context context, String packageName) {
        Collection<String> applications = getAllValidScorers(context);
        return packageName != null && applications.contains(packageName);
    }
}