1 /* 2 * Copyright 2022 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.google.android.wearable.compat; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 22 import org.jspecify.annotations.Nullable; 23 24 /** 25 * Mock version of {@link WearableActivityController}. During instrumentation testing, the tests 26 * would end up using this instead of the version implemented on device. 27 */ 28 public class WearableActivityController { 29 public static final java.lang.String EXTRA_BURN_IN_PROTECTION = 30 "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION"; 31 public static final java.lang.String EXTRA_LOWBIT_AMBIENT = 32 "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT"; 33 34 private static WearableActivityController sLastInstance; 35 getLastInstance()36 public static WearableActivityController getLastInstance() { 37 return sLastInstance; 38 } 39 40 private AmbientCallback mCallback; 41 private boolean mAmbientEnabled = false; 42 private boolean mAutoResumeEnabled = true; 43 private boolean mAmbient = false; 44 private boolean mAmbientOffloadEnabled = false; 45 46 public boolean mCreateCalled = false; 47 public boolean mResumeCalled = false; 48 public boolean mPauseCalled = false; 49 public boolean mStopCalled = false; 50 public boolean mDestroyCalled = false; 51 WearableActivityController(String tag, Activity activity, AmbientCallback callback)52 public WearableActivityController(String tag, Activity activity, AmbientCallback callback) { 53 sLastInstance = this; 54 mCallback = callback; 55 } 56 57 // Methods required by the stub but not currently used in tests. onCreate()58 public void onCreate() { 59 mCreateCalled = true; 60 } 61 onResume()62 public void onResume() { 63 mResumeCalled = true; 64 } 65 onPause()66 public void onPause() { 67 mPauseCalled = true; 68 } 69 onStop()70 public void onStop() { 71 mStopCalled = true; 72 } 73 onDestroy()74 public void onDestroy() { 75 mDestroyCalled = true; 76 } 77 enterAmbient()78 public void enterAmbient() { 79 enterAmbient(null); 80 } 81 enterAmbient(@ullable Bundle enterAmbientArgs)82 public void enterAmbient(@Nullable Bundle enterAmbientArgs) { 83 mCallback.onEnterAmbient(enterAmbientArgs); 84 } 85 exitAmbient()86 public void exitAmbient() { 87 mCallback.onExitAmbient(); 88 } 89 updateAmbient()90 public void updateAmbient() { 91 mCallback.onUpdateAmbient(); 92 } 93 invalidateAmbientOffload()94 public void invalidateAmbientOffload() { 95 mCallback.onInvalidateAmbientOffload(); 96 } 97 setAmbientEnabled()98 public void setAmbientEnabled() { 99 mAmbientEnabled = true; 100 } 101 isAmbientEnabled()102 public boolean isAmbientEnabled() { 103 return mAmbientEnabled; 104 } 105 setAutoResumeEnabled(boolean enabled)106 public void setAutoResumeEnabled(boolean enabled) { 107 mAutoResumeEnabled = enabled; 108 } 109 isAutoResumeEnabled()110 public boolean isAutoResumeEnabled() { 111 return mAutoResumeEnabled; 112 } 113 isAmbient()114 public final boolean isAmbient() { 115 return mAmbient; 116 } 117 setAmbient(boolean ambient)118 public void setAmbient(boolean ambient) { 119 mAmbient = ambient; 120 } 121 setAmbientOffloadEnabled(boolean enabled)122 public void setAmbientOffloadEnabled(boolean enabled) { 123 mAmbientOffloadEnabled = enabled; 124 } 125 isAmbientOffloadEnabled()126 public boolean isAmbientOffloadEnabled() { 127 return mAmbientOffloadEnabled; 128 } 129 130 /** Stub version of {@link WearableActivityController.AmbientCallback}. */ 131 public static class AmbientCallback { onEnterAmbient(Bundle ambientDetails)132 public void onEnterAmbient(Bundle ambientDetails) {} 133 onExitAmbient()134 public void onExitAmbient() {} 135 onUpdateAmbient()136 public void onUpdateAmbient() {} 137 onInvalidateAmbientOffload()138 public void onInvalidateAmbientOffload() {} 139 } 140 } 141