Merge "Properly check wallpaper state before showing suggestion" into oc-dev
am: db68ddc1cc
Change-Id: I9fb77a7f0b01e694d51a4a08ae6f925dc868ce80
This commit is contained in:
@@ -17,19 +17,13 @@
|
|||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
import android.app.AutomaticZenRule;
|
||||||
import android.app.IWallpaperManager;
|
|
||||||
import android.app.IWallpaperManager.Stub;
|
|
||||||
import android.app.IWallpaperManagerCallback;
|
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.WallpaperManager;
|
import android.app.WallpaperManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.os.Bundle;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
|
|
||||||
import com.android.ims.ImsManager;
|
import com.android.ims.ImsManager;
|
||||||
import com.android.settings.Settings.FingerprintEnrollSuggestionActivity;
|
import com.android.settings.Settings.FingerprintEnrollSuggestionActivity;
|
||||||
@@ -49,10 +43,14 @@ import java.util.Collection;
|
|||||||
*/
|
*/
|
||||||
public class SuggestionsChecks {
|
public class SuggestionsChecks {
|
||||||
|
|
||||||
|
private static final String TAG = "SuggestionsChecks";
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final WallpaperManagerWrapper mWallpaperManager;
|
||||||
|
|
||||||
public SuggestionsChecks(Context context) {
|
public SuggestionsChecks(Context context) {
|
||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
|
mWallpaperManager = new WallpaperManagerWrapper(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuggestionComplete(Tile suggestion) {
|
public boolean isSuggestionComplete(Tile suggestion) {
|
||||||
@@ -114,16 +112,9 @@ public class SuggestionsChecks {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasWallpaperSet() {
|
@VisibleForTesting
|
||||||
IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
|
boolean hasWallpaperSet() {
|
||||||
IWallpaperManager service = Stub.asInterface(b);
|
return mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
|
||||||
try {
|
|
||||||
return !service.isSetWallpaperAllowed(mContext.getOpPackageName()) ||
|
|
||||||
service.getWallpaper(mCallback, WallpaperManager.FLAG_SYSTEM,
|
|
||||||
new Bundle(), mContext.getUserId()) != null;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFingerprintEnabled() {
|
private boolean isFingerprintEnabled() {
|
||||||
@@ -133,11 +124,4 @@ public class SuggestionsChecks {
|
|||||||
mContext.getUserId());
|
mContext.getUserId());
|
||||||
return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
|
return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IWallpaperManagerCallback mCallback = new IWallpaperManagerCallback.Stub() {
|
|
||||||
@Override
|
|
||||||
public void onWallpaperChanged() throws RemoteException {
|
|
||||||
// Don't care.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@@ -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.dashboard.suggestions;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 Google Inc.
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,12 +17,12 @@
|
|||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.WallpaperManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -41,6 +41,8 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
@@ -54,7 +56,8 @@ public class SuggestionsChecksTest {
|
|||||||
private FingerprintManager mFingerprintManager;
|
private FingerprintManager mFingerprintManager;
|
||||||
@Mock
|
@Mock
|
||||||
private DevicePolicyManager mDevicePolicyManager;
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
|
@Mock
|
||||||
|
private WallpaperManagerWrapper mWallpaperManager;
|
||||||
private SuggestionsChecks mSuggestionsChecks;
|
private SuggestionsChecks mSuggestionsChecks;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -118,4 +121,24 @@ public class SuggestionsChecksTest {
|
|||||||
Settings.FingerprintEnrollSuggestionActivity.class));
|
Settings.FingerprintEnrollSuggestionActivity.class));
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hasWallpaperSet_no_shouldReturnFalse() {
|
||||||
|
ReflectionHelpers.setField(mSuggestionsChecks, "mWallpaperManager", mWallpaperManager);
|
||||||
|
when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM))
|
||||||
|
.thenReturn(0);
|
||||||
|
|
||||||
|
assertThat(mSuggestionsChecks.hasWallpaperSet())
|
||||||
|
.isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hasWallpaperSet_yes_shouldReturnTrue() {
|
||||||
|
ReflectionHelpers.setField(mSuggestionsChecks, "mWallpaperManager", mWallpaperManager);
|
||||||
|
when(mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM))
|
||||||
|
.thenReturn(100);
|
||||||
|
|
||||||
|
assertThat(mSuggestionsChecks.hasWallpaperSet())
|
||||||
|
.isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user