Consolidate all wrappers used for testing.

- Add the wrapper package and move all wrappers to the wrapper package.
- Get rid of some wrapper interface/impl implementation and have a
wrapper class directly.

Bug: 65634579
Test: make RunSettingsRoboTests
Change-Id: Ic757d8f7bacfa7a034c7e692205bc1dc4b0e1de1
This commit is contained in:
Doris Ling
2017-08-31 16:17:30 -07:00
parent fe18f8e876
commit dee1a22c45
138 changed files with 421 additions and 1010 deletions

View File

@@ -26,6 +26,7 @@ import android.telephony.TelephonyManager;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.wrapper.RestrictedLockUtilsWrapper;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;

View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import android.annotation.Nullable;
import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppData;
import java.util.List;
/**
* Wrapper around {@link NetworkScoreManager} to facilitate unit testing.
*
* TODO: delete this class once robolectric supports Android O
*/
public class NetworkScoreManagerWrapper {
private final NetworkScoreManager mNetworkScoreManager;
public NetworkScoreManagerWrapper(NetworkScoreManager networkScoreManager) {
mNetworkScoreManager = networkScoreManager;
}
/**
* Returns the list of available scorer apps. The list will be empty if there are
* no valid scorers.
*/
public List<NetworkScorerAppData> getAllValidScorers() {
return mNetworkScoreManager.getAllValidScorers();
}
/**
* Obtain the package name of the current active network scorer.
*
* <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_ACTIVE} intent.
* @return the full package name of the current active scorer, or null if there is no active
* scorer.
*/
@Nullable
public String getActiveScorerPackage() {
return mNetworkScoreManager.getActiveScorerPackage();
}
/**
* Returns metadata about the active scorer or <code>null</code> if there is no active scorer.
*/
@Nullable
public NetworkScorerAppData getActiveScorer() {
return mNetworkScoreManager.getActiveScorer();
}
/**
* Set the active scorer to a new package and clear existing scores.
*
* <p>Should never be called directly without obtaining user consent. This can be done by using
* the {@link #ACTION_CHANGE_ACTIVE} broadcast, or using a custom configuration activity.
*
* @return true if the operation succeeded, or false if the new package is not a valid scorer.
* @throws SecurityException if the caller is not a system process or does not hold the
* {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission
*/
public boolean setActiveScorer(String packageName) throws SecurityException {
return mNetworkScoreManager.setActiveScorer(packageName);
}
}

View File

@@ -30,6 +30,7 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.widget.RadioButtonPreference;
import com.android.settings.wrapper.NetworkScoreManagerWrapper;
import java.util.List;

View File

@@ -21,6 +21,7 @@ import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.wrapper.NetworkScoreManagerWrapper;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.List;

View File

@@ -1,15 +0,0 @@
package com.android.settings.network;
import android.content.Context;
import com.android.settingslib.RestrictedLockUtils;
/**
* Wrapper class needed to be able to test classes which use RestrictedLockUtils methods.
* Unfortunately there is no way to deal with this until robolectric is updated due to the fact
* that it is a static method and it uses new API's.
*/
public class RestrictedLockUtilsWrapper {
public boolean hasBaseUserRestriction(Context context, String userRestriction, int userId) {
return RestrictedLockUtils.hasBaseUserRestriction(context, userRestriction, userId);
}
}