Home | History | Annotate | Download | only in stubs
      1 /*
      2  * Copyright (C) 2019 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 android.app.stubs;
     18 
     19 import android.content.ComponentName;
     20 import android.os.Debug;
     21 import android.service.quicksettings.TileService;
     22 import android.util.Log;
     23 
     24 import java.util.concurrent.atomic.AtomicBoolean;
     25 
     26 public class TestTileService extends TileService {
     27 
     28     public static final String TAG = "TestTileService";
     29     public static final String PKG = "android.app.stubs";
     30     public static final int ICON_ID = R.drawable.robot;
     31 
     32     private static TestTileService sTestTileService = null;
     33     AtomicBoolean isConnected = new AtomicBoolean(false);
     34     AtomicBoolean isListening = new AtomicBoolean(false);
     35     AtomicBoolean hasBeenClicked = new AtomicBoolean(false);
     36 
     37     public static String getId() {
     38         return String.format("%s/%s", TestTileService.class.getPackage().getName(),
     39                 TestTileService.class.getName());
     40     }
     41 
     42     public static ComponentName getComponentName() {
     43         return new ComponentName(TestTileService.class.getPackage().getName(),
     44                 TestTileService.class.getName());
     45     }
     46 
     47     @Override
     48     public void onCreate() {
     49         super.onCreate();
     50     }
     51 
     52     public static TileService getInstance() {
     53         return sTestTileService;
     54     }
     55 
     56     public static boolean isConnected() {
     57         return sTestTileService != null && sTestTileService.isConnected.get();
     58     }
     59 
     60     public static boolean isListening() {
     61         return sTestTileService.isListening.get();
     62     }
     63 
     64     public static boolean hasBeenClicked() {
     65         return sTestTileService.hasBeenClicked.get();
     66     }
     67 
     68     @Override
     69     public void onStartListening() {
     70         super.onStartListening();
     71         isListening.set(true);
     72     }
     73 
     74     @Override
     75     public void onStopListening() {
     76         super.onStopListening();
     77         isListening.set(false);
     78     }
     79 
     80     @Override
     81     public void onClick() {
     82         super.onClick();
     83         hasBeenClicked.set(true);
     84     }
     85 
     86     @Override
     87     public void onTileAdded() {
     88         super.onTileAdded();
     89         sTestTileService = this;
     90         isConnected.set(true);
     91     }
     92 
     93     @Override
     94     public void onTileRemoved() {
     95         super.onTileRemoved();
     96         sTestTileService = null;
     97         isConnected.set(false);
     98         isListening.set(false);
     99         hasBeenClicked.set(false);
    100     }
    101 }
    102