1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.settings.dashboard; 16 17 import android.app.AutomaticZenRule; 18 import android.app.IWallpaperManager; 19 import android.app.IWallpaperManager.Stub; 20 import android.app.IWallpaperManagerCallback; 21 import android.app.KeyguardManager; 22 import android.app.NotificationManager; 23 import android.app.WallpaperManager; 24 import android.content.Context; 25 import android.hardware.fingerprint.FingerprintManager; 26 import android.os.Bundle; 27 import android.os.IBinder; 28 import android.os.RemoteException; 29 import android.os.ServiceManager; 30 31 import com.android.ims.ImsManager; 32 import com.android.settings.Settings.FingerprintEnrollSuggestionActivity; 33 import com.android.settings.Settings.FingerprintSuggestionActivity; 34 import com.android.settings.Settings.ScreenLockSuggestionActivity; 35 import com.android.settings.Settings.WallpaperSuggestionActivity; 36 import com.android.settings.Settings.WifiCallingSuggestionActivity; 37 import com.android.settings.Settings.ZenModeAutomationSuggestionActivity; 38 import com.android.settingslib.drawer.Tile; 39 40 import java.util.Collection; 41 42 /** 43 * The Home of all stupidly dynamic Settings Suggestions checks. 44 */ 45 public class SuggestionsChecks { 46 47 private final Context mContext; 48 SuggestionsChecks(Context context)49 public SuggestionsChecks(Context context) { 50 mContext = context.getApplicationContext(); 51 } 52 isSuggestionComplete(Tile suggestion)53 public boolean isSuggestionComplete(Tile suggestion) { 54 String className = suggestion.intent.getComponent().getClassName(); 55 if (className.equals(ZenModeAutomationSuggestionActivity.class.getName())) { 56 return hasEnabledZenAutoRules(); 57 } else if (className.equals(WallpaperSuggestionActivity.class.getName())) { 58 return hasWallpaperSet(); 59 } else if (className.equals(WifiCallingSuggestionActivity.class.getName())) { 60 return isWifiCallingUnavailableOrEnabled(); 61 } else if (className.equals(FingerprintSuggestionActivity.class.getName())) { 62 return isNotSingleFingerprintEnrolled(); 63 } else if (className.equals(ScreenLockSuggestionActivity.class.getName()) 64 || className.equals(FingerprintEnrollSuggestionActivity.class.getName())) { 65 return isDeviceSecured(); 66 } 67 return false; 68 } 69 isDeviceSecured()70 private boolean isDeviceSecured() { 71 KeyguardManager km = mContext.getSystemService(KeyguardManager.class); 72 return km.isKeyguardSecure(); 73 } 74 isNotSingleFingerprintEnrolled()75 private boolean isNotSingleFingerprintEnrolled() { 76 FingerprintManager manager = mContext.getSystemService(FingerprintManager.class); 77 return manager == null || manager.getEnrolledFingerprints().size() != 1; 78 } 79 isWifiCallingUnavailableOrEnabled()80 public boolean isWifiCallingUnavailableOrEnabled() { 81 if (!ImsManager.isWfcEnabledByPlatform(mContext)) { 82 return true; 83 } 84 return ImsManager.isWfcEnabledByUser(mContext) 85 && ImsManager.isNonTtyOrTtyOnVolteEnabled(mContext); 86 } 87 hasEnabledZenAutoRules()88 private boolean hasEnabledZenAutoRules() { 89 Collection<AutomaticZenRule> zenRules = 90 NotificationManager.from(mContext).getAutomaticZenRules().values(); 91 for (AutomaticZenRule rule : zenRules) { 92 if (rule.isEnabled()) { 93 return true; 94 } 95 } 96 return false; 97 } 98 hasWallpaperSet()99 private boolean hasWallpaperSet() { 100 IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE); 101 IWallpaperManager service = Stub.asInterface(b); 102 try { 103 return service.getWallpaper(mCallback, WallpaperManager.FLAG_SYSTEM, 104 new Bundle(), mContext.getUserId()) != null; 105 } catch (RemoteException e) { 106 } 107 return false; 108 } 109 110 private final IWallpaperManagerCallback mCallback = new IWallpaperManagerCallback.Stub() { 111 @Override 112 public void onWallpaperChanged() throws RemoteException { 113 // Don't care. 114 } 115 }; 116 } 117