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:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the {@link android.view.accessibility.AccessibilityManager}.
|
||||
* The interface exists so that we can use a thin wrapper around the AccessibilityManager in
|
||||
* production code and a mock in tests.
|
||||
*/
|
||||
public class AccessibilityManagerWrapper {
|
||||
|
||||
/**
|
||||
* Determines if the accessibility button within the system navigation area is supported.
|
||||
*
|
||||
* @return {@code true} if the accessibility button is supported on this device,
|
||||
* {@code false} otherwise
|
||||
* @hide
|
||||
*/
|
||||
public static boolean isAccessibilityButtonSupported() {
|
||||
return AccessibilityManager.isAccessibilityButtonSupported();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.ComponentName;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the
|
||||
* {@link android.accessibilityservice.AccessibilityServiceInfo}. The class
|
||||
* exists so that we can use a thin wrapper around it in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow it, because some of the methods we rely on are newer than
|
||||
* the API version supported by Robolectric.
|
||||
*/
|
||||
public class AccessibilityServiceInfoWrapper {
|
||||
|
||||
private final AccessibilityServiceInfo mServiceInfo;
|
||||
|
||||
public AccessibilityServiceInfoWrapper(AccessibilityServiceInfo serviceInfo) {
|
||||
mServiceInfo = serviceInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the real {@code AccessibilityServiceInfo} object.
|
||||
*/
|
||||
public AccessibilityServiceInfo getAccessibilityServiceInfo() {
|
||||
return mServiceInfo;
|
||||
}
|
||||
|
||||
public ComponentName getComponentName() {
|
||||
return mServiceInfo.getComponentName();
|
||||
}
|
||||
}
|
||||
40
src/com/android/settings/wrapper/ActivityInfoWrapper.java
Normal file
40
src/com/android/settings/wrapper/ActivityInfoWrapper.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.content.pm.ActivityInfo. The class
|
||||
* exists so that we can use a thin wrapper around the ActivityInfo in production code and a mock in
|
||||
* tests.
|
||||
*/
|
||||
public class ActivityInfoWrapper {
|
||||
|
||||
private final ActivityInfo mInfo;
|
||||
|
||||
public ActivityInfoWrapper(ActivityInfo info) {
|
||||
mInfo = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this activity supports picture-in-picture.
|
||||
*/
|
||||
public boolean supportsPictureInPicture() {
|
||||
return mInfo.supportsPictureInPicture();
|
||||
}
|
||||
}
|
||||
59
src/com/android/settings/wrapper/AutofillManagerWrapper.java
Normal file
59
src/com/android/settings/wrapper/AutofillManagerWrapper.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.view.autofill.AutofillManager;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.view.autofill.AutofillManager (AFM). The
|
||||
* class exists so that we can use a thin wrapper around the AFM in production code and a mock
|
||||
* in tests. We cannot directly mock or shadow the AFM, because some of the methods we rely on are
|
||||
* newer than the API version supported by Robolectric.
|
||||
*/
|
||||
public class AutofillManagerWrapper {
|
||||
private final AutofillManager mAfm;
|
||||
|
||||
public AutofillManagerWrapper(AutofillManager afm) {
|
||||
mAfm = afm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code AutofillManager.hasAutofillFeature()}.
|
||||
*
|
||||
* @see AutofillManager#hasAutofillFeature
|
||||
*/
|
||||
public boolean hasAutofillFeature() {
|
||||
if (mAfm == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mAfm.hasAutofillFeature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code AutofillManager.isAutofillSupported()}.
|
||||
*
|
||||
* @see AutofillManager#isAutofillSupported
|
||||
*/
|
||||
public boolean isAutofillSupported() {
|
||||
if (mAfm == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mAfm.isAutofillSupported();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Handler;
|
||||
import android.net.ProxyInfo;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.net.ConnectivityManager (CM). The class
|
||||
* exists so that we can use a thin wrapper around the CM in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow the CM, because some of the methods we rely on are marked as
|
||||
* hidden and are thus invisible to Robolectric.
|
||||
*/
|
||||
public class ConnectivityManagerWrapper {
|
||||
|
||||
private final ConnectivityManager mCm;
|
||||
|
||||
public ConnectivityManagerWrapper(ConnectivityManager cm) {
|
||||
mCm = cm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the real ConnectivityManager object wrapped by this wrapper.
|
||||
*/
|
||||
public ConnectivityManager getConnectivityManager() {
|
||||
return mCm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code ConnectivityManager.getAlwaysOnVpnPackageForUser()}.
|
||||
*
|
||||
* @see android.net.ConnectivityManager#getAlwaysOnVpnPackageForUser
|
||||
*/
|
||||
public String getAlwaysOnVpnPackageForUser(int userId) {
|
||||
return mCm.getAlwaysOnVpnPackageForUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code ConnectivityManager.getGlobalProxy()}.
|
||||
*
|
||||
* @see android.net.ConnectivityManager#getGlobalProxy
|
||||
*/
|
||||
public ProxyInfo getGlobalProxy() {
|
||||
return mCm.getGlobalProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code ConnectivityManager.registerNetworkCallback()}.
|
||||
*
|
||||
* This is part of the ConnectivityManager public API in SDK 26 or above, but is not yet visible
|
||||
* to the robolectric tests, which currently build with SDK 23.
|
||||
* TODO: delete this once the robolectric tests build with SDK 26 or above.
|
||||
*
|
||||
* @see android.net.ConnectivityManager#registerNetworkCallback(NetworkRequest,NetworkCallback,Handler)
|
||||
*/
|
||||
public void registerNetworkCallback(NetworkRequest request, NetworkCallback callback,
|
||||
Handler handler) {
|
||||
mCm.registerNetworkCallback(request, callback, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code ConnectivityManager.startCaptivePortalApp()}.
|
||||
*
|
||||
* This is part of the ConnectivityManager public API in SDK 26 or above, but is not yet visible
|
||||
* to the robolectric tests, which currently build with SDK 23.
|
||||
* TODO: delete this once the robolectric tests build with SDK 26 or above.
|
||||
*
|
||||
* @see android.net.ConnectivityManager#startCaptivePortalApp(Network)
|
||||
*/
|
||||
public void startCaptivePortalApp(Network network) {
|
||||
mCm.startCaptivePortalApp(network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ConnectivityManager#stopTethering}
|
||||
*/
|
||||
public void stopTethering(int type) {
|
||||
mCm.stopTethering(type);
|
||||
}
|
||||
}
|
||||
203
src/com/android/settings/wrapper/DevicePolicyManagerWrapper.java
Normal file
203
src/com/android/settings/wrapper/DevicePolicyManagerWrapper.java
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.wrapper;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The
|
||||
* class exists so that we can use a thin wrapper around the DPM in production code and a mock
|
||||
* in tests. We cannot directly mock or shadow the DPM, because some of the methods we rely on are
|
||||
* newer than the API version supported by Robolectric.
|
||||
*/
|
||||
public class DevicePolicyManagerWrapper {
|
||||
private final DevicePolicyManager mDpm;
|
||||
|
||||
public DevicePolicyManagerWrapper(DevicePolicyManager dpm) {
|
||||
mDpm = dpm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getActiveAdminsAsUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getActiveAdminsAsUser
|
||||
*/
|
||||
public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId) {
|
||||
return mDpm.getActiveAdminsAsUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getMaximumFailedPasswordsForWipe
|
||||
*/
|
||||
public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
|
||||
return mDpm.getMaximumFailedPasswordsForWipe(admin, userHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnCallingUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnCallingUser
|
||||
*/
|
||||
public ComponentName getDeviceOwnerComponentOnCallingUser() {
|
||||
return mDpm.getDeviceOwnerComponentOnCallingUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnAnyUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnAnyUser
|
||||
*/
|
||||
public ComponentName getDeviceOwnerComponentOnAnyUser() {
|
||||
return mDpm.getDeviceOwnerComponentOnAnyUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getProfileOwnerAsUser
|
||||
*/
|
||||
public @Nullable ComponentName getProfileOwnerAsUser(final int userId) {
|
||||
return mDpm.getProfileOwnerAsUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getDeviceOwnerNameOnAnyUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getDeviceOwnerNameOnAnyUser
|
||||
*/
|
||||
public CharSequence getDeviceOwnerOrganizationName() {
|
||||
return mDpm.getDeviceOwnerOrganizationName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getPermissionGrantState()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getPermissionGrantState
|
||||
*/
|
||||
public int getPermissionGrantState(@Nullable ComponentName admin, String packageName,
|
||||
String permission) {
|
||||
return mDpm.getPermissionGrantState(admin, packageName, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isSecurityLoggingEnabled()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isSecurityLoggingEnabled
|
||||
*/
|
||||
public boolean isSecurityLoggingEnabled(@Nullable ComponentName admin) {
|
||||
return mDpm.isSecurityLoggingEnabled(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isNetworkLoggingEnabled()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isNetworkLoggingEnabled
|
||||
*/
|
||||
public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
|
||||
return mDpm.isNetworkLoggingEnabled(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastSecurityLogRetrievalTime()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getLastSecurityLogRetrievalTime
|
||||
*/
|
||||
public long getLastSecurityLogRetrievalTime() {
|
||||
return mDpm.getLastSecurityLogRetrievalTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastBugReportRequestTime()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getLastBugReportRequestTime
|
||||
*/
|
||||
public long getLastBugReportRequestTime() {
|
||||
return mDpm.getLastBugReportRequestTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getLastNetworkLogRetrievalTime()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getLastNetworkLogRetrievalTime
|
||||
*/
|
||||
public long getLastNetworkLogRetrievalTime() {
|
||||
return mDpm.getLastNetworkLogRetrievalTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isCurrentInputMethodSetByOwner()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isCurrentInputMethodSetByOwner
|
||||
*/
|
||||
public boolean isCurrentInputMethodSetByOwner() {
|
||||
return mDpm.isCurrentInputMethodSetByOwner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.getOwnerInstalledCaCerts()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#getOwnerInstalledCaCerts
|
||||
*/
|
||||
public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
|
||||
return mDpm.getOwnerInstalledCaCerts(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isDeviceOwnerAppOnAnyUser()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isDeviceOwnerAppOnAnyUser
|
||||
*/
|
||||
public boolean isDeviceOwnerAppOnAnyUser(String packageName) {
|
||||
return mDpm.isDeviceOwnerAppOnAnyUser(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.packageHasActiveAdmins()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#packageHasActiveAdmins
|
||||
*/
|
||||
public boolean packageHasActiveAdmins(String packageName) {
|
||||
return mDpm.packageHasActiveAdmins(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isUninstallInQueue()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isUninstallInQueue
|
||||
*/
|
||||
public boolean isUninstallInQueue(String packageName) {
|
||||
return mDpm.isUninstallInQueue(packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.createAdminSupportIntent()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#createAdminSupportIntent
|
||||
*/
|
||||
public Intent createAdminSupportIntent(@NonNull String restriction) {
|
||||
return mDpm.createAdminSupportIntent(restriction);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.wrapper;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.fingerprint.FingerprintManager.EnrollmentCallback;
|
||||
import android.os.CancellationSignal;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
/**
|
||||
* Wrapper of {@link FingerprintManager}. Workaround for robolectic testing.
|
||||
*
|
||||
* This is the workaround to allow us test {@link SetNewPasswordController} which uses a new hidden
|
||||
* API {@link android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints(int)} that
|
||||
* robolectric does not support yet. Having robolectic to support latest platform API is tracked
|
||||
* in b/30995831.
|
||||
*/
|
||||
public class FingerprintManagerWrapper {
|
||||
private @NonNull FingerprintManager mFingerprintManager;
|
||||
|
||||
public FingerprintManagerWrapper(@NonNull FingerprintManager fingerprintManager) {
|
||||
Preconditions.checkNotNull(fingerprintManager);
|
||||
mFingerprintManager = fingerprintManager;
|
||||
}
|
||||
|
||||
public boolean isHardwareDetected() {
|
||||
return mFingerprintManager.isHardwareDetected();
|
||||
}
|
||||
|
||||
public boolean hasEnrolledFingerprints(int userId) {
|
||||
return mFingerprintManager.hasEnrolledFingerprints(userId);
|
||||
}
|
||||
|
||||
public long preEnroll() {
|
||||
return mFingerprintManager.preEnroll();
|
||||
}
|
||||
|
||||
public void setActiveUser(int userId) {
|
||||
mFingerprintManager.setActiveUser(userId);
|
||||
}
|
||||
|
||||
public void enroll(
|
||||
byte[] token,
|
||||
CancellationSignal cancel,
|
||||
int flags,
|
||||
int userId,
|
||||
EnrollmentCallback callback) {
|
||||
mFingerprintManager.enroll(token, cancel, flags, userId, callback);
|
||||
}
|
||||
}
|
||||
97
src/com/android/settings/wrapper/IPackageManagerWrapper.java
Normal file
97
src/com/android/settings/wrapper/IPackageManagerWrapper.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.content.pm.IPackageManager (PMS). The class
|
||||
* exists so that we can use a thin wrapper around the PMS in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow the PMS, because some of the methods we rely on are newer than
|
||||
* the API version supported by Robolectric.
|
||||
*/
|
||||
public class IPackageManagerWrapper {
|
||||
|
||||
private final IPackageManager mPms;
|
||||
|
||||
public IPackageManagerWrapper(IPackageManager pms) {
|
||||
mPms = pms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.checkUidPermission()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#checkUidPermission
|
||||
*/
|
||||
public int checkUidPermission(String permName, int uid) throws RemoteException {
|
||||
return mPms.checkUidPermission(permName, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.findPersistentPreferredActivity()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#findPersistentPreferredActivity
|
||||
*/
|
||||
public ResolveInfo findPersistentPreferredActivity(Intent intent, int userId)
|
||||
throws RemoteException {
|
||||
return mPms.findPersistentPreferredActivity(intent, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.getPackageInfo()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#getPackageInfo
|
||||
*/
|
||||
public PackageInfo getPackageInfo(String packageName, int flags, int userId)
|
||||
throws RemoteException {
|
||||
return mPms.getPackageInfo(packageName, flags, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.getAppOpPermissionPackages()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#getAppOpPermissionPackages
|
||||
*/
|
||||
public String[] getAppOpPermissionPackages(String permissionName) throws RemoteException {
|
||||
return mPms.getAppOpPermissionPackages(permissionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.isPackageAvailable()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#isPackageAvailable
|
||||
*/
|
||||
public boolean isPackageAvailable(String packageName, int userId) throws RemoteException {
|
||||
return mPms.isPackageAvailable(packageName, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@code IPackageManager.getPackagesHoldingPermissions()}.
|
||||
*
|
||||
* @see android.content.pm.IPackageManager#getPackagesHoldingPermissions
|
||||
*/
|
||||
public ParceledListSlice<PackageInfo> getPackagesHoldingPermissions(
|
||||
String[] permissions, int flags, int userId) throws RemoteException {
|
||||
return mPms.getPackagesHoldingPermissions(permissions, flags, userId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.util.KeyValueListParser;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the {@link KeyValueListParser}. The class
|
||||
* exists so that we can use a thin wrapper around the PM in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow the {@link KeyValueListParser}, because some of the methods
|
||||
* we rely on are newer than the API version supported by Robolectric.
|
||||
*/
|
||||
public class KeyValueListParserWrapper {
|
||||
private KeyValueListParser mParser;
|
||||
|
||||
public KeyValueListParserWrapper(KeyValueListParser parser) {
|
||||
mParser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get real {@link KeyValueListParser}
|
||||
*/
|
||||
public KeyValueListParser getKeyValueListParser() {
|
||||
return mParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the parser with a new string to parse. The string is expected to be in the following
|
||||
* format:
|
||||
* <pre>key1=value,key2=value,key3=value</pre>
|
||||
*
|
||||
* where the delimiter is a comma.
|
||||
*
|
||||
* @param str the string to parse.
|
||||
* @throws IllegalArgumentException if the string is malformed.
|
||||
*/
|
||||
public void setString(String str) throws IllegalArgumentException {
|
||||
mParser.setString(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for key as a boolean.
|
||||
* @param key The key to lookup.
|
||||
* @param defaultValue The value to return if the key was not found.
|
||||
* @return the string value associated with the key.
|
||||
*/
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return mParser.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for key as a long.
|
||||
* @param key The key to lookup.
|
||||
* @param defaultValue The value to return if the key was not found, or the value was not a
|
||||
* long.
|
||||
* @return the long value associated with the key.
|
||||
*/
|
||||
public long getLong(String key, long defaultValue) {
|
||||
return mParser.getLong(key, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
49
src/com/android/settings/wrapper/PowerManagerWrapper.java
Normal file
49
src/com/android/settings/wrapper/PowerManagerWrapper.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.os.PowerManager;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.os.PowerManager. The class exists so that we can
|
||||
* use a thin wrapper around the PowerManager in production code and a mock in tests. We cannot
|
||||
* directly mock or shadow the PowerManager, because some of the methods we rely on are newer than
|
||||
* the API version supported by Robolectric or are hidden.
|
||||
*/
|
||||
public class PowerManagerWrapper {
|
||||
private final PowerManager mPowerManager;
|
||||
|
||||
public PowerManagerWrapper(PowerManager powerManager) {
|
||||
mPowerManager = powerManager;
|
||||
}
|
||||
|
||||
public int getMinimumScreenBrightnessSetting() {
|
||||
return mPowerManager.getMinimumScreenBrightnessSetting();
|
||||
}
|
||||
|
||||
public int getMaximumScreenBrightnessSetting() {
|
||||
return mPowerManager.getMaximumScreenBrightnessSetting();
|
||||
}
|
||||
|
||||
public int getMinimumScreenBrightnessForVrSetting() {
|
||||
return mPowerManager.getMinimumScreenBrightnessForVrSetting();
|
||||
}
|
||||
|
||||
public int getMaximumScreenBrightnessForVrSetting() {
|
||||
return mPowerManager.getMaximumScreenBrightnessForVrSetting();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
44
src/com/android/settings/wrapper/UserManagerWrapper.java
Normal file
44
src/com/android/settings/wrapper/UserManagerWrapper.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.os.UserManager. The class
|
||||
* exists so that we can use a thin wrapper around the UserManager in production code and a mock in
|
||||
* tests. We cannot directly mock or shadow the UserManager, because some of the methods we rely on
|
||||
* are newer than the API version supported by Robolectric or are hidden.
|
||||
*/
|
||||
public class UserManagerWrapper {
|
||||
private UserManager mUserManager;
|
||||
|
||||
public UserManagerWrapper(UserManager userManager) {
|
||||
mUserManager = userManager;
|
||||
}
|
||||
|
||||
public UserInfo getPrimaryUser() {
|
||||
return mUserManager.getPrimaryUser();
|
||||
}
|
||||
|
||||
public List<UserInfo> getUsers() {
|
||||
return mUserManager.getUsers();
|
||||
}
|
||||
}
|
||||
29
src/com/android/settings/wrapper/UserPackageWrapper.java
Normal file
29
src/com/android/settings/wrapper/UserPackageWrapper.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
|
||||
/**
|
||||
* Wrapper class around android.webkit.UserPackage - to be able to use UserPackage in Robolectric
|
||||
* tests (such tests currently don't support mocking hidden classes).
|
||||
*/
|
||||
public interface UserPackageWrapper {
|
||||
UserInfo getUserInfo();
|
||||
PackageInfo getPackageInfo();
|
||||
boolean isEnabledPackage();
|
||||
boolean isInstalledPackage();
|
||||
}
|
||||
46
src/com/android/settings/wrapper/UserPackageWrapperImpl.java
Normal file
46
src/com/android/settings/wrapper/UserPackageWrapperImpl.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.webkit.UserPackage;
|
||||
|
||||
/**
|
||||
* Default implementation of UserPackageWrapper.
|
||||
*/
|
||||
public class UserPackageWrapperImpl implements UserPackageWrapper {
|
||||
private final UserPackage mUserPackage;
|
||||
|
||||
public UserPackageWrapperImpl(UserPackage userPackage) {
|
||||
mUserPackage = userPackage;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
return mUserPackage.getUserInfo();
|
||||
}
|
||||
|
||||
public PackageInfo getPackageInfo() {
|
||||
return mUserPackage.getPackageInfo();
|
||||
}
|
||||
|
||||
public boolean isEnabledPackage() {
|
||||
return mUserPackage.isEnabledPackage();
|
||||
}
|
||||
|
||||
public boolean isInstalledPackage() {
|
||||
return mUserPackage.isInstalledPackage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.wrapper;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
|
||||
public class WallpaperManagerWrapper {
|
||||
|
||||
private final WallpaperManager mWallpaperManager;
|
||||
|
||||
public WallpaperManagerWrapper(Context context) {
|
||||
mWallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
|
||||
}
|
||||
|
||||
public int getWallpaperId(int which) {
|
||||
return mWallpaperManager.getWallpaperId(which);
|
||||
}
|
||||
}
|
||||
23
src/com/android/settings/wrapper/WifiManagerWrapper.java
Normal file
23
src/com/android/settings/wrapper/WifiManagerWrapper.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
/**
|
||||
* Wrapper around {@link WifiManager} to facilitate unit testing.
|
||||
*
|
||||
* TODO: delete this class once robolectric supports Android O
|
||||
*/
|
||||
public class WifiManagerWrapper {
|
||||
private final WifiManager mWifiManager;
|
||||
|
||||
public WifiManagerWrapper(WifiManager wifiManager) {
|
||||
mWifiManager = wifiManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link WifiManager#getCurrentNetworkWpsNfcConfigurationToken}
|
||||
*/
|
||||
public String getCurrentNetworkWpsNfcConfigurationToken() {
|
||||
return mWifiManager.getCurrentNetworkWpsNfcConfigurationToken();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user