1 /*
2  * Copyright (C) 2024 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.screenshot.scroll;
18 
19 import com.android.systemui.dagger.SysUISingleton;
20 import com.android.systemui.screenshot.ScreenshotController;
21 
22 import java.util.concurrent.atomic.AtomicReference;
23 
24 import javax.inject.Inject;
25 
26 /**
27  * LongScreenshotData holds on to 1 LongScreenshot reference and 1 TransitionDestination
28  * reference, to facilitate indirect in-process passing.
29  */
30 @SysUISingleton
31 public class LongScreenshotData {
32     private final AtomicReference<ScrollCaptureController.LongScreenshot> mLongScreenshot;
33     private final AtomicReference<ScreenshotController.TransitionDestination>
34             mTransitionDestinationCallback;
35 
36     @Inject
LongScreenshotData()37     public LongScreenshotData() {
38         mLongScreenshot = new AtomicReference<>();
39         mTransitionDestinationCallback = new AtomicReference<>();
40     }
41 
42     /**
43      * Set the holder's stored LongScreenshot.
44      */
setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot)45     public void setLongScreenshot(ScrollCaptureController.LongScreenshot longScreenshot) {
46         mLongScreenshot.set(longScreenshot);
47     }
48 
49     /**
50      * @return true if the holder has a non-null LongScreenshot.
51      */
hasLongScreenshot()52     public boolean hasLongScreenshot() {
53         return mLongScreenshot.get() != null;
54     }
55 
56     /**
57      * Return the current stored LongScreenshot, clear the holder's storage.
58      */
takeLongScreenshot()59     public ScrollCaptureController.LongScreenshot takeLongScreenshot() {
60         return mLongScreenshot.getAndSet(null);
61     }
62 
63     /**
64      * Set the holder's TransitionDestination callback.
65      */
setTransitionDestinationCallback( ScreenshotController.TransitionDestination destination)66     public void setTransitionDestinationCallback(
67             ScreenshotController.TransitionDestination destination) {
68         mTransitionDestinationCallback.set(destination);
69     }
70 
71     /**
72      * Return the current TransitionDestination callback and clear.
73      */
takeTransitionDestinationCallback()74     public ScreenshotController.TransitionDestination takeTransitionDestinationCallback() {
75         return mTransitionDestinationCallback.getAndSet(null);
76     }
77 }
78