Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.doze; |
| 18 | |
| 19 | import android.app.IWallpaperManager; |
| 20 | import android.content.Context; |
| 21 | import android.os.RemoteException; |
| 22 | import android.os.ServiceManager; |
| 23 | import android.util.Log; |
| 24 | |
| 25 | import com.android.internal.annotations.VisibleForTesting; |
| 26 | |
| 27 | import java.io.PrintWriter; |
| 28 | |
| 29 | /** |
| 30 | * Propagates doze state to wallpaper engine. |
| 31 | */ |
| 32 | public class DozeWallpaperState implements DozeMachine.Part { |
| 33 | |
| 34 | private static final String TAG = "DozeWallpaperState"; |
| 35 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 36 | |
| 37 | @VisibleForTesting |
| 38 | final IWallpaperManager mWallpaperManagerService; |
| 39 | private boolean mIsAmbientMode; |
| 40 | |
| 41 | public DozeWallpaperState() { |
| 42 | this(IWallpaperManager.Stub.asInterface( |
| 43 | ServiceManager.getService(Context.WALLPAPER_SERVICE))); |
| 44 | } |
| 45 | |
| 46 | @VisibleForTesting |
| 47 | DozeWallpaperState(IWallpaperManager wallpaperManagerService) { |
| 48 | mWallpaperManagerService = wallpaperManagerService; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) { |
| 53 | final boolean isAmbientMode; |
| 54 | switch (newState) { |
| 55 | case DOZE_AOD: |
Lucas Dupin | 10ff88f | 2017-12-19 17:28:31 -0800 | [diff] [blame] | 56 | case DOZE_AOD_PAUSING: |
| 57 | case DOZE_AOD_PAUSED: |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 58 | case DOZE_REQUEST_PULSE: |
| 59 | case DOZE_PULSING: |
| 60 | case DOZE_PULSE_DONE: |
| 61 | isAmbientMode = true; |
| 62 | break; |
| 63 | default: |
| 64 | isAmbientMode = false; |
| 65 | } |
| 66 | |
| 67 | if (isAmbientMode != mIsAmbientMode) { |
| 68 | mIsAmbientMode = isAmbientMode; |
| 69 | try { |
| 70 | Log.i(TAG, "AoD wallpaper state changed to: " + mIsAmbientMode); |
| 71 | mWallpaperManagerService.setInAmbientMode(mIsAmbientMode); |
| 72 | } catch (RemoteException e) { |
| 73 | // Cannot notify wallpaper manager service, but it's fine, let's just skip it. |
| 74 | Log.w(TAG, "Cannot notify state to WallpaperManagerService: " + mIsAmbientMode); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void dump(PrintWriter pw) { |
| 81 | pw.println("DozeWallpaperState:"); |
| 82 | pw.println(" isAmbientMode: " + mIsAmbientMode); |
| 83 | } |
| 84 | } |