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

Commit 47347373 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Restore @VisibleForTesting on NetworkScorerAppManager." into oc-dev

parents 101b1515 f1acc1e8
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import java.util.List;
 *
 *
 * @hide
 * @hide
 */
 */
@VisibleForTesting
public class NetworkScorerAppManager {
public class NetworkScorerAppManager {
    private static final String TAG = "NetworkScorerAppManager";
    private static final String TAG = "NetworkScorerAppManager";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -63,7 +64,8 @@ public class NetworkScorerAppManager {
     * Returns the list of available scorer apps. The list will be empty if there are
     * Returns the list of available scorer apps. The list will be empty if there are
     * no valid scorers.
     * no valid scorers.
     */
     */
    List<NetworkScorerAppData> getAllValidScorers() {
    @VisibleForTesting
    public List<NetworkScorerAppData> getAllValidScorers() {
        if (VERBOSE) Log.v(TAG, "getAllValidScorers()");
        if (VERBOSE) Log.v(TAG, "getAllValidScorers()");
        final PackageManager pm = mContext.getPackageManager();
        final PackageManager pm = mContext.getPackageManager();
        final Intent serviceIntent = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS);
        final Intent serviceIntent = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS);
@@ -168,7 +170,8 @@ public class NetworkScorerAppManager {
     *     it was disabled or uninstalled).
     *     it was disabled or uninstalled).
     */
     */
    @Nullable
    @Nullable
    NetworkScorerAppData getActiveScorer() {
    @VisibleForTesting
    public NetworkScorerAppData getActiveScorer() {
        final int enabledSetting = getNetworkRecommendationsEnabledSetting();
        final int enabledSetting = getNetworkRecommendationsEnabledSetting();
        if (enabledSetting == NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF) {
        if (enabledSetting == NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF) {
            return null;
            return null;
@@ -211,7 +214,8 @@ public class NetworkScorerAppManager {
     * @return true if the scorer was changed, or false if the package is not a valid scorer or
     * @return true if the scorer was changed, or false if the package is not a valid scorer or
     *         a valid network recommendation provider exists.
     *         a valid network recommendation provider exists.
     */
     */
    boolean setActiveScorer(String packageName) {
    @VisibleForTesting
    public boolean setActiveScorer(String packageName) {
        final String oldPackageName = getNetworkRecommendationsPackage();
        final String oldPackageName = getNetworkRecommendationsPackage();


        if (TextUtils.equals(oldPackageName, packageName)) {
        if (TextUtils.equals(oldPackageName, packageName)) {
@@ -246,7 +250,8 @@ public class NetworkScorerAppManager {
     * is no longer valid then {@link Settings.Global#NETWORK_RECOMMENDATIONS_ENABLED} will be set
     * is no longer valid then {@link Settings.Global#NETWORK_RECOMMENDATIONS_ENABLED} will be set
     * to <code>0</code> (disabled).
     * to <code>0</code> (disabled).
     */
     */
    void updateState() {
    @VisibleForTesting
    public void updateState() {
        final int enabledSetting = getNetworkRecommendationsEnabledSetting();
        final int enabledSetting = getNetworkRecommendationsEnabledSetting();
        if (enabledSetting == NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF) {
        if (enabledSetting == NetworkScoreManager.RECOMMENDATIONS_ENABLED_FORCED_OFF) {
            // Don't change anything if it's forced off.
            // Don't change anything if it's forced off.
@@ -284,7 +289,8 @@ public class NetworkScorerAppManager {
    /**
    /**
     * Migrates the NETWORK_SCORER_APP Setting to the USE_OPEN_WIFI_PACKAGE Setting.
     * Migrates the NETWORK_SCORER_APP Setting to the USE_OPEN_WIFI_PACKAGE Setting.
     */
     */
    void migrateNetworkScorerAppSettingIfNeeded() {
    @VisibleForTesting
    public void migrateNetworkScorerAppSettingIfNeeded() {
        final String scorerAppPkgNameSetting =
        final String scorerAppPkgNameSetting =
                mSettingsFacade.getString(mContext, Settings.Global.NETWORK_SCORER_APP);
                mSettingsFacade.getString(mContext, Settings.Global.NETWORK_SCORER_APP);
        if (TextUtils.isEmpty(scorerAppPkgNameSetting)) {
        if (TextUtils.isEmpty(scorerAppPkgNameSetting)) {
+0 −14
Original line number Original line Diff line number Diff line
@@ -644,20 +644,6 @@ public class NetworkScoreServiceTest {
        }
        }
    }
    }


    @Test
    public void testDump_noDumpPermission() {
        doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission(
                eq(permission.DUMP), anyString());

        try {
            mNetworkScoreService.dump(
                    new FileDescriptor(), new PrintWriter(new StringWriter()), new String[0]);
            fail("SecurityException expected");
        } catch (SecurityException e) {
            // expected
        }
    }

    @Test
    @Test
    public void testDump_doesNotCrash() {
    public void testDump_doesNotCrash() {
        when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(NEW_SCORER);
        when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(NEW_SCORER);